linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* include/asm-ppc/atomic.h: fluff in inline assembly code?
@ 2005-06-29 14:50 Frank van Maarseveen
  2005-06-29 16:14 ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Frank van Maarseveen @ 2005-06-29 14:50 UTC (permalink / raw)
  To: linuxppc-dev

Does anyone know why there are often excess arguments in asm() here?

For example,

	static __inline__ void atomic_add(int a, atomic_t *v)
	{
		int t;

		__asm__ __volatile__(
	"1:     lwarx   %0,0,%3         # atomic_add\n\
		add     %0,%2,%0\n"
		PPC405_ERR77(0,%3)
	"       stwcx.  %0,0,%3 \n\
		bne-    1b"
		: "=&r" (t), "=m" (v->counter)
		: "r" (a), "r" (&v->counter), "m" (v->counter)
		: "cc");
	}

seems equivalent to 

	static __inline__ void atomic_add(int a, atomic_t *v)
	{
		int t;

		__asm__ __volatile__(
	"1:     lwarx   %0,0,%2         # atomic_add\n\
		add     %0,%1,%0\n"
		PPC405_ERR77(0,%2)
	"       stwcx.  %0,0,%2 \n\
		bne-    1b"
		: "=&r" (t)
		: "r" (a), "r" (&v->counter)
		: "cc");
	}

What is the point of all those v->counter arguments?

-- 
Frank

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

* Re: include/asm-ppc/atomic.h: fluff in inline assembly code?
  2005-06-29 14:50 include/asm-ppc/atomic.h: fluff in inline assembly code? Frank van Maarseveen
@ 2005-06-29 16:14 ` Andreas Schwab
  2005-06-29 18:36   ` Frank van Maarseveen
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2005-06-29 16:14 UTC (permalink / raw)
  To: Frank van Maarseveen; +Cc: linuxppc-dev

Frank van Maarseveen <frankvm@frankvm.com> writes:

> What is the point of all those v->counter arguments?

It tells the compiler that v->counter is changed by the asm.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: include/asm-ppc/atomic.h: fluff in inline assembly code?
  2005-06-29 16:14 ` Andreas Schwab
@ 2005-06-29 18:36   ` Frank van Maarseveen
  2005-06-29 22:34     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: Frank van Maarseveen @ 2005-06-29 18:36 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: linuxppc-dev

On Wed, Jun 29, 2005 at 06:14:52PM +0200, Andreas Schwab wrote:
> Frank van Maarseveen <frankvm@frankvm.com> writes:
> 
> > What is the point of all those v->counter arguments?
> 
> It tells the compiler that v->counter is changed by the asm.

So it's an optimized alternative for "memory" in the clobber list?
ok, I couldn't find that anywhere in the doc.

But v->counter is not supposed to be accessed directly by the
compiler (i.e. by C code) at all, is it? so it shouldn't matter.

Even if it would be: the counter itself is declared "volatile int"
which basically tells the compiler not to cache it in a register.

-- 
Frank

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

* Re: include/asm-ppc/atomic.h: fluff in inline assembly code?
  2005-06-29 18:36   ` Frank van Maarseveen
@ 2005-06-29 22:34     ` Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2005-06-29 22:34 UTC (permalink / raw)
  To: Frank van Maarseveen; +Cc: linuxppc-dev

Frank van Maarseveen <frankvm@frankvm.com> writes:

> But v->counter is not supposed to be accessed directly by the
> compiler (i.e. by C code) at all, is it? so it shouldn't matter.
>
> Even if it would be: the counter itself is declared "volatile int"
> which basically tells the compiler not to cache it in a register.

Never lie to the compiler, or it gets its revenge, sooner or later.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

end of thread, other threads:[~2005-06-29 22:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-29 14:50 include/asm-ppc/atomic.h: fluff in inline assembly code? Frank van Maarseveen
2005-06-29 16:14 ` Andreas Schwab
2005-06-29 18:36   ` Frank van Maarseveen
2005-06-29 22:34     ` Andreas Schwab

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 NNTP newsgroup(s).