From 823a5918e73e47585cdf3c4504d9f7e85e18b7cc Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 18 Feb 2011 15:44:02 +0100 Subject: [PATCH] Retire SearchStack sstack[] from SplitPoint Use a local variable instead. To make it work we need to correctly init next ply search stack at the beginning of the search because now that ss is allocated on the stack instead of on the global storage it contains garbage. As a side effect we can peform a fast search stack init in id_loop(). With this patch size of SplitPoint goes from 71944 to 136 bytes, and consequently size of Thread goes from 575568 to 1104 bytes. Finally the size of ThreadsManager that contains all the thread info goes from 9209248 to just 17824 bytes !! No functional change also in faked split. Signed-off-by: Marco Costalba --- src/search.cpp | 20 +++++++++++--------- src/thread.h | 1 - 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index fd5378f9..aa8817ac 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -611,7 +611,7 @@ namespace { // Initialize FIXME move before Rml.init() TT.new_search(); H.clear(); - memset(ss, 0, PLY_MAX_PLUS_2 * sizeof(SearchStack)); + memset(ss, 0, 4 * sizeof(SearchStack)); *ponderMove = bestMove = easyMove = MOVE_NONE; depth = aspirationDelta = 0; ss->currentMove = MOVE_NULL; // Hack to skip update_gains() @@ -801,7 +801,8 @@ namespace { bestValue = alpha; // Step 1. Initialize node and poll. Polling can abort search - ss->currentMove = ss->bestMove = threatMove = MOVE_NONE; + ss->currentMove = ss->bestMove = threatMove = (ss+1)->excludedMove = MOVE_NONE; + (ss+1)->skipNullMove = false; (ss+1)->reduction = DEPTH_ZERO; (ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE; if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls) @@ -2109,16 +2110,19 @@ split_point_start: // At split points actual search starts from here threads[threadID].state = THREAD_SEARCHING; - // Here we call search() with SplitPoint template parameter set to true + // Copy SplitPoint position and search stack and call search() + // with SplitPoint template parameter set to true. + SearchStack ss[PLY_MAX_PLUS_2]; SplitPoint* tsp = threads[threadID].splitPoint; Position pos(*tsp->pos, threadID); - SearchStack* ss = tsp->sstack[threadID] + 1; - ss->sp = tsp; + + memcpy(ss, tsp->parentSstack - 1, 4 * sizeof(SearchStack)); + (ss+1)->sp = tsp; if (tsp->pvNode) - search(pos, ss, tsp->alpha, tsp->beta, tsp->depth, tsp->ply); + search(pos, ss+1, tsp->alpha, tsp->beta, tsp->depth, tsp->ply); else - search(pos, ss, tsp->alpha, tsp->beta, tsp->depth, tsp->ply); + search(pos, ss+1, tsp->alpha, tsp->beta, tsp->depth, tsp->ply); assert(threads[threadID].state == THREAD_SEARCHING); @@ -2394,8 +2398,6 @@ split_point_start: // At split points actual search starts from here for (i = 0; i < activeThreads; i++) if (i == master || splitPoint.slaves[i]) { - memcpy(splitPoint.sstack[i], ss - 1, 4 * sizeof(SearchStack)); - assert(i == master || threads[i].state == THREAD_BOOKED); threads[i].state = THREAD_WORKISWAITING; // This makes the slave to exit from idle_loop() diff --git a/src/thread.h b/src/thread.h index d06291eb..d0eb1b4f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -57,7 +57,6 @@ struct SplitPoint { int ply; int master; Move threatMove; - SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2]; // Const pointers to shared data MovePicker* mp; -- 2.39.2