From 2e46f0d1cd23b716071a131938cf0fbbb428b839 Mon Sep 17 00:00:00 2001 From: rektdie Date: Fri, 7 Nov 2025 10:55:31 +0100 Subject: [PATCH] a bit more efficient accumulator updating | bench 4699541 --- source/accumulator.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/source/accumulator.cpp b/source/accumulator.cpp index 70f894d..0461d78 100644 --- a/source/accumulator.cpp +++ b/source/accumulator.cpp @@ -26,11 +26,11 @@ void AccumulatorPair::addSub(bool stm, int add, int addPT, int sub, int subPT) { int subB = CalculateIndex(Black, stm, subPT, sub, mirroredBlack); for (int i = 0; i < NNUE::HL_SIZE; i++) { - white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i]; - black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i]; - - white[i] -= NNUE::net.accumulator_weights[subW * NNUE::HL_SIZE + i]; - black[i] -= NNUE::net.accumulator_weights[subB * NNUE::HL_SIZE + i]; + white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subW * NNUE::HL_SIZE + i]; + + black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subB * NNUE::HL_SIZE + i]; } } @@ -46,14 +46,13 @@ void AccumulatorPair::addSubSub(bool stm, int add, int addPT, int sub1, int subP int subB2 = CalculateIndex(Black, !stm, subPT2, sub2, mirroredBlack); for (int i = 0; i < NNUE::HL_SIZE; i++) { - white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i]; - black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i]; + white[i] += NNUE::net.accumulator_weights[addW * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i]; - white[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i]; - black[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i]; - - white[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i]; - black[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i]; + black[i] += NNUE::net.accumulator_weights[addB * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i]; } } @@ -72,17 +71,15 @@ void AccumulatorPair::addAddSubSub(bool stm, int add1, int addPT1, int add2, int int subB2 = CalculateIndex(Black, stm, subPT2, sub2, mirroredBlack); for (int i = 0; i < NNUE::HL_SIZE; i++) { - white[i] += NNUE::net.accumulator_weights[addW1 * NNUE::HL_SIZE + i]; - black[i] += NNUE::net.accumulator_weights[addB1 * NNUE::HL_SIZE + i]; + white[i] += NNUE::net.accumulator_weights[addW1 * NNUE::HL_SIZE + i] + + NNUE::net.accumulator_weights[addW2 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i]; - white[i] += NNUE::net.accumulator_weights[addW2 * NNUE::HL_SIZE + i]; - black[i] += NNUE::net.accumulator_weights[addB2 * NNUE::HL_SIZE + i]; - - white[i] -= NNUE::net.accumulator_weights[subW1 * NNUE::HL_SIZE + i]; - black[i] -= NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i]; - - white[i] -= NNUE::net.accumulator_weights[subW2 * NNUE::HL_SIZE + i]; - black[i] -= NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i]; + black[i] += NNUE::net.accumulator_weights[addB1 * NNUE::HL_SIZE + i] + + NNUE::net.accumulator_weights[addB2 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subB1 * NNUE::HL_SIZE + i] + - NNUE::net.accumulator_weights[subB2 * NNUE::HL_SIZE + i]; } }