X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fbitboard.cpp;h=82608eab4f1ba1e937dc4dd56b29a73b5b2a6e20;hp=dd5b57995056a356b0b2235253596e6e8bd7325b;hb=c2cd75843eb0b6a29ce291fc3ac041b5a082afbc;hpb=189b6fc270f91f4111c1a8049c97455093f8be97 diff --git a/src/bitboard.cpp b/src/bitboard.cpp index dd5b5799..82608eab 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -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; } }