This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: help with __sync for "long long" types
On 07/07/2010 05:00 PM, Preeti Sharma wrote:
> Thanks for the response :
> also wanted you to know that the problem is only for a 64 bit value ;
> it compiles fine for a 32 bit int.
Yes, I get the same problem with 4.1.2.
Maybe you should upgrade.
Andrew.
> On Wed, Jul 7, 2010 at 8:43 AM, Andrew Haley <aph@redhat.com> wrote:
>> On 07/07/2010 04:26 PM, Preeti Sharma wrote:
>>> I am trying to use __sync_fetch_and_add with type as "long long" .
>>>
>>> This gives me the link error :
>>> undefined reference to `__sync_fetch_and_add_8'
>>>
>>> This compiles for a "int " type though. I am using the the gcc option
>>> -march=i686
>>>
>>> Is it possible to do a 64 bit integer operation atomically with the
>>> __sync .. builtin functions ?
>>
>> Works for me:
>>
>> long long a;
>>
>> t()
>> {
>> __sync_fetch_and_add(&a, 1);
>> }
>>
>> $ gcc -S t.c -m32 -march=i686 -O2
>>
>> .file "t.c"
>> .text
>> .p2align 4,,15
>> .globl t
>> .type t, @function
>> t:
>> pushl %ebp
>> movl %esp, %ebp
>> subl $12, %esp
>> movl %ebx, (%esp)
>> movl %esi, 4(%esp)
>> movl %edi, 8(%esp)
>> movl a, %eax
>> movl a+4, %edx
>> .L2:
>> movl %eax, %esi
>> movl %edx, %edi
>> addl $1, %esi
>> adcl $0, %edi
>> movl %esi, %ebx
>> movl %edi, %ecx
>> lock cmpxchg8b a
>> jne .L2
>> movl (%esp), %ebx
>> movl 4(%esp), %esi
>> movl 8(%esp), %edi
>> movl %ebp, %esp
>> popl %ebp
>> ret
>> .size t, .-t
>> .comm a,8,8
>> .ident "GCC: (GNU) 4.4.3 20100127 (Red Hat 4.4.3-4)"
>> .section .note.GNU-stack,"",@progbits
>>
>>