refactor update_piece_threats to reduce branching

Passed STC Non-Regression:
https://tests.stockfishchess.org/tests/view/696f1a398b64097dacd231c3
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 122272 W: 31587 L: 31466 D: 59219
Ptnml(0-2): 301, 13358, 33750, 13373, 354

slight speedup as well:

1 thread bench:
sf_base =  2238429 +/-   1221 (95%)
sf_test =  2248298 +/-   1371 (95%)
diff    =     9869 +/-   1571 (95%)
speedup = 0.44090% +/- 0.070% (95%)

32 thread speedtest:
sf_base = 41016996 +/-  83654 (95%)
sf_test = 41185801 +/-  84269 (95%)
diff    =   168805 +/-  79986 (95%)
speedup = 0.41155% +/- 0.195% (95%)

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

No functional change
This commit is contained in:
KazApps
2026-02-04 18:09:00 +01:00
committed by Joost VandeVondele
parent 9cc2985f51
commit 9f42980dd2
+5 -10
View File
@@ -1069,8 +1069,8 @@ inline void add_dirty_threat(
DirtyThreats* const dts, Piece pc, Piece threatened, Square s, Square threatenedSq) {
if (PutPiece)
{
dts->threatenedSqs |= square_bb(threatenedSq);
dts->threateningSqs |= square_bb(s);
dts->threatenedSqs |= threatenedSq;
dts->threateningSqs |= s;
}
dts->list.push_back({pc, threatened, s, threatenedSq, PutPiece});
@@ -1139,30 +1139,25 @@ void Position::update_piece_threats(Piece pc,
| (attacks_bb<PAWN>(s, BLACK) & whitePawns) | (PseudoAttacks[KING][s] & kings);
#ifdef USE_AVX512ICL
if (threatened)
{
if constexpr (PutPiece)
{
dts->threatenedSqs |= threatened;
dts->threateningSqs |= square_bb(s);
dts->threateningSqs |= s;
}
DirtyThreat dt_template{pc, NO_PIECE, s, Square(0), PutPiece};
write_multiple_dirties<DirtyThreat::ThreatenedSqOffset, DirtyThreat::ThreatenedPcOffset>(
*this, threatened, dt_template, dts);
}
Bitboard all_attackers = sliders | incoming_threats;
if (!all_attackers)
return; // Square s is threatened iff there's at least one attacker
if constexpr (PutPiece)
{
dts->threatenedSqs |= square_bb(s);
dts->threatenedSqs |= s;
dts->threateningSqs |= all_attackers;
}
DirtyThreat dt_template{NO_PIECE, pc, Square(0), s, PutPiece};
dt_template = {NO_PIECE, pc, Square(0), s, PutPiece};
write_multiple_dirties<DirtyThreat::PcSqOffset, DirtyThreat::PcOffset>(*this, all_attackers,
dt_template, dts);
#else