MS/CW-style inline assembly for GCC
Stan Shebs
shebs@apple.com
Fri May 7 02:09:00 GMT 2004
Ian Lance Taylor wrote:
>Stan Shebs <shebs@apple.com> writes:
>
>
>>It's almost comical to have people working so hard to rationalize the
>>GCC syntax; if you sat a bunch of users down with the different
>>syntaxes, and said "which do you prefer?" do you really think they
>>would choose the GCC syntax over the CW syntax?
>>
>
>I would. The gcc syntax lets me say what I want in a clear and
>unambiguous manner. For me the gcc asm syntax, when I first started
>using it back in 1990 on the 68k, was a breath of fresh air. There is
>no guesswork about what is going to happen. You say what you want,
>and the compiler handles the details you don't want to worry about.
>
>
Heh, you're hardly representative of the user population! I'll bet
you cheated and looked at the compiler sources too... :-)
>I haven't used the CW syntax. But even on a fairly regular
>architecture like the PowerPC, it seems fraught with potential for
>confusion. What happens with
> asm { addi a, b, c }
>? When writing in gcc syntax, you can specify that "c" must be an
>integer, and get an appropriate error if it is not. While I'm sure
>that you also get an error in CW syntax, what error do you get?
>
>
The assembler gives you an error.
>>Memory clobbering
>>issues are the same as for asm statements today,
>>
>
>Why is it the same? In gcc syntax I can specify whether memory is
>clobbered. In CW syntax I can not. How do I use CW syntax to make a
>supervisor call into my RTOS? How do I tell gcc what has been changed
>if I do that? In particular, how do I tell gcc that memory is not
>clobbered but that specific registers are clobbered?
>
What I meant is that you can't specify every possible pattern of
memory clobbering with either syntax; in some cases you'd have
to be pessimistic no matter what. Now in the case of the supervisor
call, I'd say that in that case the GCC syntax has the capability
for fine-grained clobber specification not available in the CW
syntax. Note that I'm arguing for CW syntax as a simpler
alternative for typical uses, not as a total replacement for
all cases simple and complicated (although adding clobber
specifications would not be hard).
>>and registers it
>>knows about because it parses all the operands.
>>
>
>Isn't this going to be rather problematic on a less regular
>architecture, like the 68k, or the x86? On the x86, it seems like the
>compiler will have to understand all the weird and wonderful
>instructions like "rep movs". That's a lot of parsing.
>
>
Well yeah, but isn't that the kind of knowledge you want in the
software tool, and not as a little quiz for the programmer ("write
down all the clobbers, and if you make a mistake, I'll punish
you with flaky runtime behavior when you do -Os during a new
moon").
>>Implicitly clobbered
>>registers would be more work, but worth it - that is another
>>limitation of the GCC asm statement that drives users crazy.
>>
>
>What is the limitation? The gcc syntax lets you specify precisely
>which registers are clobbered.
>
See above. This is what I mean about working hard to justify the
status quo - why should programmers be writing down lists of
clobbers when the software could be building a completely accurate
list instead? It's not like the clobbers for "movs" change from
week to week.
The GCC syntax was a cheap quickie hack thrown in nearly twenty
years ago and hardly improved since then, even though empirically
it's one of the leading causes of bugs and problems with using GCC.
It may suit you just fine, but most users only put up with it
because they have no alternative.
Stan
More information about the Gcc
mailing list