From: Marco Costalba Date: Mon, 7 Apr 2014 19:04:34 +0000 (+0200) Subject: Switch to hardware PEXT X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=da2f8880b96004505e27b0b87f5df5bfe67a72a9 Switch to hardware PEXT 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. --- diff --git a/src/bitboard.cpp b/src/bitboard.cpp index b7fce20d..d4b433fc 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -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. @@ -299,7 +282,7 @@ namespace { 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]; diff --git a/src/bitboard.h b/src/bitboard.h index cd6c280c..98142683 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -23,8 +23,6 @@ #include "types.h" -extern Bitboard pext(Bitboard b, Bitboard mask); - 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) - return unsigned(pext(occ, Masks[s])); + return unsigned(_pext_u64(occ, Masks[s])); if (Is64Bit) return unsigned(((occ & Masks[s]) * Magics[s]) >> Shifts[s]); diff --git a/src/types.h b/src/types.h index 5dcfe51e..eea7d264 100644 --- a/src/types.h +++ b/src/types.h @@ -54,6 +54,12 @@ # include // Intel header for _mm_popcnt_u64() intrinsic #endif +#if defined(USE_PEXT) +# include // 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 // Intel and Microsoft header for _mm_prefetch() # endif