From bb5f0100b033d7b337a7eb1a3ebcfd7619bd9f00 Mon Sep 17 00:00:00 2001 From: Ryan Lefkowitz Date: Wed, 15 Apr 2026 19:03:55 +0200 Subject: [PATCH] fix syzygy crash on Apple Silicon by unrolling tbprobe adjustment loop A bit tricky to identify, but in `apple-silicon` builds, specifying a value for `SyzygyPath` could still lead to crashes at certain depths from a SIGBUS/SIGSEGV. This PR replaces the `std::count_if()` adjustment in `tbprobe.cpp`'s `do_probe_table()` with an annotated handwritten loop, avoiding the clang/LTO miscompilation behind the crash. closes https://github.com/official-stockfish/Stockfish/pull/6721 No functional change. --- AUTHORS | 1 + src/syzygy/tbprobe.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0d157b655..1f0b9e37c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -223,6 +223,7 @@ Ron Britvich (Britvich) rqs Rui Coelho (ruicoelhopedro) rustam-cpp +Ryan Lefkowitz (rlefko) Ryan Hirsch Ryan Schmitt Ryan Takker diff --git a/src/syzygy/tbprobe.cpp b/src/syzygy/tbprobe.cpp index ba808ee4b..b75b6046a 100644 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@ -949,8 +949,10 @@ encode_remaining: // groups (similar to what was done earlier for leading group pieces). for (int i = 0; i < d->groupLen[next]; ++i) { - auto f = [&](Square s) { return groupSq[i] > s; }; - auto adjust = std::count_if(squares, groupSq, f); + int adjust = 0; + DISABLE_CLANG_LOOP_VEC + for (Square* sq = squares; sq != groupSq; ++sq) + adjust += groupSq[i] > *sq; n += Binomial[i + 1][groupSq[i] - adjust - 8 * remainingPawns]; }