Inline assembler for cmpxchg8b on x86 + PIC + frame pointer

Brian Dessent
Thu Sep 25 16:05:00 GMT 2008

Frank Mehnert wrote:

> I would like to get some help in writing an inline assembler function
> for the cmpxchg8b command. Especially for the x86 target and PIC support.
> PIC (position independant code) implies that EBX must not be changed. And
> the x86 target has only a limited number of registers available. And of
> course the code should work regardless if we have -fomit-frame-pointer
> enabled or not (so no EBP register available). So far I have the following
> function:

I think you're making life a lot harder than it needs to be.  gcc
already has intrinsics for these things, and
__sync_{bool,val}_compare_and_swap() will use cmpxchg8b if you use a 8
byte type and if your selected architecture supports it.  Note that the
default (-march=386) does not, so you need to specify something higher.



More information about the Gcc-help mailing list