From: Marco Costalba Date: Mon, 9 Apr 2012 08:23:52 +0000 (+0100) Subject: Micro-optimize do_castle_move() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=68885f78f39c2d4b96d3a9b0dbf8f31ba12e50bf;hp=4a310baae2416055167a137e972a1160e236195a Micro-optimize do_castle_move() Use the same tables update trick used in do_move(). No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/position.cpp b/src/position.cpp index 8b043af8..9af42558 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -830,7 +830,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI prefetch((char*)TT.first_entry(k)); // 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[pt] ^= 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 - Bitboard from_to_bb = SquareBB[from] | SquareBB[to]; + Bitboard from_to_bb = SquareBB[from] ^ SquareBB[to]; byTypeBB[ALL_PIECES] ^= from_to_bb; byTypeBB[pt] ^= 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(rfrom) == make_piece(us, ROOK)); - // Remove pieces from source squares - byTypeBB[ALL_PIECES] ^= kfrom; - byTypeBB[KING] ^= kfrom; - byColorBB[us] ^= kfrom; - byTypeBB[ALL_PIECES] ^= rfrom; - byTypeBB[ROOK] ^= rfrom; - byColorBB[us] ^= rfrom; - - // 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; + // Move the pieces, with some care; in chess960 could be kto == rfrom + Bitboard k_from_to_bb = SquareBB[kfrom] ^ SquareBB[kto]; + Bitboard r_from_to_bb = SquareBB[rfrom] ^ SquareBB[rto]; + byTypeBB[KING] ^= k_from_to_bb; + byTypeBB[ROOK] ^= r_from_to_bb; + byTypeBB[ALL_PIECES] ^= k_from_to_bb ^ r_from_to_bb; + byColorBB[us] ^= k_from_to_bb ^ r_from_to_bb; // Update board Piece king = make_piece(us, KING);