From 95cfc0e3069e2bd573e37c42785a1d7b287295c2 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 20 Feb 2009 10:20:08 +0100 Subject: [PATCH] In Position backup and restore contiguous data Give the compiler one more chance to optimize the copy. No functional change. Signed-off-by: Marco Costalba --- src/position.cpp | 34 ++++++++++++++++------------------ src/position.h | 28 +++++++++++++++------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index fdf3e911..2fc73b66 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -678,24 +678,23 @@ bool Position::move_is_capture(Move m) const { void Position::backup(UndoInfo& u) const { - u.castleRights = castleRights; - u.epSquare = epSquare; + for (Color c = WHITE; c <= BLACK; c++) + { + u.pinners[c] = pinners[c]; + u.pinned[c] = pinned[c]; + u.dcCandidates[c] = dcCandidates[c]; + } u.checkersBB = checkersBB; u.key = key; u.pawnKey = pawnKey; u.materialKey = materialKey; + u.castleRights = castleRights; u.rule50 = rule50; + u.epSquare = epSquare; u.lastMove = lastMove; u.mgValue = mgValue; u.egValue = egValue; u.capture = NO_PIECE_TYPE; - - for (Color c = WHITE; c <= BLACK; c++) - { - u.pinners[c] = pinners[c]; - u.pinned[c] = pinned[c]; - u.dcCandidates[c] = dcCandidates[c]; - } } @@ -704,24 +703,23 @@ void Position::backup(UndoInfo& u) const { void Position::restore(const UndoInfo& u) { - castleRights = u.castleRights; - epSquare = u.epSquare; + for (Color c = WHITE; c <= BLACK; c++) + { + pinners[c] = u.pinners[c]; + pinned[c] = u.pinned[c]; + dcCandidates[c] = u.dcCandidates[c]; + } checkersBB = u.checkersBB; key = u.key; pawnKey = u.pawnKey; materialKey = u.materialKey; + castleRights = u.castleRights; rule50 = u.rule50; + epSquare = u.epSquare; lastMove = u.lastMove; mgValue = u.mgValue; egValue = u.egValue; // u.capture is restored in undo_move() - - for (Color c = WHITE; c <= BLACK; c++) - { - pinners[c] = u.pinners[c]; - pinned[c] = u.pinned[c]; - dcCandidates[c] = u.dcCandidates[c]; - } } diff --git a/src/position.h b/src/position.h index 94b70033..02e3a245 100644 --- a/src/position.h +++ b/src/position.h @@ -74,17 +74,16 @@ enum CastleRights { /// The UndoInfo struct stores information we need to restore a Position -/// object to its previous state when we retract a move. Whenever a move +/// object to its previous state when we retract a move. Whenever a move /// is made on the board (by calling Position::do_move), an UndoInfo object -/// must be passed as a parameter. When the move is unmade (by calling +/// must be passed as a parameter. When the move is unmade (by calling /// Position::undo_move), the same UndoInfo object must be passed again. struct UndoInfo { - int castleRights; - Square epSquare; - Bitboard checkersBB, pinners[2], pinned[2], dcCandidates[2]; + Bitboard pinners[2], pinned[2], dcCandidates[2], checkersBB; Key key, pawnKey, materialKey; - int rule50; + int castleRights, rule50; + Square epSquare; Move lastMove; Value mgValue, egValue; PieceType capture; @@ -326,8 +325,6 @@ private: // Bitboards Bitboard byColorBB[2], byTypeBB[8]; - Bitboard checkersBB; - mutable Bitboard pinners[2], pinned[2], dcCandidates[2]; // Board Piece board[64]; @@ -340,16 +337,21 @@ private: int index[64]; // Other info + Square kingSquare[2]; Color sideToMove; - int castleRights; + int gamePly; + Key history[MaxGameLength]; + Value npMaterial[2]; File initialKFile, initialKRFile, initialQRFile; + + // Info backed up in do_move() + mutable Bitboard pinners[2], pinned[2], dcCandidates[2]; + Bitboard checkersBB; + Key key, pawnKey, materialKey; + int castleRights, rule50; Square epSquare; - Square kingSquare[2]; Move lastMove; - Key key, pawnKey, materialKey, history[MaxGameLength]; - int rule50, gamePly; Value mgValue, egValue; - Value npMaterial[2]; // Static variables static int castleRightsMask[64]; -- 2.39.2