From b3a810a1c4201059bb97f6917df3276c03167a50 Mon Sep 17 00:00:00 2001 From: anematode Date: Sat, 7 Mar 2026 07:48:15 -0800 Subject: [PATCH] Fix avx512icl update_piece_threats bug Thanks to MinetaS for discovering this and finding the culprit commit, specific to this architecture. 9f42980 was subtly incorrect, leading to spurious wrong benches on avx512icl. Because this piece of code has twice been the source of wrong benches, I also added a brief comment explaining why it needs to be this way, and added a sample position to bench. closes https://github.com/official-stockfish/Stockfish/pull/6654 Bench: 2288704 --- src/benchmark.cpp | 1 + src/position.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/benchmark.cpp b/src/benchmark.cpp index 4e266db89..03bf10ae1 100644 --- a/src/benchmark.cpp +++ b/src/benchmark.cpp @@ -64,6 +64,7 @@ const std::vector Defaults = { "r3k2r/3nnpbp/q2pp1p1/p7/Pp1PPPP1/4BNN1/1P5P/R2Q1RK1 w kq - 0 16", "3Qb1k1/1r2ppb1/pN1n2q1/Pp1Pp1Pr/4P2p/4BP2/4B1R1/1R5K b - - 11 40", "4k3/3q1r2/1N2r1b1/3ppN2/2nPP3/1B1R2n1/2R1Q3/3K4 w - - 5 1", + "1r6/1P4bk/3qr1p1/N6p/3pp2P/6R1/3Q1PP1/1R4K1 w - - 1 42", // Positions with high numbers of changed threats "k7/2n1n3/1nbNbn2/2NbRBn1/1nbRQR2/2NBRBN1/3N1N2/7K w - - 0 1", diff --git a/src/position.cpp b/src/position.cpp index 3b7b197ff..daadf59ec 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1131,7 +1131,9 @@ void Position::update_piece_threats(Piece pc, if constexpr (PutPiece) { dts->threatenedSqs |= threatened; - dts->threateningSqs |= s; + // A bit may only be set if that square actually produces a threat, so we + // must guard setting the square accordingly + dts->threateningSqs |= Bitboard(bool(threatened)) << s; } DirtyThreat dt_template{pc, NO_PIECE, s, Square(0), PutPiece}; @@ -1142,7 +1144,7 @@ void Position::update_piece_threats(Piece pc, if constexpr (PutPiece) { - dts->threatenedSqs |= s; + dts->threatenedSqs |= Bitboard(bool(all_attackers)) << s; // same as above dts->threateningSqs |= all_attackers; }