- typedef unsigned (Fn)(Square, Bitboard);
-
- void init_magics(Bitboard table[], Bitboard* attacks[], Bitboard magics[],
- Bitboard masks[], unsigned shifts[], Square deltas[], Fn index);
-
- // bsf_index() returns the index into BSFTable[] to look up the bitscan. Uses
- // Matt Taylor's folding for 32 bit case, extended to 64 bit by Kim Walisch.
-
- FORCE_INLINE unsigned bsf_index(Bitboard b) {
- b ^= b - 1;
- return Is64Bit ? (b * DeBruijn64) >> 58
- : ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
- }
-}
-
-#ifndef USE_BSFQ
-
-/// Software fall-back of lsb() and msb() for CPU lacking hardware support
-
-Square lsb(Bitboard b) {
- return BSFTable[bsf_index(b)];
-}
-
-Square msb(Bitboard b) {
-
- unsigned b32;
- int result = 0;
-
- if (b > 0xFFFFFFFF)
- {
- b >>= 32;
- result = 32;
- }
-
- b32 = unsigned(b);
-
- if (b32 > 0xFFFF)
- {
- b32 >>= 16;
- result += 16;
- }
-
- if (b32 > 0xFF)
- {
- b32 >>= 8;
- result += 8;
- }
-
- return Square(result + MS1BTable[b32]);