This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: help with __sync for "long long" types

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;

  __sync_fetch_and_add(&a, 1);

$ gcc -S t.c -m32 -march=i686 -O2

	.file	"t.c"
	.p2align 4,,15
.globl t
	.type	t, @function
	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
	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
	.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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]