Skip to content

Commit b9aa732

Browse files
committed
Remove dead code left from the NNUE accumulator merge
After merging the HalfKA and Threats accumulators (7c7fe32) and the subsequent removal of the double-incremental/fused update, a number of NNUE helpers and fields became unreachable. Each was verified to have zero callers/readers across the source tree: - FusedUpdateData logic in FullThreats: the fused-update branch of append_changed_indices and the FusedUpdateData parameter are unused; the accumulator update no longer passes fused data. - FullThreats::requires_refresh: never called. The live king-bucket refresh check is HalfKAv2_hm::requires_refresh (PSQFeatureSet), used in nnue_accumulator. - HalfKAv2_hm::append_active_indices: never called. The live active-index builder is FullThreats::append_active_indices (ThreatFeatureSet). - DirtyThreats::us, prevKsq and ksq: written in do_move but only read by the now-removed FullThreats::requires_refresh. Removing them also drops three stores from the do_move path. - Unused feature Name constants and the unused FtOneVal / HiddenMaxVal constants in nnue_common.h. - Two stale feature-header banner comments. No functional change
1 parent 86f1df7 commit b9aa732

8 files changed

Lines changed: 8 additions & 89 deletions

File tree

src/nnue/features/full_threats.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ void FullThreats::append_changed_indices(Color perspective,
275275
const DiffType& diff,
276276
IndexList& removed,
277277
IndexList& added,
278-
FusedUpdateData* fusedData,
279-
bool first,
280278
const ThreatWeightType* prefetchBase,
281279
IndexType prefetchStride) {
282280

@@ -288,36 +286,6 @@ void FullThreats::append_changed_indices(Color perspective,
288286
auto to = dirty.threatened_sq();
289287
auto add = dirty.add();
290288

291-
if (fusedData)
292-
{
293-
if (from == fusedData->dp2removed)
294-
{
295-
if (add)
296-
{
297-
if (first)
298-
{
299-
fusedData->dp2removedOriginBoard |= to;
300-
continue;
301-
}
302-
}
303-
else if (fusedData->dp2removedOriginBoard & to)
304-
continue;
305-
}
306-
else if (to != SQ_NONE && to == fusedData->dp2removed)
307-
{
308-
if (add)
309-
{
310-
if (first)
311-
{
312-
fusedData->dp2removedTargetBoard |= from;
313-
continue;
314-
}
315-
}
316-
else if (fusedData->dp2removedTargetBoard & from)
317-
continue;
318-
}
319-
}
320-
321289
auto& insert = add ? added : removed;
322290
const IndexType index = make_index(perspective, attacker, from, to, attacked, ksq);
323291

@@ -328,8 +296,4 @@ void FullThreats::append_changed_indices(Color perspective,
328296
}
329297
}
330298

331-
bool FullThreats::requires_refresh(const DiffType& diff, Color perspective) {
332-
return perspective == diff.us && (i8(diff.ksq) & 0b100) != (i8(diff.prevKsq) & 0b100);
333-
}
334-
335299
} // namespace Stockfish::Eval::NNUE::Features

src/nnue/features/full_threats.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
along with this program. If not, see <http://www.gnu.org/licenses/>.
1414
*/
1515

16-
//Definition of input features Simplified_Threats of NNUE evaluation function
16+
//Definition of input features Full_Threats of NNUE evaluation function
1717

1818
#ifndef NNUE_FEATURES_FULL_THREATS_INCLUDED
1919
#define NNUE_FEATURES_FULL_THREATS_INCLUDED
@@ -34,9 +34,6 @@ static constexpr int numValidTargets[PIECE_NB] = {0, 6, 10, 8, 8, 10, 0, 0,
3434

3535
class FullThreats {
3636
public:
37-
// Feature name
38-
static constexpr const char* Name = "Full_Threats(Friend)";
39-
4037
// Hash value embedded in the evaluation file
4138
static constexpr u32 HashValue = 0x8f234cb8u;
4239

@@ -66,13 +63,6 @@ class FullThreats {
6663
};
6764
// clang-format on
6865

69-
struct FusedUpdateData {
70-
Bitboard dp2removedOriginBoard = 0;
71-
Bitboard dp2removedTargetBoard = 0;
72-
73-
Square dp2removed;
74-
};
75-
7666
// Maximum number of simultaneously active features.
7767
static constexpr IndexType MaxActiveDimensions = 128;
7868
using IndexList = ValueList<IndexType, MaxActiveDimensions>;
@@ -90,14 +80,8 @@ class FullThreats {
9080
const DiffType& diff,
9181
IndexList& removed,
9282
IndexList& added,
93-
FusedUpdateData* fd = nullptr,
94-
bool first = false,
9583
const ThreatWeightType* prefetchBase = nullptr,
9684
IndexType prefetchStride = 0);
97-
98-
// Returns whether the change stored in this DirtyPiece means
99-
// that a full accumulator refresh is required.
100-
static bool requires_refresh(const DiffType& diff, Color perspective);
10185
};
10286

10387
} // namespace Stockfish::Eval::NNUE::Features

src/nnue/features/half_ka_v2_hm.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020

2121
#include "half_ka_v2_hm.h"
2222

23-
#include "../../bitboard.h"
24-
#include "../../position.h"
2523
#include "../../types.h"
2624
#include "../nnue_common.h"
2725

26+
#if defined(USE_AVX512ICL)
27+
#include "../../bitboard.h"
28+
#endif
29+
2830
namespace Stockfish::Eval::NNUE::Features {
2931

3032
#if defined(USE_AVX512ICL)
@@ -91,18 +93,6 @@ IndexType HalfKAv2_hm::make_index(Color perspective, Square s, Piece pc, Square
9193
+ KingBuckets[int(ksq) ^ flip];
9294
}
9395

94-
// Get a list of indices for active features
95-
96-
void HalfKAv2_hm::append_active_indices(Color perspective, const Position& pos, IndexList& active) {
97-
Square ksq = pos.square<KING>(perspective);
98-
Bitboard bb = pos.pieces();
99-
while (bb)
100-
{
101-
Square s = pop_lsb(bb);
102-
active.push_back(make_index(perspective, s, pos.piece_on(s), ksq));
103-
}
104-
}
105-
10696
// Get a list of indices for recently changed features
10797

10898
void HalfKAv2_hm::append_changed_indices(

src/nnue/features/half_ka_v2_hm.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
//Definition of input features HalfKP of NNUE evaluation function
19+
//Definition of input features HalfKAv2_hm of NNUE evaluation function
2020

2121
#ifndef NNUE_FEATURES_HALF_KA_V2_HM_H_INCLUDED
2222
#define NNUE_FEATURES_HALF_KA_V2_HM_H_INCLUDED
@@ -25,10 +25,6 @@
2525
#include "../../types.h"
2626
#include "../nnue_common.h"
2727

28-
namespace Stockfish {
29-
class Position;
30-
}
31-
3228
namespace Stockfish::Eval::NNUE::Features {
3329

3430
// Feature HalfKAv2_hm: Combination of the position of own king and the
@@ -61,9 +57,6 @@ class HalfKAv2_hm {
6157
PS_NONE, PS_W_PAWN, PS_W_KNIGHT, PS_W_BISHOP, PS_W_ROOK, PS_W_QUEEN, PS_KING, PS_NONE}};
6258

6359
public:
64-
// Feature name
65-
static constexpr const char* Name = "HalfKAv2_hm(Friend)";
66-
6760
// Hash value embedded in the evaluation file
6861
static constexpr u32 HashValue = 0x7f234cb8u;
6962

@@ -120,10 +113,6 @@ class HalfKAv2_hm {
120113

121114
static IndexType make_index(Color perspective, Square s, Piece pc, Square ksq);
122115

123-
// Get a list of indices for active features
124-
125-
static void append_active_indices(Color perspective, const Position& pos, IndexList& active);
126-
127116
// Get a list of indices for recently changed features
128117
static void append_changed_indices(
129118
Color perspective, Square ksq, const DiffType& diff, IndexList& removed, IndexList& added);

src/nnue/nnue_accumulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ void update_accumulator_incremental(Color perspective,
358358
if constexpr (Forward)
359359
{
360360
ThreatFeatureSet::append_changed_indices(perspective, ksq, dirtyThreats, thrRemoved,
361-
thrAdded, nullptr, false, pfBase, pfStride);
361+
thrAdded, pfBase, pfStride);
362362
PSQFeatureSet::append_changed_indices(perspective, ksq, dirtyPiece, psqRemoved, psqAdded);
363363
}
364364
else
365365
{
366366
ThreatFeatureSet::append_changed_indices(perspective, ksq, dirtyThreats, thrAdded,
367-
thrRemoved, nullptr, false, pfBase, pfStride);
367+
thrRemoved, pfBase, pfStride);
368368
PSQFeatureSet::append_changed_indices(perspective, ksq, dirtyPiece, psqAdded, psqRemoved);
369369
}
370370

src/nnue/nnue_common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ constexpr u32 Version = 0x6A448AFAu;
6767
// Constant used in evaluation value calculation
6868
constexpr int OutputScale = 16;
6969
constexpr int WeightScaleBits = 6;
70-
constexpr int FtOneVal = 256;
7170
constexpr int FtMaxVal = 255;
7271
constexpr int HiddenOneVal = 128;
73-
constexpr int HiddenMaxVal = 127;
7472

7573
// Size of cache line (in bytes)
7674
constexpr usize CacheLineSize = 64;

src/position.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,6 @@ void Position::do_move(Move m,
866866
dp.from = from;
867867
dp.to = to;
868868
dp.add_sq = SQ_NONE;
869-
dts.us = us;
870-
dts.prevKsq = square<KING>(us);
871869

872870
assert(color_of(pc) == us);
873871
assert(captured == NO_PIECE || color_of(captured) == (m.type_of() != CASTLING ? them : us));
@@ -1080,8 +1078,6 @@ void Position::do_move(Move m,
10801078
}
10811079
}
10821080

1083-
dts.ksq = square<KING>(us);
1084-
10851081
assert(pos_is_ok());
10861082

10871083
assert(dp.pc != NO_PIECE);

src/types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ using DirtyThreatList = ValueList<DirtyThreat, 96>;
339339

340340
struct DirtyThreats {
341341
DirtyThreatList list;
342-
Color us;
343-
Square prevKsq, ksq;
344342
};
345343

346344
#define ENABLE_INCR_OPERATORS_ON(T) \

0 commit comments

Comments
 (0)