]> git.sesse.net Git - stockfish/commitdiff
Micro optimize copy of new state in do_move()
authorMarco Costalba <mcostalba@gmail.com>
Mon, 2 Mar 2009 16:32:30 +0000 (17:32 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 2 Mar 2009 17:00:42 +0000 (18:00 +0100)
Instead of copying all, copy only the fields that
are updated incrementally, not the ones that are
recalcuated form scratch anyway.

This reduces copy overhead of 30%.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp
src/position.h

index 67680b1fbac52c46360109abdabbd6bcf585863a..fc9e23c91a9342d635d33e9c7a18da0215742cf6 100644 (file)
@@ -707,10 +707,17 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   assert(is_ok());
   assert(move_is_ok(m));
 
   assert(is_ok());
   assert(move_is_ok(m));
 
-  // Copy some fields of old state to our new StateInfo object (except the
-  // captured piece, which is taken care of later) and switch state pointer
-  // to point to the new, ready to be updated, state.
-  newSt = *st;
+  // 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.
+  struct ReducedStateInfo {
+    Key key, pawnKey, materialKey;
+    int castleRights, rule50;
+    Square epSquare;
+    Value mgValue, egValue;
+  };
+
+  memcpy(&newSt, st, sizeof(ReducedStateInfo));
   newSt.capture = NO_PIECE_TYPE;
   newSt.previous = st;
   st = &newSt;
   newSt.capture = NO_PIECE_TYPE;
   newSt.previous = st;
   st = &newSt;
index bd59b5c959d624c90c66a63f943a04f33d19fd0b..8e29eb13458390ff2d4a405ffd61cebd794f46ee 100644 (file)
@@ -79,14 +79,15 @@ enum CastleRights {
 /// must be passed as a parameter.
 
 struct StateInfo {
 /// must be passed as a parameter.
 
 struct StateInfo {
-  Bitboard checkersBB;
   Key key, pawnKey, materialKey;
   int castleRights, rule50;
   Square epSquare;
   Value mgValue, egValue;
   Key key, pawnKey, materialKey;
   int castleRights, rule50;
   Square epSquare;
   Value mgValue, egValue;
+
   PieceType capture;
   PieceType capture;
-  StateInfo* previous;
+  Bitboard checkersBB;
   Move lastMove;
   Move lastMove;
+  StateInfo* previous;
 };
 
 
 };