X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.cpp;h=ebd048be8474800eb6507a5dfb64bfacc18061eb;hp=84e576c62d1577a3615e4e11f465ae8bb3d82c45;hb=374c9e6b63d0e233371;hpb=32d3a07c6710e84d78999cb69c6a866b0bfff482 diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 84e576c6..ebd048be 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 @@ -140,6 +141,26 @@ Square pop_1st_bit(Bitboard* b) { #endif // !defined(USE_BSFQ) +#if !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. @@ -196,6 +217,11 @@ void bitboards_init() { else BSFTable[((1ULL << i) * 0x218A392CD3D5DBFULL) >> 58] = i; + MS1BTable[0] = 0; + for (int i = 0, k = 1; i < 8; i++) + for (int j = 0; j < (1 << i); j++) + MS1BTable[k++] = i; + int steps[][9] = { {}, { 7, 9 }, { 17, 15, 10, 6, -6, -10, -15, -17 }, {}, {}, {}, { 9, 7, -7, -9, 8, 1, -1, -8 } };