X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsearch.cpp;h=f82197f87286f83b678b593d8526b479235c9325;hb=4c7a71a44bbe37a5e5dd971650c9b22790cae302;hp=9980dcf95b1aeb347986ce6cab2e6ac2000fe00f;hpb=77c91ac1ba45c55584de81b58116361564c6a69a;p=stockfish diff --git a/src/search.cpp b/src/search.cpp index 9980dcf9..f82197f8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -524,7 +524,7 @@ namespace { if (!RootNode) { // Step 2. Check for aborted search and immediate draw - if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) + if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY) return DrawValue[pos.side_to_move()]; // Step 3. Mate distance pruning. Even if we mate at the next move our score @@ -538,10 +538,6 @@ namespace { if (alpha >= beta) return alpha; } - else - { - if(pos.is_draw()) return DrawValue[pos.side_to_move()]; - } // Step 4. Transposition table lookup // We don't want the score of a partial search to overwrite a previous full search @@ -557,13 +553,13 @@ namespace { // smooth experience in analysis mode. We don't probe at Root nodes otherwise // we should also update RootMoveList to avoid bogus output. if ( !RootNode - && tte && tte->depth() >= depth + && tte + && tte->depth() >= depth + && ttValue != VALUE_NONE // Only in case of TT access race && ( PvNode ? tte->type() == BOUND_EXACT : ttValue >= beta ? (tte->type() & BOUND_LOWER) : (tte->type() & BOUND_UPPER))) { - assert(ttValue != VALUE_NONE); // Due to depth > DEPTH_NONE - TT.refresh(tte); ss->currentMove = ttMove; // Can be MOVE_NONE @@ -584,16 +580,22 @@ namespace { else if (tte) { - assert(tte->static_value() != VALUE_NONE); - assert(ttValue != VALUE_NONE || tte->type() == BOUND_NONE); + // Following asserts are valid only in single thread condition because + // TT access is always racy and its contents cannot be trusted. + assert(tte->static_value() != VALUE_NONE || Threads.size() > 1); + assert(ttValue != VALUE_NONE || tte->type() == BOUND_NONE || Threads.size() > 1); ss->staticEval = eval = tte->static_value(); ss->evalMargin = tte->static_value_margin(); + if (eval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race + eval = ss->staticEval = evaluate(pos, ss->evalMargin); + // Can ttValue be used as a better position evaluation? - if ( ((tte->type() & BOUND_LOWER) && ttValue > eval) - || ((tte->type() & BOUND_UPPER) && ttValue < eval)) - eval = ttValue; + if (ttValue != VALUE_NONE) + if ( ((tte->type() & BOUND_LOWER) && ttValue > eval) + || ((tte->type() & BOUND_UPPER) && ttValue < eval)) + eval = ttValue; } else { @@ -1107,7 +1109,7 @@ split_point_start: // At split points actual search starts from here ss->ply = (ss-1)->ply + 1; // Check for an instant draw or maximum ply reached - if (pos.is_draw() || ss->ply > MAX_PLY) + if (pos.is_draw() || ss->ply > MAX_PLY) return DrawValue[pos.side_to_move()]; // Transposition table lookup. At PV nodes, we don't use the TT for @@ -1122,13 +1124,13 @@ split_point_start: // At split points actual search starts from here // only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS. ttDepth = inCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS : DEPTH_QS_NO_CHECKS; - if ( tte && tte->depth() >= ttDepth + if ( tte + && tte->depth() >= ttDepth + && ttValue != VALUE_NONE // Only in case of TT access race && ( PvNode ? tte->type() == BOUND_EXACT : ttValue >= beta ? (tte->type() & BOUND_LOWER) : (tte->type() & BOUND_UPPER))) { - assert(ttValue != VALUE_NONE); // Due to ttDepth > DEPTH_NONE - ss->currentMove = ttMove; // Can be MOVE_NONE return ttValue; } @@ -1144,10 +1146,13 @@ split_point_start: // At split points actual search starts from here { if (tte) { - assert(tte->static_value() != VALUE_NONE); + assert(tte->static_value() != VALUE_NONE || Threads.size() > 1); ss->staticEval = bestValue = tte->static_value(); ss->evalMargin = tte->static_value_margin(); + + if (ss->staticEval == VALUE_NONE || ss->evalMargin == VALUE_NONE) // Due to a race + ss->staticEval = bestValue = evaluate(pos, ss->evalMargin); } else ss->staticEval = bestValue = evaluate(pos, ss->evalMargin); @@ -1556,7 +1561,7 @@ void RootMove::extract_pv_from_tt(Position& pos) { && pos.is_pseudo_legal(m) && pos.pl_move_is_legal(m, pos.pinned_pieces()) && ply < MAX_PLY - && (!pos.is_draw() || ply < 2)) + && (!pos.is_draw() || ply < 2)) { pv.push_back(m); pos.do_move(m, *st++);