[Gc] [libatomic_ops] bug with gcc/x86_64/CAS

Andrew Haley aph at redhat.com
Wed Feb 17 06:54:31 PST 2010


On 02/17/2010 12:17 PM, Patrick MARLIER wrote:

> I think I found a bug into libatomic_ops into AO_compare_and_swap_full
> function for gcc and x86_64 cpu.
> 
> **** Possible FIX 2: set RAX as earlyclobbered output ****
> AO_INLINE int
> AO_compare_and_swap_full(volatile AO_t *addr,
> AO_t old, AO_t new_val)
> {
> char result;
> __asm__ __volatile__("lock; cmpxchgq %4, %0; setz %1"
> : "=m"(*addr), "=q"(result) , "=&a" (old)
> : "m"(*addr), "r" (new_val), "0"(old) : "memory");
> return (int) result;
> }

I think this asm is best, but it's pretty questionable to use an asm
at all, given that this is a built-in gcc function.

Andrew.



More information about the Gc mailing list