]> git.sesse.net Git - stockfish/commitdiff
Retire SearchStack sstack[] from SplitPoint
authorMarco Costalba <mcostalba@gmail.com>
Fri, 18 Feb 2011 14:44:02 +0000 (15:44 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 18 Feb 2011 15:54:49 +0000 (16:54 +0100)
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 <mcostalba@gmail.com>
src/search.cpp
src/thread.h

index fd5378f92e751050f2217a7d877213926b9dd39c..aa8817ac050b40fe02a51ee8ab17b189b7df7810 100644 (file)
@@ -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<PV, true, false>(pos, ss, tsp->alpha, tsp->beta, tsp->depth, tsp->ply);
+                search<PV, true, false>(pos, ss+1, tsp->alpha, tsp->beta, tsp->depth, tsp->ply);
             else
-                search<NonPV, true, false>(pos, ss, tsp->alpha, tsp->beta, tsp->depth, tsp->ply);
+                search<NonPV, true, false>(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()
index d06291ebd61526a1a4b672833489ba2979d5c185..d0eb1b4fe2d6982ed96ed0a8f778591c945b7d38 100644 (file)
@@ -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;