1818
1919#include " nnue_accumulator.h"
2020
21- #include < algorithm>
2221#include < cassert>
2322#include < cstdint>
2423#include < new>
@@ -338,22 +337,23 @@ struct AccumulatorUpdateContext {
338337 };
339338
340339 fused_row_reduce<Vec16Wrapper, Dimensions, ops...>(
341- (from.template acc <Dimensions>()).accumulation [perspective],
342- (to.template acc <Dimensions>()).accumulation [perspective], to_weight_vector (indices)...);
340+ (from.template acc <Dimensions>()).accumulation [perspective].data (),
341+ (to.template acc <Dimensions>()).accumulation [perspective].data (),
342+ to_weight_vector (indices)...);
343343
344344 fused_row_reduce<Vec32Wrapper, PSQTBuckets, ops...>(
345- (from.template acc <Dimensions>()).psqtAccumulation [perspective],
346- (to.template acc <Dimensions>()).psqtAccumulation [perspective],
345+ (from.template acc <Dimensions>()).psqtAccumulation [perspective]. data () ,
346+ (to.template acc <Dimensions>()).psqtAccumulation [perspective]. data () ,
347347 to_psqt_weight_vector (indices)...);
348348 }
349349
350350 void apply (const typename FeatureSet::IndexList& added,
351351 const typename FeatureSet::IndexList& removed) {
352- const auto fromAcc = from.template acc <Dimensions>().accumulation [perspective];
353- const auto toAcc = to.template acc <Dimensions>().accumulation [perspective];
352+ const auto & fromAcc = from.template acc <Dimensions>().accumulation [perspective];
353+ auto & toAcc = to.template acc <Dimensions>().accumulation [perspective];
354354
355- const auto fromPsqtAcc = from.template acc <Dimensions>().psqtAccumulation [perspective];
356- const auto toPsqtAcc = to.template acc <Dimensions>().psqtAccumulation [perspective];
355+ const auto & fromPsqtAcc = from.template acc <Dimensions>().psqtAccumulation [perspective];
356+ auto & toPsqtAcc = to.template acc <Dimensions>().psqtAccumulation [perspective];
357357
358358#ifdef VECTOR
359359 using Tiling = SIMDTiling<Dimensions, Dimensions, PSQTBuckets>;
@@ -448,8 +448,8 @@ struct AccumulatorUpdateContext {
448448
449449#else
450450
451- std::copy_n (fromAcc, Dimensions, toAcc) ;
452- std::copy_n (fromPsqtAcc, PSQTBuckets, toPsqtAcc) ;
451+ toAcc = fromAcc ;
452+ toPsqtAcc = fromPsqtAcc ;
453453
454454 for (const auto index : removed)
455455 {
@@ -589,13 +589,10 @@ void update_accumulator_incremental(
589589 auto & targetAcc = target_state.template acc <TransformedFeatureDimensions>();
590590 const auto & sourceAcc = computed.template acc <TransformedFeatureDimensions>();
591591
592- std::memcpy (targetAcc.accumulation [perspective], sourceAcc.accumulation [perspective],
593- sizeof (targetAcc.accumulation [perspective]));
594- std::memcpy (targetAcc.psqtAccumulation [perspective],
595- sourceAcc.psqtAccumulation [perspective],
596- sizeof (targetAcc.psqtAccumulation [perspective]));
592+ targetAcc.accumulation [perspective] = sourceAcc.accumulation [perspective];
593+ targetAcc.psqtAccumulation [perspective] = sourceAcc.psqtAccumulation [perspective];
594+ targetAcc.computed [perspective] = true ;
597595
598- targetAcc.computed [perspective] = true ;
599596 return ;
600597 }
601598
@@ -643,15 +640,16 @@ void update_accumulator_incremental(
643640 (target_state.template acc <TransformedFeatureDimensions>()).computed [perspective] = true ;
644641}
645642
646- Bitboard get_changed_pieces (const Piece oldPieces[SQUARE_NB], const Piece newPieces[SQUARE_NB]) {
643+ Bitboard get_changed_pieces (const std::array<Piece, SQUARE_NB>& oldPieces,
644+ const std::array<Piece, SQUARE_NB>& newPieces) {
647645#if defined(USE_AVX512) || defined(USE_AVX2)
648646 static_assert (sizeof (Piece) == 1 );
649647 Bitboard sameBB = 0 ;
650648
651649 for (int i = 0 ; i < 64 ; i += 32 )
652650 {
653- const __m256i old_v = _mm256_loadu_si256 (reinterpret_cast <const __m256i*>(oldPieces + i ));
654- const __m256i new_v = _mm256_loadu_si256 (reinterpret_cast <const __m256i*>(newPieces + i ));
651+ const __m256i old_v = _mm256_loadu_si256 (reinterpret_cast <const __m256i*>(& oldPieces[i] ));
652+ const __m256i new_v = _mm256_loadu_si256 (reinterpret_cast <const __m256i*>(& newPieces[i] ));
655653 const __m256i cmpEqual = _mm256_cmpeq_epi8 (old_v, new_v);
656654 const std::uint32_t equalMask = _mm256_movemask_epi8 (cmpEqual);
657655 sameBB |= static_cast <Bitboard>(equalMask) << i;
@@ -680,7 +678,7 @@ void update_accumulator_refresh_cache(Color pers
680678 auto & entry = cache[ksq][perspective];
681679 PSQFeatureSet::IndexList removed, added;
682680
683- const Bitboard changedBB = get_changed_pieces (entry.pieces , pos.piece_array (). data () );
681+ const Bitboard changedBB = get_changed_pieces (entry.pieces , pos.piece_array ());
684682 Bitboard removedBB = changedBB & entry.pieceBB ;
685683 Bitboard addedBB = changedBB & pos.pieces ();
686684
@@ -696,7 +694,7 @@ void update_accumulator_refresh_cache(Color pers
696694 }
697695
698696 entry.pieceBB = pos.pieces ();
699- std::copy_n (pos. piece_array (). begin (), SQUARE_NB, entry. pieces );
697+ entry. pieces = pos. piece_array ( );
700698
701699 auto & accumulator = accumulatorState.acc <Dimensions>();
702700 accumulator.computed [perspective] = true ;
@@ -812,12 +810,8 @@ void update_accumulator_refresh_cache(Color pers
812810
813811 // The accumulator of the refresh entry has been updated.
814812 // Now copy its content to the actual accumulator we were refreshing.
815-
816- std::memcpy (accumulator.accumulation [perspective], entry.accumulation .data (),
817- sizeof (BiasType) * Dimensions);
818-
819- std::memcpy (accumulator.psqtAccumulation [perspective], entry.psqtAccumulation .data (),
820- sizeof (int32_t ) * PSQTBuckets);
813+ accumulator.accumulation [perspective] = entry.accumulation ;
814+ accumulator.psqtAccumulation [perspective] = entry.psqtAccumulation ;
821815#endif
822816}
823817
0 commit comments