]> git.sesse.net Git - stockfish/commitdiff
Use new 64 bit De Bruijn BitScan
authorMarco Costalba <mcostalba@gmail.com>
Sat, 13 Oct 2012 11:34:50 +0000 (13:34 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 13 Oct 2012 11:45:45 +0000 (13:45 +0200)
Allows to sync 32 and 64 bits implementations.

Idea by Kim Walisch, reported by Gerd Isenberg:
http://talkchess.com/forum/viewtopic.php?t=45554

No functional change.

src/bitboard.cpp

index dd5b57995056a356b0b2235253596e6e8bd7325b..82608eab4f1ba1e937dc4dd56b29a73b5b2a6e20 100644 (file)
@@ -57,7 +57,7 @@ int SquareDistance[64][64];
 namespace {
 
   // De Bruijn sequences. See chessprogramming.wikispaces.com/BitScan
-  const uint64_t DeBruijn_64 = 0x218A392CD3D5DBFULL;
+  const uint64_t DeBruijn_64 = 0x3F79D71B4CB0A89ULL;
   const uint32_t DeBruijn_32 = 0x783A9B23;
 
   CACHE_LINE_ALIGNMENT
@@ -75,12 +75,10 @@ namespace {
 
   FORCE_INLINE unsigned bsf_index(Bitboard b) {
 
-    if (Is64Bit)
-        return ((b & -b) * DeBruijn_64) >> 58;
-
-    // Use Matt Taylor's folding trick for 32 bit systems
+    // Matt Taylor's folding for 32 bit systems, extended to 64 bits by Kim Walisch
     b ^= (b - 1);
-    return ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn_32) >> 26;
+    return Is64Bit ? (b * DeBruijn_64) >> 58
+                   : ((unsigned(b) ^ unsigned(b >> 32)) * DeBruijn_32) >> 26;
   }
 }