mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-22 12:47:08 +00:00
Simplify out double_inc_update
Passed STC https://tests.stockfishchess.org/tests/view/69e82e200e9667dd5a765631 LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 115424 W: 29950 L: 29822 D: 55652 Ptnml(0-2): 318, 12712, 31544, 12800, 338 Passed AVX2-only STC https://tests.stockfishchess.org/tests/view/69e953080e9667dd5a7657c0 LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 134720 W: 34773 L: 34665 D: 65282 Ptnml(0-2): 344, 14958, 36694, 14974, 390 Now that our L1 size is much smaller, the overhead of tracking diffs for `double_inc_update` is a larger share of the cost. Interestingly ces42 measured a -0.9% slowdown locally (avxvnni build). Meanwhile Torom and I find this branch to be 2% faster. I'm not sure exactly what's going on but more tests may be in order closes https://github.com/official-stockfish/Stockfish/pull/6776 No functional change
This commit is contained in:
committed by
Joost VandeVondele
parent
0e78190b72
commit
1a882efc7f
+21
-38
@@ -860,13 +860,12 @@ void Position::do_move(Move m,
|
||||
Piece pc = piece_on(from);
|
||||
Piece captured = m.type_of() == EN_PASSANT ? make_piece(them, PAWN) : piece_on(to);
|
||||
|
||||
dp.pc = pc;
|
||||
dp.from = from;
|
||||
dp.to = to;
|
||||
dp.add_sq = SQ_NONE;
|
||||
dts.us = us;
|
||||
dts.prevKsq = square<KING>(us);
|
||||
dts.threatenedSqs = dts.threateningSqs = 0;
|
||||
dp.pc = pc;
|
||||
dp.from = from;
|
||||
dp.to = to;
|
||||
dp.add_sq = SQ_NONE;
|
||||
dts.us = us;
|
||||
dts.prevKsq = square<KING>(us);
|
||||
|
||||
assert(color_of(pc) == us);
|
||||
assert(captured == NO_PIECE || color_of(captured) == (m.type_of() != CASTLING ? them : us));
|
||||
@@ -1151,16 +1150,13 @@ void Position::undo_move(Move m) {
|
||||
assert(pos_is_ok());
|
||||
}
|
||||
|
||||
template<bool PutPiece>
|
||||
inline void add_dirty_threat(
|
||||
DirtyThreats* const dts, Piece pc, Piece threatened, Square s, Square threatenedSq) {
|
||||
if (PutPiece)
|
||||
{
|
||||
dts->threatenedSqs |= threatenedSq;
|
||||
dts->threateningSqs |= s;
|
||||
}
|
||||
|
||||
dts->list.push_back({pc, threatened, s, threatenedSq, PutPiece});
|
||||
inline void add_dirty_threat(DirtyThreats* const dts,
|
||||
bool putPiece,
|
||||
Piece pc,
|
||||
Piece threatened,
|
||||
Square s,
|
||||
Square threatenedSq) {
|
||||
dts->list.push_back({pc, threatened, s, threatenedSq, putPiece});
|
||||
}
|
||||
|
||||
#ifdef USE_AVX512ICL
|
||||
@@ -1198,8 +1194,9 @@ void write_multiple_dirties(const Position& p,
|
||||
}
|
||||
#endif
|
||||
|
||||
template<bool PutPiece, bool ComputeRay>
|
||||
template<bool ComputeRay>
|
||||
void Position::update_piece_threats(Piece pc,
|
||||
bool putPiece,
|
||||
Square s,
|
||||
DirtyThreats* const dts,
|
||||
[[maybe_unused]] Bitboard noRaysContaining) const {
|
||||
@@ -1226,11 +1223,11 @@ void Position::update_piece_threats(Piece pc,
|
||||
{
|
||||
const Square threatenedSq = lsb(discovered);
|
||||
const Piece threatenedPc = piece_on(threatenedSq);
|
||||
add_dirty_threat<!PutPiece>(dts, slider, threatenedPc, sliderSq, threatenedSq);
|
||||
add_dirty_threat(dts, !putPiece, slider, threatenedPc, sliderSq, threatenedSq);
|
||||
}
|
||||
|
||||
if (addDirectAttacks)
|
||||
add_dirty_threat<PutPiece>(dts, slider, pc, sliderSq, s);
|
||||
add_dirty_threat(dts, putPiece, slider, pc, sliderSq, s);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1270,27 +1267,13 @@ void Position::update_piece_threats(Piece pc,
|
||||
}
|
||||
|
||||
#ifdef USE_AVX512ICL
|
||||
if constexpr (PutPiece)
|
||||
{
|
||||
dts->threatenedSqs |= threatened;
|
||||
// A bit may only be set if that square actually produces a threat, so we
|
||||
// must guard setting the square accordingly
|
||||
dts->threateningSqs |= Bitboard(bool(threatened)) << s;
|
||||
}
|
||||
|
||||
DirtyThreat dt_template{pc, NO_PIECE, s, Square(0), PutPiece};
|
||||
DirtyThreat dt_template{pc, NO_PIECE, s, Square(0), putPiece};
|
||||
write_multiple_dirties<DirtyThreat::ThreatenedSqOffset, DirtyThreat::ThreatenedPcOffset>(
|
||||
*this, threatened, dt_template, dts);
|
||||
|
||||
Bitboard all_attackers = sliders | incoming_threats;
|
||||
|
||||
if constexpr (PutPiece)
|
||||
{
|
||||
dts->threatenedSqs |= Bitboard(bool(all_attackers)) << s; // same as above
|
||||
dts->threateningSqs |= all_attackers;
|
||||
}
|
||||
|
||||
dt_template = {NO_PIECE, pc, Square(0), s, PutPiece};
|
||||
dt_template = {NO_PIECE, pc, Square(0), s, putPiece};
|
||||
write_multiple_dirties<DirtyThreat::PcSqOffset, DirtyThreat::PcOffset>(*this, all_attackers,
|
||||
dt_template, dts);
|
||||
#else
|
||||
@@ -1302,7 +1285,7 @@ void Position::update_piece_threats(Piece pc,
|
||||
assert(threatenedSq != s);
|
||||
assert(threatenedPc);
|
||||
|
||||
add_dirty_threat<PutPiece>(dts, pc, threatenedPc, s, threatenedSq);
|
||||
add_dirty_threat(dts, putPiece, pc, threatenedPc, s, threatenedSq);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1328,7 +1311,7 @@ void Position::update_piece_threats(Piece pc,
|
||||
assert(srcSq != s);
|
||||
assert(srcPc != NO_PIECE);
|
||||
|
||||
add_dirty_threat<PutPiece>(dts, srcPc, pc, srcSq, s);
|
||||
add_dirty_threat(dts, putPiece, srcPc, pc, srcSq, s);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user