Leading Zero Count Question
Posted: Sun Sep 16, 2012 2:36 pm
The PowerPC cntlzw asm-instruction is 32-bit, so when we scan a 64 bit value >> 32, do we add 32 then XOR by 63 , or do we XOR by 63 then add 32?
To put it another way, would the following code produce the correct result?
Matthew:out
To put it another way, would the following code produce the correct result?
Code: Select all
Square msb(Bitboard b) {
unsigned b32;
int result = 0;
asm ("cntlzw %1,%0" : "=r"(result) : "r"(b >> 32));
if (result != 32)
{
return Square((result + 32) ^ 63);
}
result = 0;
asm ("cntlzw %1,%0" : "=r"(result) : "r"(b & 0xFFFFFFFF));
if (result != 32)
{
return Square(result ^ 63);
}
return Square(0);
}