From b1983e465ad2ef1c8d88013eb8ff9136f40e971f Mon Sep 17 00:00:00 2001 From: xu-shawn <50402888+xu-shawn@users.noreply.github.com> Date: Tue, 24 Dec 2024 11:52:08 -0800 Subject: [PATCH] Speed up finny table refreshes (#500) Elo | 3.35 +- 2.30 (95%) SPRT | 4.0+0.04s Threads=1 Hash=16MB LLR | 2.91 (-2.25, 2.89) [0.00, 3.00] Games | N: 23658 W: 6190 L: 5962 D: 11506 Penta | [121, 2573, 6239, 2749, 147] Bench: 8476323 --- src/nnue.cpp | 13 ++++++++++++- src/types.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/nnue.cpp b/src/nnue.cpp index c598fd85..07bdbb76 100644 --- a/src/nnue.cpp +++ b/src/nnue.cpp @@ -138,6 +138,18 @@ void NNUE::Pov_Accumulator::refresh(Position *pos) { // figure out a diff for (int piece = WP; piece <= BK; piece++) { auto added = pos->bitboards[piece] & ~cachedEntry->occupancies[piece]; + auto removed = cachedEntry->occupancies[piece] & ~pos->bitboards[piece]; + while (added && removed) { + auto added_square = popLsb(added); + auto added_index = GetIndex(piece, added_square, kingSq, flip); + const auto Add = &net.FTWeights[added_index * L1_SIZE]; + auto removed_square = popLsb(removed); + auto removed_index = GetIndex(piece, removed_square, kingSq, flip); + const auto Sub = &net.FTWeights[removed_index * L1_SIZE]; + for (int i = 0; i < L1_SIZE; i++) { + this->values[i] = this->values[i] + Add[i] - Sub[i]; + } + } while (added) { auto square = popLsb(added); auto index = GetIndex(piece, square, kingSq, flip); @@ -146,7 +158,6 @@ void NNUE::Pov_Accumulator::refresh(Position *pos) { this->values[i] += Add[i]; } } - auto removed = cachedEntry->occupancies[piece] & ~pos->bitboards[piece]; while (removed) { auto square = popLsb(removed); auto index = GetIndex(piece, square, kingSq, flip); diff --git a/src/types.h b/src/types.h index e01f3179..fb40c4c2 100644 --- a/src/types.h +++ b/src/types.h @@ -4,7 +4,7 @@ // include the tune stuff here to give it global visibility #include "tune.h" -#define NAME "Alexandria-7.1.5" +#define NAME "Alexandria-7.1.6" inline int reductions[2][64][64]; inline int lmp_margin[64][2];