]> git.sesse.net Git - stockfish/commitdiff
Introduce and use TranspositionTable::refresh()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 30 Oct 2010 14:22:10 +0000 (15:22 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 30 Oct 2010 14:22:10 +0000 (15:22 +0100)
No functional change.

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

index eb14e861020928bc20c8730202654653f0818832..dcfedcdbe0b05afa14e2c3b6221ee4cfff67ad61 100644 (file)
@@ -1001,10 +1001,8 @@ namespace {
     }
 
     // Step 2. Check for aborted search and immediate draw
-    if (AbortSearch || ThreadsMgr.thread_should_stop(threadID))
-        return VALUE_DRAW;
-
-    if (pos.is_draw() || ply >= PLY_MAX - 1)
+    if (   AbortSearch   || ThreadsMgr.thread_should_stop(threadID)
+        || pos.is_draw() || ply >= PLY_MAX - 1)
         return VALUE_DRAW;
 
     // Step 3. Mate distance pruning
@@ -1021,7 +1019,7 @@ namespace {
     posKey = excludedMove ? pos.get_exclusion_key() : pos.get_key();
 
     tte = TT.retrieve(posKey);
-    ttMove = (tte ? tte->move() : MOVE_NONE);
+    ttMove = tte ? tte->move() : MOVE_NONE;
 
     // At PV nodes, we don't use the TT for pruning, but only for move ordering.
     // This is to avoid problems in the following areas:
@@ -1030,12 +1028,9 @@ namespace {
     // * Fifty move rule detection
     // * Searching for a mate
     // * Printing of full PV line
-
     if (!PvNode && tte && ok_to_use_TT(tte, depth, beta, ply))
     {
-        // Refresh tte entry to avoid aging
-        TT.store(posKey, tte->value(), tte->type(), tte->depth(), ttMove, tte->static_value(), tte->static_value_margin());
-
+        TT.refresh(tte);
         ss->bestMove = ttMove; // Can be MOVE_NONE
         return value_from_tt(tte->value(), ply);
     }
index 9babce8cdc9f10e14500c1f9c4e5cdc6a071d033..ad362de343612296ae0cd435024960b3e57ddc05 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -64,6 +64,7 @@ public:
       staticValue = int16_t(statV);
       staticValueMargin  = int16_t(kd);
   }
+  void set_generation(int g) { data = move() | (type() << 21) | (g << 23); }
 
   uint32_t key() const { return key32; }
   Depth depth() const { return Depth(depth16); }
@@ -114,6 +115,7 @@ public:
   TTEntry* retrieve(const Key posKey) const;
   void new_search();
   TTEntry* first_entry(const Key posKey) const;
+  void refresh(const TTEntry* tte) const;
 
 private:
   size_t size;
@@ -133,4 +135,13 @@ inline TTEntry* TranspositionTable::first_entry(const Key posKey) const {
   return entries[uint32_t(posKey) & (size - 1)].data;
 }
 
+
+/// TranspositionTable::refresh updates the 'generation' value of the TTEntry
+/// to avoid aging. Normally called after a TT hit, before to return.
+
+inline void TranspositionTable::refresh(const TTEntry* tte) const {
+
+  const_cast<TTEntry*>(tte)->set_generation(generation);
+}
+
 #endif // !defined(TT_H_INCLUDED)