Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent use of anonymous namespace #5118

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ HEADERS = benchmark.h bitboard.h evaluate.h misc.h movegen.h movepick.h \
nnue/layers/sqr_clipped_relu.h nnue/nnue_accumulator.h nnue/nnue_architecture.h \
nnue/nnue_common.h nnue/nnue_feature_transformer.h position.h \
search.h syzygy/tbprobe.h thread.h thread_win32_osx.h timeman.h \
tt.h tune.h types.h uci.h ucioption.h perft.h nnue/network.cpp
tt.h tune.h types.h uci.h ucioption.h perft.h nnue/network.h

OBJS = $(notdir $(SRCS:.cpp=.o))

Expand Down
8 changes: 5 additions & 3 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
7 changes: 4 additions & 3 deletions src/nnue/nnue_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '+' : ' ');

Expand Down Expand Up @@ -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));

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
52 changes: 29 additions & 23 deletions src/tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,22 @@ 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;

string Tune::next(string& names, bool pop) {

string name;

do
{
string token = names.substr(0, names.find(','));

if (pop)
names.erase(0, token.size() + 1);

std::stringstream ws(token);
name += (ws >> token, token); // Remove trailing whitespace

} while (std::count(name.begin(), name.end(), '(') - std::count(name.begin(), name.end(), ')'));

return name;
}
namespace {
std::map<std::string, int> TuneResults;

static void on_tune(const Option& o) {
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) {

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)
Expand All @@ -77,6 +62,27 @@ static void make_option(OptionsMap* options, const string& n, int v, const SetRa
<< (r(v).second - r(v).first) / 20.0 << ","
<< "0.0020" << std::endl;
}
}

string Tune::next(string& names, bool pop) {

string name;

do
{
string token = names.substr(0, names.find(','));

if (pop)
names.erase(0, token.size() + 1);

std::stringstream ws(token);
name += (ws >> token, token); // Remove trailing whitespace

} while (std::count(name.begin(), name.end(), '(') - std::count(name.begin(), name.end(), ')'));

return name;
}


template<>
void Tune::Entry<int>::init_option() {
Expand Down