MS/CW-style inline assembly for GCC

Stan Shebs shebs@apple.com
Tue May 4 21:51:00 GMT 2004


Andrew Pinski wrote:

>
> On May 4, 2004, at 15:00, Stan Shebs wrote:
>
>>
>> That's why I said "were" poorly documented - it's much better than
>> it used to be.
>>
>> It's still kind of mysterious to developers though; for instance in
>> the PowerPC case, sometimes you have to use "b" and other times "r"
>> for a register, because r0 is not a "base register" and can't be used
>> in all the same contexts. Worse, the mistaken choice of "r" may not
>> bite immediately, depending on how the phase of the moon is affecting
>> register allocation, then manifests itself as a assembler complaint
>> about a register not mentioned in the source code. After a couple
>> experiences like that, developers spew all over us about GCC's
>> lameness and go back to CodeWarrior. :-)
>
>
> But this is a documentation defect for rs6000 rather than a defect in 
> the style.
> I386's documentation for their constraints are hugely better than rs6000.
> But then again if the person who is writing the asm does not know if the
> register should be an address base register or not, they should not be 
> writing the
> asm in the first place as they would get it wrong even if the 
> constrains for
> rs6000 are better documented and most likely the inline-asm which you 
> are providing
> with the CW/MS style of inline asm will not produce optimal code or 
> unless you
> actually parse the asm and know what each instruction takes.

You touch on a good point - how much abstraction should the inline
assembly machinery provide? MS, CW, and GCC have each chosen a
different level of abstraction. GCC's mechanism is oriented towards
the notion that inline asm should work by exposing a bit of the
backend mechanism in hopes that the asm can be incorporated without
trashing optimization, and it works reasonably well for that purpose.
It's also been a leading source of problems with using GCC since
the very beginning, and people coming to GCC from other systems
are always mystified as to why the GCC syntax seems so arcane
compared to what they've used before.

The MS and CW syntaxes are more abstract, in that they figure out
which constraint letters you must have had in mind. The "b"/"r"
choice in PowerPC is a good example in that yes, a good assembly
language programmer will always know which one to use, but if that's
the case, why make the programmer go through the motions of typing
in the correct one? It's sort of like a sobriety test for assembly
coding :-) except that it punishes typos just as severely as genuine
boneheadedness.

> If that is done
> then you are going to integrate gas into GCC or even better just 
> update the
> current binutils so that it can assemble into mach-o object files and 
> the other
> targets where GNU binutils does not work right?

My new charter includes binutils hackery, heh-heh, so be careful
what you suggest!

Stan



More information about the Gcc mailing list