z constraint in powerpc inline assembly ?

Segher Boessenkool segher at kernel.crashing.org
Fri Jan 17 01:01:01 AEDT 2020


Hi!

On Thu, Jan 16, 2020 at 07:11:36AM +0100, Christophe Leroy wrote:
> I'm trying to see if we could enhance TCP checksum calculations by 
> splitting inline assembly blocks to give GCC the opportunity to mix it 
> with other stuff, but I'm getting difficulties with the carry.
> 
> As far as I can read in the documentation, the z constraint represents 
> '‘XER[CA]’ carry bit (part of the XER register)'
> 
> I've tried the following, but I get errors. Can you help ?
> 
> unsigned long cksum(unsigned long a, unsigned long b, unsigned long c)
> {
> 	unsigned long sum;
> 	unsigned long carry;
> 
> 	asm("addc %0, %2, %3" : "=r"(sum), "=z"(carry) : "r"(a), "r"(b));
> 	asm("adde %0, %0, %2" : "+r"(sum), "+z"(carry) : "r"(c));
> 	asm("addze %0, %0" : "+r"(sum) : "z"(carry));
> 
> 	return sum;
> }

The only register allowed by "z" is a fixed register.  You cannot use "z"
in inline asm.

Just write this as C?  It should do a reasonable job of it.  If you want
*good* code, you need to write it in *actual* assembler code, anyway (hand
scheduled and everything).


Segher


More information about the Linuxppc-dev mailing list