Inline assembly questions
Richard Henderson
rth@redhat.com
Mon Apr 7 22:24:00 GMT 2003
On Sun, Apr 06, 2003 at 11:54:53PM -0700, Zack Weinberg wrote:
> Because there is no absolute-jump-to-immediate instruction on the x86.
> The hardware instruction that "call *%cs:addr" maps to is PC-relative.
> You have no choice but to use a scratch register.
Well, there's lcall, but it's *so* much slower that you
don't ever want to use it unless you really are changing
segments at the same time.
> Also, the above constitutes lying to the compiler about control flow;
> the correct thing to do is
>
> {
> void (*ptr)(void);
> asm ("lea %%cs:SomeFunction, %0" : "=r" (ptr))
> ptr();
> }
Which is also silly because (1) segment overrides are
ignored for lea and (2) this is equivalent to
void (*ptr)(void);
ptr = &SomeFunction;
ptr();
which the compiler will happily collapse to
SomeFunction();
which is what you should have written in the first place.
> > Also, how do I make a function in a GCC C file that is strictly
> > inline assembly be completely bare with no prologue/epilogue (stack
> > frame) or optimizations?
>
> You write an .s file and feed it directly to the assembler.
Indeed.
r~
More information about the Gcc
mailing list