From e3660b47bdd8249c3e647b11f506058a99167a69 Mon Sep 17 00:00:00 2001 From: Shawn Xu Date: Sun, 2 Mar 2025 21:38:11 -0800 Subject: [PATCH] Add dbg_clear helper function closes https://github.com/official-stockfish/Stockfish/pull/5921 No functional change --- src/misc.cpp | 15 ++++++++++++++- src/misc.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/misc.cpp b/src/misc.cpp index 06a8c624a..f85356c59 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -287,12 +287,18 @@ namespace { template struct DebugInfo { - std::atomic data[N] = {0}; + std::array, N> data = {0}; [[nodiscard]] constexpr std::atomic& operator[](size_t index) { assert(index < N); return data[index]; } + + constexpr DebugInfo& operator=(const DebugInfo& other) { + for (size_t i = 0; i < N; i++) + data[i].store(other.data[i].load()); + return *this; + } }; struct DebugExtremes: public DebugInfo<3> { @@ -393,6 +399,13 @@ void dbg_print() { } } +void dbg_clear() { + hit.fill({}); + mean.fill({}); + stdev.fill({}); + correl.fill({}); + extremes.fill({}); +} // Used to serialize access to std::cout // to avoid multiple threads writing at the same time. diff --git a/src/misc.h b/src/misc.h index d2cbb699d..84f11d6de 100644 --- a/src/misc.h +++ b/src/misc.h @@ -73,6 +73,7 @@ void dbg_stdev_of(int64_t value, int slot = 0); void dbg_extremes_of(int64_t value, int slot = 0); void dbg_correl_of(int64_t value1, int64_t value2, int slot = 0); void dbg_print(); +void dbg_clear(); using TimePoint = std::chrono::milliseconds::rep; // A value in milliseconds static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");