]> git.sesse.net Git - stockfish/commitdiff
Get rid of ReducedStateInfo struct
authorMarco Costalba <mcostalba@gmail.com>
Sun, 28 Oct 2012 16:12:40 +0000 (17:12 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 29 Oct 2012 07:07:17 +0000 (08:07 +0100)
ReducedStateInfo is a redundant struct that is also
prone to errors, indeed must be updated any time is
updated StateInfo. It is a trick to partial copy a
StateInfo object in do_move().

This patch takes advantage of builtin macro offsetof()
to directly calculate the number of quad words to copy.
Note that we still use memcpy to do the actual job of
copying the (48 bytes) of data.

Idea by Richard Vida.

No functional and no performance change.

src/position.cpp
src/position.h

index 40ea30f79f520d6d74ff0fa4de9cfd64e2b20e3b..be9e7ac847f68eac2e2bb339eaa84adb715f949a 100644 (file)
@@ -770,9 +770,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   Key k = st->key;
 
   // Copy some fields of old state to our new StateInfo object except the ones
-  // which are recalculated from scratch anyway, then switch our state pointer
-  // to point to the new, ready to be updated, state.
-  memcpy(&newSt, st, sizeof(ReducedStateInfo));
+  // which are going to be recalculated from scratch anyway, then switch our state
+  // pointer to point to the new, ready to be updated, state.
+  memcpy(&newSt, st, StateCopySize64 * sizeof(uint64_t));
 
   newSt.previous = st;
   st = &newSt;
index 3014b2354b91f12e0c538a8efae7d9d986afbca6..ff75848ecacfab4fd4dc1f4f099abc358a6c26b0 100644 (file)
@@ -21,6 +21,7 @@
 #define POSITION_H_INCLUDED
 
 #include <cassert>
+#include <cstddef>
 
 #include "bitboard.h"
 #include "types.h"
@@ -44,7 +45,7 @@ struct CheckInfo {
 
 /// The StateInfo struct stores information we need to restore a Position
 /// object to its previous state when we retract a move. Whenever a move
-/// is made on the board (by calling Position::do_move), an StateInfo object
+/// is made on the board (by calling Position::do_move), a StateInfo object
 /// must be passed as a parameter.
 
 struct StateInfo {
@@ -60,13 +61,10 @@ struct StateInfo {
   StateInfo* previous;
 };
 
-struct ReducedStateInfo {
-  Key pawnKey, materialKey;
-  Value npMaterial[COLOR_NB];
-  int castleRights, rule50, pliesFromNull;
-  Score psqScore;
-  Square epSquare;
-};
+
+/// When making a move the current StateInfo up to 'key' excluded is copied to
+/// the new one. Here we calculate the quad words (64bits) needed to be copied.
+const size_t StateCopySize64 = offsetof(StateInfo, key) / sizeof(uint64_t) + 1;
 
 
 /// The position data structure. A position consists of the following data: