1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

Consistent use of anonymous namespace

Also change `bindThisThread` to match the current code style for function naming.

closes https://github.com/official-stockfish/Stockfish/pull/5118

No functional change
This commit is contained in:
Disservin 2024-03-17 10:33:03 +01:00
parent ed60460004
commit 134e6d7bb4
6 changed files with 45 additions and 36 deletions

View file

@ -596,14 +596,15 @@ namespace WinProcGroup {
#ifndef _WIN32
void bindThisThread(size_t) {}
void bind_this_thread(size_t) {}
#else
namespace {
// Retrieves logical processor information using Windows-specific
// API and returns the best node id for the thread with index idx. Original
// code from Texel by Peter Österlund.
static int best_node(size_t idx) {
int best_node(size_t idx) {
int threads = 0;
int nodes = 0;
@ -668,10 +669,11 @@ static int best_node(size_t idx) {
// then return -1 and let the OS to decide what to do.
return idx < groups.size() ? groups[idx] : -1;
}
}
// Sets the group affinity of the current thread
void bindThisThread(size_t idx) {
void bind_this_thread(size_t idx) {
// Use only local variables to be thread-safe
int node = best_node(idx);

View file

@ -200,7 +200,7 @@ inline uint64_t mul_hi64(uint64_t a, uint64_t b) {
// called to set group affinity for each thread. Original code from Texel by
// Peter Österlund.
namespace WinProcGroup {
void bindThisThread(size_t idx);
void bind_this_thread(size_t idx);
}

View file

@ -51,10 +51,10 @@ void hint_common_parent_position(const Position& pos, const Networks& networks)
networks.big.hint_common_access(pos, false);
}
namespace {
// Converts a Value into (centi)pawns and writes it in a buffer.
// The buffer must have capacity for at least 5 chars.
static void format_cp_compact(Value v, char* buffer) {
void format_cp_compact(Value v, char* buffer) {
buffer[0] = (v < 0 ? '-' : v > 0 ? '+' : ' ');
@ -90,7 +90,7 @@ static void format_cp_compact(Value v, char* buffer) {
// Converts a Value into pawns, always keeping two decimals
static void format_cp_aligned_dot(Value v, std::stringstream& stream) {
void format_cp_aligned_dot(Value v, std::stringstream& stream) {
const double pawns = std::abs(0.01 * UCI::to_cp(v));
@ -99,6 +99,7 @@ static void format_cp_aligned_dot(Value v, std::stringstream& stream) {
: ' ')
<< std::setiosflags(std::ios::fixed) << std::setw(6) << std::setprecision(2) << pawns;
}
}
// Returns a string with the value of each piece on a board,

View file

@ -91,7 +91,7 @@ void Thread::idle_loop() {
// just check if running threads are below a threshold, in this case, all this
// NUMA machinery is not needed.
if (nthreads > 8)
WinProcGroup::bindThisThread(idx);
WinProcGroup::bind_this_thread(idx);
while (true)
{

View file

@ -95,7 +95,7 @@ void TranspositionTable::clear(size_t threadCount) {
threads.emplace_back([this, idx, threadCount]() {
// Thread binding gives faster search on systems with a first-touch policy
if (threadCount > 8)
WinProcGroup::bindThisThread(idx);
WinProcGroup::bind_this_thread(idx);
// Each thread will zero its part of the hash table
const size_t stride = size_t(clusterCount / threadCount), start = size_t(stride * idx),

View file

@ -30,10 +30,39 @@ using std::string;
namespace Stockfish {
bool Tune::update_on_last;
const Option* LastOption = nullptr;
OptionsMap* Tune::options;
static std::map<std::string, int> TuneResults;
bool Tune::update_on_last;
const Option* LastOption = nullptr;
OptionsMap* Tune::options;
namespace {
std::map<std::string, int> TuneResults;
void on_tune(const Option& o) {
if (!Tune::update_on_last || LastOption == &o)
Tune::read_options();
}
void make_option(OptionsMap* options, const string& n, int v, const SetRange& r) {
// Do not generate option when there is nothing to tune (ie. min = max)
if (r(v).first == r(v).second)
return;
if (TuneResults.count(n))
v = TuneResults[n];
(*options)[n] << Option(v, r(v).first, r(v).second, on_tune);
LastOption = &((*options)[n]);
// Print formatted parameters, ready to be copy-pasted in Fishtest
std::cout << n << "," << v << "," << r(v).first << "," << r(v).second << ","
<< (r(v).second - r(v).first) / 20.0 << ","
<< "0.0020" << std::endl;
}
}
string Tune::next(string& names, bool pop) {
@ -54,29 +83,6 @@ string Tune::next(string& names, bool pop) {
return name;
}
static void on_tune(const Option& o) {
if (!Tune::update_on_last || LastOption == &o)
Tune::read_options();
}
static void make_option(OptionsMap* options, const string& n, int v, const SetRange& r) {
// Do not generate option when there is nothing to tune (ie. min = max)
if (r(v).first == r(v).second)
return;
if (TuneResults.count(n))
v = TuneResults[n];
(*options)[n] << Option(v, r(v).first, r(v).second, on_tune);
LastOption = &((*options)[n]);
// Print formatted parameters, ready to be copy-pasted in Fishtest
std::cout << n << "," << v << "," << r(v).first << "," << r(v).second << ","
<< (r(v).second - r(v).first) / 20.0 << ","
<< "0.0020" << std::endl;
}
template<>
void Tune::Entry<int>::init_option() {