]> git.sesse.net Git - stockfish/commitdiff
Revert to byTypeBB[0] storing occupied squares
authorMarco Costalba <mcostalba@gmail.com>
Sun, 18 Mar 2012 10:33:54 +0000 (11:33 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 18 Mar 2012 11:02:23 +0000 (12:02 +0100)
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 <mcostalba@gmail.com>
src/position.cpp
src/position.h
src/types.h

index d18cf2f88fcf9421cbecb42eb7601c6e67623594..12ef1a3092fc9befaa6baf6b889741f655c6bc0d 100644 (file)
@@ -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
           st->npMaterial[them] -= PieceValueMidgame[capture];
 
       // Remove the captured piece
-      byColorBB[them] ^= capsq;
+      byTypeBB[ALL_PIECES] ^= capsq;
       byTypeBB[capture] ^= capsq;
       byTypeBB[capture] ^= capsq;
-      occupied ^= capsq;
+      byColorBB[them] ^= capsq;
 
       // Update piece list, move the last piece at index[capsq] position and
       // shrink the list.
 
       // 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];
 
   // 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;
   byTypeBB[pt] ^= from_to_bb;
-  occupied ^= from_to_bb;
+  byColorBB[us] ^= from_to_bb;
 
   board[to] = board[from];
   board[from] = NO_PIECE;
 
   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];
 
   // 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;
   byTypeBB[pt] ^= from_to_bb;
-  occupied ^= from_to_bb;
+  byColorBB[us] ^= from_to_bb;
 
   board[from] = board[to];
   board[to] = NO_PIECE;
 
   board[from] = board[to];
   board[to] = NO_PIECE;
@@ -1029,9 +1029,9 @@ void Position::undo_move(Move m) {
       }
 
       // Restore the captured piece
       }
 
       // Restore the captured piece
-      byColorBB[them] |= capsq;
+      byTypeBB[ALL_PIECES] |= capsq;
       byTypeBB[capture] |= capsq;
       byTypeBB[capture] |= capsq;
-      occupied |= capsq;
+      byColorBB[them] |= capsq;
 
       board[capsq] = make_piece(them, capture);
 
 
       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
   assert(piece_on(rfrom) == make_piece(us, ROOK));
 
   // Remove pieces from source squares
-  byColorBB[us] ^= kfrom;
+  byTypeBB[ALL_PIECES] ^= kfrom;
   byTypeBB[KING] ^= kfrom;
   byTypeBB[KING] ^= kfrom;
-  occupied ^= kfrom;
-  byColorBB[us] ^= rfrom;
+  byColorBB[us] ^= kfrom;
+  byTypeBB[ALL_PIECES] ^= rfrom;
   byTypeBB[ROOK] ^= rfrom;
   byTypeBB[ROOK] ^= rfrom;
-  occupied ^= rfrom;
+  byColorBB[us] ^= rfrom;
 
   // Put pieces on destination squares
 
   // Put pieces on destination squares
-  byColorBB[us] |= kto;
+  byTypeBB[ALL_PIECES] |= kto;
   byTypeBB[KING] |= kto;
   byTypeBB[KING] |= kto;
-  occupied |= kto;
-  byColorBB[us] |= rto;
+  byColorBB[us] |= kto;
+  byTypeBB[ALL_PIECES] |= rto;
   byTypeBB[ROOK] |= rto;
   byTypeBB[ROOK] |= rto;
-  occupied |= rto;
+  byColorBB[us] |= rto;
 
   // Update board
   Piece king = make_piece(us, KING);
 
   // 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;
 
   index[s] = pieceCount[c][pt]++;
   pieceList[c][pt][index[s]] = s;
 
+  byTypeBB[ALL_PIECES] |= s;
   byTypeBB[pt] |= s;
   byColorBB[c] |= s;
   byTypeBB[pt] |= s;
   byColorBB[c] |= s;
-  occupied |= s;
 }
 
 
 }
 
 
index d2ad99557427dedae4dcd3cbebcd23d1e070b8db..488ed09f0a649b5dd4f9ff7e16904eea3497697b 100644 (file)
@@ -231,7 +231,6 @@ private:
   // Bitboards
   Bitboard byTypeBB[8];        // [pieceType]
   Bitboard byColorBB[2];       // [color]
   // Bitboards
   Bitboard byTypeBB[8];        // [pieceType]
   Bitboard byColorBB[2];       // [color]
-  Bitboard occupied;
 
   // Piece counts
   int pieceCount[2][8];        // [color][pieceType]
 
   // Piece counts
   int pieceCount[2][8];        // [color][pieceType]
@@ -286,7 +285,7 @@ inline Color Position::side_to_move() const {
 }
 
 inline Bitboard Position::pieces() const {
 }
 
 inline Bitboard Position::pieces() const {
-  return occupied;
+  return byTypeBB[ALL_PIECES];
 }
 
 inline Bitboard Position::pieces(Color c) const {
 }
 
 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 {
 }
 
 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 {
 }
 
 inline Square Position::castle_rook_square(CastleRight f) const {
@@ -354,11 +353,11 @@ inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
 }
 
 inline Bitboard Position::attacks_from(Piece p, Square s) 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 {
 }
 
 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 {
 }
 
 inline Bitboard Position::checkers() const {
index 4c8c813408993a33706d4eab4aaf1b0c1d3f8587..9567d6b851a0a8ec8d0cae53419e0aa71531e4de 100644 (file)
@@ -200,7 +200,7 @@ enum Value {
 };
 
 enum PieceType {
 };
 
 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
 };
 
   PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
 };