mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
Micro-optimize castleRights update
When updating castleRights in do_move() perform only one 64bit xor with zobCastle[] instead of two. The trick here is to define zobCastle[] keys of composite castling rights as a xor combination of the keys of the single castling rights, instead of 16 independent keys. Idea from Critter although implementation is different. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
6088ac2108
commit
821e1c7233
1 changed files with 15 additions and 8 deletions
|
@ -843,9 +843,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
|
||||||
if ( st->castleRights != CASTLES_NONE
|
if ( st->castleRights != CASTLES_NONE
|
||||||
&& (castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
|
&& (castleRightsMask[from] & castleRightsMask[to]) != ALL_CASTLES)
|
||||||
{
|
{
|
||||||
k ^= zobCastle[st->castleRights];
|
int cr = castleRightsMask[from] & castleRightsMask[to];
|
||||||
st->castleRights &= castleRightsMask[from] & castleRightsMask[to];
|
k ^= zobCastle[st->castleRights & (cr ^ ALL_CASTLES)];
|
||||||
k ^= zobCastle[st->castleRights];
|
st->castleRights &= cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefetch TT access as soon as we know key is updated
|
// Prefetch TT access as soon as we know key is updated
|
||||||
|
@ -1151,9 +1151,9 @@ void Position::do_castle_move(Move m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update castling rights
|
// Update castling rights
|
||||||
st->key ^= zobCastle[st->castleRights];
|
int cr = castleRightsMask[kfrom];
|
||||||
st->castleRights &= castleRightsMask[kfrom];
|
st->key ^= zobCastle[st->castleRights & (cr ^ ALL_CASTLES)];
|
||||||
st->key ^= zobCastle[st->castleRights];
|
st->castleRights &= cr;
|
||||||
|
|
||||||
// Update checkers BB
|
// Update checkers BB
|
||||||
st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
|
st->checkersBB = attackers_to(king_square(~us)) & pieces(us);
|
||||||
|
@ -1545,8 +1545,15 @@ void Position::init() {
|
||||||
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
for (Square s = SQ_A1; s <= SQ_H8; s++)
|
||||||
zobEp[s] = rk.rand<Key>();
|
zobEp[s] = rk.rand<Key>();
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++)
|
||||||
zobCastle[i] = rk.rand<Key>();
|
{
|
||||||
|
Bitboard b = cr;
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
Key k = zobCastle[1 << pop_1st_bit(&b)];
|
||||||
|
zobCastle[cr] ^= k ? k : rk.rand<Key>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
zobSideToMove = rk.rand<Key>();
|
zobSideToMove = rk.rand<Key>();
|
||||||
zobExclusion = rk.rand<Key>();
|
zobExclusion = rk.rand<Key>();
|
||||||
|
|
Loading…
Add table
Reference in a new issue