mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Introducing NodeType Root
We transform rootNode into constexpr by adding a new NodeType `Root`, which causes a speed up. Local test: ``` Build Tester: 1.4.7.0 Windows 10 (Version 10.0, Build 0, 64-bit Edition) Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz SafeMode: No Running In VM: No HyperThreading Enabled: Yes CPU Warmup: Yes Command Line: bench Tests per Build: 25 ANOVA: n/a Engine# (NPS) Speedup Sp Conf. 95% S.S. patch (920.179,4) ---> master (906.329,2) ---> 1,528% 20.336,5 Yes No ``` --------- STC: LLR: 2.94 (-2.94,2.94) <-0.50,2.50> Total: 98216 W: 8348 L: 8102 D: 81766 Ptnml(0-2): 295, 6357, 35549, 6621, 286 https://tests.stockfishchess.org/tests/view/60b797e2457376eb8bcaa0ab Yellow LTC: LLR: -2.95 (-2.94,2.94) <0.50,3.50> Total: 76936 W: 2651 L: 2626 D: 71659 Ptnml(0-2): 29, 2233, 33916, 2264, 26 https://tests.stockfishchess.org/tests/view/60b80d6d457376eb8bcaa145 closes https://github.com/official-stockfish/Stockfish/pull/3522 No functional change
This commit is contained in:
parent
9353e72103
commit
0b7cc8bd2f
1 changed files with 16 additions and 15 deletions
|
@ -59,7 +59,7 @@ using namespace Search;
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Different node types, used as a template parameter
|
// Different node types, used as a template parameter
|
||||||
enum NodeType { NonPV, PV };
|
enum NodeType { NonPV, PV, Root };
|
||||||
|
|
||||||
constexpr uint64_t TtHitAverageWindow = 4096;
|
constexpr uint64_t TtHitAverageWindow = 4096;
|
||||||
constexpr uint64_t TtHitAverageResolution = 1024;
|
constexpr uint64_t TtHitAverageResolution = 1024;
|
||||||
|
@ -102,10 +102,10 @@ namespace {
|
||||||
Move best = MOVE_NONE;
|
Move best = MOVE_NONE;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType nodeType>
|
||||||
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType nodeType>
|
||||||
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth = 0);
|
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth = 0);
|
||||||
|
|
||||||
Value value_to_tt(Value v, int ply);
|
Value value_to_tt(Value v, int ply);
|
||||||
|
@ -384,7 +384,7 @@ void Thread::search() {
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt - searchAgainCounter);
|
Depth adjustedDepth = std::max(1, rootDepth - failedHighCnt - searchAgainCounter);
|
||||||
bestValue = Stockfish::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
bestValue = Stockfish::search<Root>(rootPos, ss, alpha, beta, adjustedDepth, false);
|
||||||
|
|
||||||
// Bring the best move to the front. It is critical that sorting
|
// Bring the best move to the front. It is critical that sorting
|
||||||
// is done with a stable algorithm because all the values but the
|
// is done with a stable algorithm because all the values but the
|
||||||
|
@ -527,18 +527,18 @@ namespace {
|
||||||
|
|
||||||
// search<>() is the main search function for both PV and non-PV nodes
|
// search<>() is the main search function for both PV and non-PV nodes
|
||||||
|
|
||||||
template <NodeType NT>
|
template <NodeType nodeType>
|
||||||
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
|
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
|
||||||
|
|
||||||
constexpr bool PvNode = NT == PV;
|
constexpr bool PvNode = nodeType != NonPV;
|
||||||
const bool rootNode = PvNode && ss->ply == 0;
|
constexpr bool rootNode = nodeType == Root;
|
||||||
const Depth maxNextDepth = rootNode ? depth : depth + 1;
|
const Depth maxNextDepth = rootNode ? depth : depth + 1;
|
||||||
|
|
||||||
// Check if we have an upcoming move which draws by repetition, or
|
// Check if we have an upcoming move which draws by repetition, or
|
||||||
// if the opponent had an alternative move earlier to this position.
|
// if the opponent had an alternative move earlier to this position.
|
||||||
if ( pos.rule50_count() >= 3
|
if ( !rootNode
|
||||||
|
&& pos.rule50_count() >= 3
|
||||||
&& alpha < VALUE_DRAW
|
&& alpha < VALUE_DRAW
|
||||||
&& !rootNode
|
|
||||||
&& pos.has_game_cycle(ss->ply))
|
&& pos.has_game_cycle(ss->ply))
|
||||||
{
|
{
|
||||||
alpha = value_draw(pos.this_thread());
|
alpha = value_draw(pos.this_thread());
|
||||||
|
@ -548,7 +548,7 @@ namespace {
|
||||||
|
|
||||||
// Dive into quiescence search when the depth reaches zero
|
// Dive into quiescence search when the depth reaches zero
|
||||||
if (depth <= 0)
|
if (depth <= 0)
|
||||||
return qsearch<NT>(pos, ss, alpha, beta);
|
return qsearch<PvNode ? PV : NonPV>(pos, ss, alpha, beta);
|
||||||
|
|
||||||
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
|
||||||
assert(PvNode || (alpha == beta - 1));
|
assert(PvNode || (alpha == beta - 1));
|
||||||
|
@ -1054,9 +1054,9 @@ moves_loop: // When in check, search starts from here
|
||||||
// then that move is singular and should be extended. To verify this we do
|
// then that move is singular and should be extended. To verify this we do
|
||||||
// a reduced search on all the other moves but the ttMove and if the
|
// a reduced search on all the other moves but the ttMove and if the
|
||||||
// result is lower than ttValue minus a margin, then we will extend the ttMove.
|
// result is lower than ttValue minus a margin, then we will extend the ttMove.
|
||||||
if ( depth >= 7
|
if ( !rootNode
|
||||||
|
&& depth >= 7
|
||||||
&& move == ttMove
|
&& move == ttMove
|
||||||
&& !rootNode
|
|
||||||
&& !excludedMove // Avoid recursive singular search
|
&& !excludedMove // Avoid recursive singular search
|
||||||
/* && ttValue != VALUE_NONE Already implicit in the next condition */
|
/* && ttValue != VALUE_NONE Already implicit in the next condition */
|
||||||
&& abs(ttValue) < VALUE_KNOWN_WIN
|
&& abs(ttValue) < VALUE_KNOWN_WIN
|
||||||
|
@ -1351,10 +1351,11 @@ moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
// qsearch() is the quiescence search function, which is called by the main search
|
// qsearch() is the quiescence search function, which is called by the main search
|
||||||
// function with zero depth, or recursively with further decreasing depth per call.
|
// function with zero depth, or recursively with further decreasing depth per call.
|
||||||
template <NodeType NT>
|
template <NodeType nodeType>
|
||||||
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
|
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth) {
|
||||||
|
|
||||||
constexpr bool PvNode = NT == PV;
|
static_assert(nodeType != Root);
|
||||||
|
constexpr bool PvNode = nodeType == PV;
|
||||||
|
|
||||||
assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
|
assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
|
||||||
assert(PvNode || (alpha == beta - 1));
|
assert(PvNode || (alpha == beta - 1));
|
||||||
|
@ -1532,7 +1533,7 @@ moves_loop: // When in check, search starts from here
|
||||||
|
|
||||||
// Make and search the move
|
// Make and search the move
|
||||||
pos.do_move(move, st, givesCheck);
|
pos.do_move(move, st, givesCheck);
|
||||||
value = -qsearch<NT>(pos, ss+1, -beta, -alpha, depth - 1);
|
value = -qsearch<nodeType>(pos, ss+1, -beta, -alpha, depth - 1);
|
||||||
pos.undo_move(move);
|
pos.undo_move(move);
|
||||||
|
|
||||||
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
assert(value > -VALUE_INFINITE && value < VALUE_INFINITE);
|
||||||
|
|
Loading…
Add table
Reference in a new issue