All of lore.kernel.org
 help / color / mirror / Atom feed
* __asm__  C code in mips-Linux
@ 2003-04-03  1:02 Mike K.
  2003-04-03  2:09 ` Ralf Baechle
  2003-04-03 12:58   ` Kevin D. Kissell
  0 siblings, 2 replies; 4+ messages in thread
From: Mike K. @ 2003-04-03  1:02 UTC (permalink / raw)
  To: linux-mips

extern __inline__ void atomic_add(int i, atomic_t * v)
{
	unsigned long temp;

	__asm__ __volatile__(
		"1:   ll      %0, %1      # atomic_add\n"
		"     addu    %0, %2                  \n"
		"     sc      %0, %1                  \n"
		"     beqz    %0, 1b                  \n"
		: "=&r" (temp), "=m" (v->counter)
		: "Ir" (i), "m" (v->counter));
}


Beginner questions on the above code:
1. what is %0 %1 %2?
2. what is the details meaning of the last two line of the above code?
3. Very thanksful if you can comment each line with detail description  for 
me, thanks a lot!


_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail

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

* Re: __asm__  C code in mips-Linux
  2003-04-03  1:02 __asm__ C code in mips-Linux Mike K.
@ 2003-04-03  2:09 ` Ralf Baechle
  2003-04-03 12:58   ` Kevin D. Kissell
  1 sibling, 0 replies; 4+ messages in thread
From: Ralf Baechle @ 2003-04-03  2:09 UTC (permalink / raw)
  To: Mike K.; +Cc: linux-mips

On Wed, Apr 02, 2003 at 05:02:08PM -0800, Mike K. wrote:

> extern __inline__ void atomic_add(int i, atomic_t * v)
> {
> 	unsigned long temp;
> 
> 	__asm__ __volatile__(
> 		"1:   ll      %0, %1      # atomic_add\n"
> 		"     addu    %0, %2                  \n"
> 		"     sc      %0, %1                  \n"
> 		"     beqz    %0, 1b                  \n"
> 		: "=&r" (temp), "=m" (v->counter)
> 		: "Ir" (i), "m" (v->counter));
> }
> 
> 
> Beginner questions on the above code:
> 1. what is %0 %1 %2?
> 2. what is the details meaning of the last two line of the above code?

%0 stands for the 0th operand of the asm statement, that is the temp
variable, %1 for the first that is v->counter, %2 for the second that is
the variable i.  In the strings like "=&r" the = means that the argument
will be assigned to, r means the argument / result is to be passed in a
register (%0 will then be replaced by gcc with that register) and m
means some memory location, gcc will then replace %1 with that memory
location.  "Ir" means gcc can pass the variable i in either a register
(that's the r) or as a 16-bit constant (the I).  Again %3 will be
replaced with whatever gcc deciedes to pass here.  All the output
operands are listed after the first colon - and be marked with a = sign;
the input operands are listed after the second colon.  After a third
colon all registers that get destroyed by a piece of inline assembly
can be listed like :"$5","$6" but we don't need that here.

> 3. Very thanksful if you can comment each line with detail description  for 
> me, thanks a lot!

Your basic spinlock described in the R4000 manual from 10 years ago :-)

  Ralf

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

* Re: __asm__  C code in mips-Linux
@ 2003-04-03 12:58   ` Kevin D. Kissell
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin D. Kissell @ 2003-04-03 12:58 UTC (permalink / raw)
  To: Mike K., linux-mips

> extern __inline__ void atomic_add(int i, atomic_t * v)
> {
> unsigned long temp;
> 
> __asm__ __volatile__(
> "1:   ll      %0, %1      # atomic_add\n"
> "     addu    %0, %2                  \n"
> "     sc      %0, %1                  \n"
> "     beqz    %0, 1b                  \n"
> : "=&r" (temp), "=m" (v->counter)
> : "Ir" (i), "m" (v->counter));
> }
> 
> 
> Beginner questions on the above code...

See http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC93
or any of a number of other on-line copies of the gcc documentation.
Gcc has a very powerful and cool means of binding C variables to
assembly-language operands.  The syntax can be painful, but you
can do amazing things with it - in this case, an in-line atomic add
for C.

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

* Re: __asm__  C code in mips-Linux
@ 2003-04-03 12:58   ` Kevin D. Kissell
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin D. Kissell @ 2003-04-03 12:58 UTC (permalink / raw)
  To: Mike K., linux-mips

> extern __inline__ void atomic_add(int i, atomic_t * v)
> {
> unsigned long temp;
> 
> __asm__ __volatile__(
> "1:   ll      %0, %1      # atomic_add\n"
> "     addu    %0, %2                  \n"
> "     sc      %0, %1                  \n"
> "     beqz    %0, 1b                  \n"
> : "=&r" (temp), "=m" (v->counter)
> : "Ir" (i), "m" (v->counter));
> }
> 
> 
> Beginner questions on the above code...

See http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC93
or any of a number of other on-line copies of the gcc documentation.
Gcc has a very powerful and cool means of binding C variables to
assembly-language operands.  The syntax can be painful, but you
can do amazing things with it - in this case, an in-line atomic add
for C.

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

end of thread, other threads:[~2003-04-03 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-03  1:02 __asm__ C code in mips-Linux Mike K.
2003-04-03  2:09 ` Ralf Baechle
2003-04-03 12:58 ` Kevin D. Kissell
2003-04-03 12:58   ` Kevin D. Kissell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.