+ if (st->accumulator.state[c] == COMPUTED)
+ {
+ if (next == nullptr)
+ return;
+
+ // Update incrementally in two steps. First, we update the "next"
+ // accumulator. Then, we update the current accumulator (pos.state()).
+
+ // Gather all features to be updated. This code assumes HalfKP features
+ // only and doesn't support refresh triggers.
+ static_assert(std::is_same_v<Features::FeatureSet<Features::HalfKP<Features::Side::kFriend>>,
+ RawFeatures>);
+ Features::IndexList removed[2], added[2];
+ Features::HalfKP<Features::Side::kFriend>::AppendChangedIndices(pos,
+ next->dirtyPiece, c, &removed[0], &added[0]);
+ for (StateInfo *st2 = pos.state(); st2 != next; st2 = st2->previous)
+ Features::HalfKP<Features::Side::kFriend>::AppendChangedIndices(pos,
+ st2->dirtyPiece, c, &removed[1], &added[1]);
+
+ // Mark the accumulators as computed.
+ next->accumulator.state[c] = COMPUTED;
+ pos.state()->accumulator.state[c] = COMPUTED;
+
+ // Now update the accumulators listed in info[], where the last element is a sentinel.
+ StateInfo *info[3] =
+ { next, next == pos.state() ? nullptr : pos.state(), nullptr };
+ #ifdef VECTOR
+ for (IndexType j = 0; j < kHalfDimensions / kTileHeight; ++j)
+ {
+ // Load accumulator
+ auto accTile = reinterpret_cast<vec_t*>(
+ &st->accumulator.accumulation[c][0][j * kTileHeight]);
+ for (IndexType k = 0; k < kNumRegs; ++k)
+ acc[k] = vec_load(&accTile[k]);
+
+ for (IndexType i = 0; info[i]; ++i)
+ {
+ // Difference calculation for the deactivated features
+ for (const auto index : removed[i])
+ {
+ const IndexType offset = kHalfDimensions * index + j * kTileHeight;
+ auto column = reinterpret_cast<const vec_t*>(&weights_[offset]);
+ for (IndexType k = 0; k < kNumRegs; ++k)
+ acc[k] = vec_sub_16(acc[k], column[k]);
+ }
+
+ // Difference calculation for the activated features
+ for (const auto index : added[i])
+ {
+ const IndexType offset = kHalfDimensions * index + j * kTileHeight;
+ auto column = reinterpret_cast<const vec_t*>(&weights_[offset]);
+ for (IndexType k = 0; k < kNumRegs; ++k)
+ acc[k] = vec_add_16(acc[k], column[k]);
+ }
+
+ // Store accumulator
+ accTile = reinterpret_cast<vec_t*>(
+ &info[i]->accumulator.accumulation[c][0][j * kTileHeight]);
+ for (IndexType k = 0; k < kNumRegs; ++k)
+ vec_store(&accTile[k], acc[k]);
+ }
+ }