[hjl@gnu-9 gcc]$ cat /tmp/x.c
extern int __sync_bool_compare_and_swap_di (long *, long, long);
#define __sync_bool_compare_and_swap_di __sync_bool_compare_and_swap
foo (long *x)
long address = *x;
if (!__sync_bool_compare_and_swap_di (x, address, (address | 1)))
long val = 0;
printf ("val: 0x%lx\n", val);
ret = foo (&val);
printf ("ret: %d: val: 0x%lx\n", ret, val);
[hjl@gnu-9 gcc]$ ./xgcc -B./ -O2 /tmp/x.c
[hjl@gnu-9 gcc]$ ./a.out
ret: 1: val: 0x1
[hjl@gnu-9 gcc]$ ./xgcc -B./ -O2 /tmp/x.c -m32
/tmp/ccQy8ACO.o: In function `foo':
x.c:(.text+0x1c): undefined reference to `__sync_bool_compare_and_swap_4'
collect2: ld returned 1 exit status
When, exactly, did you think that cmpxchg was added? Use -march=i486. Duh.
But there is no __sync_bool_compare_and_swap_4 in source code.
If it isn't available, shouldn't gcc leave __sync_bool_compare_and_swap
No, because __sync_bool_compare_and_swap is overloaded.
This expansion to __sync_bool_compare_and_swap_N is documented.