Subject: Re: in_cksum asm chunks.
To: Chris Gilbert <chris@paradox.demon.co.uk>
From: Richard Earnshaw <rearnsha@arm.com>
List: port-arm
Date: 08/31/2001 09:55:06
> Hi,
> 
> I've just been looking over the asm chunks in in_chksum_arm.c, and noticed 
> that we don't say that they overwrite the condition codes, I was wondering if 
> any knew if this isn't needed on arm?

It's good form to mention this in the clobber list, but the compiler will 
assume that condition codes are clobbered by ASM statements.

>  I was also pondering if there's a way 
> to really make sure that all the inputs are seperate registers,

Yes you can, for outputs/temporaries that must not overlap inputs, put '&' 
in the constraint.

> I was 
> wondering if you could infact have multiple outputs, eg:

Yes you can

> 
> #define ADD4	__asm __volatile("	\n\
> 	ldr	%1,[%3],#4		\n\
> 	adds	%0,%0,%1		\n\
> 	adcs	%0,%0,#0\n"		\
> 	: "=r" (sum), "=r" (tmp1)	\
> 	: "0" (sum), "r" (w)		\
> 	: "cc")
> 
> The docs on asm don't seem to make this very clear.

This operation has a side-effect on w which isn't mentioned in the 
constraints.

For sum, we don't need to force it into the same register for both input 
and output, so we can use a different number here.  The compiler will 
merge them if it suits it best to do so.

The best way to write this is 

#define ADD4	__asm __volatile("		\
	ldr	%2, [%0], #4			\n\
	adds	%1, %4, %2			\n\
	adcs	%1, %1, #0\n"			\
	: "=r" (w), "=r" (sum), "=&r" (tmp1)	\
	: "0" (w), "r" (sum)			\
	: "cc")

R.