yet another test case: long long usage generates horrific code
Ben LaHaise
bcrl@redhat.com
Wed Sep 6 13:45:00 GMT 2000
The following assembly (ak! ptewy!) is generated with
gcc -O2 -Wall -fomit-frame-pointer -S longlong.c
in a recent snapshort of gcc used in Red Hat on x86.
test3:
pushl %edi
pushl %esi
xorl %ecx, %ecx
pushl %ebx
movl 16(%esp), %esi
movl %ecx, %eax
movl %ecx, %edx
#APP
cmpxchg8 (%esi)
#NO_APP
movl %edx, %esi
movl %eax, %ecx
movl %esi, %eax
movl %eax, %edx
xorl %eax, %eax
xorl %ebx, %ebx
movl %eax, %esi
movl %edx, %edi
orl %ebx, %edi
orl %ecx, %esi
popl %ebx
movl %esi, %eax
movl %edi, %edx
popl %esi
popl %edi
ret
-------------------------
And the source:
long long test(void)
{
return 0;
}
long long test2(void)
{
return -1;
}
extern inline long long xchg64(void *ptr, long long val)
{
unsigned long low, high;
low = val;
high = val >> 32;
__asm__ __volatile__(
"cmpxchg8 (%2)"
: "=a" (low), "=d" (high)
: "r" (ptr), "0" (low), "1" (high)
:"memory");
return ((unsigned long long)high << 32) | low;
}
long long test3(void *ptr)
{
return xchg64(ptr, 0);
}
More information about the Gcc-bugs
mailing list