This is the mail archive of the
mailing list for the GCC project.
Re: inline asm clobbers
- From: David Wohlferd <dw at LimeGreenSocks dot com>
- To: Paul_Koning at Dell dot com, Ian Lance Taylor <iant at google dot com>
- Cc: gcc at gcc dot gnu dot org, Sandra Loosemore <sandra at codesourcery dot com>, jakub at redhat dot com, Jeff Law <law at redhat dot com>
- Date: Thu, 12 Mar 2015 15:09:52 -0700
- Subject: Re: inline asm clobbers
- Authentication-results: sourceware.org; auth=none
- References: <5500C898 dot 3000601 at LimeGreenSocks dot com> <CAKOQZ8yG4fPx8Ce3JiZMtW8MwXAMFk5W3_JAJ=b2WMQ4mXDDdA at mail dot gmail dot com> <7DD652D7-C369-4E2D-AEA0-9C75ABAB8636 at dell dot com> <5500E372 dot 3010207 at LimeGreenSocks dot com> <64361D38-32E1-4DEF-81B3-158CC45103BC at dell dot com>
On 3/12/2015 7:24 AM, Paul_Koning@Dell.com wrote:
On Mar 11, 2015, at 8:53 PM, David Wohlferd <dw@LimeGreenSocks.com> wrote:
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.
It certainly would. Itâs not all that common, but I have seen this done in production code. Come to think of it, this certainly makes sense in machines where some instructions act on fixed registers.
Really? While I've seen much code that uses clobbers, I have never (until this week) see anyone attempt to clobber by index. Since I'm basically an i386 guy, maybe this is a platform thing? Do you have some examples/links?
The example I remember was not in open code. It may have been cleaned up by now, but as supplied to us by the vendor, there were some bits of assembly code that needed a scratch register and used a fixed register (t0 == %8) for that purpose rather than having GCC deal with temporaries. So there was a clobber with â8â in it. Obviously thereâs a better way in that instance, but if GCC had removed the feature before we found and cleaned up that code, we would have had a failure on our hands.
An example of hardwired registers I remember is some VAX instructions (string instructions). You could write those by name, of course, but if you didnât know that GCC supports names, you might just use numbers. On machines like VAX where the register names are really just numbers (R0, R1, etc.) that isnât such a strange thing to do.
Register names would be nice as an additional capability.
Every example I've ever seen uses register names. Perhaps that what you've seen before?
No; I didnât know that gcc supports register names. The examples I had seen all use numbers. Or more often, preprocessor symbols. It may be thatâs because the most common asm code I run into is MIPS coprocessor references, and while general registers may be known by name, coprocessor registers may not be. Or it may just be a case of lack of awareness.
Ahh. So perhaps as I suspected: this is more commonly used on non-i386
platforms. So clearly removing this is out of the question.
This brings us to the question of documentation. Right now the docs
only refer to register names. I expect it would be helpful for people
to understand what it means when they come across code that uses
indices. A few words in the 'clobbers' section and the two Reg Vars
sections would probably cover it.
Perhaps some variation of:
In addition to specifying registers by name, it is also possible to use
a register index (ie "3" to refer to the 3rd register). The list of
registers and their order is platform specific. See the REGISTER_NAMES
defined for your platform in the gcc source.
I'm not excited about pointing people vaguely toward the source, but
that's the only place I know to find this info.
I realize this may seem a bit redundant for people who are used to
registers named R0,R1,R2..., but on the i386, the order is: