> The score, sh and sparc instructions may or may not display canonical
> behavior; their ports do not define CLZ_DEFINED_VALUE_AT_ZERO and I was
> not able to find documentation of the relevant instruction.

The operation the nsb instruction of the SHmedia instruction set performs
is 'count number of sign bit copies'.

For the 32 bit ffs, first a mask for the least significant bit is computed.
Thus, the upper 32 bit of the 64 bit registers are all zero, so we merely
have to subtract the result of nsb from 63.
So this is more or less what you describe as canonical behaviour.

For the 64 bit ffs, the input is shifted right by one to obtain an unsigned
value.  This has the effect that the value obtained for zero input is the
same as the one for one input, which is compensated for with a conditional
move.  In this sense, for 64 bit operation you have 'non-canonical'
behaviour.

The ARC700 has a NORM instruction, which again counts the number of
sign bit copies.  There is a variant NORM.F which sets the N flag if the
input is negative.

Thus,
      __asm__ ("norm.f\t%0,%1\n\tmov.mi\t%0,-1" : "=r" (c_) : "r" (x) : "cc");
performs a 'canonical' count leading zeros operation, except that you have
to add one to the result.

Reply via email to