mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 06:17:49 +00:00
Remove two xors by setting the hash keys for unreachable squares to zero
performance before: 3.6714 +- 0.20% Gcycles 3.6620 +- 0.12% Gcycles 3.6704 +- 0.26% Gcycles 3.6602 +- 0.27% Gcycles 3.6799 +- 0.37% Gcycles after: 3.6540 +- 0.30% Gcycles 3.6388 +- 0.25% Gcycles 3.6557 +- 0.17% Gcycles 3.6449 +- 0.15% Gcycles 3.6460 +- 0.26% Gcycles (every line is a different `profile-build` and shows the number of cycles needed for `./stockfish bench`, measured with `perf stat -r 10`) closes https://github.com/official-stockfish/Stockfish/pull/5754 No functional change
This commit is contained in:
committed by
Disservin
parent
d66e603070
commit
e089f723d8
+9
-6
@@ -119,6 +119,9 @@ void Position::init() {
|
|||||||
for (Piece pc : Pieces)
|
for (Piece pc : Pieces)
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
for (Square s = SQ_A1; s <= SQ_H8; ++s)
|
||||||
Zobrist::psq[pc][s] = rng.rand<Key>();
|
Zobrist::psq[pc][s] = rng.rand<Key>();
|
||||||
|
// pawns on these squares will promote
|
||||||
|
std::fill_n(Zobrist::psq[W_PAWN] + SQ_A8, 8, 0);
|
||||||
|
std::fill_n(Zobrist::psq[B_PAWN], 8, 0);
|
||||||
|
|
||||||
for (File f = FILE_A; f <= FILE_H; ++f)
|
for (File f = FILE_A; f <= FILE_H; ++f)
|
||||||
Zobrist::enpassant[f] = rng.rand<Key>();
|
Zobrist::enpassant[f] = rng.rand<Key>();
|
||||||
@@ -376,7 +379,7 @@ void Position::set_state() const {
|
|||||||
|
|
||||||
for (Piece pc : Pieces)
|
for (Piece pc : Pieces)
|
||||||
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
|
for (int cnt = 0; cnt < pieceCount[pc]; ++cnt)
|
||||||
st->materialKey ^= Zobrist::psq[pc][cnt];
|
st->materialKey ^= Zobrist::psq[pc][8 + cnt];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -776,7 +779,7 @@ void Position::do_move(Move m,
|
|||||||
remove_piece(capsq);
|
remove_piece(capsq);
|
||||||
|
|
||||||
k ^= Zobrist::psq[captured][capsq];
|
k ^= Zobrist::psq[captured][capsq];
|
||||||
st->materialKey ^= Zobrist::psq[captured][pieceCount[captured]];
|
st->materialKey ^= Zobrist::psq[captured][8 + pieceCount[captured]];
|
||||||
|
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
@@ -840,10 +843,10 @@ void Position::do_move(Move m,
|
|||||||
dp.dirty_num++;
|
dp.dirty_num++;
|
||||||
|
|
||||||
// Update hash keys
|
// Update hash keys
|
||||||
k ^= Zobrist::psq[pc][to] ^ Zobrist::psq[promotion][to];
|
// Zobrist::psq[pc][to] is zero, so we don't need to clear it
|
||||||
st->pawnKey ^= Zobrist::psq[pc][to];
|
k ^= Zobrist::psq[promotion][to];
|
||||||
st->materialKey ^=
|
st->materialKey ^= Zobrist::psq[promotion][8 + pieceCount[promotion] - 1]
|
||||||
Zobrist::psq[promotion][pieceCount[promotion] - 1] ^ Zobrist::psq[pc][pieceCount[pc]];
|
^ Zobrist::psq[pc][8 + pieceCount[pc]];
|
||||||
|
|
||||||
if (promotionType <= BISHOP)
|
if (promotionType <= BISHOP)
|
||||||
st->minorPieceKey ^= Zobrist::psq[promotion][to];
|
st->minorPieceKey ^= Zobrist::psq[promotion][to];
|
||||||
|
|||||||
Reference in New Issue
Block a user