From 7bc36887144bc6a682e54a91044641f913176449 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 18 Mar 2012 11:33:54 +0100 Subject: [PATCH 1/1] Revert to byTypeBB[0] storing occupied squares As it was in Glaurung times. Also rearranged order so that byTypeBB[0] is accessed before byTypeBB[x] to be more cache friendly. It seems there is even a small speedup. No functional change. Signed-off-by: Marco Costalba --- src/position.cpp | 34 +++++++++++++++++----------------- src/position.h | 9 ++++----- src/types.h | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index d18cf2f8..12ef1a30 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -787,9 +787,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI st->npMaterial[them] -= PieceValueMidgame[capture]; // Remove the captured piece - byColorBB[them] ^= capsq; + byTypeBB[ALL_PIECES] ^= capsq; byTypeBB[capture] ^= capsq; - occupied ^= capsq; + byColorBB[them] ^= capsq; // Update piece list, move the last piece at index[capsq] position and // shrink the list. @@ -837,9 +837,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Move the piece Bitboard from_to_bb = SquareBB[from] | SquareBB[to]; - byColorBB[us] ^= from_to_bb; + byTypeBB[ALL_PIECES] ^= from_to_bb; byTypeBB[pt] ^= from_to_bb; - occupied ^= from_to_bb; + byColorBB[us] ^= from_to_bb; board[to] = board[from]; board[from] = NO_PIECE; @@ -1002,9 +1002,9 @@ void Position::undo_move(Move m) { // Put the piece back at the source square Bitboard from_to_bb = SquareBB[from] | SquareBB[to]; - byColorBB[us] ^= from_to_bb; + byTypeBB[ALL_PIECES] ^= from_to_bb; byTypeBB[pt] ^= from_to_bb; - occupied ^= from_to_bb; + byColorBB[us] ^= from_to_bb; board[from] = board[to]; board[to] = NO_PIECE; @@ -1029,9 +1029,9 @@ void Position::undo_move(Move m) { } // Restore the captured piece - byColorBB[them] |= capsq; + byTypeBB[ALL_PIECES] |= capsq; byTypeBB[capture] |= capsq; - occupied |= capsq; + byColorBB[them] |= capsq; board[capsq] = make_piece(them, capture); @@ -1085,20 +1085,20 @@ void Position::do_castle_move(Move m) { assert(piece_on(rfrom) == make_piece(us, ROOK)); // Remove pieces from source squares - byColorBB[us] ^= kfrom; + byTypeBB[ALL_PIECES] ^= kfrom; byTypeBB[KING] ^= kfrom; - occupied ^= kfrom; - byColorBB[us] ^= rfrom; + byColorBB[us] ^= kfrom; + byTypeBB[ALL_PIECES] ^= rfrom; byTypeBB[ROOK] ^= rfrom; - occupied ^= rfrom; + byColorBB[us] ^= rfrom; // Put pieces on destination squares - byColorBB[us] |= kto; + byTypeBB[ALL_PIECES] |= kto; byTypeBB[KING] |= kto; - occupied |= kto; - byColorBB[us] |= rto; + byColorBB[us] |= kto; + byTypeBB[ALL_PIECES] |= rto; byTypeBB[ROOK] |= rto; - occupied |= rto; + byColorBB[us] |= rto; // Update board Piece king = make_piece(us, KING); @@ -1345,9 +1345,9 @@ void Position::put_piece(Piece p, Square s) { index[s] = pieceCount[c][pt]++; pieceList[c][pt][index[s]] = s; + byTypeBB[ALL_PIECES] |= s; byTypeBB[pt] |= s; byColorBB[c] |= s; - occupied |= s; } diff --git a/src/position.h b/src/position.h index d2ad9955..488ed09f 100644 --- a/src/position.h +++ b/src/position.h @@ -231,7 +231,6 @@ private: // Bitboards Bitboard byTypeBB[8]; // [pieceType] Bitboard byColorBB[2]; // [color] - Bitboard occupied; // Piece counts int pieceCount[2][8]; // [color][pieceType] @@ -286,7 +285,7 @@ inline Color Position::side_to_move() const { } inline Bitboard Position::pieces() const { - return occupied; + return byTypeBB[ALL_PIECES]; } inline Bitboard Position::pieces(Color c) const { @@ -334,7 +333,7 @@ inline bool Position::can_castle(Color c) const { } inline bool Position::castle_impeded(CastleRight f) const { - return occupied & castlePath[f]; + return byTypeBB[ALL_PIECES] & castlePath[f]; } inline Square Position::castle_rook_square(CastleRight f) const { @@ -354,11 +353,11 @@ inline Bitboard Position::attacks_from(Square s, Color c) const { } inline Bitboard Position::attacks_from(Piece p, Square s) const { - return attacks_from(p, s, occupied); + return attacks_from(p, s, byTypeBB[ALL_PIECES]); } inline Bitboard Position::attackers_to(Square s) const { - return attackers_to(s, occupied); + return attackers_to(s, byTypeBB[ALL_PIECES]); } inline Bitboard Position::checkers() const { diff --git a/src/types.h b/src/types.h index 4c8c8134..9567d6b8 100644 --- a/src/types.h +++ b/src/types.h @@ -200,7 +200,7 @@ enum Value { }; enum PieceType { - NO_PIECE_TYPE = 0, + NO_PIECE_TYPE = 0, ALL_PIECES = 0, PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6 }; -- 2.39.2