mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
speed up update_piece_threats after SFNNv12
with the removal of all king-related threats in SFNNv12 we can avoid some work in update_piece_threats STC for anematode's swan: https://tests.stockfishchess.org/tests/view/6986b920b0f3ca5200aaf80a LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 262880 W: 68379 L: 67747 D: 126754 Ptnml(0-2): 808, 29001, 71223, 29567, 841 STC of further speedups on top of swan: https://tests.stockfishchess.org/tests/view/698d7f8362a8f472da3a8a35 LLR: 2.93 (-2.94,2.94) <0.00,2.00> Total: 65920 W: 17126 L: 16781 D: 32013 Ptnml(0-2): 186, 7084, 18105, 7369, 216 closes https://github.com/official-stockfish/Stockfish/pull/6614 No functional change Co-Authored-By: Timothy Herchen <timothy.herchen@gmail.com>
This commit is contained in:
committed by
Joost VandeVondele
co-authored by
Timothy Herchen
parent
e6d04b4ec5
commit
cf559b2c17
+44
-27
@@ -1072,7 +1072,7 @@ void write_multiple_dirties(const Position& p,
|
||||
|
||||
const __m512i dirties =
|
||||
_mm512_ternarylogic_epi32(template_v, threat_squares, threat_pieces, 254 /* A | B | C */);
|
||||
_mm512_storeu_si512(reinterpret_cast<__m512i*>(write), dirties);
|
||||
_mm512_storeu_si512(write, dirties);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1084,16 +1084,48 @@ void Position::update_piece_threats(Piece pc,
|
||||
const Bitboard occupied = pieces();
|
||||
const Bitboard rookQueens = pieces(ROOK, QUEEN);
|
||||
const Bitboard bishopQueens = pieces(BISHOP, QUEEN);
|
||||
const Bitboard knights = pieces(KNIGHT);
|
||||
const Bitboard rAttacks = attacks_bb<ROOK>(s, occupied);
|
||||
const Bitboard bAttacks = attacks_bb<BISHOP>(s, occupied);
|
||||
const Bitboard kings = pieces(KING);
|
||||
const Bitboard whitePawns = pieces(WHITE, PAWN);
|
||||
const Bitboard blackPawns = pieces(BLACK, PAWN);
|
||||
Bitboard occupiedNoK = occupied ^ kings;
|
||||
|
||||
const Bitboard rAttacks = attacks_bb<ROOK>(s, occupied);
|
||||
const Bitboard bAttacks = attacks_bb<BISHOP>(s, occupied);
|
||||
Bitboard sliders = (rookQueens & rAttacks) | (bishopQueens & bAttacks);
|
||||
auto process_sliders = [&](bool addDirectAttacks) {
|
||||
while (sliders)
|
||||
{
|
||||
Square sliderSq = pop_lsb(sliders);
|
||||
Piece slider = piece_on(sliderSq);
|
||||
|
||||
Bitboard threatened = attacks_bb(pc, s, occupied) & occupied;
|
||||
Bitboard sliders = (rookQueens & rAttacks) | (bishopQueens & bAttacks);
|
||||
const Bitboard ray = RayPassBB[sliderSq][s];
|
||||
const Bitboard discovered = ray & (rAttacks | bAttacks) & occupiedNoK;
|
||||
|
||||
assert(!more_than_one(discovered));
|
||||
if (discovered && (RayPassBB[sliderSq][s] & noRaysContaining) != noRaysContaining)
|
||||
{
|
||||
const Square threatenedSq = lsb(discovered);
|
||||
const Piece threatenedPc = piece_on(threatenedSq);
|
||||
add_dirty_threat<!PutPiece>(dts, slider, threatenedPc, sliderSq, threatenedSq);
|
||||
}
|
||||
|
||||
if (addDirectAttacks)
|
||||
add_dirty_threat<PutPiece>(dts, slider, pc, sliderSq, s);
|
||||
}
|
||||
};
|
||||
|
||||
if (type_of(pc) == KING)
|
||||
{
|
||||
if constexpr (ComputeRay)
|
||||
process_sliders(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const Bitboard knights = pieces(KNIGHT);
|
||||
const Bitboard whitePawns = pieces(WHITE, PAWN);
|
||||
const Bitboard blackPawns = pieces(BLACK, PAWN);
|
||||
|
||||
|
||||
Bitboard threatened = attacks_bb(pc, s, occupied) & occupiedNoK;
|
||||
Bitboard incoming_threats =
|
||||
(PseudoAttacks[KNIGHT][s] & knights) | (attacks_bb<PAWN>(s, WHITE) & blackPawns)
|
||||
| (attacks_bb<PAWN>(s, BLACK) & whitePawns) | (PseudoAttacks[KING][s] & kings);
|
||||
@@ -1135,26 +1167,11 @@ void Position::update_piece_threats(Piece pc,
|
||||
|
||||
if constexpr (ComputeRay)
|
||||
{
|
||||
while (sliders)
|
||||
{
|
||||
Square sliderSq = pop_lsb(sliders);
|
||||
Piece slider = piece_on(sliderSq);
|
||||
|
||||
const Bitboard ray = RayPassBB[sliderSq][s] & ~BetweenBB[sliderSq][s];
|
||||
const Bitboard discovered = ray & (rAttacks | bAttacks) & occupied;
|
||||
|
||||
assert(!more_than_one(discovered));
|
||||
if (discovered && (RayPassBB[sliderSq][s] & noRaysContaining) != noRaysContaining)
|
||||
{
|
||||
const Square threatenedSq = lsb(discovered);
|
||||
const Piece threatenedPc = piece_on(threatenedSq);
|
||||
add_dirty_threat<!PutPiece>(dts, slider, threatenedPc, sliderSq, threatenedSq);
|
||||
}
|
||||
|
||||
#ifndef USE_AVX512ICL // for ICL, direct threats were processed earlier (all_attackers)
|
||||
add_dirty_threat<PutPiece>(dts, slider, pc, sliderSq, s);
|
||||
#ifndef USE_AVX512ICL
|
||||
process_sliders(true);
|
||||
#else // for ICL, direct threats were processed earlier (all_attackers)
|
||||
process_sliders(false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user