public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* gcc inline asm - short question
@ 2002-03-18 23:27 Carl Spalletta
  2002-03-18 23:50 ` Keith Owens
  2002-03-19  5:27 ` H. Peter Anvin
  0 siblings, 2 replies; 3+ messages in thread
From: Carl Spalletta @ 2002-03-18 23:27 UTC (permalink / raw)
  To: linux-kernel

  In studying the kernel I find many gcc inline 'asm' statements,
like so.
	
        asm ( assembler template
	    : output operands			 	(optional)
	    : input operands			 	(optional)
	    : list of clobbered registers 	  	(optional)
	    );	

  I have read all the docs and I still can't clearly understand when it 
is required to specify a clobberlist - a register or memory that will
be modified and must be preserved by gcc.

  In searching the kernel source there were very few clobbers given
and most of those were for memory.

  For example in arch/i386/lib/delay.c:

71         __asm__("mull %0"
72         :"=d" (xloops), "=&a" (d0)
73         :"1" (xloops),"" (current_cpu_data.loops_per_jiffy));
74         __delay(xloops * HZ);

  It's pretty obvious that eax gets clobbered, as I know clobber.  Why is
it not listed as such? Does the answer to this question apply in all cases? 
What about memory clobbers - how do they happen?


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/

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

* Re: gcc inline asm - short question
  2002-03-18 23:27 gcc inline asm - short question Carl Spalletta
@ 2002-03-18 23:50 ` Keith Owens
  2002-03-19  5:27 ` H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: Keith Owens @ 2002-03-18 23:50 UTC (permalink / raw)
  To: Carl Spalletta; +Cc: linux-kernel

On Mon, 18 Mar 2002 15:27:40 -0800 (PST), 
Carl Spalletta <cspalletta@yahoo.com> wrote:
>        asm ( assembler template
>	    : output operands			 	(optional)
>	    : input operands			 	(optional)
>	    : list of clobbered registers 	  	(optional)
>	    );	
>
>  I have read all the docs and I still can't clearly understand when it 
>is required to specify a clobberlist - a register or memory that will
>be modified and must be preserved by gcc.

The clobber list is _extra_ clobbers, registers or memory that gcc
cannot deduce from the other parameters.  =d" (xloops), "=&a" (d0)
already tells gcc that edx and eax are used, you do not need to
explicitly specify them as clobbers.  OTOH, asm ("mov 1, %eax")
requires a clobber because the operands do not mention eax.


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

* Re: gcc inline asm - short question
  2002-03-18 23:27 gcc inline asm - short question Carl Spalletta
  2002-03-18 23:50 ` Keith Owens
@ 2002-03-19  5:27 ` H. Peter Anvin
  1 sibling, 0 replies; 3+ messages in thread
From: H. Peter Anvin @ 2002-03-19  5:27 UTC (permalink / raw)
  To: linux-kernel

Followup to:  <20020318232740.39289.qmail@web13305.mail.yahoo.com>
By author:    Carl Spalletta <cspalletta@yahoo.com>
In newsgroup: linux.dev.kernel
> 
>   I have read all the docs and I still can't clearly understand when it 
> is required to specify a clobberlist - a register or memory that will
> be modified and must be preserved by gcc.
> 
>   In searching the kernel source there were very few clobbers given
> and most of those were for memory.
> 
>   For example in arch/i386/lib/delay.c:
> 
> 71         __asm__("mull %0"
> 72         :"=d" (xloops), "=&a" (d0)
> 73         :"1" (xloops),"" (current_cpu_data.loops_per_jiffy));
> 74         __delay(xloops * HZ);
> 
>   It's pretty obvious that eax gets clobbered, as I know clobber.  Why is
> it not listed as such? Does the answer to this question apply in all cases? 
> What about memory clobbers - how do they happen?
> 

It's not listed as such because it's an output (the second output),
not a clobber.  This is particularly common on x86 where registers are
so specialized that they all have their own constraint letters.

Incidentally, the above asm statement is technically incorrect, "=&a"
(d0) means eax is an "early clobber", however, the instruction doesn't
require it to be early clobbered.

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<amsp@zytor.com>

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

end of thread, other threads:[~2002-03-19  5:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-03-18 23:27 gcc inline asm - short question Carl Spalletta
2002-03-18 23:50 ` Keith Owens
2002-03-19  5:27 ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox