Partial registers in asm constraints/clobber lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

My question is this.
Is it safe to mention part of a register only in a constraint or clobber list?

Two examples:

    asm( "xor %%eax,%%eax" ::: "eax" );

This is fine for 32 bits, but in 64 bit mode, the upper half of rax is
zeroed.  So do I have to
give rax in the clobber list? (which means separate code for 32 and 64
versions which I'd prefer to avoid).

Secondly:

bool have_tsc( void )
{
  bool present;
  asm( "mov $1,%%eax;  cpuid;  test $16,%%edx;  setnz %0" : "=a"
(present) :: "ebx", "ecx", "edx" );
  return present;
}

Here only "al" is mentioned but of course "eax" is altered.  (of
course I could use "=q"
but it creates an extra mov, as the function will return the bool in "al").

Does gcc treat registers as a whole so that a mention of any part of a
register refers to all of it (e.g. register "a").

Thanks
Jeremy


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux