Skip to content

Commit 12b9b8e

Browse files
committed
Speedup and simplify nnue_can_update()
No test run on OpenBench, but appears to be a 10k-12k NPS gain. BENCH : 3,489,457
1 parent 4ff2f90 commit 12b9b8e

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/nnue/accumulator.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,23 @@ static int nnue_index(Board *board, int relksq, int colour, int sq) {
5858

5959
int nnue_can_update(NNUEAccumulator *accum, Board *board, int colour) {
6060

61-
const NNUEAccumulator *start = board->thread->nnueStack;
62-
63-
// We can't recurse to update if we are at the start, or if our King has moved.
64-
if ( (accum == start)
65-
|| (accum->changes && accum->deltas[0].piece == makePiece(KING, colour)))
66-
return 0;
67-
68-
// We can always update if our parent accum is accurate, without a King move
69-
if ((accum-1)->accurate[colour])
70-
return 1;
71-
72-
// Otherwise, search back through the tree to find an accurate accum
73-
while (accum != start) {
74-
75-
// We found it, so we can update the entire tree
76-
if (accum->accurate[colour])
77-
return 1;
61+
// Search back through the tree to find an accurate accum
62+
while (accum != board->thread->nnueStack) {
7863

7964
// A King move prevents the entire tree from being updated
8065
if ( accum->changes
8166
&& accum->deltas[0].piece == makePiece(KING, colour))
82-
return 0;
67+
return FALSE;
8368

69+
// Step back, since the root can't be accurate
8470
accum = accum - 1;
71+
72+
// We found it, so we can update the entire tree
73+
if (accum->accurate[colour])
74+
return TRUE;
8575
}
8676

87-
return 0;
77+
return FALSE;
8878
}
8979

9080
void nnue_refresh_accumulator(NNUEAccumulator *accum, Board *board, int colour, int relsq) {

src/uci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "types.h"
2424

25-
#define VERSION_ID "14.05"
25+
#define VERSION_ID "14.06"
2626

2727
#ifndef LICENSE_OWNER
2828
#define LICENSE_OWNER "Unlicensed"

0 commit comments

Comments
 (0)