X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fsearch.cpp;h=5447ed3c6694c74b398effebbe3ad41a704e9778;hp=8f3c4552076e69951b1def82695fa7638ed54951;hb=3cb02004596f868ae405b09fbf3a2038a680a989;hpb=ebc563059c5fc103ca6d79edb04bb6d5f182eaf5 diff --git a/src/search.cpp b/src/search.cpp index 8f3c4552..5447ed3c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -85,7 +85,7 @@ namespace { // History and stats update bonus, based on depth int stat_bonus(Depth depth) { - int d = depth / ONE_PLY ; + int d = depth / ONE_PLY; return d > 17 ? 0 : d * d + 2 * d - 2; } @@ -335,7 +335,7 @@ void Thread::search() { MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr); std::memset(ss-4, 0, 7 * sizeof(Stack)); - for(int i = 4; i > 0; i--) + for (int i = 4; i > 0; i--) (ss-i)->history = &this->counterMoveHistory[NO_PIECE][0]; // Use as sentinel bestValue = delta = alpha = -VALUE_INFINITE; @@ -361,7 +361,7 @@ void Thread::search() { multiPV = std::min(multiPV, rootMoves.size()); // Iterative deepening loop until requested to stop or the target depth is reached - while ( (rootDepth += ONE_PLY) < DEPTH_MAX + while ( (rootDepth = rootDepth + ONE_PLY) < DEPTH_MAX && !Signals.stop && (!Limits.depth || Threads.main()->rootDepth / ONE_PLY <= Limits.depth)) { @@ -400,6 +400,9 @@ void Thread::search() { { bestValue = ::search(rootPos, ss, alpha, beta, rootDepth, false, false); + this->tbHits = rootPos.tb_hits(); + this->nodes = rootPos.nodes_searched(); + // Bring the best move to the front. It is critical that sorting // is done with a stable algorithm because all the values but the // first and eventually the new best one are set to -VALUE_INFINITE @@ -568,6 +571,9 @@ namespace { { thisThread->resetCalls = false; + thisThread->tbHits = pos.tb_hits(); + thisThread->nodes = pos.nodes_searched(); + // At low node count increase the checking rate to about 0.1% of nodes // otherwise use a default value. thisThread->callsCnt = Limits.nodes ? std::min(4096, int(Limits.nodes / 1024)) @@ -668,7 +674,7 @@ namespace { if (err != TB::ProbeState::FAIL) { - thisThread->tbHits++; + pos.increment_tbHits(); int drawScore = TB::UseRule50 ? 1 : 0; @@ -784,9 +790,7 @@ namespace { && abs(beta) < VALUE_MATE_IN_MAX_PLY) { Value rbeta = std::min(beta + 200, VALUE_INFINITE); - Depth rdepth = depth - 4 * ONE_PLY; - assert(rdepth >= ONE_PLY); assert(is_ok((ss-1)->currentMove)); MovePicker mp(pos, ttMove, rbeta - ss->staticEval); @@ -797,8 +801,9 @@ namespace { ss->currentMove = move; ss->history = &thisThread->counterMoveHistory[pos.moved_piece(move)][to_sq(move)]; + assert(depth >= 5 * ONE_PLY); pos.do_move(move, st); - value = -search(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode, false); + value = -search(pos, ss+1, -rbeta, -rbeta+1, depth - 4 * ONE_PLY, !cutNode, false); pos.undo_move(move); if (value >= rbeta) return value; @@ -1257,6 +1262,9 @@ moves_loop: // When in check search starts from here { assert(is_ok(move)); + // Speculative prefetch as early as possible + prefetch(TT.first_entry(pos.key_after(move))); + givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates() ? pos.check_squares(type_of(pos.piece_on(from_sq(move)))) & to_sq(move) : pos.gives_check(move); @@ -1298,9 +1306,6 @@ moves_loop: // When in check search starts from here && !pos.see_ge(move)) continue; - // Speculative prefetch as early as possible - prefetch(TT.first_entry(pos.key_after(move))); - // Check for legality just before making the move if (!pos.legal(move)) { @@ -1474,7 +1479,7 @@ moves_loop: // When in check search starts from here void check_time() { - static TimePoint lastInfoTime = now(); + static std::atomic lastInfoTime = { now() }; int elapsed = Time.elapsed(); TimePoint tick = Limits.startTime + elapsed;