yet another test case: long long usage generates horrific code

Linus Torvalds torvalds@transmeta.com
Wed Sep 6 14:20:00 GMT 2000


In article < Pine.LNX.4.21.0009061631450.27593-100000@devserv.devel.redhat.com >,
Ben LaHaise  <bcrl@redhat.com> wrote:
>The following assembly (ak! ptewy!) is generated with
>
> gcc -O2 -Wall -fomit-frame-pointer -S longlong.c

Don't do that, then.

I'd love for gcc to be able to handle the case of

	unsigned long lone = (unsigned long << 32) | (unsigned long)

better, but at least for inline asm you are better off rewriting your
program to use "A", like this:

	extern inline long long xchg64(void *ptr, long long val)
	{
		__asm__ __volatile__(
			"cmpxchg8 (%1)"
			: "=A" (val)
			: "r" (ptr), "0" (val)
			:"memory");
		return val;
	}
	
	long long test3(void *ptr)
	{
		return xchg64(ptr, 0);
	}

which generates (still incomprehensible, but better):

	test3:
		pushl %edi
		pushl %esi
		pushl %ebx
		movl $0,%eax
		movl $0,%edx
		movl 16(%esp),%ecx
	#APP
		cmpxchg8 (%ecx)
	#NO_APP
		movl %eax,%esi
		movl %edx,%edi
		popl %ebx
		popl %esi
		popl %edi
		ret

(Don't ask me about the %esi/%edi crap - and it might be fixed already
in later gcc versions than the one I have).

		Linus


More information about the Gcc-bugs mailing list