From: Fabian Fichter Date: Thu, 7 Feb 2019 22:19:45 +0000 (+0100) Subject: Fix msb calculation for large-board version X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=9ffc78af565aafd6d75782d26385ea6a89d00782;p=fairystockfish.git Fix msb calculation for large-board version A bug in the calculation of the most significant bit caused undefined behavior in the king safety evaluation. The fix significantly improves playing strength of the large-board version: chess LLR: 2.97 (-2.94,2.94) [-10.00,5.00] Total: 100 W: 72 L: 15 D: 13 capablanca LLR: 2.98 (-2.94,2.94) [-10.00,5.00] Total: 82 W: 62 L: 8 D: 12 shogi LLR: 2.97 (-2.94,2.94) [-10.00,5.00] Total: 256 W: 157 L: 92 D: 7 No functional change for normal version. --- diff --git a/src/bitboard.h b/src/bitboard.h index a6aa395..d1be518 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -406,9 +406,11 @@ inline Square msb(Bitboard b) { assert(b); #ifdef LARGEBOARDS if (b >> 64) - return Square(SQUARE_BIT_MASK ^ (__builtin_clzll(b >> 64) + 64)); -#endif + return Square(SQUARE_BIT_MASK ^ __builtin_clzll(b >> 64)); + return Square(SQUARE_BIT_MASK ^ (__builtin_clzll(b) + 64)); +#else return Square(SQUARE_BIT_MASK ^ __builtin_clzll(b)); +#endif } #elif defined(_MSC_VER) // MSVC