1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Micro-optimize do_castle_move()

Use the same tables update trick used in do_move().

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-04-09 09:23:52 +01:00
parent 4a310baae2
commit 68885f78f3

View file

@ -830,7 +830,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
prefetch((char*)TT.first_entry(k)); prefetch((char*)TT.first_entry(k));
// Move the piece // Move the piece
Bitboard from_to_bb = SquareBB[from] | SquareBB[to]; Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
byTypeBB[ALL_PIECES] ^= from_to_bb; byTypeBB[ALL_PIECES] ^= from_to_bb;
byTypeBB[pt] ^= from_to_bb; byTypeBB[pt] ^= from_to_bb;
byColorBB[us] ^= from_to_bb; byColorBB[us] ^= from_to_bb;
@ -995,7 +995,7 @@ void Position::undo_move(Move m) {
} }
// Put the piece back at the source square // Put the piece back at the source square
Bitboard from_to_bb = SquareBB[from] | SquareBB[to]; Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to];
byTypeBB[ALL_PIECES] ^= from_to_bb; byTypeBB[ALL_PIECES] ^= from_to_bb;
byTypeBB[pt] ^= from_to_bb; byTypeBB[pt] ^= from_to_bb;
byColorBB[us] ^= from_to_bb; byColorBB[us] ^= from_to_bb;
@ -1078,21 +1078,13 @@ void Position::do_castle_move(Move m) {
assert(piece_on(kfrom) == make_piece(us, KING)); assert(piece_on(kfrom) == make_piece(us, KING));
assert(piece_on(rfrom) == make_piece(us, ROOK)); assert(piece_on(rfrom) == make_piece(us, ROOK));
// Remove pieces from source squares // Move the pieces, with some care; in chess960 could be kto == rfrom
byTypeBB[ALL_PIECES] ^= kfrom; Bitboard k_from_to_bb = SquareBB[kfrom] ^ SquareBB[kto];
byTypeBB[KING] ^= kfrom; Bitboard r_from_to_bb = SquareBB[rfrom] ^ SquareBB[rto];
byColorBB[us] ^= kfrom; byTypeBB[KING] ^= k_from_to_bb;
byTypeBB[ALL_PIECES] ^= rfrom; byTypeBB[ROOK] ^= r_from_to_bb;
byTypeBB[ROOK] ^= rfrom; byTypeBB[ALL_PIECES] ^= k_from_to_bb ^ r_from_to_bb;
byColorBB[us] ^= rfrom; byColorBB[us] ^= k_from_to_bb ^ r_from_to_bb;
// Put pieces on destination squares
byTypeBB[ALL_PIECES] |= kto;
byTypeBB[KING] |= kto;
byColorBB[us] |= kto;
byTypeBB[ALL_PIECES] |= rto;
byTypeBB[ROOK] |= rto;
byColorBB[us] |= rto;
// Update board // Update board
Piece king = make_piece(us, KING); Piece king = make_piece(us, KING);