X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fbitboard.cpp;h=64cba6b5fc301322299a0eb3cf0d8c5102b07867;hb=46a50cbf38bdfa5e48358585f4c98668507700ae;hp=84e576c62d1577a3615e4e11f465ae8bb3d82c45;hpb=3b906ffc2765856948f1baac5ceb5209fe4380e2;p=stockfish diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 84e576c6..64cba6b5 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -138,8 +138,32 @@ 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 + BitCount8Bit[b]); +} + +#endif // !defined(USE_BSFQ) /// bitboards_init() initializes various bitboard arrays. It is called during /// program initialization.