Fix msb calculation for large-board version
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 7 Feb 2019 22:19:45 +0000 (23:19 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 7 Feb 2019 22:19:45 +0000 (23:19 +0100)
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.

src/bitboard.h

index a6aa395..d1be518 100644 (file)
@@ -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