Don't prefetch if not needed
authorMarco Costalba <mcostalba@gmail.com>
Sun, 27 Jan 2013 09:15:59 +0000 (10:15 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 27 Jan 2013 09:19:11 +0000 (10:19 +0100)
Prefetch access to hash tables only in case we
have changed pawn or material hash keys.

No functional change.

src/position.cpp

index a005d5df2809e069318f0bbb7fec1c67d04ffea9..599350888d86cca9243a081334b5fd48b3911d1b 100644 (file)
@@ -802,9 +802,10 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       pieceList[them][capture][index[lastSquare]] = lastSquare;
       pieceList[them][capture][pieceCount[them][capture]] = SQ_NONE;
 
-      // Update hash keys
+      // Update material hash key and prefetch access to materialTable
       k ^= Zobrist::psq[them][capture][capsq];
       st->materialKey ^= Zobrist::psq[them][capture][pieceCount[them][capture]];
+      prefetch((char*)thisThread->materialTable[st->materialKey]);
 
       // Update incremental scores
       st->psqScore -= pieceSquareTable[make_piece(them, capture)][capsq];
@@ -831,7 +832,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       st->castleRights &= ~cr;
   }
 
-  // Prefetch TT access as soon as we know key is updated
+  // Prefetch TT access as soon as we know the new hash key
   prefetch((char*)TT.first_entry(k));
 
   // Move the piece
@@ -894,17 +895,14 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
           st->npMaterial[us] += PieceValue[MG][promotion];
       }
 
-      // Update pawn hash key
+      // Update pawn hash key and prefetch access to pawnsTable
       st->pawnKey ^= Zobrist::psq[us][PAWN][from] ^ Zobrist::psq[us][PAWN][to];
+      prefetch((char*)thisThread->pawnsTable[st->pawnKey]);
 
       // Reset rule 50 draw counter
       st->rule50 = 0;
   }
 
-  // Prefetch pawn and material hash tables
-  prefetch((char*)thisThread->pawnsTable[st->pawnKey]);
-  prefetch((char*)thisThread->materialTable[st->materialKey]);
-
   // Update incremental scores
   st->psqScore += psq_delta(piece, from, to);