------- Comment #3 from m dot rosellini at f5 dot com 2009-07-09 20:29 ------- OK, maybe some assembly will make the issue clearer. Or perhaps you just want to close this bug if you're not fixing bugs in the 4.1 compiler. I verified that the problem does occur with 4.1 and that it does not occur with 4.2. The relevant built-ins seem not to exist in 4.0.
Below is the output from a 4.1 compiler and a 4.2 compiler. I have annotated the relevant instructions with "<<<". In the first example, from a 4.1 compiler, you can see that there is a constant of "0" passed to adcl (which is incorrect), whereas in the second example, from a 4.2 compiler, there is a constant of "-1" passed to adcl (which is correct). seapddev(catalan) ~/ 503$ cat t.c int main(int ac, char **av) { volatile long long x; __sync_fetch_and_add(&x, -1); return x; } seapddev(catalan) ~/ 504$ gcc --version gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. seapddev(catalan) ~/ 505$ gcc -march=pentium t.c seapddev(catalan) ~/ 506$ cat t.s .file "t.c" .text .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %edi pushl %esi pushl %ebx pushl %ecx subl $40, %esp leal -24(%ebp), %eax movl %eax, -36(%ebp) movl -36(%ebp), %edx movl (%edx), %eax movl 4(%edx), %edx movl %eax, -48(%ebp) movl %edx, -44(%ebp) .L2: movl -48(%ebp), %eax movl -44(%ebp), %edx movl %eax, -56(%ebp) movl %edx, -52(%ebp) movl -56(%ebp), %ecx movl -52(%ebp), %ebx addl $-1, %ecx adcl $0, %ebx <<< movl %ecx, %esi movl %ebx, %ecx movl -36(%ebp), %edi movl -56(%ebp), %eax movl -52(%ebp), %edx movl %esi, %ebx lock cmpxchg8b (%edi) movl %eax, -48(%ebp) movl %edx, -44(%ebp) jne .L2 movl -24(%ebp), %eax movl -20(%ebp), %edx addl $40, %esp popl %ecx popl %ebx popl %esi popl %edi popl %ebp leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (GNU) 4.1.2 20080704 (Red Hat 4.1.2-44)" .section .note.GNU-stack,"",@progbits seapddev(catalan) ~/ 507$ wayward ~/ 537$ cat t.c int main(int ac, char **av) { volatile long long x; __sync_fetch_and_add(&x, -1); return x; } wayward ~/ 538$ gcc-4.2 --version i686-apple-darwin9-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5574) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. wayward ~/ 539$ rm t.s rm: t.s: No such file or directory wayward ~/ 540$ gcc-4.2 -march=pentium -S t.c wayward ~/ 541$ cat t.s .text .globl _main _main: pushl %ebp movl %esp, %ebp pushl %edi pushl %esi subl $64, %esp leal -16(%ebp), %eax movl %eax, -28(%ebp) movl -28(%ebp), %edi movl (%edi), %esi movl 4(%edi), %edi movl %esi, -40(%ebp) movl %edi, -36(%ebp) L2: movl -40(%ebp), %eax movl -36(%ebp), %edx movl %eax, -64(%ebp) movl %edx, -60(%ebp) movl -64(%ebp), %esi movl -60(%ebp), %edi addl $-1, %esi adcl $-1, %edi <<< movl %esi, -44(%ebp) movl %edi, %ecx movl -28(%ebp), %esi movl -64(%ebp), %eax movl -60(%ebp), %edx movl -44(%ebp), %edi xchgl %ebx, %edi lock cmpxchg8b (%esi) xchgl %ebx, %edi movl %eax, -40(%ebp) movl %edx, -36(%ebp) jne L2 movl -16(%ebp), %eax movl -12(%ebp), %edx addl $64, %esp popl %esi popl %edi popl %ebp ret .subsections_via_symbols wayward ~/ 542$ -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40693