Bit Scan (equivalent to ASM instructions bsr and bsf)

Discussion of chess software programming and technical issues.

Moderator: Ras

pgeorges

Re: Bit Scan (equivalent to ASM instructions bsr and bsf)

Post by pgeorges »

[quote]
Since ARM has no trailing zero count, you may even end up with following code for bsf32:

Code: Select all

static inline int BSF32(uint32 bb) {

#ifdef USE_ARM_ASM
 
  return  __builtin_clz(bb & -bb)  ^ 31;
     
#else

[/quote]
Thanks, I will try that also. But I am unable to find such bit tricks by myself, and to understand that it works, I had to check with an example !

Pascal Georges
pgeorges

Re: Bit Scan (equivalent to ASM instructions bsr and bsf)

Post by pgeorges »

diep wrote:Small question: why use bitboards at a 32 bits ARM processor?

You know, you can try put car wheels underneath a bicycle, but the question is whether that makes any sense.

Vincent
This is an engine port.

Pascal Georges
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Bit Scan (equivalent to ASM instructions bsr and bsf)

Post by Gerd Isenberg »

pgeorges wrote: Thanks, I will try that also. But I am unable to find such bit tricks by myself, and to understand that it works, I had to check with an example !

Pascal Georges
bb & -bb isolates the least significant bit thanks to the two's complement:

Code: Select all

0010 0001 0110 0000
1101 1110 1010 0000 -> copy bits from bit zero until first one, then complement
0000 0000 0010 0000
Subtracting a subset of a set, is equivalent to xor:

Code: Select all

31 - x(0..31) == 31 ^ x(0..31) == x(0..31) ^ 31
which can be applied with one x86 opcode with immediate operand and also safes a register.