X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fbitboard.cpp;h=36d582d3a6a2ebec48639658a20241f6efb11786;hb=adb71b8096436a54bf2326d5c69991b16ba5bafa;hp=84e576c62d1577a3615e4e11f465ae8bb3d82c45;hpb=3b906ffc2765856948f1baac5ceb5209fe4380e2;p=stockfish diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 84e576c6..36d582d3 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -58,6 +58,7 @@ namespace { CACHE_LINE_ALIGNMENT int BSFTable[64]; + int MS1BTable[256]; Bitboard RTable[0x19000]; // Storage space for rook attacks Bitboard BTable[0x1480]; // Storage space for bishop attacks @@ -138,14 +139,42 @@ Square pop_1st_bit(Bitboard* b) { return Square(BSFTable[((~(u.b.h ^ (u.b.h - 1))) * 0x783A9B23) >> 26]); } -#endif // !defined(USE_BSFQ) +Square last_1(Bitboard b) { + + int result = 0; + + if (b > 0xFFFFFFFF) + { + b >>= 32; + result = 32; + } + if (b > 0xFFFF) + { + b >>= 16; + result += 16; + } + + if (b > 0xFF) + { + b >>= 8; + result += 8; + } + + return Square(result + MS1BTable[b]); +} + +#endif // !defined(USE_BSFQ) /// bitboards_init() initializes various bitboard arrays. It is called during /// program initialization. void bitboards_init() { + for (int k = 0, i = 0; i < 8; i++) + while (k < (2 << i)) + MS1BTable[k++] = i; + for (Bitboard b = 0; b < 256; b++) BitCount8Bit[b] = (uint8_t)popcount(b);