]> git.sesse.net Git - stockfish/commitdiff
Switch to hardware PEXT
authorMarco Costalba <mcostalba@gmail.com>
Mon, 7 Apr 2014 19:04:34 +0000 (21:04 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 12 Apr 2014 06:55:30 +0000 (08:55 +0200)
Retire software pext and introduce hardware
call when USE_PEXT is defined during compilation.

This is a full complete implementation of sliding
attacks using PEXT.

No functional change.

src/bitboard.cpp
src/bitboard.h
src/types.h

index b7fce20d9206a4fdab6716ef7158b08e27a5b12f..d4b433fcdc7e0e9e5756ccc75ed8696a7ab24dfd 100644 (file)
@@ -79,23 +79,6 @@ 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.
 
 /// 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.
 
@@ -299,7 +282,7 @@ namespace {
             reference[size] = sliding_attack(deltas, s, b);
 
             if (HasPext)
             reference[size] = sliding_attack(deltas, s, b);
 
             if (HasPext)
-                attacks[s][pext(occupancy[size], masks[s])] = reference[size];
+                attacks[s][_pext_u64(b, masks[s])] = reference[size];
 
             size++;
             b = (b - masks[s]) & masks[s];
 
             size++;
             b = (b - masks[s]) & masks[s];
index cd6c280c8c444d9e349c1895b4c792ef8325d77d..9814268327afdd9c269d728077d1f82770035c87 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "types.h"
 
 
 #include "types.h"
 
-extern Bitboard pext(Bitboard b, Bitboard mask);
-
 namespace Bitboards {
 
 void init();
 namespace Bitboards {
 
 void init();
@@ -244,7 +242,7 @@ FORCE_INLINE unsigned magic_index(Square s, Bitboard occ) {
   unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts;
 
   if (HasPext)
   unsigned* const Shifts = Pt == ROOK ? RShifts : BShifts;
 
   if (HasPext)
-      return unsigned(pext(occ, Masks[s]));
+      return unsigned(_pext_u64(occ, Masks[s]));
 
   if (Is64Bit)
       return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]);
 
   if (Is64Bit)
       return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]);
index 5dcfe51e82185884cfa610dc15df15b5df55b20e..eea7d26460e6ac7b88101713ae97081129d13337 100644 (file)
 #  include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
 #endif
 
 #  include <nmmintrin.h> // Intel header for _mm_popcnt_u64() intrinsic
 #endif
 
+#if defined(USE_PEXT)
+#  include <x86intrin.h> // Gcc header for _pext_u64() intrinsic
+#else
+#  define _pext_u64(b, m) (0)
+#endif
+
 #  if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
 #   include <xmmintrin.h> // Intel and Microsoft header for _mm_prefetch()
 #  endif
 #  if !defined(NO_PREFETCH) && (defined(__INTEL_COMPILER) || defined(_MSC_VER))
 #   include <xmmintrin.h> // Intel and Microsoft header for _mm_prefetch()
 #  endif