[MPlayer-dev-eng] [PATCH] missing regs in clobber list

Martin Simmons vyslnqaaxytp at spammotel.com
Sat Dec 25 01:16:09 CET 2004


>>>>> On Tue, 21 Dec 2004 23:49:40 +0100, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de> said:

> > I think the c_longcount_tsc fragment should have eax in the clobber list as
> > well as edx.

> The "a"(z) assigns the z variable to the eax register so it is
> "clobbered" implicitly. At least that is how I remmeber it.

No, "a"(z) just tells the compiler to put z in eax, but it might use that
knowledge later when computing values derived from z (including the value of z
itself).

E.g. if I compile the following with -O4 in gcc 3.2.2 then &x is placed in
eax, but the second use of &x also uses eax and so the printf outputs a random
number for the %p argument.

------------------------------------------------------------------------
static void c_longcount_tsc(long long* z)
{
    __asm__ __volatile__
	(
	 "pushl %%ebx\n\t"
	 "movl %%eax, %%ebx\n\t"
	 "rdtsc\n\t"
	 "movl %%eax, 0(%%ebx)\n\t"
	 "movl %%edx, 4(%%ebx)\n\t"
	 "popl %%ebx\n\t"
	 ::"a"(z)
	 :"edx"
	);
}

int main(int argc, char **argv)
{
  long long x;
  c_longcount_tsc(&x);
  printf("%lld %p\n", x, &x);
  return 0;
}
------------------------------------------------------------------------


> Anyway, it won't compile if you add eax.

Hmm, you're right.  This could be a gcc bug, or else gcc defines "clobber" as
"totally disallow" (which has its uses).

This one works, using ebx from the start:

    __asm__ __volatile__
	(
	 "rdtsc\n\t"
	 "movl %%eax, 0(%%ebx)\n\t"
	 "movl %%edx, 4(%%ebx)\n\t"
	 ::"b"(z)
	 :"eax","edx"
	);

__Martin




More information about the MPlayer-dev-eng mailing list