On 3/11/2015 4:19 PM, Ian Lance Taylor wrote:
On Wed, Mar 11, 2015 at 3:58 PM, David Wohlferd <d...@limegreensocks.com> wrote:
Why does gcc allow you to specify clobbers using numbers:
asm ("" : : "r" (var) : "0"); // i386: clobbers eax
How is this better than using register names?
This makes even less sense when you realize that (apparently) the indices of
registers aren't fixed. Which means there is no way to know which register
you have clobbered in order to use it in the template.
Having just seen someone trying (unsuccessfully) to use this, it seems like
there is no practical way you can.
Which makes me wonder why it's there. And whether it still should be.
I don't know why it works. It should be consistent, though. It's
simply GCC's internal hard register number, which doesn't normally
change.
The reason I believe the order can change is this comment from i386.h:
/* Order in which to allocate registers. Each register must be
listed once, even those in FIXED_REGISTERS. List frame pointer
late and fixed registers last. Note that, in general, we prefer
registers listed in CALL_USED_REGISTERS, keeping the others
available for storage of persistent values.
The ADJUST_REG_ALLOC_ORDER actually overwrite the order,
so this is just empty initializer for array. */
My attempts to follow ADJUST_REG_ALLOC_ORDER were not particularly
successful, but it did take me to this comment in ira.c:
/* This is called every time when register related information is
changed. */
I would agree that one should avoid it. I'd be wary of removing it
from GCC at this point since it might break working code.
I hear you on this. Removing existing functionality is definitely
risky, so I agree with your caution. And of course changing anything is
much less important if the register order here really is fixed.
On the other hand, what if my fear about register order changing is
correct? In that case people who assume (as you have) that they don't
change are clobbering random registers. Also, the fellow I saw trying
to use this (incorrectly) assumed that "0" was referring to the same
thing as the template's "%0."
If people don't (or if in fact it is impossible to) use this safely,
"breaking" their code by forcing them to use register names might be the
best way to fix it.
dw