From a98c3f687816348dd8d047dd9229171d23c1bfe8 Mon Sep 17 00:00:00 2001 From: Timothy Herchen Date: Mon, 1 Dec 2025 16:23:18 -0800 Subject: [PATCH] Small threat-related cleanups Remove a couple unused things, mark `noRaysContaining` as `[[maybe_unused]]` (suggested by Viz) to silence a warning on GCC 10, update a comment, and replace inline constants closes https://github.com/official-stockfish/Stockfish/pull/6460 No functional change --- src/nnue/nnue_accumulator.h | 1 - src/position.cpp | 8 ++++---- src/position.h | 2 +- src/types.h | 22 +++++++++------------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/nnue/nnue_accumulator.h b/src/nnue/nnue_accumulator.h index 69ab49632..1ccab5f2f 100644 --- a/src/nnue/nnue_accumulator.h +++ b/src/nnue/nnue_accumulator.h @@ -157,7 +157,6 @@ class AccumulatorStack { [[nodiscard]] const AccumulatorState& latest() const noexcept; void reset() noexcept; - void push(const DirtyBoardData& dirtyBoardData) noexcept; std::pair push() noexcept; void pop() noexcept; diff --git a/src/position.cpp b/src/position.cpp index 3125d1f7a..cd778011f 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1093,10 +1093,10 @@ void write_multiple_dirties(const Position& p, #endif template -void Position::update_piece_threats(Piece pc, - Square s, - DirtyThreats* const dts, - Bitboard noRaysContaining) { +void Position::update_piece_threats(Piece pc, + Square s, + DirtyThreats* const dts, + [[maybe_unused]] Bitboard noRaysContaining) const { const Bitboard occupied = pieces(); const Bitboard rookQueens = pieces(ROOK, QUEEN); const Bitboard bishopQueens = pieces(BISHOP, QUEEN); diff --git a/src/position.h b/src/position.h index 7a029ce18..e5d3f6d28 100644 --- a/src/position.h +++ b/src/position.h @@ -190,7 +190,7 @@ class Position { void update_piece_threats(Piece pc, Square s, DirtyThreats* const dts, - Bitboard noRaysContaining = -1ULL); + Bitboard noRaysContaining = -1ULL) const; void move_piece(Square from, Square to, DirtyThreats* const dts = nullptr); template void do_castling(Color us, diff --git a/src/types.h b/src/types.h index c6613f2f2..1bb8bd3cc 100644 --- a/src/types.h +++ b/src/types.h @@ -306,24 +306,25 @@ struct DirtyThreat { | (threatened_sq << ThreatenedSqOffset) | (pc_sq << PcSqOffset); } - Piece pc() const { return static_cast(data >> 20 & 0xf); } - Piece threatened_pc() const { return static_cast(data >> 16 & 0xf); } - Square threatened_sq() const { return static_cast(data >> 8 & 0xff); } - Square pc_sq() const { return static_cast(data & 0xff); } - bool add() const { return data >> 31; } + Piece pc() const { return static_cast(data >> PcOffset & 0xf); } + Piece threatened_pc() const { return static_cast(data >> ThreatenedPcOffset & 0xf); } + Square threatened_sq() const { return static_cast(data >> ThreatenedSqOffset & 0xff); } + Square pc_sq() const { return static_cast(data >> PcSqOffset & 0xff); } + bool add() const { return data >> 31; } uint32_t raw() const { return data; } private: uint32_t data; }; -using DirtyThreatList = ValueList; - // A piece can be involved in at most 8 outgoing attacks and 16 incoming attacks. // Moving a piece also can reveal at most 8 discovered attacks. // This implies that a non-castling move can change at most (8 + 16) * 3 + 8 = 80 features. // By similar logic, a castling move can change at most (5 + 1 + 3 + 9) * 2 = 36 features. -// Thus, 80 should work as an upper bound. +// Thus, 80 should work as an upper bound. Finally, 16 entries are added to accommodate +// unmasked vector stores near the end of the list. + +using DirtyThreatList = ValueList; struct DirtyThreats { DirtyThreatList list; @@ -333,11 +334,6 @@ struct DirtyThreats { Bitboard threatenedSqs, threateningSqs; }; -struct DirtyBoardData { - DirtyPiece dp; - DirtyThreats dts; -}; - #define ENABLE_INCR_OPERATORS_ON(T) \ constexpr T& operator++(T& d) { return d = T(int(d) + 1); } \ constexpr T& operator--(T& d) { return d = T(int(d) - 1); }