Joern Rennecke wrote:
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'.
[...]

It sounds like the SH should probably be lumped in with the x86 as not
doing "canonical behavior".  Conveniently enough for my grand plan, it
already uses an UNSPEC for the actual instruction :-)

What is the result of the instruction for (64-bit) all-bits-zero or
all-bits-one?  64?  Assuming so, it occurs to me that the result of an
unsigned clz() on any negative 64-bit value will be zero; thus, you
could get a "canonical" clz out of nsb by doing (pseudo-assembly)

        mov     result, 0
        cmp/pz  arg
        bf      1f
        nsb     result, arg
1:

Similarly, the x & (x-1) operation used to set up for ctz/ffs in terms
of clz will leave the high bit set *only* for x == 0x8000 0000 0000
0000; which can be tested for as x == (x&(x-1)) and the nsb skipped.

Would these sequences be slower than the current logic?

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.

Sorry, I don't recognize the ARC700 - which GCC back end is that?  It
might be worth teaching optabs.c about sign-bit-count operations, but
only if we have more than one architecture that can use it.

zw

Reply via email to