From aeb3bf33a9bbf6dd662e9e570accf56c57eafbd7 Mon Sep 17 00:00:00 2001 From: anematode Date: Wed, 31 Dec 2025 17:44:43 -0800 Subject: [PATCH] port get_changed_pieces to ARM NEON passed STC: LLR: 2.94 (-2.94,2.94) <0.00,2.00> Total: 71968 W: 18833 L: 18489 D: 34646 Ptnml(0-2): 192, 7310, 20643, 7640, 199 https://tests.stockfishchess.org/tests/view/69509e5c572093c1986d7a0a closes https://github.com/official-stockfish/Stockfish/pull/6512 No functional change --- src/nnue/nnue_accumulator.cpp | 12 ++++++++++++ src/search.cpp | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/nnue/nnue_accumulator.cpp b/src/nnue/nnue_accumulator.cpp index 763fb7a5e..338d291e8 100644 --- a/src/nnue/nnue_accumulator.cpp +++ b/src/nnue/nnue_accumulator.cpp @@ -645,6 +645,18 @@ Bitboard get_changed_pieces(const std::array& oldPieces, sameBB |= static_cast(equalMask) << i; } return ~sameBB; +#elif defined(USE_NEON) + uint8x16x4_t old_v = vld4q_u8(reinterpret_cast(oldPieces.data())); + uint8x16x4_t new_v = vld4q_u8(reinterpret_cast(newPieces.data())); + auto cmp = [=](const int i) { return vceqq_u8(old_v.val[i], new_v.val[i]); }; + + uint8x16_t cmp0_1 = vsriq_n_u8(cmp(1), cmp(0), 1); + uint8x16_t cmp2_3 = vsriq_n_u8(cmp(3), cmp(2), 1); + uint8x16_t merged = vsriq_n_u8(cmp2_3, cmp0_1, 2); + merged = vsriq_n_u8(merged, merged, 4); + uint8x8_t sameBB = vshrn_n_u16(vreinterpretq_u16_u8(merged), 4); + + return ~vget_lane_u64(vreinterpret_u64_u8(sameBB), 0); #else Bitboard changed = 0; diff --git a/src/search.cpp b/src/search.cpp index 05f9b47fa..a880a741f 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -65,7 +65,7 @@ using namespace Search; namespace { constexpr int SEARCHEDLIST_CAPACITY = 32; -constexpr int mainHistoryDefault = 68; +constexpr int mainHistoryDefault = 68; using SearchedList = ValueList; // (*Scalers): @@ -313,9 +313,10 @@ void Search::Worker::iterative_deepening() { lowPlyHistory.fill(97); - for (Color c: {WHITE, BLACK}) + for (Color c : {WHITE, BLACK}) for (int i = 0; i < UINT_16_HISTORY_SIZE; i++) - mainHistory[c][i] = (mainHistory[c][i] - mainHistoryDefault) * 3 / 4 + mainHistoryDefault; + mainHistory[c][i] = + (mainHistory[c][i] - mainHistoryDefault) * 3 / 4 + mainHistoryDefault; // Iterative deepening loop until requested to stop or the target depth is reached while (++rootDepth < MAX_PLY && !threads.stop