From c416133e2fd1b6bb74fda07cd6050227bbe8994a Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 30 Oct 2010 15:22:10 +0100 Subject: [PATCH] Introduce and use TranspositionTable::refresh() No functional change. Signed-off-by: Marco Costalba --- src/search.cpp | 13 ++++--------- src/tt.h | 11 +++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index eb14e861..dcfedcdb 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -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); } diff --git a/src/tt.h b/src/tt.h index 9babce8c..ad362de3 100644 --- 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(tte)->set_generation(generation); +} + #endif // !defined(TT_H_INCLUDED) -- 2.39.2