mik老大请帮忙看看gcc的一个问题
我问的:
================
Hi,
from the info manual of gcc, I get this:
info gcc: C extensions: Constraints: Modifiers
%
Declares the instruction to be commutative for this operand and the
following operand. This means that the compiler may interchange
the two operands if that is the cheapest way to make all operands
fit the constraints. GCC can only handle one commutative pair in
an asm; if you use more, the compiler may fail.
But I missed the point. What's the benefit of using `%' to exchange two
operands?
I'm writing a gcc inline assembly HOWTO, and I'd like to get everything,
at least those who was mentioned in gcc.info or gccint.info, documented.
So would someone be kind enough to give an example on this? I searched
the Linux kernel with:
$ find arch/x86 -name "*.[ch]" -exec grep -H "asm[ _( ]" {} \;
for `asm' followed by a space, `(', `_' or a Tab. Nothing useful.
Thanks in advance.
-Jike
别人回答的:
==============
Let's say you have an opcode that adds two values, but if one is in a
register and one is in memory then the register has to be listed first
(perhaps because it's also the destination, for 2-op adds). You have
two choices:
1. Describe all permutations of register/memory vs memory/register
plus all the other things you might be able to add (constants, etc).
2. Describe one set and tell gcc that it doesn't matter which operand
is which.
The '%' constraint modifier tells gcc that it may swap the two
operands if it wants to, without affecting the semantics of the insn.
This is often used for 2-op add and multiply so that gcc has more
flexibility about what the *output* register is (it can now match
either input reg, not just the 1st input reg) but obviously you
wouldn't use it with, say, subtraction.
Thus, it's mostly to help gcc do register allocation and optimization.
Also, this is more likely to be found in the MD pattern files used to
port gcc to your chip, than in inline assembly.
<<EOF
他说的2-op是什么意思? 我完全不懂opcode编码,看不懂啊
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里的op是operand
albcamus :
偶的英文其实很菜,看看文档还可以。你能不能用中文来表述。
2-op 应该是指 2 个 operand 或者是 第 2 个operand
琢磨明白了,谢谢2位呀! ^_^