Skip to content

Commit f4d7770

Browse files
committed
Don't waste time copying the accum after a NULL move
Purely a speedup in practice. ELO | 2.30 +- 1.85 (95%) SPRT | 10.0+0.10s Threads=1 Hash=8MB LLR | 2.97 (-2.94, 2.94) [0.00, 3.00] GAMES | N: 66512 W: 16514 L: 16074 D: 33924 http://chess.grantnet.us/test/31799/ NO FUNCTIONAL CHANGE BENCH : 3,349,466
1 parent bb87549 commit f4d7770

7 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/move.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,6 @@ void applyNullMove(Board *board, Undo *undo) {
379379
}
380380

381381
board->threats = allAttackedSquares(board, !board->turn);
382-
383-
nnue_push(board);
384382
}
385383

386384

@@ -412,6 +410,9 @@ void revertMove(Board *board, uint16_t move, Undo *undo) {
412410
board->numMoves--;
413411
board->fullMoveCounter--;
414412

413+
// Update Accumulator pointer
414+
nnue_pop(board);
415+
415416
if (MoveType(move) == NORMAL_MOVE) {
416417

417418
const int fromType = pieceType(board->squares[to]);

src/nnue/accumulator.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ void nnue_update_accumulator(NNUEAccumulator *accum, Board *board, int colour, i
132132
if (!(accum-1)->accurate[colour])
133133
nnue_update_accumulator((accum-1), board, colour, relksq);
134134

135-
// The last move was a NULL move so we can cheat and copy
136-
if (!accum->changes) {
137-
memcpy(&accum->values[colour], &(accum-1)->values[colour], sizeof(int16_t) * KPSIZE);
138-
accum->accurate[colour] = TRUE;
139-
return;
140-
}
141-
142135
// Determine the features that have changed, by looping through them
143136
for (NNUEDelta *x = &accum->deltas[0]; x < &accum->deltas[0] + accum->changes; x++) {
144137

src/nnue/accumulator.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@ INLINE void nnue_delete_accumulators(NNUEAccumulator* ptr) {
3535
align_free(ptr);
3636
}
3737

38+
INLINE void nnue_pop(Board *board) {
39+
if (USE_NNUE && board->thread != NULL)
40+
--board->thread->nnuePointer;
41+
}
42+
3843
INLINE void nnue_push(Board *board) {
3944
if (USE_NNUE && board->thread != NULL) {
40-
const int height = board->thread->height;
41-
NNUEAccumulator *accum = &board->thread->nnueStack[height+1];
45+
NNUEAccumulator *accum = ++board->thread->nnuePointer;
4246
accum->accurate[WHITE] = accum->accurate[BLACK] = FALSE;
4347
accum->changes = 0;
4448
}
4549
}
4650

4751
INLINE void nnue_move_piece(Board *board, int piece, int from, int to) {
4852
if (USE_NNUE && board->thread != NULL) {
49-
const int height = board->thread->height;
50-
NNUEAccumulator *accum = &board->thread->nnueStack[height+1];
53+
NNUEAccumulator *accum = board->thread->nnuePointer;
5154
accum->deltas[accum->changes++] = (NNUEDelta) { piece, from, to };
5255
}
5356
}

src/nnue/nnue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ int nnue_evaluate(Thread *thread, Board *board) {
481481
ALIGN64 float outN1[L1SIZE];
482482
ALIGN64 float outN2[L1SIZE];
483483

484-
NNUEAccumulator *accum = &thread->nnueStack[thread->height];
484+
NNUEAccumulator *accum = thread->nnuePointer;
485485

486486
if (!accum->accurate[WHITE]) {
487487

src/thread.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void newSearchThreadPool(Thread *threads, Board *board, Limits *limits, TimeMana
102102

103103
threads[i].nnueStack[0].accurate[WHITE] = 0;
104104
threads[i].nnueStack[0].accurate[BLACK] = 0;
105+
threads[i].nnuePointer = &threads[i].nnueStack[0];
105106

106107
memset(threads[i].nodeStates, 0, sizeof(NodeState) * STACK_SIZE);
107108
}

src/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct Thread {
6565
int depth, seldepth, height, completed;
6666

6767
NodeState *states, nodeStates[STACK_SIZE];
68-
NNUEAccumulator *nnueStack;
68+
NNUEAccumulator *nnueStack, *nnuePointer;
6969
Undo undoStack[STACK_SIZE];
7070

7171
ALIGN64 PKTable pktable;

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.08"
25+
#define VERSION_ID "14.09"
2626

2727
#ifndef LICENSE_OWNER
2828
#define LICENSE_OWNER "Unlicensed"

0 commit comments

Comments
 (0)