Inline assembler can't return 64-bit values in registers

Richard Henderson rth@redhat.com
Wed Dec 6 16:33:00 GMT 2000


On Wed, Dec 06, 2000 at 05:58:52PM -0600, Timur Tabi wrote:
>     register u64 temp1, temp2;
> 
>     __asm__ __volatile__ (
> 	"movq (%2), %%mm0 \n\t"
> 	"movd %%mm0, %0 \n\t"
> 	"punpckhdq %%mm0, %%mm0 \n\t"
> 	"movd %%mm0, %1 \n\t"
> 	: "=r" (temp1), "=r" (temp2)
> 	: "r" (pInput)
>     );
> 
>     return (temp2 << 32) | temp1;

This doesn't do what you think it does.  One, you clearly didn't
want 64-bit temporaries, since you try to do shifty things with
them after the asm.

Two, gcc can in fact return 64-bit values from asms.  In fact,
that's what it was doing when producing the "confusing" output
you were looking at.

Don't work so hard.  Try:

	register u64 temp;
	__asm__ __volatile__ (
	  "movq %1, %%mm0 \n\t"
	  "movd %%mm0, %%eax \n\t"
	  "punpckhdq %%mm0, %%mm0 \n\t"
	  "movd %%mm0, %%edx \n\t"
	  : "=A" (temp)
	  : "m" (*pInput)
	);
	return temp;



r~


More information about the Gcc-bugs mailing list