- 论坛徽章:
- 0
|
我问的:
================
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编码,看不懂啊 |
|