]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.h
Generalize shift_bb() to handle double pushes
[stockfish] / src / bitboard.h
index 140867fa94a466272d55be020451b0eb8b012f77..888e96905469b1c907340a79beaca613d2b90c41 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "types.h"
 
-extern Bitboard pext(Bitboard b, Bitboard mask);
-
 namespace Bitboards {
 
 void init();
@@ -132,10 +130,9 @@ inline int rank_distance(Square s1, Square s2) {
 template<Square Delta>
 inline Bitboard shift_bb(Bitboard b) {
 
-  return  Delta == DELTA_N  ?  b             << 8 : Delta == DELTA_S  ?  b             >> 8
-        : Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
+  return  Delta == DELTA_NE ? (b & ~FileHBB) << 9 : Delta == DELTA_SE ? (b & ~FileHBB) >> 7
         : Delta == DELTA_NW ? (b & ~FileABB) << 7 : Delta == DELTA_SW ? (b & ~FileABB) >> 9
-        : 0;
+        : Delta > 0 ? b << Delta : b >> -Delta;
 }
 
 
@@ -243,6 +240,9 @@ FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) {
   Bitboard* const Magics = Pt == ROOK ? RMagics : BMagics;
   unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts;
 
+  if (HasPext)
+      return unsigned(_pext_u64(occ, Masks[s]));
+
   if (Is64Bit)
       return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]);