1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

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 <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-02-18 15:44:02 +01:00
parent 932ae761c6
commit 823a5918e7
2 changed files with 11 additions and 10 deletions

View file

@ -611,7 +611,7 @@ namespace {
// Initialize FIXME move before Rml.init() // Initialize FIXME move before Rml.init()
TT.new_search(); TT.new_search();
H.clear(); H.clear();
memset(ss, 0, PLY_MAX_PLUS_2 * sizeof(SearchStack)); memset(ss, 0, 4 * sizeof(SearchStack));
*ponderMove = bestMove = easyMove = MOVE_NONE; *ponderMove = bestMove = easyMove = MOVE_NONE;
depth = aspirationDelta = 0; depth = aspirationDelta = 0;
ss->currentMove = MOVE_NULL; // Hack to skip update_gains() ss->currentMove = MOVE_NULL; // Hack to skip update_gains()
@ -801,7 +801,8 @@ namespace {
bestValue = alpha; bestValue = alpha;
// Step 1. Initialize node and poll. Polling can abort search // 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; (ss+2)->killers[0] = (ss+2)->killers[1] = (ss+2)->mateKiller = MOVE_NONE;
if (threadID == 0 && ++NodesSincePoll > NodesBetweenPolls) 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; 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; SplitPoint* tsp = threads[threadID].splitPoint;
Position pos(*tsp->pos, threadID); 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) 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 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); 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++) for (i = 0; i < activeThreads; i++)
if (i == master || splitPoint.slaves[i]) if (i == master || splitPoint.slaves[i])
{ {
memcpy(splitPoint.sstack[i], ss - 1, 4 * sizeof(SearchStack));
assert(i == master || threads[i].state == THREAD_BOOKED); assert(i == master || threads[i].state == THREAD_BOOKED);
threads[i].state = THREAD_WORKISWAITING; // This makes the slave to exit from idle_loop() threads[i].state = THREAD_WORKISWAITING; // This makes the slave to exit from idle_loop()

View file

@ -57,7 +57,6 @@ struct SplitPoint {
int ply; int ply;
int master; int master;
Move threatMove; Move threatMove;
SearchStack sstack[MAX_THREADS][PLY_MAX_PLUS_2];
// Const pointers to shared data // Const pointers to shared data
MovePicker* mp; MovePicker* mp;