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>
// Initialize FIXME move before Rml.init()
TT.new_search();
H.clear();
// 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()
*ponderMove = bestMove = easyMove = MOVE_NONE;
depth = aspirationDelta = 0;
ss->currentMove = MOVE_NULL; // Hack to skip update_gains()
bestValue = alpha;
// Step 1. Initialize node and poll. Polling can abort search
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)
(ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE;
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls)
threads[threadID].state = THREAD_SEARCHING;
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);
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;
- 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);
- 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);
assert(threads[threadID].state == THREAD_SEARCHING);
for (i = 0; i < activeThreads; i++)
if (i == master || splitPoint.slaves[i])
{
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()
assert(i == master || threads[i].state == THREAD_BOOKED);
threads[i].state = THREAD_WORKISWAITING; // This makes the slave to exit from idle_loop()
int ply;
int master;
Move threatMove;
int ply;
int master;
Move threatMove;
- SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
// Const pointers to shared data
MovePicker* mp;
// Const pointers to shared data
MovePicker* mp;