public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Partial registers in asm constraints/clobber lists
@ 2012-05-21  9:00 Jeremy Hall
  2012-05-21 18:56 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Hall @ 2012-05-21  9:00 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Partial registers in asm constraints/clobber lists
  2012-05-21  9:00 Partial registers in asm constraints/clobber lists Jeremy Hall
@ 2012-05-21 18:56 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2012-05-21 18:56 UTC (permalink / raw)
  To: Jeremy Hall; +Cc: gcc-help

Jeremy Hall <gcc.hall@gmail.com> writes:

> Is it safe to mention part of a register only in a constraint or clobber list?

Yes.

> 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").

Yes.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-21 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-21  9:00 Partial registers in asm constraints/clobber lists Jeremy Hall
2012-05-21 18:56 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).