diff --git a/AUTHORS b/AUTHORS index 092980fe5..54c5f8a21 100644 --- a/AUTHORS +++ b/AUTHORS @@ -20,6 +20,7 @@ Alexander Kure Alexander Pagel (Lolligerhans) Alfredo Menezes (lonfom169) Ali AlZhrani (Cooffe) +AliceRoselia Andreas Jan van der Meulen (Andyson007) Andreas Matthies (Matthies) Andrei Vetrov (proukornew) @@ -57,8 +58,8 @@ Dale Weiler (graphitemaster) Daniel Axtens (daxtens) Daniel Dugovic (ddugovic) Daniel Monroe (Ergodice) +Daniel Samek (DanSamek) Dan Schmidt (dfannius) -DanSamek Dariusz Orzechowski (dorzechowski) David (dav1312) David Zar diff --git a/src/movepick.cpp b/src/movepick.cpp index 6ee5fad7c..11317f113 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -162,7 +162,6 @@ void MovePicker::score() { m.value += (*continuationHistory[1])[pc][to]; m.value += (*continuationHistory[2])[pc][to]; m.value += (*continuationHistory[3])[pc][to]; - m.value += (*continuationHistory[4])[pc][to] / 3; m.value += (*continuationHistory[5])[pc][to]; // bonus for checks diff --git a/src/nnue/network.cpp b/src/nnue/network.cpp index 1016aed10..7517cef27 100644 --- a/src/nnue/network.cpp +++ b/src/nnue/network.cpp @@ -220,13 +220,13 @@ Network::evaluate(const Position& pos #if defined(ALIGNAS_ON_STACK_VARIABLES_BROKEN) TransformedFeatureType - transformedFeaturesUnaligned[FeatureTransformer::BufferSize + transformedFeaturesUnaligned[FeatureTransformer::BufferSize + alignment / sizeof(TransformedFeatureType)]; auto* transformedFeatures = align_ptr_up(&transformedFeaturesUnaligned[0]); #else - alignas(alignment) TransformedFeatureType - transformedFeatures[FeatureTransformer::BufferSize]; + alignas(alignment) + TransformedFeatureType transformedFeatures[FeatureTransformer::BufferSize]; #endif ASSERT_ALIGNED(transformedFeatures, alignment); @@ -292,13 +292,13 @@ Network::trace_evaluate(const Position& #if defined(ALIGNAS_ON_STACK_VARIABLES_BROKEN) TransformedFeatureType - transformedFeaturesUnaligned[FeatureTransformer::BufferSize + transformedFeaturesUnaligned[FeatureTransformer::BufferSize + alignment / sizeof(TransformedFeatureType)]; auto* transformedFeatures = align_ptr_up(&transformedFeaturesUnaligned[0]); #else - alignas(alignment) TransformedFeatureType - transformedFeatures[FeatureTransformer::BufferSize]; + alignas(alignment) + TransformedFeatureType transformedFeatures[FeatureTransformer::BufferSize]; #endif ASSERT_ALIGNED(transformedFeatures, alignment); @@ -454,12 +454,10 @@ bool Network::write_parameters(std::ostream& stream, // Explicit template instantiations -template class Network< - NetworkArchitecture, - FeatureTransformer>; +template class Network, + FeatureTransformer>; -template class Network< - NetworkArchitecture, - FeatureTransformer>; +template class Network, + FeatureTransformer>; } // namespace Stockfish::Eval::NNUE diff --git a/src/nnue/network.h b/src/nnue/network.h index 21df4b0a1..cd32c5312 100644 --- a/src/nnue/network.h +++ b/src/nnue/network.h @@ -110,13 +110,11 @@ class Network { }; // Definitions of the network types -using SmallFeatureTransformer = - FeatureTransformer; +using SmallFeatureTransformer = FeatureTransformer; using SmallNetworkArchitecture = NetworkArchitecture; -using BigFeatureTransformer = - FeatureTransformer; +using BigFeatureTransformer = FeatureTransformer; using BigNetworkArchitecture = NetworkArchitecture; using NetworkBig = Network; diff --git a/src/nnue/nnue_accumulator.cpp b/src/nnue/nnue_accumulator.cpp index 1f241c76e..2153cd4a6 100644 --- a/src/nnue/nnue_accumulator.cpp +++ b/src/nnue/nnue_accumulator.cpp @@ -29,7 +29,6 @@ #include "../types.h" #include "network.h" #include "nnue_architecture.h" -#include "nnue_common.h" #include "nnue_feature_transformer.h" namespace Stockfish::Eval::NNUE { @@ -48,24 +47,18 @@ namespace Stockfish::Eval::NNUE { namespace { -template AccumulatorState::* accPtr> +template void update_accumulator_incremental( - const FeatureTransformer& featureTransformer, - const Square ksq, - AccumulatorState& target_state, - const AccumulatorState& computed); + const FeatureTransformer& featureTransformer, + const Square ksq, + AccumulatorState& target_state, + const AccumulatorState& computed); -template AccumulatorState::* accPtr> -void update_accumulator_refresh_cache( - const FeatureTransformer& featureTransformer, - const Position& pos, - AccumulatorState& accumulatorState, - AccumulatorCaches::Cache& cache); +template +void update_accumulator_refresh_cache(const FeatureTransformer& featureTransformer, + const Position& pos, + AccumulatorState& accumulatorState, + AccumulatorCaches::Cache& cache); } @@ -88,18 +81,14 @@ void AccumulatorStack::reset(const Position& rootPos, AccumulatorCaches& caches) noexcept { m_current_idx = 1; - update_accumulator_refresh_cache( + update_accumulator_refresh_cache( *networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big); - update_accumulator_refresh_cache( + update_accumulator_refresh_cache( *networks.big.featureTransformer, rootPos, m_accumulators[0], caches.big); - update_accumulator_refresh_cache( + update_accumulator_refresh_cache( *networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small); - update_accumulator_refresh_cache( + update_accumulator_refresh_cache( *networks.small.featureTransformer, rootPos, m_accumulators[0], caches.small); } @@ -114,26 +103,23 @@ void AccumulatorStack::pop() noexcept { m_current_idx--; } -template AccumulatorState::* accPtr> -void AccumulatorStack::evaluate(const Position& pos, - const FeatureTransformer& featureTransformer, - AccumulatorCaches::Cache& cache) noexcept { +template +void AccumulatorStack::evaluate(const Position& pos, + const FeatureTransformer& featureTransformer, + AccumulatorCaches::Cache& cache) noexcept { evaluate_side(pos, featureTransformer, cache); evaluate_side(pos, featureTransformer, cache); } -template AccumulatorState::* accPtr> -void AccumulatorStack::evaluate_side( - const Position& pos, - const FeatureTransformer& featureTransformer, - AccumulatorCaches::Cache& cache) noexcept { +template +void AccumulatorStack::evaluate_side(const Position& pos, + const FeatureTransformer& featureTransformer, + AccumulatorCaches::Cache& cache) noexcept { - const auto last_usable_accum = find_last_usable_accumulator(); + const auto last_usable_accum = find_last_usable_accumulator(); - if ((m_accumulators[last_usable_accum].*accPtr).computed[Perspective]) + if ((m_accumulators[last_usable_accum].template acc()).computed[Perspective]) forward_update_incremental(pos, featureTransformer, last_usable_accum); else @@ -145,14 +131,12 @@ void AccumulatorStack::evaluate_side( // Find the earliest usable accumulator, this can either be a computed accumulator or the accumulator // state just before a change that requires full refresh. -template AccumulatorState::* accPtr> +template std::size_t AccumulatorStack::find_last_usable_accumulator() const noexcept { for (std::size_t curr_idx = m_current_idx - 1; curr_idx > 0; curr_idx--) { - if ((m_accumulators[curr_idx].*accPtr).computed[Perspective]) + if ((m_accumulators[curr_idx].template acc()).computed[Perspective]) return curr_idx; if (FeatureSet::requires_refresh(m_accumulators[curr_idx].dirtyPiece, Perspective)) @@ -162,59 +146,51 @@ std::size_t AccumulatorStack::find_last_usable_accumulator() const noexcept { return 0; } -template AccumulatorState::* accPtr> +template void AccumulatorStack::forward_update_incremental( - const Position& pos, - const FeatureTransformer& featureTransformer, - const std::size_t begin) noexcept { + const Position& pos, + const FeatureTransformer& featureTransformer, + const std::size_t begin) noexcept { assert(begin < m_accumulators.size()); - assert((m_accumulators[begin].*accPtr).computed[Perspective]); + assert((m_accumulators[begin].acc()).computed[Perspective]); const Square ksq = pos.square(Perspective); for (std::size_t next = begin + 1; next < m_current_idx; next++) - update_accumulator_incremental(featureTransformer, ksq, m_accumulators[next], - m_accumulators[next - 1]); + update_accumulator_incremental( + featureTransformer, ksq, m_accumulators[next], m_accumulators[next - 1]); - assert((latest().*accPtr).computed[Perspective]); + assert((latest().acc()).computed[Perspective]); } -template AccumulatorState::* accPtr> +template void AccumulatorStack::backward_update_incremental( - const Position& pos, - const FeatureTransformer& featureTransformer, - const std::size_t end) noexcept { + const Position& pos, + const FeatureTransformer& featureTransformer, + const std::size_t end) noexcept { assert(end < m_accumulators.size()); assert(end < m_current_idx); - assert((latest().*accPtr).computed[Perspective]); + assert((latest().acc()).computed[Perspective]); const Square ksq = pos.square(Perspective); for (std::size_t next = m_current_idx - 2; next >= end; next--) - update_accumulator_incremental( + update_accumulator_incremental( featureTransformer, ksq, m_accumulators[next], m_accumulators[next + 1]); - assert((m_accumulators[end].*accPtr).computed[Perspective]); + assert((m_accumulators[end].acc()).computed[Perspective]); } // Explicit template instantiations -template void -AccumulatorStack::evaluate( - const Position& pos, - const FeatureTransformer& - featureTransformer, +template void AccumulatorStack::evaluate( + const Position& pos, + const FeatureTransformer& featureTransformer, AccumulatorCaches::Cache& cache) noexcept; -template void -AccumulatorStack::evaluate( - const Position& pos, - const FeatureTransformer& - featureTransformer, +template void AccumulatorStack::evaluate( + const Position& pos, + const FeatureTransformer& featureTransformer, AccumulatorCaches::Cache& cache) noexcept; @@ -237,17 +213,15 @@ void fused_row_reduce(const ElementType* in, ElementType* out, const Ts* const.. vecIn[i], reinterpret_cast(rows)[i]...); } -template AccumulatorState::* accPtr> +template struct AccumulatorUpdateContext { - const FeatureTransformer& featureTransformer; - const AccumulatorState& from; - AccumulatorState& to; + const FeatureTransformer& featureTransformer; + const AccumulatorState& from; + AccumulatorState& to; - AccumulatorUpdateContext(const FeatureTransformer& ft, - const AccumulatorState& accF, - AccumulatorState& accT) noexcept : + AccumulatorUpdateContext(const FeatureTransformer& ft, + const AccumulatorState& accF, + AccumulatorState& accT) noexcept : featureTransformer{ft}, from{accF}, to{accT} {} @@ -264,43 +238,33 @@ struct AccumulatorUpdateContext { return &featureTransformer.psqtWeights[index * PSQTBuckets]; }; - fused_row_reduce((from.*accPtr).accumulation[Perspective], - (to.*accPtr).accumulation[Perspective], - to_weight_vector(indices)...); + fused_row_reduce( + (from.acc()).accumulation[Perspective], + (to.acc()).accumulation[Perspective], to_weight_vector(indices)...); fused_row_reduce( - (from.*accPtr).psqtAccumulation[Perspective], (to.*accPtr).psqtAccumulation[Perspective], - to_psqt_weight_vector(indices)...); + (from.acc()).psqtAccumulation[Perspective], + (to.acc()).psqtAccumulation[Perspective], to_psqt_weight_vector(indices)...); } }; -template AccumulatorState::* accPtr> -auto make_accumulator_update_context( - const FeatureTransformer& featureTransformer, - const AccumulatorState& accumulatorFrom, - AccumulatorState& accumulatorTo) noexcept { - return AccumulatorUpdateContext{ - featureTransformer, accumulatorFrom, accumulatorTo}; +template +auto make_accumulator_update_context(const FeatureTransformer& featureTransformer, + const AccumulatorState& accumulatorFrom, + AccumulatorState& accumulatorTo) noexcept { + return AccumulatorUpdateContext{featureTransformer, accumulatorFrom, + accumulatorTo}; } -template AccumulatorState::* accPtr> +template void update_accumulator_incremental( - const FeatureTransformer& featureTransformer, - const Square ksq, - AccumulatorState& target_state, - const AccumulatorState& computed) { - [[maybe_unused]] constexpr bool Forward = Direction == FORWARD; - [[maybe_unused]] constexpr bool Backward = Direction == BACKWARD; + const FeatureTransformer& featureTransformer, + const Square ksq, + AccumulatorState& target_state, + const AccumulatorState& computed) { - assert(Forward != Backward); - - assert((computed.*accPtr).computed[Perspective]); - assert(!(target_state.*accPtr).computed[Perspective]); + assert((computed.acc()).computed[Perspective]); + assert(!(target_state.acc()).computed[Perspective]); // The size must be enough to contain the largest possible update. // That might depend on the feature set and generally relies on the @@ -317,11 +281,8 @@ void update_accumulator_incremental( assert(added.size() == 1 || added.size() == 2); assert(removed.size() == 1 || removed.size() == 2); - - if (Forward) - assert(added.size() <= removed.size()); - else - assert(removed.size() <= added.size()); + assert((Forward && added.size() <= removed.size()) + || (!Forward && added.size() >= removed.size())); // Workaround compiler warning for uninitialized variables, replicated on // profile builds on windows with gcc 14.2.0. @@ -332,7 +293,7 @@ void update_accumulator_incremental( auto updateContext = make_accumulator_update_context(featureTransformer, computed, target_state); - if ((Forward && removed.size() == 1) || (Backward && added.size() == 1)) + if ((Forward && removed.size() == 1) || (!Forward && added.size() == 1)) { assert(added.size() == 1 && removed.size() == 1); updateContext.template apply(added[0], removed[0]); @@ -342,7 +303,7 @@ void update_accumulator_incremental( assert(removed.size() == 2); updateContext.template apply(added[0], removed[0], removed[1]); } - else if (Backward && removed.size() == 1) + else if (!Forward && removed.size() == 1) { assert(added.size() == 2); updateContext.template apply(added[0], added[1], removed[0]); @@ -354,17 +315,14 @@ void update_accumulator_incremental( removed[1]); } - (target_state.*accPtr).computed[Perspective] = true; + (target_state.acc()).computed[Perspective] = true; } -template AccumulatorState::* accPtr> -void update_accumulator_refresh_cache( - const FeatureTransformer& featureTransformer, - const Position& pos, - AccumulatorState& accumulatorState, - AccumulatorCaches::Cache& cache) { +template +void update_accumulator_refresh_cache(const FeatureTransformer& featureTransformer, + const Position& pos, + AccumulatorState& accumulatorState, + AccumulatorCaches::Cache& cache) { using Tiling [[maybe_unused]] = SIMDTiling; const Square ksq = pos.square(Perspective); @@ -394,12 +352,10 @@ void update_accumulator_refresh_cache( } } - auto& accumulator = accumulatorState.*accPtr; + auto& accumulator = accumulatorState.acc(); accumulator.computed[Perspective] = true; #ifdef VECTOR - const bool combineLast3 = - std::abs((int) removed.size() - (int) added.size()) == 1 && removed.size() + added.size() > 2; vec_t acc[Tiling::NumRegs]; psqt_vec_t psqt[Tiling::NumPsqtRegs]; @@ -412,8 +368,8 @@ void update_accumulator_refresh_cache( for (IndexType k = 0; k < Tiling::NumRegs; ++k) acc[k] = entryTile[k]; - std::size_t i = 0; - for (; i < std::min(removed.size(), added.size()) - combineLast3; ++i) + IndexType i = 0; + for (; i < std::min(removed.size(), added.size()); ++i) { IndexType indexR = removed[i]; const IndexType offsetR = Dimensions * indexR + j * Tiling::TileHeight; @@ -425,58 +381,23 @@ void update_accumulator_refresh_cache( for (IndexType k = 0; k < Tiling::NumRegs; ++k) acc[k] = fused(acc[k], columnA[k], columnR[k]); } - if (combineLast3) + for (; i < removed.size(); ++i) { - IndexType indexR = removed[i]; - const IndexType offsetR = Dimensions * indexR + j * Tiling::TileHeight; - auto* columnR = reinterpret_cast(&featureTransformer.weights[offsetR]); - IndexType indexA = added[i]; - const IndexType offsetA = Dimensions * indexA + j * Tiling::TileHeight; - auto* columnA = reinterpret_cast(&featureTransformer.weights[offsetA]); + IndexType index = removed[i]; + const IndexType offset = Dimensions * index + j * Tiling::TileHeight; + auto* column = reinterpret_cast(&featureTransformer.weights[offset]); - if (removed.size() > added.size()) - { - IndexType indexR2 = removed[i + 1]; - const IndexType offsetR2 = Dimensions * indexR2 + j * Tiling::TileHeight; - auto* columnR2 = - reinterpret_cast(&featureTransformer.weights[offsetR2]); - - for (IndexType k = 0; k < Tiling::NumRegs; ++k) - acc[k] = fused(acc[k], columnA[k], columnR[k], - columnR2[k]); - } - else - { - IndexType indexA2 = added[i + 1]; - const IndexType offsetA2 = Dimensions * indexA2 + j * Tiling::TileHeight; - auto* columnA2 = - reinterpret_cast(&featureTransformer.weights[offsetA2]); - - for (IndexType k = 0; k < Tiling::NumRegs; ++k) - acc[k] = fused(acc[k], columnA[k], columnA2[k], - columnR[k]); - } + for (IndexType k = 0; k < Tiling::NumRegs; ++k) + acc[k] = vec_sub_16(acc[k], column[k]); } - else + for (; i < added.size(); ++i) { - for (; i < removed.size(); ++i) - { - IndexType index = removed[i]; - const IndexType offset = Dimensions * index + j * Tiling::TileHeight; - auto* column = reinterpret_cast(&featureTransformer.weights[offset]); + IndexType index = added[i]; + const IndexType offset = Dimensions * index + j * Tiling::TileHeight; + auto* column = reinterpret_cast(&featureTransformer.weights[offset]); - for (IndexType k = 0; k < Tiling::NumRegs; ++k) - acc[k] = vec_sub_16(acc[k], column[k]); - } - for (; i < added.size(); ++i) - { - IndexType index = added[i]; - const IndexType offset = Dimensions * index + j * Tiling::TileHeight; - auto* column = reinterpret_cast(&featureTransformer.weights[offset]); - - for (IndexType k = 0; k < Tiling::NumRegs; ++k) - acc[k] = vec_add_16(acc[k], column[k]); - } + for (IndexType k = 0; k < Tiling::NumRegs; ++k) + acc[k] = vec_add_16(acc[k], column[k]); } for (IndexType k = 0; k < Tiling::NumRegs; k++) @@ -492,10 +413,10 @@ void update_accumulator_refresh_cache( auto* entryTilePsqt = reinterpret_cast(&entry.psqtAccumulation[j * Tiling::PsqtTileHeight]); - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) psqt[k] = entryTilePsqt[k]; - for (std::size_t i = 0; i < removed.size(); ++i) + for (IndexType i = 0; i < removed.size(); ++i) { IndexType index = removed[i]; const IndexType offset = PSQTBuckets * index + j * Tiling::PsqtTileHeight; @@ -505,7 +426,7 @@ void update_accumulator_refresh_cache( for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) psqt[k] = vec_sub_psqt_32(psqt[k], columnPsqt[k]); } - for (std::size_t i = 0; i < added.size(); ++i) + for (IndexType i = 0; i < added.size(); ++i) { IndexType index = added[i]; const IndexType offset = PSQTBuckets * index + j * Tiling::PsqtTileHeight; @@ -516,9 +437,9 @@ void update_accumulator_refresh_cache( psqt[k] = vec_add_psqt_32(psqt[k], columnPsqt[k]); } - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) vec_store_psqt(&entryTilePsqt[k], psqt[k]); - for (std::size_t k = 0; k < Tiling::NumPsqtRegs; ++k) + for (IndexType k = 0; k < Tiling::NumPsqtRegs; ++k) vec_store_psqt(&accTilePsqt[k], psqt[k]); } diff --git a/src/nnue/nnue_accumulator.h b/src/nnue/nnue_accumulator.h index 1586abf23..d83a5a446 100644 --- a/src/nnue/nnue_accumulator.h +++ b/src/nnue/nnue_accumulator.h @@ -46,10 +46,7 @@ struct Networks; template struct alignas(CacheLineSize) Accumulator; -struct AccumulatorState; - -template AccumulatorState::* accPtr> +template class FeatureTransformer; // Class that holds the result of affine transformation of input features @@ -121,6 +118,30 @@ struct AccumulatorState { Accumulator accumulatorSmall; DirtyPiece dirtyPiece; + template + auto& acc() noexcept { + static_assert(Size == TransformedFeatureDimensionsBig + || Size == TransformedFeatureDimensionsSmall, + "Invalid size for accumulator"); + + if constexpr (Size == TransformedFeatureDimensionsBig) + return accumulatorBig; + else if constexpr (Size == TransformedFeatureDimensionsSmall) + return accumulatorSmall; + } + + template + const auto& acc() const noexcept { + static_assert(Size == TransformedFeatureDimensionsBig + || Size == TransformedFeatureDimensionsSmall, + "Invalid size for accumulator"); + + if constexpr (Size == TransformedFeatureDimensionsBig) + return accumulatorBig; + else if constexpr (Size == TransformedFeatureDimensionsSmall) + return accumulatorSmall; + } + void reset(const DirtyPiece& dp) noexcept; }; @@ -138,41 +159,31 @@ class AccumulatorStack { void push(const DirtyPiece& dirtyPiece) noexcept; void pop() noexcept; - template AccumulatorState::* accPtr> - void evaluate(const Position& pos, - const FeatureTransformer& featureTransformer, - AccumulatorCaches::Cache& cache) noexcept; + template + void evaluate(const Position& pos, + const FeatureTransformer& featureTransformer, + AccumulatorCaches::Cache& cache) noexcept; private: [[nodiscard]] AccumulatorState& mut_latest() noexcept; - template AccumulatorState::* accPtr> - void evaluate_side(const Position& pos, - const FeatureTransformer& featureTransformer, - AccumulatorCaches::Cache& cache) noexcept; + template + void evaluate_side(const Position& pos, + const FeatureTransformer& featureTransformer, + AccumulatorCaches::Cache& cache) noexcept; - template AccumulatorState::* accPtr> + template [[nodiscard]] std::size_t find_last_usable_accumulator() const noexcept; - template AccumulatorState::* accPtr> - void - forward_update_incremental(const Position& pos, - const FeatureTransformer& featureTransformer, - const std::size_t begin) noexcept; + template + void forward_update_incremental(const Position& pos, + const FeatureTransformer& featureTransformer, + const std::size_t begin) noexcept; - template AccumulatorState::* accPtr> - void - backward_update_incremental(const Position& pos, - const FeatureTransformer& featureTransformer, - const std::size_t end) noexcept; + template + void backward_update_incremental(const Position& pos, + const FeatureTransformer& featureTransformer, + const std::size_t end) noexcept; std::vector m_accumulators; std::size_t m_current_idx; diff --git a/src/nnue/nnue_common.h b/src/nnue/nnue_common.h index e6e3017d2..f21a8dec7 100644 --- a/src/nnue/nnue_common.h +++ b/src/nnue/nnue_common.h @@ -279,11 +279,6 @@ inline void write_leb_128(std::ostream& stream, const IntType* values, std::size flush(); } -enum IncUpdateDirection { - FORWARD, - BACKWARD -}; - } // namespace Stockfish::Eval::NNUE #endif // #ifndef NNUE_COMMON_H_INCLUDED diff --git a/src/nnue/nnue_feature_transformer.h b/src/nnue/nnue_feature_transformer.h index e8403bb1a..beb0c7f1c 100644 --- a/src/nnue/nnue_feature_transformer.h +++ b/src/nnue/nnue_feature_transformer.h @@ -192,6 +192,10 @@ fused(const typename VecWrapper::type& in, const T& operand, const Ts&... operan return fused(VecWrapper::add(in, operand), operands...); case Sub : return fused(VecWrapper::sub(in, operand), operands...); + default : + static_assert(update_op == Add || update_op == Sub, + "Only Add and Sub are currently supported."); + return typename VecWrapper::type(); } } @@ -292,8 +296,7 @@ class SIMDTiling { // Input feature converter -template AccumulatorState::* accPtr> +template class FeatureTransformer { // Number of output dimensions for one side @@ -398,12 +401,12 @@ class FeatureTransformer { const auto& accumulatorState = accumulatorStack.latest(); const Color perspectives[2] = {pos.side_to_move(), ~pos.side_to_move()}; - const auto& psqtAccumulation = (accumulatorState.*accPtr).psqtAccumulation; + const auto& psqtAccumulation = (accumulatorState.acc()).psqtAccumulation; const auto psqt = (psqtAccumulation[perspectives[0]][bucket] - psqtAccumulation[perspectives[1]][bucket]) / 2; - const auto& accumulation = (accumulatorState.*accPtr).accumulation; + const auto& accumulation = (accumulatorState.acc()).accumulation; for (IndexType p = 0; p < 2; ++p) { diff --git a/src/search.cpp b/src/search.cpp index 3870f37d2..050c8d353 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -103,9 +103,7 @@ int risk_tolerance(const Position& pos, Value v) { return 644800 * x / ((x * x + 3 * y * y) * y); }; - int m = (67 * pos.count() + 182 * pos.count() + 182 * pos.count() - + 337 * pos.count() + 553 * pos.count()) - / 64; + int m = pos.count() + pos.non_pawn_material() / 300; // a and b are the crude approximation of the wdl model. // The win rate is: 1/(1+exp((a-v)/b)) @@ -907,7 +905,8 @@ Value Search::Worker::search( // The depth condition is important for mate finding. if (!ss->ttPv && depth < 14 && eval - futility_margin(depth, cutNode && !ss->ttHit, improving, opponentWorsening) - - (ss - 1)->statScore / 301 + 37 - std::abs(correctionValue) / 139878 + - (ss - 1)->statScore / 301 + 37 + ((eval - beta) / 8) + - std::abs(correctionValue) / 139878 >= beta && eval >= beta && (!ttData.move || ttCapture) && !is_loss(beta) && !is_win(eval)) return beta + (eval - beta) / 3; @@ -1498,7 +1497,7 @@ moves_loop: // When in check, search starts here else if (!priorCapture && prevSq != SQ_NONE) { int bonusScale = - (std::clamp(80 * depth - 320, 0, 200) + 34 * !allNode + 164 * ((ss - 1)->moveCount > 8) + (std::min(78 * depth - 312, 194) + 34 * !allNode + 164 * ((ss - 1)->moveCount > 8) + 141 * (!ss->inCheck && bestValue <= ss->staticEval - 100) + 121 * (!(ss - 1)->inCheck && bestValue <= -(ss - 1)->staticEval - 75) + 86 * ((ss - 1)->isTTMove) + 86 * (ss->cutoffCnt <= 3) diff --git a/src/types.h b/src/types.h index 5f9cb421e..d7f9dfb74 100644 --- a/src/types.h +++ b/src/types.h @@ -37,6 +37,7 @@ // | only in 64-bit mode and requires hardware with pext support. #include + #include #include #include