]> git.sesse.net Git - stockfish/blobdiff - src/bitboard.cpp
Implement PEXT based attacks
[stockfish] / src / bitboard.cpp
index bfacc4121a0312b2d2461239008344c940c3857f..b7fce20d9206a4fdab6716ef7158b08e27a5b12f 100644 (file)
@@ -79,6 +79,23 @@ namespace {
   }
 }
 
+
+/// Intel PEXT (parallel extraction) software implementation
+Bitboard pext(Bitboard b, Bitboard mask) {
+
+  Bitboard res = 0;
+
+  for (Bitboard bb = 1; mask; bb += bb)
+  {
+      if (b & mask & -mask)
+          res |= bb;
+
+      mask &= mask - 1;
+  }
+  return res;
+}
+
+
 /// lsb()/msb() finds the least/most significant bit in a non-zero bitboard.
 /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard.
 
@@ -279,7 +296,12 @@ namespace {
         b = size = 0;
         do {
             occupancy[size] = b;
-            reference[size++] = sliding_attack(deltas, s, b);
+            reference[size] = sliding_attack(deltas, s, b);
+
+            if (HasPext)
+                attacks[s][pext(occupancy[size], masks[s])] = reference[size];
+
+            size++;
             b = (b - masks[s]) & masks[s];
         } while (b);
 
@@ -288,6 +310,9 @@ namespace {
         if (s < SQ_H8)
             attacks[s + 1] = attacks[s] + size;
 
+        if (HasPext)
+            continue;
+
         booster = MagicBoosters[Is64Bit][rank_of(s)];
 
         // Find a magic for square 's' picking up an (almost) random number