Re[2]: [Gc] [libatomic_ops] bug with gcc/x86_64/CAS

Ivan Maidanski ivmai at mail.ru
Wed Feb 17 08:45:26 PST 2010


Hi!
Andrew Haley <aph at redhat.com> wrote:
> 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 -
1. could you explain why fix 1 is not so good as fix 2;

2. thanks for noting that __sync_... built-in funcs exist in GCC but:
- from which GCC version they are supported?;
- they are supported for all targets (where applicable) or for Intel only?;
- it would be good if someone send me a draft (at least) code using them;
- as only bug fixes are accepted for gc72, the changes would go to the next major release (unless Hans says the opposite).

Bye.

2. not clear to me what do you mean by "but it's pretty questionable to use an asm at all, given that this is a built-in gcc function" - you mean CAS


More information about the Gc mailing list