]> git.sesse.net Git - stockfish/commitdiff
Speculative prefetch
authorjoergoster <osterj165@googlemail.com>
Thu, 2 Oct 2014 21:19:14 +0000 (22:19 +0100)
committerJoona Kiiski <joona.kiiski@gmail.com>
Thu, 2 Oct 2014 21:19:14 +0000 (22:19 +0100)
Idea by Peter Oesterlund.
Implemented and tested by Joerg Oester

STC 3 threads
ELO: 3.19 +-2.1 (95%) LOS: 99.9%
Total: 40000 W: 7576 L: 7209 D: 25215

LTC
LLR: 2.96 (-2.94,2.94) [0.00,6.00]
Total: 22026 W: 3829 L: 3619 D: 14578

STC
LLR: 2.95 (-2.94,2.94) [-1.50,4.50]
Total: 7291 W: 1531 L: 1404 D: 4356

No functional change

Resolves #61

src/position.cpp
src/position.h
src/search.cpp

index b00bda24b0596b56a4661a315cfebc2e6c0195e0..b2d46b83a6a3b3d19494f2f0c424cd0df8188905 100644 (file)
@@ -1015,6 +1015,21 @@ void Position::undo_null_move() {
   sideToMove = ~sideToMove;
 }
 
   sideToMove = ~sideToMove;
 }
 
+// Position::hash_after_move() updates the hash key needed for the speculative prefetch.
+// It doesn't recognize special moves like castling, en-passant and promotions.
+Key Position::hash_after_move(Move m) const {
+
+  int from = from_sq(m);
+  int to = to_sq(m);
+  Piece p = board[from];
+  Piece capP = board[to];
+  Key ret = st->key ^ Zobrist::side;
+  if (capP != NO_PIECE)
+      ret ^= Zobrist::psq[color_of(capP)][type_of(capP)][to];
+  ret ^= Zobrist::psq[color_of(p)][type_of(p)][to];
+  ret ^= Zobrist::psq[color_of(p)][type_of(p)][from];
+  return ret;
+}
 
 /// Position::see() is a static exchange evaluator: It tries to estimate the
 /// material gain or loss resulting from a move.
 
 /// Position::see() is a static exchange evaluator: It tries to estimate the
 /// material gain or loss resulting from a move.
index 8f5fb75aa7f4630d07e203764277057cc3a8d8f6..7565abb92cf90dbadebaf59cea290e3e05a7876b 100644 (file)
@@ -139,6 +139,7 @@ public:
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
+  Key hash_after_move(Move m) const;
 
   // Static exchange evaluation
   Value see(Move m) const;
 
   // Static exchange evaluation
   Value see(Move m) const;
index 152de13c861d6689f803327424c8a419db79b19c..32f42cf07e879777c8b7241fe8a517d65e33f8b2 100644 (file)
@@ -788,6 +788,9 @@ moves_loop: // When in check and at SpNode search starts from here
           }
       }
 
           }
       }
 
+      // Speculative prefetch
+      prefetch((char*)TT.first_entry(pos.hash_after_move(move)));
+
       // Check for legality just before making the move
       if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
       {
       // Check for legality just before making the move
       if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
       {
@@ -1137,6 +1140,9 @@ moves_loop: // When in check and at SpNode search starts from here
           &&  pos.see_sign(move) < VALUE_ZERO)
           continue;
 
           &&  pos.see_sign(move) < VALUE_ZERO)
           continue;
 
+      // Speculative prefetch
+      prefetch((char*)TT.first_entry(pos.hash_after_move(move)));
+
       // Check for legality just before making the move
       if (!pos.legal(move, ci.pinned))
           continue;
       // Check for legality just before making the move
       if (!pos.legal(move, ci.pinned))
           continue;