Simplify out pext attacks

Passed STC non-regression on avx512icl (https://tests.stockfishchess.org/tests/view/6a421b46f97ff95f78795061)
LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 81632 W: 21240 L: 21075 D: 39317
Ptnml(0-2): 184, 8907, 22464, 9082, 179

Passed STC non-regression on bmi2 (https://tests.stockfishchess.org/tests/view/6a41f6f9f97ff95f7879503e)
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 78112 W: 20411 L: 20245 D: 37456
Ptnml(0-2): 188, 8449, 21632, 8583, 204

After #6845 , pext attacks are slower or equal to parallel-hyperbola attacks which works on all architectures that pext supports. SVE2 supports pext/pdep in vector registers, but it's much slower than the `rbit`-based HQ that we have on ARM, so I don't foresee the code being useful there.

Ofc I don't think we should remove the `bmi2` build or anything, because it's nice for people to be able to freely use pext when testing ideas, and I'm sure we'll some day find another use for it!

closes https://github.com/official-stockfish/Stockfish/pull/6939

No functional change

Co-authored-by: Dubslow <bunslow@gmail.com>
This commit is contained in:
anematode
2026-07-03 20:27:33 +02:00
committed by Joost VandeVondele
co-authored by Dubslow
parent 46428b9346
commit 99489f57dd
3 changed files with 18 additions and 171 deletions
+3 -17
View File
@@ -31,7 +31,7 @@
#define USE_HYPERBOLA_QUINT
#elif defined(__loongarch__) && __loongarch_grlen == 64
#define USE_HYPERBOLA_QUINT
#elif defined(USE_AVX2) && !defined(USE_PEXT)
#elif defined(USE_AVX2)
#include <immintrin.h>
#define USE_DUAL_HYPERBOLA_QUINT
#endif
@@ -75,7 +75,7 @@ const Magic& magic(Square s, PieceType pt);
#elif defined(USE_DUAL_HYPERBOLA_QUINT)
struct DualMagic {
struct alignas(32) DualMagic {
// file, diagonal, unused, antidiagonal
Bitboard maskFile, maskDiag, maskNone, maskAntidiag;
// Precomputed 2 * square_bb(sq), 2 * reverse(square_bb(sq))
@@ -128,37 +128,23 @@ const DualMagic& dual_magic(Square s);
#else
// Magic holds all magic bitboards relevant data for a single square
struct Magic {
Bitboard mask;
#ifdef USE_PEXT
u16* attacks;
Bitboard pseudoAttacks;
#else
Bitboard mask;
Bitboard* attacks;
Bitboard magic;
unsigned shift;
#endif
// Compute the attack's index using the 'magic bitboards' approach
unsigned index(Bitboard occupied) const {
#ifdef USE_PEXT
return unsigned(pext(occupied, mask));
#else
if (Is64Bit)
return unsigned(((occupied & mask) * magic) >> shift);
unsigned lo = unsigned(occupied) & unsigned(mask);
unsigned hi = unsigned(occupied >> 32) & unsigned(mask >> 32);
return (lo * unsigned(magic) ^ hi * unsigned(magic >> 32)) >> shift;
#endif
}
Bitboard attacks_bb([[maybe_unused]] Square s, Bitboard occupied) const {
#ifdef USE_PEXT
return pdep(attacks[index(occupied)], pseudoAttacks);
#else
return attacks[index(occupied)];
#endif
}
};