- 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.
-
- unsigned bsf_index(Bitboard b) {
- b ^= b - 1;
- return Is64Bit ? (b * DeBruijn64) >> 58
- : ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn32) >> 26;
- }
-
-
- // popcount16() counts the non-zero bits using SWAR-Popcount algorithm
-
- unsigned popcount16(unsigned u) {
- u -= (u >> 1) & 0x5555U;
- u = ((u >> 2) & 0x3333U) + (u & 0x3333U);
- u = ((u >> 4) + u) & 0x0F0FU;
- return (u * 0x0101U) >> 8;
- }
-}
-
-#ifdef NO_BSF
-
-/// Software fall-back of lsb() and msb() for CPU lacking hardware support
-
-Square lsb(Bitboard b) {
- assert(b);
- return BSFTable[bsf_index(b)];
-}
-
-Square msb(Bitboard b) {
-
- assert(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 + MSBTable[b32]);