Add ability to disable performance-sensitive relaxed atomic operations at compile time

Adds a `RelaxedAtomic`  wrapper around either `T` or `std::atomic<T>` and `USE_SLOPPY_ATOMICS` preprocessor define. The intent of this flag is to allow easy disabling of atomics on WASM, where even relaxed atomics are expensive because all atomics have `seq_cst` semantics.

Passed non regression STC
LLR: 2.99 (-2.94,2.94) <-1.75,0.25>
Total: 50624 W: 12976 L: 12776 D: 24872
Ptnml(0-2): 112, 5445, 14005, 5631, 119
https://tests.stockfishchess.org/tests/view/6a1f690e818cacc1db0ad2c7

Passed non-regression STC SMP
 LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 163696 W: 41514 L: 41438 D: 80744
Ptnml(0-2): 162, 18272, 44904, 18348, 162
https://tests.stockfishchess.org/tests/view/6a21fb97351b79f679cc44b3

Using this class for the TT also allows us to remove the TSAN suppressions, since the UB is fixed.

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

No functional change
This commit is contained in:
anematode
2026-06-09 21:52:29 +02:00
committed by Joost VandeVondele
parent 415ff793a0
commit 0111d11e23
9 changed files with 115 additions and 61 deletions
+2 -4
View File
@@ -623,8 +623,7 @@ void Search::Worker::do_move(Position& pos, const Move move, StateInfo& st, Stac
void Search::Worker::do_move(
Position& pos, const Move move, StateInfo& st, const bool givesCheck, Stack* const ss) {
bool capture = pos.capture_stage(move);
// Preferable over fetch_add to avoid locking instructions
nodes.store(nodes.load(std::memory_order_relaxed) + 1, std::memory_order_relaxed);
++nodes;
auto [dirtyPiece, dirtyThreats] = accumulatorStack.push();
pos.do_move(move, st, givesCheck, dirtyPiece, dirtyThreats, &tt, &sharedHistory);
@@ -901,8 +900,7 @@ Value Search::Worker::search(
if (err != TB::ProbeState::FAIL)
{
// Preferable over fetch_add to avoid locking instructions
tbHits.store(tbHits.load(std::memory_order_relaxed) + 1, std::memory_order_relaxed);
++tbHits;
int drawScore = tbConfig.useRule50 ? 1 : 0;