mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Retire slavesPositions
Save the current active position in each Thread instead of keeping a centralized array in struct SplitPoint. This allow to skip a memset() call at each split. No functional change.
This commit is contained in:
parent
880726c13a
commit
e5bc79fb9c
3 changed files with 12 additions and 10 deletions
|
@ -1672,9 +1672,9 @@ void Thread::idle_loop() {
|
||||||
|
|
||||||
sp->mutex.lock();
|
sp->mutex.lock();
|
||||||
|
|
||||||
assert(sp->slavesPositions[idx] == NULL);
|
assert(activePosition == NULL);
|
||||||
|
|
||||||
sp->slavesPositions[idx] = &pos;
|
activePosition = &pos;
|
||||||
|
|
||||||
switch (sp->nodeType) {
|
switch (sp->nodeType) {
|
||||||
case Root:
|
case Root:
|
||||||
|
@ -1693,7 +1693,7 @@ void Thread::idle_loop() {
|
||||||
assert(searching);
|
assert(searching);
|
||||||
|
|
||||||
searching = false;
|
searching = false;
|
||||||
sp->slavesPositions[idx] = NULL;
|
activePosition = NULL;
|
||||||
sp->slavesMask &= ~(1ULL << idx);
|
sp->slavesMask &= ~(1ULL << idx);
|
||||||
sp->nodes += pos.nodes_searched();
|
sp->nodes += pos.nodes_searched();
|
||||||
|
|
||||||
|
@ -1742,7 +1742,7 @@ void check_time() {
|
||||||
nodes = RootPos.nodes_searched();
|
nodes = RootPos.nodes_searched();
|
||||||
|
|
||||||
// Loop across all split points and sum accumulated SplitPoint nodes plus
|
// Loop across all split points and sum accumulated SplitPoint nodes plus
|
||||||
// all the currently active slaves positions.
|
// all the currently active positions nodes.
|
||||||
for (size_t i = 0; i < Threads.size(); i++)
|
for (size_t i = 0; i < Threads.size(); i++)
|
||||||
for (int j = 0; j < Threads[i]->splitPointsSize; j++)
|
for (int j = 0; j < Threads[i]->splitPointsSize; j++)
|
||||||
{
|
{
|
||||||
|
@ -1754,8 +1754,9 @@ void check_time() {
|
||||||
Bitboard sm = sp.slavesMask;
|
Bitboard sm = sp.slavesMask;
|
||||||
while (sm)
|
while (sm)
|
||||||
{
|
{
|
||||||
Position* pos = sp.slavesPositions[pop_lsb(&sm)];
|
Position* pos = Threads[pop_lsb(&sm)]->activePosition;
|
||||||
nodes += pos ? pos->nodes_searched() : 0;
|
if (pos)
|
||||||
|
nodes += pos->nodes_searched();
|
||||||
}
|
}
|
||||||
|
|
||||||
sp.mutex.unlock();
|
sp.mutex.unlock();
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include <algorithm> // For std::count
|
#include <algorithm> // For std::count
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring> // For memset
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "movegen.h"
|
#include "movegen.h"
|
||||||
|
@ -49,6 +48,7 @@ Thread::Thread() /* : splitPoints() */ { // Value-initialization bug in MSVC
|
||||||
searching = exit = false;
|
searching = exit = false;
|
||||||
maxPly = splitPointsSize = 0;
|
maxPly = splitPointsSize = 0;
|
||||||
activeSplitPoint = NULL;
|
activeSplitPoint = NULL;
|
||||||
|
activePosition = NULL;
|
||||||
idx = Threads.size();
|
idx = Threads.size();
|
||||||
|
|
||||||
if (!thread_create(handle, start_routine, this))
|
if (!thread_create(handle, start_routine, this))
|
||||||
|
@ -281,8 +281,6 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
|
||||||
sp.cutoff = false;
|
sp.cutoff = false;
|
||||||
sp.ss = ss;
|
sp.ss = ss;
|
||||||
|
|
||||||
memset(sp.slavesPositions, 0, sizeof(sp.slavesPositions));
|
|
||||||
|
|
||||||
// Try to allocate available threads and ask them to start searching setting
|
// Try to allocate available threads and ask them to start searching setting
|
||||||
// 'searching' flag. This must be done under lock protection to avoid concurrent
|
// 'searching' flag. This must be done under lock protection to avoid concurrent
|
||||||
// allocation of the same slave by another master.
|
// allocation of the same slave by another master.
|
||||||
|
@ -291,6 +289,7 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
|
||||||
|
|
||||||
splitPointsSize++;
|
splitPointsSize++;
|
||||||
activeSplitPoint = &sp;
|
activeSplitPoint = &sp;
|
||||||
|
activePosition = NULL;
|
||||||
|
|
||||||
size_t slavesCnt = 1; // This thread is always included
|
size_t slavesCnt = 1; // This thread is always included
|
||||||
Thread* slave;
|
Thread* slave;
|
||||||
|
@ -318,6 +317,7 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
|
||||||
// In helpful master concept a master can help only a sub-tree of its split
|
// In helpful master concept a master can help only a sub-tree of its split
|
||||||
// point, and because here is all finished is not possible master is booked.
|
// point, and because here is all finished is not possible master is booked.
|
||||||
assert(!searching);
|
assert(!searching);
|
||||||
|
assert(!activePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have returned from the idle loop, which means that all threads are
|
// We have returned from the idle loop, which means that all threads are
|
||||||
|
@ -329,6 +329,7 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes
|
||||||
searching = true;
|
searching = true;
|
||||||
splitPointsSize--;
|
splitPointsSize--;
|
||||||
activeSplitPoint = sp.parentSplitPoint;
|
activeSplitPoint = sp.parentSplitPoint;
|
||||||
|
activePosition = &pos;
|
||||||
pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
|
pos.set_nodes_searched(pos.nodes_searched() + sp.nodes);
|
||||||
*bestMove = sp.bestMove;
|
*bestMove = sp.bestMove;
|
||||||
*bestValue = sp.bestValue;
|
*bestValue = sp.bestValue;
|
||||||
|
|
|
@ -75,7 +75,6 @@ struct SplitPoint {
|
||||||
|
|
||||||
// Shared data
|
// Shared data
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
Position* slavesPositions[MAX_THREADS];
|
|
||||||
volatile uint64_t slavesMask;
|
volatile uint64_t slavesMask;
|
||||||
volatile int64_t nodes;
|
volatile int64_t nodes;
|
||||||
volatile Value alpha;
|
volatile Value alpha;
|
||||||
|
@ -110,6 +109,7 @@ struct Thread {
|
||||||
Material::Table materialTable;
|
Material::Table materialTable;
|
||||||
Endgames endgames;
|
Endgames endgames;
|
||||||
Pawns::Table pawnsTable;
|
Pawns::Table pawnsTable;
|
||||||
|
Position* activePosition;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
int maxPly;
|
int maxPly;
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
|
Loading…
Add table
Reference in a new issue