]> git.sesse.net Git - stockfish/commitdiff
Don't copy the key in do_move
authorMarco Costalba <mcostalba@gmail.com>
Sun, 8 Nov 2009 16:56:41 +0000 (17:56 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Mon, 9 Nov 2009 07:45:30 +0000 (08:45 +0100)
It will be overwritten anyway.

Also other little small touches that seem to increase
speed more then the whole enum Score patch series :-(

Optimization is really a black art.

No functional change.

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

index edfe6b2a56e7eb391bb4375f1d815d713cc7debe..77a6d604523f40a841a5f73ba6a2e67e41a760f3 100644 (file)
@@ -718,7 +718,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   // 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;
+    Key pawnKey, materialKey;
     int castleRights, rule50, pliesFromNull;
     Square epSquare;
     Value value;
@@ -758,16 +758,15 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
 
   Piece piece = piece_on(from);
   PieceType pt = type_of_piece(piece);
+  PieceType capture = ep ? PAWN : type_of_piece_on(to);
 
   assert(color_of_piece_on(from) == us);
   assert(color_of_piece_on(to) == them || square_is_empty(to));
   assert(!(ep || pm) || piece == piece_of_color_and_type(us, PAWN));
   assert(!pm || relative_rank(us, to) == RANK_8);
 
-  st->capture = ep ? PAWN : type_of_piece_on(to);
-
-  if (st->capture)
-      do_capture_move(key, st->capture, them, to, ep);
+  if (capture)
+      do_capture_move(key, capture, them, to, ep);
 
   // Update hash key
   key ^= zobrist[us][pt][from] ^ zobrist[us][pt][to];
@@ -817,7 +816,7 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
       st->pawnKey ^= zobrist[us][PAWN][from] ^ zobrist[us][PAWN][to];
 
       // Set en passant square, only if moved pawn can be captured
-      if (abs(int(to) - int(from)) == 16)
+      if ((to ^ from) == 16)
       {
           if (attacks_from<PAWN>(from + (us == WHITE ? DELTA_N : DELTA_S), us) & pieces(PAWN, them))
           {
@@ -830,6 +829,9 @@ void Position::do_move(Move m, StateInfo& newSt, Bitboard dcCandidates) {
   // Update incremental scores
   st->value += pst_delta(piece, from, to);
 
+  // Set capture piece
+  st->capture = capture;
+
   if (pm) // promotion ?
   {
       PieceType promotion = move_promotion_piece(m);
index e2365a68f306266bb1ec4ba84c09fab8762c15c2..09c630062dd3984ea5a2fcc0ffaa647c7ff4fe2a 100644 (file)
@@ -87,12 +87,13 @@ enum Phase {
 /// must be passed as a parameter.
 
 struct StateInfo {
-  Key key, pawnKey, materialKey;
+  Key pawnKey, materialKey;
   int castleRights, rule50, pliesFromNull;
   Square epSquare;
   Score value;
   Value npMaterial[2];
 
+  Key key;
   PieceType capture;
   Bitboard checkersBB;
   StateInfo* previous;