This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Inline assembler for cmpxchg8b on x86 + PIC + frame pointer
- From: Brian Dessent <brian at dessent dot net>
- To: Frank Mehnert <Frank dot Mehnert at Sun dot COM>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 25 Sep 2008 09:04:15 -0700
- Subject: Re: Inline assembler for cmpxchg8b on x86 + PIC + frame pointer
- References: <200809251504.59725.frank.mehnert@sun.com>
- Reply-to: gcc-help at gcc dot gnu dot org
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.
<http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html>
Brian