Commit Graph
65 Commits
Author SHA1 Message Date
anematodeandJoost VandeVondele 31e89adf70 [RfC] Make CI faster
We can straightforwardly parallelize the `check_universal.sh` script, which takes quite a bit of time for the x86 builds.

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

No functional change
2026-06-25 13:03:07 +02:00
anematodeandDisservin f9b002cf7d Share continuation history between threads
Passed 8th 5+0.05 https://tests.stockfishchess.org/tests/view/6a0bfdb46524d21ee79b879b
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 23472 W: 6103 L: 5823 D: 11546
Ptnml(0-2): 26, 2501, 6403, 2779, 27

Passed 8th 20+0.2 https://tests.stockfishchess.org/tests/view/6a0c87196524d21ee79b885c
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 44692 W: 11640 L: 11319 D: 21733
Ptnml(0-2): 12, 4418, 13169, 4731, 16

Passed 16th 5+0.05 https://tests.stockfishchess.org/tests/view/6a20533f818cacc1db0ad32b
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 14720 W: 3910 L: 3642 D: 7168
Ptnml(0-2): 6, 1434, 4223, 1680, 17

Passed 64th 10+0.1 https://tests.stockfishchess.org/tests/view/6a20ae8e818cacc1db0ad369

LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 34096 W: 8889 L: 8607 D: 16600
Ptnml(0-2): 4, 2974, 10808, 3260, 2

Continuation history is fixed size so there's a much more false sharing and a larger speed loss here at high thread counts, unfortunately.

vondele's machine, 4x70

```
==== master ====
Average (over 3):  294528128
==== shared-conthist ====
Average (over 3):  282364217 (~4% slowdown)
```

my machine, 8x32
```
Nodes/second               : 243157385
Nodes/second               : 228374554 (~6% slowdown)
```

Evidently it still gains at 64th, but a few followup ideas to try get the speed back:
- Add padding in `PieceToHistory` stats so there's less false sharing.
- Subdivide continuation history more finely than shared correction history.
- Scramble the `PieceToHistory` indexing so there's less false sharing

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

No functional change
2026-06-14 09:58:13 +02:00
anematodeandJoost VandeVondele 86f1df7134 Fix material key computation error
Fixes an error introduced in 278a755fb5 https://github.com/official-stockfish/Stockfish/pull/6891

Also enables more checking in debug builds

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

No functional change
2026-06-10 23:01:50 +02:00
anematodeandJoost VandeVondele 7c7fe322ea Merge HalfKA and Threats accumulators
Passed STC (https://tests.stockfishchess.org/tests/view/6a2893ad7c758d82accea129):
LLR: 3.20 (-2.94,2.94) <0.00,2.00>
Total: 23328 W: 6145 L: 5838 D: 11345
Ptnml(0-2): 50, 2463, 6346, 2740, 65

Instead of repeatedly doing the sum HalfKA + threats at the end, it's profitable to simply store one accumulator per side that combines them. This also avoids an extra/load store of an accumulator, and halves the cache footprint of the accumulators.

For full refreshes, we always compute both halfka and threats simultaneously. Any threat full refresh is always a halfka refresh because it occurs when the king crosses the center line, while halfka refreshes are required for ANY king move, so we don't need a separate detection path for threats.

I get about a 2.5% speedup locally with this, but I'd appreciate other ppl's measurements.

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

No functional change
2026-06-10 08:40:26 +02:00
anematodeandJoost VandeVondele 0111d11e23 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
2026-06-09 21:52:29 +02:00
anematodeandJoost VandeVondele 8e711c29fe Add wasm32 and wasm32-relaxed-simd targets, and light optimizations
Lichess maintains some patches on top of SF dev to get it working with Emscripten. This PR moves some of these patches into SF and adds WASM to CI. It also adds a few changes in places where the x86 intrinsics don't cleanly map onto WebAssembly SIMD instructions; otherwise, we use Emscripten's x86 compatibility layer and take SSE4.1 code paths.

Summary of the compatibility changes:

- Define `wasm32` and `wasm32-relaxed-simd` targets.
    - We don't support wasm without SIMD; it'd be a waste of time.
- Add option to disable TBs
    - This is required because `tbprobe.cpp` pulls in `mmap`. This option can be used on any target, of course, but it's only enabled by default for wasm.
- Add compilation job + test to CI

And the changes for performance:

- Disable atomics for shared history on wasm
    - Atomics are always `seq_cst` there, which can be quite slow (even on the x86, stores are locked `xchg [mem], reg`)
- Add SSE code path to `get_changed_pieces`, modeled after the AVX2 path
- `_mm_mulhi_epi16` has a complicated emulation sequence, so for the pairwise multiplication, use an approach similar to the NEON impl.
- __int128 is gets lowered to runtime functions on wasm, so use the fallback impl for `mul_hi64`
- V8 does a poor job with the NNZ finding, so use a slightly different sequence there
- Add relaxed simd support for `m128_dpbusd`.

Some local perf figures (single-threaded speedtest):

```
wasm
Nodes/second               : 902523
sse4.1
Nodes/second               : 1155380
avx512icl
Nodes/second               : 1676184
```

Further avenues to explore:
- Optimize for performance under V8's experimental AVX revectorizer (Currently it's about +10% in my testing, but could definittely be more)
- Branch hinting. For example, run bench while collecting branch frequency info, then inject it late in the WASM compilation pipeline. I tried this locally and it didn't help much, but maybe I'm missing something.
- PGO. Gives +1.5% NPS locally, but hard to integrate with WASM compilation wrokflows

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

No functional change
2026-06-09 19:35:05 +02:00
anematodeandJoost VandeVondele db6cba47d6 More loongarch optimizations
Passed STC:
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 113120 W: 29094 L: 28674 D: 55352
Ptnml(0-2): 362, 12619, 30248, 12899, 432
https://tests.stockfishchess.org/tests/view/6a1486f7818cacc1db0ac832

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

No functional change
2026-06-06 10:03:25 +02:00
8cbca11a53 macOS universal binary, take 2
- Add new target `macos-lipo`.
   - Created by compiling a universal x86 binary (no PGO) and a standard Apple silicon binary (with PGO), then combining them into a Mach-O fat binary
   - To keep only one copy of the net, we add custom loading logic in the x86 section. The executable reads its own path and mmaps the net that's in the ARM section.
       - The offset and size (from the executable base) of the mapping is injected after compilation in `patch_x86_slice.sh`
   - avx512 on macOS isn't advertised in the xcr0 register by default. The simple solution I came up with is to execute a dummy AVX512 instruction, which sets up the register, before calling `__builtin_cpu_init`.

Some housekeeping as well:
- Rename `armv8-universal` -> `arm64-universal`.
- Add standard copyright headers to the files we've added recently.

Potential follow-ups:
- Disservin's Makefile cleanup
- Alternative ideas for the net loading. In particular, this will error out if the user strips the binary (since that'll invalidate the offset).

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

No functional change

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-29 19:05:53 +02:00
anematodeandJoost VandeVondele 564f9f9c85 Fix sloppy L3 cache detection code
Fixes https://github.com/official-stockfish/Stockfish/issues/6857

Many thanks to Andrew for the repro

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

No functional change
2026-05-27 07:05:56 +02:00
anematodeandJoost VandeVondele 77a8f6ccf3 HQ attacks for AVX2
passed STC (https://tests.stockfishchess.org/tests/view/6a1157dc818cacc1db0ac172):

LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 29792 W: 7759 L: 7465 D: 14568
Ptnml(0-2): 75, 3206, 8033, 3514, 68

Also passed STC after cleanups https://tests.stockfishchess.org/tests/view/6a121beb818cacc1db0ac35e

vondele's local test:

Result of 100 runs
base (./stockfish.master       ) =    1136025  +/- 2816
test (./stockfish.patch2       ) =    1171370  +/- 2848
diff                             =     +35346  +/- 3275

speedup        = +0.0311
P(speedup > 0) =  1.0000

Basically we just do hyperbola quintessence in parallel. AVX2 doesn't have efficient bit reversal so we only do it for file and bishop attacks, then do rank attacks separately with a lookup table. This LUT is much smaller which is why this seems to be faster than standard magics.

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

No functional change
2026-05-25 11:20:24 +02:00
anematodeandJoost VandeVondele 05f48577e1 Fix partial MADV_POPULATE_WRITE
Potentially fixes https://github.com/official-stockfish/Stockfish/issues/6846

I'm not a Linux guru but here's my understanding of what's going on, from looking at strace logs.

If `/dev/shm` is undersized or too full, `MADV_POPULATE_WRITE` can partially fault in the pages and then return an error. The crash then happens in the second process, on the first read to `header_ptr_->initialized`. There's a TOCTOU between when the region is attachable (the second process can see it in `/dev/shm`) and when we can actually safely read from it. The SIGBUS happens because `/dev/shm` is so full from partially faulted pages that we can't even fault in a single additional page.

This didn't happen before because a failed `posix_fallocate` *rolls back any faulted pages*. Then the second process faults in one page (which succeeds), reads a `0` from `header_ptr_->initialized`, declares the region invalid, and continues to try (and fail) to set up its own region.

There's still a problem here, methinks, if the process gets killed/interrupted between the failed `madvise` and the `ftruncate`. I think a more robust approach is to create the file anonymously first (to prevent other processes from attaching to it), then `linkat` to publish it atomically, but that would be more implementation work. (Could create a follow-up issue for that as an nice first issue for new contribs?)

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

No functional change
2026-05-25 11:19:40 +02:00
anematodeandJoost VandeVondele be9df38f27 Add 1GB page support on x86 Linux
1GB pages for the TT give a small performance bump (`./stockfish speedtest 256 32000`):

master:
Nodes/second               : 230514479
patch
Nodes/second               : 237997728

With a large enough TT there is still dTLB thrashing with 2MB pages. 1GB pages reduces that and makes page table walks a bit faster (they're shorter, and there's fewer PTEs, which fits better in cache). `madvise` won't give you huge pages, only large pages, so we use mmap here.

We guard the huge page attempt to x86 + at least 8 huge pages per NUMA node, to avoid memory oversubscription when for example running with a 1.1 GB hash. Additionally, we change the TT clearing slightly so that the pages are better distributed across NUMA nodes.

Data from Torom:

master:
Nodes/second               : 43524292
patch:
Nodes/second               : 44080034

Data on an 8-thread Emerald Rapids VM:

./stockfish speedtest 8 65536

Baseline speedtest (2MB huge pages):

Nodes/second : 7366232
Nodes/second : 7262794
Nodes/second : 7355431
Nodes/second : 7318777

Baseline speedtest (1GB huge pages):

Nodes/second : 7541027
Nodes/second : 7572720
Nodes/second : 7550268
Nodes/second : 7538925

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

No functional change
2026-05-24 14:17:54 +02:00
anematodeandJoost VandeVondele 90890c5f1f Loongarch opts
optimize loongarch64 inference

passed STC:
 LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 14208 W: 3792 L: 3510 D: 6906
Ptnml(0-2): 54, 1485, 3765, 1725, 75
https://tests.stockfishchess.org/tests/view/6a0a2a956524d21ee79b85a8

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

No functional change
2026-05-19 18:39:58 +02:00
anematodeandJoost VandeVondele 24abab9f6c Universal builds for Android armv8 and compatibility with older compilers
- We add a new path for supporting universal builds without #embed . `xxd` causes the compiler to run out of memory, so instead we embed it as a string literal created at compile time.
    - This file is created in `net.sh`, and only if `--embed-dir` isn't supported + we are doing a universal build.
    - This was necessary because Android NDK seems to not support embed, idk why
- A couple other Makefile tweaks were necessary for the Android path.
- While we're at it, remove the non-universal arm64 windows and android binaries.

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

No functional change
2026-05-19 18:39:06 +02:00
anematodeandJoost VandeVondele b82f5b59f7 Port sqr_clipped_relu.h to NEON
Passed STC (https://tests.stockfishchess.org/tests/view/69fd70c39392f0c317213b99)

LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 315360 W: 80995 L: 80315 D: 154050
Ptnml(0-2): 573, 33687, 88501, 34325, 594

Data from vondele:

```
==== master ====
1 Nodes/second : 278894157
2 Nodes/second : 279192601
3 Nodes/second : 278279517
Average (over 3):  278788758
==== neonnnn ====
1 Nodes/second : 280614075
2 Nodes/second : 279971502
3 Nodes/second : 280613919
Average (over 3):  280399832
```

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

No functional change
2026-05-19 18:37:09 +02:00
anematodeandJoost VandeVondele fff35786bf Use bitset representation for nnz and move computation into feature transformer
Passed avx2/bmi2 STC:
https://tests.stockfishchess.org/tests/view/69ff99eb9392f0c317213eda
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 20992 W: 5469 L: 5192 D: 10331
Ptnml(0-2): 38, 2197, 5751, 2470, 40

Passed avxvnni STC:
https://tests.stockfishchess.org/tests/view/6a00022b9392f0c317213f7c
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 47328 W: 12328 L: 12009 D: 22991
Ptnml(0-2): 112, 5148, 12847, 5423, 134

Passed NEON STC:
https://tests.stockfishchess.org/tests/view/69ff99d69392f0c317213ed8
LLR: 2.96 (-2.94,2.94) <0.00,2.00>
Total: 29600 W: 7664 L: 7376 D: 14560
Ptnml(0-2): 48, 3074, 8277, 3344, 57

Passed avx512icl non-regression:
https://tests.stockfishchess.org/tests/view/6a002b699392f0c317213f91
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 90112 W: 23130 L: 22975 D: 44007
Ptnml(0-2): 192, 9939, 24633, 10106, 186

Measurements from vondele (Neoverse V2, armv8-dotprod):

==== master ====
==== Bench: 2344696 ====
1 Nodes/second : 280724660
2 Nodes/second : 280647282
3 Nodes/second : 282055192
Average (over 3):  281142378
==== 50a44640a3 ====
==== Bench: 2344696 ====
1 Nodes/second : 284271937
2 Nodes/second : 285638071
3 Nodes/second : 284349426
Average (over 3):  284753144

The patch's benefit is non-uniform and is ~0 for avx512icl unfortunately -- although I think we should be able to find something there....

## Background/explanation

The idea here is to move the non-zero block computation back to the previous layer, and overlap the work better. Then, to avoid trying to emulate compress instructions on targets not supporting them (i.e., everything except for AVX512), we use a `pop_lsb` loop on a bitset enumerating the non-zero blocks, rather than first writing them out as indices.

An early AVX2 implementation worked on fishtest (https://tests.stockfishchess.org/tests/view/69c3410534b6988b1e472db4) and linrock demonstrated that it also worked for NEON (https://tests.stockfishchess.org/tests/view/69ce0dc73ddc0eccd617188f). Thanks to him for encouraging me to push this idea over the finish line.

To abstract over the particular NNZ representation (bitset or index list), we use `NNZInfo` and `NNZCursor`. The cursor is used to write to one or the other perspective of the NNZ list. I'd appreciate ideas on making the code cleaner/more readable as imo it's still a bit ugly.

## Fixing GCC 15 regression

Separately, vondele noticed a regression in ARM performance from GCC 15 caused by suboptimal codegen. See https://discord.com/channels/435943710472011776/813919248455827515/1502837886381461605 for more info, but the easiest fix that I could come up with was inserting a couple `asm` optimization barriers.

Single threaded data:
```
average: stockfish.master.13.3  1041619
average: stockfish.master.15.2   999214
average: stockfish.patched.15.2  1031369
```

There's definitely regressions elsewhere as well, which we shld chase down, but at least this should unblock the arm64 universal binary work.

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

No functional change
2026-05-19 18:36:11 +02:00
anematodeJoost VandeVondelecoderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
d6469b3980 arm64 universal binaries redux
Introduce the armv8-universal target. 🥴

The entry point is essentially the same as x86's, except we no longer have access to `__builtin_cpu_supports` so instead we need an OS-specific query for whether we support dotprod. The Makefile is modified to support both universal builds.

If in the future we add more ARM targets, such as SVE, we'll need to add qemu to the RUN_PREFIX in CI, because currently we assume (for PGO purposes) that the CI host supports all the used ARM instructions.

### clang/Windows

The painful part here is clang on Windows, which, until arm64 mingw is stabilized, is required for targeting arm64. This PR also gets it to work for x86. In the Makefile this setup corresponds to `use_lto_emit_asm=yes`.

In particular, `--defsym` and `--save-temps` are not supported by `lld-link`, and objcopy `--rename-section` doesn't work on COFF binaries because of how section names work there.
- `--defsym` is needed to define `main` for PGO purposes and assigns it to the namespaced, per-arch main function. Instead, we define `main` in `main.cpp` so that the compilation is successful, then delete it before the final link.
- Instead of `--save-temps` to get the LTO intermediate object, we pass `--lto-emit-asm` to the linker, which outputs `stockfish.exe.lto.s`.
- Finally, we have a small AWK script to find the `.ctors` section, neuter it, and put start/stop symbols around it with the same naming scheme as ELF (`__start_*_init`/`__stop_*_init`).

I'm lowk a Windows programming noob so if there's simpler ways of going about this, I'd appreciate a pointer. @PikaCat-OuO + Codex used an approach that involved going in and modifying the LLVM bitcode, but that felt more complicated to me.

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

No functional change

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-05-17 20:48:54 +02:00
anematodeandJoost VandeVondele 91736f7b4f Compute correction_value before TT lookup
Passed single-threaded STC with 128MB hash
https://tests.stockfishchess.org/tests/view/6a04a6348d9bd4cd7cd69124
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 103808 W: 26400 L: 26007 D: 51401
Ptnml(0-2): 205, 11212, 28711, 11537, 239

Passed standard SMP STC
https://tests.stockfishchess.org/tests/view/6a054f528d9bd4cd7cd69225
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 80392 W: 20580 L: 20221 D: 39591
Ptnml(0-2): 79, 8872, 21942, 9217, 86

Entering `do_move`, `correction_value` and the TT lookup are always done together, but the TT lookup happens first. Swapping the order allows the execution of `correction_value` to overlap with the in-flight TT prefetch.

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

No functional change
2026-05-17 20:48:12 +02:00
anematodeandJoost VandeVondele 6a50807e01 On Linux, allow shared-memory network weights to be backed by huge pages
This does require the user to have set `/sys/kernel/mm/transparent_hugepage/shmem_enabled` to something other than `never` (unfortunately the default, at least on Ubuntu).

```
Result of  50 runs
==================
base (...kfish.master) =    1814244  +/- 4396
test (./stockfish    ) =    1823756  +/- 3448
diff                   =      +9512  +/- 5496

speedup         = +0.0052
P(speedup > 0) =  0.9996
```

```
 Performance counter stats for './stockfish bench':

           237,561      dTLB-misses
     5,783,003,231      cycles

 Performance counter stats for './bins/stockfish.master bench':

         2,219,832      dTLB-misses
     5,932,779,255      cycles
```

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

No functional change
2026-05-10 11:46:31 +02:00
Timothy HerchenandJoost VandeVondele 1554a2ca0b Precompute moves and use magics index as compress mask on AVX512ICL
Passed STC
https://tests.stockfishchess.org/tests/view/69f6df65b64b50e29dbed427
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 112224 W: 29195 L: 28782 D: 54247
Ptnml(0-2): 312, 12345, 30381, 12766, 308

Local speedup:
```
Result of 100 runs
base (...kfish.master) =    2050387  +/- 5497
test (./stockfish    ) =    2069598  +/- 4426
diff                   =     +19211  +/- 7468
speedup         = +0.0094
P(speedup > 0) =  1.0000
```

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

No functional change
2026-05-04 08:33:01 +02:00
anematodeandJoost VandeVondele ab8f901d25 Remove small net
Failed VVLTC non-regression
https://tests.stockfishchess.org/tests/view/69d562b84088e069540a2288
LLR: -2.96 (-2.94,2.94) <-1.75,0.25>
Total: 386998 W: 99181 L: 99760 D: 188057
Ptnml(0-2): 35, 35792, 122429, 35203, 40

Failed STC non-regression
https://tests.stockfishchess.org/tests/view/69f3c6601e5788938e86a99e
LLR: -2.93 (-2.94,2.94) <-1.75,0.25>
Total: 33696 W: 8492 L: 8795 D: 16409
Ptnml(0-2): 124, 4209, 8504, 3868, 143

Many thanks to Dubslow, Torom, ces42, Shawn, vondele, Disservin and others for discussion.

## Summary

The venerable small net has been around for quite some time now, and while the big net architecture has substantially advanced with TI, the small net has stayed with plain HalfKA. It therefore presents a few burdens: multiple net architectures to maintain, multiple nets to train, and a whole lot of templates to deal with the variable L1 size.

Locally I measure a slowdown of -2.5% in NPS with this branch – and it's probably more on non-AVX512 architectures – but a pure slowdown of that magnitude would lead to more dramatic losses (even at VVLTC) than exhibited in the above tests, suggesting that the small net's lower eval quality is deleterious.

Bonus: Shawn found this interesting PGN among the VVLTC games: https://lichess.org/study/hvo8jflc/OeTOityv  `master` seems to misevaluate the fortress because all positions go to small net (the material difference is larger than the threshold).

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

Bench: 2877007
2026-05-04 08:32:42 +02:00
anematodeandJoost VandeVondele dc1686345c Hyperbola quintessence for ARM
Passed STC

https://tests.stockfishchess.org/tests/view/69f44c1e1e5788938e86aa2a
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 27680 W: 7340 L: 7053 D: 13287
Ptnml(0-2): 72, 2862, 7683, 3153, 70

x86 is unaffected

Data from Joost's machine (Neoverse V2):

```
==== master ====
==== Bench: 2723949 ====
1 Nodes/second : 276819933
2 Nodes/second : 273971948
3 Nodes/second : 275567995
Average (over 3):  275453292
==== 5b54755db23a3de29407b805b85e7bbdef28df49 ====
==== Bench: 2723949 ====
1 Nodes/second : 282861542
2 Nodes/second : 279085277
3 Nodes/second : 279612223
Average (over 3):  280519680 (+1.8%)
```

Data from my M1 macbook

```
Result of 100 runs
==================
base (./stockfish    ) =    1474702  +/- 6169
test (...fish.rbit-pr) =    1500236  +/- 6690
diff                   =     +25533  +/- 4011

speedup        = +0.0173
P(speedup > 0) =  1.0000
```

Hyperbola quintessence works nicely on ARM because it has an efficient bit reversal instruction `rbit`. This lets us avoid the large magic bitboards lookup table. Codegen looks nice (this is for rook attacks I think):

```
0000000100001ecc <__ZN9Stockfish10attacks_bbILNS_9PieceTypeE3EEEyNS_6SquareEy>:
100001ecc: 2a0003e8     mov w8, w0
100001ed0: f002cb09     adrp x9, 0x105964000 <dyld_stub_binder+0x105964000>
100001ed4: 91200129     add x9, x9, #0x800
100001ed8: 8b081928     add x8, x9, x8, lsl #6
100001edc: a9402909     ldp x9, x10, [x8]
100001ee0: 8a01012b     and x11, x9, x1
100001ee4: dac0016c     rbit x12, x11
100001ee8: a941210d     ldp x13, x8, [x8, #0x10]
100001eec: cb08018c     sub x12, x12, x8
100001ef0: dac0018c     rbit x12, x12
100001ef4: cb0d016b     sub x11, x11, x13
100001ef8: ca0b018b     eor x11, x12, x11
100001efc: 8a090169     and x9, x11, x9
100001f00: 8a01014b     and x11, x10, x1
100001f04: dac0016c     rbit x12, x11
100001f08: cb080188     sub x8, x12, x8
100001f0c: dac00108     rbit x8, x8
100001f10: cb0d016b     sub x11, x11, x13
100001f14: ca0b0108     eor x8, x8, x11
100001f18: 8a0a0108     and x8, x8, x10
100001f1c: 8b090100     add x0, x8, x9
100001f20: d65f03c0     ret
```

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

No functional change
2026-05-04 08:32:23 +02:00
fe1d2b456c Update CI Binaries
- split into multiple jobs
- remove binaries which are already covered by the universal binary

superseeds https://github.com/official-stockfish/Stockfish/pull/6779

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

No functional change

Co-authored-by: Disservin <disservin.social@gmail.com>
2026-05-04 08:32:03 +02:00
Timothy HerchenandJoost VandeVondele 04ce2c04d7 Faster movepick sorting on AVX512ICL
The core idea here is to greatly speed up the backwards insertion loop of the insertion sort. We can store up to 16 sorted moves and their values/scores in vectors. We obtain all moves with a smaller score (i.e., sorted later than the move-to-insert) as a mask, giving us something like `1111111111000000`. If we subtract one this gives us `1111111110111111` which can be can be used as an expand mask, to insert the new move.

Passed STC:
https://tests.stockfishchess.org/tests/view/69e9c9190e9667dd5a765853
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 45024 W: 11867 L: 11550 D: 21607
Ptnml(0-2): 101, 4938, 12142, 5205, 126

Local test:
```
Result of  50 runs
==================
base (...kfish.master) =    2026071  +/- 5124
test (./stockfish    ) =    2083770  +/- 5964
diff                   =     +57699  +/- 8535

speedup         = +0.0285
P(speedup > 0) =  1.0000
```

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

No functional change
2026-05-04 08:30:09 +02:00
anematodeandJoost VandeVondele 1a882efc7f Simplify out double_inc_update
Passed STC
https://tests.stockfishchess.org/tests/view/69e82e200e9667dd5a765631
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 115424 W: 29950 L: 29822 D: 55652
Ptnml(0-2): 318, 12712, 31544, 12800, 338

Passed AVX2-only STC
https://tests.stockfishchess.org/tests/view/69e953080e9667dd5a7657c0
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 134720 W: 34773 L: 34665 D: 65282
Ptnml(0-2): 344, 14958, 36694, 14974, 390

Now that our L1 size is much smaller, the overhead of tracking diffs for
`double_inc_update` is a larger share of the cost.

Interestingly ces42 measured a -0.9% slowdown locally (avxvnni build).
Meanwhile Torom and I find this branch to be 2% faster. I'm not sure exactly
what's going on but more tests may be in order

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

No functional change
2026-04-26 09:43:42 +02:00
anematodeandJoost VandeVondele 8f181af8fb Get universal binary working for clang on Linux
A few changes were necessary, mainly because clang LTO works a bit differently than GCC

Doesn't yet work on Windows

small Makefile cleanups

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

No functional change
2026-04-26 09:31:30 +02:00
anematodeandJoost VandeVondele e17725f445 Constexpr attacks (pext only)
LLR: 2.97 (-2.94,2.94) <0.00,2.00>
Total: 38400 W: 10057 L: 9749 D: 18594
Ptnml(0-2): 93, 4110, 10498, 4394, 105
https://tests.stockfishchess.org/tests/view/69d2073261a12cebe17edc04

compile time generation leads to sharing tables through the binary, resulting
in gain on fishtest, as well as reduced memory usage. The downside is slightly
longer compilation time.

Using pdep reduces table size 4x, and gains a little outside of fishtest as well.

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

No functional change
2026-04-26 09:18:06 +02:00
anematodeandJoost VandeVondele 20a8d8d3c0 Remove git dependency from Makefile
To build the universal binaries, use already defined variables with sources and
headers, as well as Makefile and incbin explicitly.

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

No functional change
2026-04-20 17:39:02 +02:00
anematodeandJoost VandeVondele 1e333b341c Add universal binaries to prerelease page
closes https://github.com/official-stockfish/Stockfish/pull/6744

No functional change
2026-04-19 11:09:24 +02:00
anematodeandJoost VandeVondele c3bcf74925 Universal binary for x86-64 Linux and Windows
We maintain support for quite a few x86 ISA extensions but relied on the end
user to select the binary that is best for their system.  We can detect at
runtime which architecture to use, and ship a single binary (per OS/ISA
combination). This PR does so, maintaining performance.

This is what I've landed on after quite a few iterations. Basically, we build
each arch separately, use `cpuid` to select one, and jump to that arch's main
function. Some details:

- The preprocessor macro `UNIVERSAL_BINARY` is defined when building for the universal binary.

- The Makefile target `universal-object-[no]pgo` is added, which produces a `stockfish.o` in each arch's build directory.

- To prevent symbol collisions between the multiple builds, we `#define Stockfish Stockfish_[arch]`. Furthermore we wrap the `main` function in `namespace Stockfish { }`.

- We can still get PGO data by linking to a per-arch binary, with `Stockfish_x86_64_avx2::main` as `main`, and running `bench`.
    - For arches not supported by the host we can use Intel SDE – this is what we do in CI.

- When embedding the NNUE, we use C++26/C23 `#embed` instead of `INCBIN`. The issue with `INCBIN` is that it injects assembly directives that we have no control over.
    - To ensure there's only one copy of the networks in the final binary, we define the network data as weak symbols in each per-arch build. Then, in the final link, we add a special nnue_embed.cpp which provides strong symbols.
    - This does require GCC 15. Statically linking libstdc++ allows the binary to still run on older OSes though. And latest msys2 already does static linking + is based off GCC 15.2.0

building can be as simple as

make -j profile-build ARCH=x86-64-universal

or using the sde if the host doesn't support all architectures supported in the
universal binary, and the default host compiler is not recent enough.

make -j profile-build ARCH=x86-64-universal RUN_PREFIX="/path/to/sde -future --" CXX=g++-15

This change is also integrated in CI, so universal binaries are available as
downloadable artifacts.

Next we could also do ARM64, especially Android (all Apple silicon users use
the same binary). It also might be worth getting this to work with clang.

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

No functional change
2026-04-19 07:07:11 +02:00
anematodeandDisservin ead7e650da Fix weird indexing bug
[Passed
STC](https://tests.stockfishchess.org/tests/live_elo/69cf6a5d1668971c9da23ae1)
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 51104 W: 13376 L: 13180 D: 24548
Ptnml(0-2): 134, 5555, 13963, 5781, 119

[Passed
LTC](https://tests.stockfishchess.org/tests/live_elo/69d00a7ee2b443cb2670b5c6)
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 101256 W: 25867 L: 25732 D: 49657
Ptnml(0-2): 59, 10423, 29520, 10576, 50

When processing a promotion we add/remove nonsensical threats, namely,
piece threats of pawns on the 1st or 8th rank. This is not only
inefficient but also seems to lead to an obscure bug during a
promotion–capture + `double_inc_update` that causes a lingering invalid
feature. Currently – as an artifact of the training process – these
parts of the net are filled with random values in [-1,1], which is why
there is a bench change.

@ces42 did a helpful analysis:

> checking bench with depth 17 actually shows that the bug in has been
there all the time since 8e5392d7 (when threat inputs was merged into
master)
> i.e. double_inc_update for ThreatFeatureSet has always been slightly
bugged

After this patch is applied we'll be able to better compress the net by
filling the invalid features with 0, w/o changing bench. I expect a
15%-ish size savings.

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

Bench: 2700393
2026-04-09 21:53:08 +02:00
anematodeandDisservin bb752eb2f6 Remove step in update_accumulator_refresh_cache
Passed simplification STC
https://tests.stockfishchess.org/tests/live_elo/69c9c050a54395a76133504c

LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 304544 W: 78502 L: 78574 D: 147468
Ptnml(0-2): 906, 33590, 83358, 33506, 912

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

No functional change
2026-04-09 21:53:08 +02:00
anematodeandDisservin 5eeca7392e Update NNUE architecture to SFNNv14 and net nn-7bf13f9655c8.nnue
[STC](https://tests.stockfishchess.org/tests/live_elo/69cb991bc025c305b7daa219)

LLR: 2.97 (-2.94,2.94) <0.00,2.00>
Total: 47520 W: 12558 L: 12219 D: 22743
Ptnml(0-2): 190, 5474, 12102, 5795, 199

[LTC](https://tests.stockfishchess.org/tests/live_elo/69cc6b42731dfb72d2e92128)

LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 123756 W: 31996 L: 31497 D: 60263
Ptnml(0-2): 81, 13512, 34221, 13955, 109

Adds features for pawns pushing against other pawns. For indexing, we
use the existing threats feature set by adding the forward square to the
squares threatened by a pawn. This threat is only enabled when another
pawn occupies that square. We then add appropriate logic changes in
`update_piece_threats` and `features/full_threats.cpp`.

The wonderful Ciekce (of Stormphrax) and peregrine (of Reckless) also
had similar ideas with adding forward pawn movements to TI, and I
appreciate their giving me motivation to figure out `nnue-pytorch` and
test it.

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

Bench: 2926703
2026-04-02 20:32:43 +02:00
anematodeandDisservin c41c9bb973 Add -fno-ipa-cp-clone on GCC
Passed non-regression STC at
tests.stockfishchess.org/tests/view/69c9b8c3a54395a761335044 (set to
gainer bounds, *mea culpa*)

There's a major performance penalty when compiling the fish with GCC 16.
@Torom 's measurements (similar to mine, but more precise):

```
GCC 15 (master) vs. 16 (master)
sf_base =  2549174 +/-   2984 (95%)
sf_test =  2435456 +/-   2239 (95%)
diff    =  -113718 +/-   3599 (95%)
speedup = -4.46100% +/- 0.141% (95%)

GCC 15 (master) vs. 16 (patch)
sf_base =  2544107 +/-   3091 (95%)
sf_test =  2568837 +/-   3164 (95%)
diff    =    24729 +/-   4359 (95%)
speedup = 0.97204% +/- 0.171% (95%)
```

Based on looking at the disassembly + profiling data of the builds, the
root cause appears to be overly aggressive code duplication from
constant propagation of various functions especially in `search.cpp`.
The worst offender is `Worker::search`, which I think is being cloned
and optimized based on the value of `cutNode`. `perf stat` indicates
that the instruction cache miss rate goes up by ~50% on the GCC 16
build.

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

No functional change
2026-04-02 20:32:34 +02:00
anematodeandDisservin 347fcaa392 Stack allocate NNUE buffer
Passed simp STC

LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 29632 W: 7772 L: 7552 D: 14308
Ptnml(0-2): 76, 3155, 8147, 3349,

Id expect there to be a small speedup (bc the compiler can skip some
stores) but i haven’t tried to measure it

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

No functional change
2026-04-02 20:30:44 +02:00
anematodeandDisservin 8132dbcb5a split affine_transform on VNNI as well
```
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 184544 W: 47990 L: 47474 D: 89080
Ptnml(0-2): 551, 20238, 50206, 20698, 579
```

Torom measured

```
sf_base =  2538696 +/-   2915 (95%)
sf_test =  2546510 +/-   3011 (95%)
diff    =     7814 +/-   4146 (95%)
speedup = 0.30782% +/- 0.163% (95%)
```

I get something similar. The benefit would be larger if we ever decide
to further increase the L2 size I think

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

No functional change
2026-04-02 20:30:33 +02:00
anematodeandDisservin d173a0655d Speedup splat_moves on avx512icl
STC
```
LLR: 5.45 (-2.94,2.94) <0.00,2.00>
Total: 612192 W: 158602 L: 157260 D: 296330
Ptnml(0-2): 1634, 67783, 166027, 68911, 1741
```

@Torom measured:
```
sf_base =  2380902 +/-   1016 (95%)
sf_test =  2391426 +/-   1065 (95%)
diff    =    10524 +/-   1336 (95%)
speedup = 0.44203% +/- 0.056% (95%)
```

I've verified that `_mm512_slli_epi16(v, 0)` gets optimized out in GCC
9+ and clang 4+. Added constants to types.h so that people messing
around with the layout of `Move` don't have to know about this part of
the code.

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

No functional change
2026-03-18 20:49:20 +01:00
anematodeandJoost VandeVondele b3a810a1c4 Fix avx512icl update_piece_threats bug
Thanks to MinetaS for discovering this and finding the culprit commit,
specific to this architecture. 9f42980 was subtly incorrect, leading to
spurious wrong benches on avx512icl. Because this piece of code has twice been
the source of wrong benches, I also added a brief comment explaining why it
needs to be this way, and added a sample position to bench.

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

Bench: 2288704
2026-03-07 22:28:06 +01:00
anematodeandJoost VandeVondele 4c0878cb0b skip setting threatByLesser[KING]
It doesn't make sense for a king to move to a square threatened by a lesser
piece, since that move would be illegal.

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

No functional change
2026-02-28 12:07:38 +01:00
anematodeandJoost VandeVondele b808fd3d55 avoid modify_and_replicate for first load
We call modify_and_replicate in load_networks, but this is quite inefficient.

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

No functional change
2026-02-13 07:06:33 +01:00
anematodeandJoost VandeVondele 0d26c61ff2 fix return type of vmovl_high_s8
also add -flax-vector-conversions=none to the build

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

No functional change
2026-02-04 17:32:48 +01:00
anematodeandDisservin 253aaefbc0 Fix compilation on BSD/macOS
fixes github.com/official-stockfish/Stockfish/issues/6571

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

No functional change
2026-01-28 20:28:27 +01:00
anematodeandJoost VandeVondele c0f245303b Make PGO builds deterministic again
some environment dependent execution (e.g. pid) were being std::hash'ed, and
net filenames put in unordered maps.  Also uses sprintf instead of
std::to_string.  Depending on precise content, this could lead to different
PGO'ed binaries. This is mitigated by using a basic hash function.

This also fixes a potential issue in net filename generation, in cases where
std::hash would use invocation dependent salt, which is not the cases today for
typical std libraries.

Closes https://github.com/official-stockfish/Stockfish/pull/6562

No functional change
2026-01-22 19:15:17 +01:00
anematodeandJoost VandeVondele f61d4317a3 use default signal handler after cleanup
With the current setup, on Linux, SIGILL (and SIGSEGV/SIGBUS etc., in the case
of a program bug) lead to no feedback if they occur after the signal handlers
are installed, they just exit silently. By invoking the default signal handler,
we can still get the appropriate feedback. This is particularly important for
feedback if someone downloads the wrong SF binary and runs it on Linux.

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

No functional change
2026-01-18 08:53:06 +01:00
anematodeandJoost VandeVondele 5b8b304ebd Skip munmap when exiting via a signal
avoid munmap of memory when exiting via signal, which avoids side effects such
as triggering asserts or (caught) segfaults while the process exists.

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

No functional change
2026-01-15 22:17:14 +01:00
Timothy HerchenandJoost VandeVondele eb5a65aeb0 Fix RelationCache on Windows 10 compiles
Windows 10 is missing the GroupMasks and GroupCount members, this breaks compiles on Windows 10.
Windows 11 builds, including the official ones, run fine on Windows 10/11.
To support developers/testers on Windows 10, fallback conditionally to the Windows 10 struct definition.

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

No functional change
2026-01-11 09:13:37 +01:00
anematodeandJoost VandeVondele b4d4eecfb2 Make shared history allocation aware of non-uniform cache access
Although shared history has been successful overall, it led to some speed
issues with large numbers of threads. Originally we just split by NUMA node,
but on systems with non-unified L3 caches (most AMD workstation and server
CPUs, and some Intel E-core based server CPUs), this can still lead to a speed
penalty at the default config. Thus, we decided to further subdivide the shared
history based on the L3 cache structure.

Based on this test, the original SPRTs, and speed experiments, we decided that
grouping L3 domains to reach 32 threads per SharedHistories was a reasonable
balance for affected systems – but we may revisit this in the future. See the
PR for full details.

In an extreme case, a single-socket EPYC 9755 configured with 1 numa domain per socket,
the nps increases from:
Nodes/second               : 182827480
to
Nodes/second               : 229118365

In many cases, when L3 caches are shared between many threads, or when several
numa nodes are already configured per socket, this patch does not influence the
default. This default setting can adjusted with the existing NumaPolicy option.

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

No functional change.
2026-01-10 15:46:01 +01:00
anematodeandJoost VandeVondele 8be6b14218 Network loading refactoring
closes https://github.com/official-stockfish/Stockfish/pull/6523

No functional change
2026-01-06 12:02:37 +01:00
anematodeandJoost VandeVondele 593eeaf24c simplify find_nnz a bit
This code path is never taken for vector sizes >= 512, so we can simplify it.

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

No functional change
2026-01-01 16:08:03 +01:00
anematodeandJoost VandeVondele aeb3bf33a9 port get_changed_pieces to ARM NEON
passed STC:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 71968 W: 18833 L: 18489 D: 34646
Ptnml(0-2): 192, 7310, 20643, 7640, 199
https://tests.stockfishchess.org/tests/view/69509e5c572093c1986d7a0a

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

No functional change
2026-01-01 16:04:43 +01:00
Timothy HerchenandDisservin 44d5467bbe Remove -Wstack-usage on (apple) clang
Clang pretends to be GCC, but is enraged by `-Wstack-usage`:

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

No functional change
2025-12-28 14:59:26 +01:00
969285fa5d Shared pawn history
[Passed STC SMP](https://tests.stockfishchess.org/tests/view/694e506c572093c1986d7276):
```
LLR: 2.97 (-2.94,2.94) <0.00,2.00>
Total: 14992 W: 3924 L: 3653 D: 7415
Ptnml(0-2): 20, 1547, 4090, 1820, 19
```

[Passed LTC SMP](https://tests.stockfishchess.org/tests/live_elo/694ead61572093c1986d7365):
```
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 41146 W: 10654 L: 10342 D: 20150
Ptnml(0-2): 17, 3999, 12225, 4319, 13
```

[Passed a sanity check STC SMP post-refactoring](https://tests.stockfishchess.org/tests/view/69503997572093c1986d763a):
```
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 46728 W: 12178 L: 11863 D: 22687
Ptnml(0-2): 82, 5093, 12685, 5436, 68
```

(The large gain of the first STC was probably a fluke, and this result
is more reasonable!)

After shared correction history, Viz suggested we try sharing other
histories, especially `pawnHistory`. As far as we're aware, sharing
history besides correction history (like Caissa does) is novel. The
implementation follows the same pattern as shared correction history –
the size of the history table is scaled with
`next_power_of_two(threadsInNumaNode)` and the entry is prefetched in
`do_move`.

A bit of refactoring was done to accommodate this new history. Note that
we prefetch `&history->pawn_entry(*this)[pc][to]` rather than
`&history->pawn_entry(*this)` because unlike the other entries, each
entry contains multiple cache lines.

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

Bench: 2503391

Co-authored-by: Michael Chaly <Vizvezdenec@gmail.com>
2025-12-28 14:59:09 +01:00
anematodeandDisservin 1a67ccc72e Share correction history between threads
We did quite a few tests because this is a pretty involved change with
unknown scaling behavior, but results are decent.

[STC 10+0.1 1th, non-regression](https://tests.stockfishchess.org/tests/live_elo/6941ce3b46f342e1ec210180)
```
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 83200 W: 21615 L: 21452 D: 40133
Ptnml(0-2): 247, 9064, 22844, 9169, 276
```

[STC 5+0.05 8th](https://tests.stockfishchess.org/tests/live_elo/693dc38346f342e1ec20f555)
```
LLR: 3.48 (-2.94,2.94) <0.00,2.00>
Total: 58536 W: 15067 L: 14688 D: 28781
Ptnml(0-2): 87, 6474, 15781, 6825, 101
```

[LTC 20+0.2 8th](https://tests.stockfishchess.org/tests/live_elo/693f2afb46f342e1ec20f847)
```
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 27716 W: 7211 L: 6925 D: 13580
Ptnml(0-2): 8, 2674, 8207, 2962, 7
```

[LTC 10+0.1 64th](https://tests.stockfishchess.org/tests/live_elo/694003aa46f342e1ec20fac4):
```
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 16918 W: 4439 L: 4182 D: 8297
Ptnml(0-2): 3, 1493, 5213, 1744, 6
```

[NUMA test, 5+0.05 256th](https://tests.stockfishchess.org/tests/view/6941ee4e46f342e1ec210203)
```
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 7124 W: 1910 L: 1678 D: 3536
Ptnml(0-2): 0, 560, 2211, 790, 1
```

[LTC 60+0.6 64th](https://tests.stockfishchess.org/tests/live_elo/6940a85346f342e1ec20fcde):
```
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 15504 W: 4045 L: 3826 D: 7633
Ptnml(0-2): 0, 1002, 5530, 1219, 1
```

Bonus (courtesy of Viz): The 1 double kill in this last test was master
blundering a cool mate in 3: https://lichess.org/jyNZuRl4

Basically the idea here is to share correction history between threads.
That way, T1 can use the correction values produced by T2, which already
searched positions with that pawn structure etc., so that T1 can search
more efficiently. The table size per thread is about the same, so we
shouldn't get a large increase in hash collisions; in fact, I'd expect a
lower collision rate overall.

Although I came up with and implemented the idea independently,
[Caissa](https://github.com/Witek902/Caissa) was the first engine to
implement corrhist sharing (and corrhist in the first place) – this idea
is not completely novel.

The table size is rounded to a power of two. In particular, it's `65536
* nextPowerOfTwo(threadCount)`. That way, the indexing operation becomes
an AND of the key bits with a mask, rather than something more expensive
(e.g., a `mul_hi64`-style approach or a modulo).

The updates are racy, like the TT, but because `entry` is hoisted into a
register, there's no risk of writing back a value that's out of the
designated range `[-D, D]`. Various attempts at rewriting using atomics
led to substantial slowdowns, so we begrudgingly ignored the functions
in thread sanitizer, but at some point we'd like to make this better.

We allocate one shared correction history per NUMA node, because the
penalty associated with crossing nodes is substantial – I get a 40% hit
with NPS=4 and 256 threads, which is intolerable. With separate tables
per NUMA node I get a 6% penalty for nodes per second, which isn't ideal
but apparently compensated for.

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

Bench: 2690604

Co-authored-by: Disservin <disservin.social@gmail.com>
2025-12-23 21:42:29 +01:00
Timothy HerchenandDisservin e0e6fdf094 Tweak nnue_accumulator indexing
```
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 92736 W: 24149 L: 23764 D: 44823
Ptnml(0-2): 280, 10056, 25334, 10395, 303
```

The use of `IndexType` in the loops is suboptimal because it requires
truncation to 32 bits, and thereby defeats some optimizations. Using
`size_t` for the loop body works nicely, and a signed index into the
index lists allows the compiler to assume the case `added.size() ==
UINT_MAX`, which would be an infinite loop, to not happen.

Passed STC
https://tests.stockfishchess.org/tests/live_elo/692fd98ab23dfeae38d01d98

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

No functional change
2025-12-21 15:43:32 +01:00
Timothy HerchenandDisservin a98c3f6878 Small threat-related cleanups
Remove a couple unused things, mark `noRaysContaining` as
`[[maybe_unused]]` (suggested by Viz) to silence a warning on GCC 10,
update a comment, and replace inline constants

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

No functional change
2025-12-21 15:43:32 +01:00
Timothy HerchenandJoost VandeVondele c109a88ebe fix missing condition
Fixes a bug in https://github.com/official-stockfish/Stockfish/pull/6453
https://github.com/official-stockfish/Stockfish/commit/abd835dcbc3a28481224f6253b00b7420d062513
The modifications to the DirtyThreats bitboards should only happen if PutPiece is true.
This somehow didn't affect bench at the default parameters.

Reference AVX2:
./stockfish.killdeer-fix.avx2 bench 64 1 23
Nodes searched  : 178140156
Nodes/second    : 1503152

before patch:
./stockfish.master.avx512icl  bench 64 1 23
Nodes searched  : 218349728
Nodes/second    : 1743450

after patch:
./stockfish.killdeer-fix.avx512icl bench 64 1 23
Nodes searched  : 178140156
Nodes/second    : 1727520

passed STC:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 39328 W: 10293 L: 10080 D: 18955
Ptnml(0-2): 113, 4306, 10629, 4487, 129
https://tests.stockfishchess.org/tests/view/692fb2d8b23dfeae38d01c81

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

Bench: 2912398
2025-12-03 12:32:29 +01:00
Timothy HerchenandJoost VandeVondele abd835dcbc Improve update_piece_threats
passed on avx512ICL:
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 30240 W: 8026 L: 7726 D: 14488
Ptnml(0-2): 95, 3235, 8171, 3513, 106
https://tests.stockfishchess.org/tests/view/69281d9ab23dfeae38cfeeb8

passed on generic architectures:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 73184 W: 19183 L: 18821 D: 35180
Ptnml(0-2): 258, 7988, 19744, 8338, 264
https://tests.stockfishchess.org/tests/view/6928ba11b23dfeae38cff276

subsequent cleanups tested as:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 72480 W: 18678 L: 18502 D: 35300
Ptnml(0-2): 242, 7925, 19718, 8125, 230
https://tests.stockfishchess.org/tests/view/692a26adb23dfeae38cff566

We add an argument noRaysContaining, which skips all discoveries which contain
all bits in the argument; if the argument is from | to, then this will
eliminate the discovery. Separately, on AVX512ICL we can speed up the
computation of DirtyThreats by moving from a pop_lsb loop to a vector
extraction with vpcompressb. See PR for details.

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

No functional change
2025-12-01 17:26:50 +01:00
Timothy HerchenandDisservin 7c7c574e6b Fix msvc macro
closes https://github.com/official-stockfish/Stockfish/pull/6449

No functional change
2025-11-30 21:58:35 +01:00
Timothy HerchenandJoost VandeVondele b083049fe0 Use non-locking operations for nodes count and tbHits
fetch_add and friends must produce a locking instruction because they guarantee
consistency in the presence of multiple writers. Because only one thread ever
writes to nodes and tbHits, we may use relaxed load and store to emit regular
loads and stores (on both x86-64 and arm64), while avoiding undefined behavior
and miscounting nodes.

Credit must go to Arseniy Surkov of Reckless (codedeliveryservice) for
uncovering this performance gotcha.

failed yellow as a gainer on fishtest:
LLR: -2.95 (-2.94,2.94) <0.00,2.00>
Total: 219616 W: 57165 L: 57105 D: 105346
Ptnml(0-2): 732, 24277, 59720, 24357, 722
https://tests.stockfishchess.org/tests/view/69086abfea4b268f1fac2809

potential small speedup on large core system:
```
==== master ====
1 Nodes/second : 294269736
2 Nodes/second : 295217629
Average (over 2):  294743682
==== patch ====
1 Nodes/second : 299003603
2 Nodes/second : 298111320
Average (over 2):  298557461
```

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

No functional change
2025-11-17 13:24:32 +01:00
Timothy HerchenandJoost VandeVondele 229bd1e2e3 check for material key validity in tbprobe
During recent work on threat inputs, there was a hard-to-debug crash in tbprobe
caused by incorrectly computing st->materialKey. This PR adds correctness
checking to pos_is_ok and a faster check in tbprobe that will actually run in
CI (because pos_is_ok checking is disabled even in debug mode, for performance
purposes).

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

No functional change
2025-11-13 22:42:10 +01:00
Timothy HerchenandJoost VandeVondele fa4f05d3ef Don't copy around DirtyThreats
The contents of DirtyThreats gets memcpyed twice for each call to do_move.
(Return value optimization doesn't apply to the do_move function itself because
it constructs a std::pair, so it gets copied; and the calls to reset also
require a copy.) This patch inserts the dirty info in place.

Sometimes the caller of do_move ignores the DirtyThreats info, so we pass in
scratch objects. I found that stack-allocating these scratch objects was bad on
Fishtest, so I begrudgingly put them in the Position struct. Both templating
the do_move function on whether dirty threats are needed and putting a
null-check branch for each use of dirty threats were slowdowns locally. Of
course, nothing prevents a future attempt at cleaning this up.

passed STC
LLR: 2.96 (-2.94,2.94) <0.00,2.00>
Total: 68448 W: 17770 L: 17418 D: 33260
Ptnml(0-2): 198, 7425, 18630, 7769, 202
https://tests.stockfishchess.org/tests/view/6914c01a7ca87818523318ba

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

No functional change
2025-11-13 22:17:03 +01:00
Timothy HerchenandJoost VandeVondele 6764561916 Improve index generation
The speedup seems to vary by machine.  The indexing function can be changed w/o needing to understand intrinsics.

Result of 100 runs
==================
base (...ish_baseline) =    1719637  +/- 3233
test (./stockfish    ) =    1734245  +/- 3534
diff                   =     +14608  +/- 4868

speedup        = +0.0085
P(speedup > 0) =  1.0000

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

No functional change
2025-11-01 10:42:42 +01:00
Timothy HerchenandJoost VandeVondele 3bb01ce7a9 prefetch earlier if checKEP is false
Only a modest amount of work happens between the transposition table prefetch
and the probe, so the probe still often stalls waiting for DRAM. The vast
majority of the time (in particular, if !checkEP), the key is known much
earlier in the do_move function and the latency can be better hidden.

passed STC SMP
https://tests.stockfishchess.org/tests/view/68f337c528e6d77fcffa066a
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 65256 W: 16806 L: 16462 D: 31988
Ptnml(0-2): 76, 7386, 17362, 7726, 78

but failed to gain STC
https://tests.stockfishchess.org/tests/view/68f3378328e6d77fcffa0665
LLR: -2.94 (-2.94,2.94) <0.00,2.00>
Total: 109824 W: 28523 L: 28618 D: 52683
Ptnml(0-2): 311, 11799, 30788, 11702, 312

In local tests, the speedup grows with thread count

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

No functional change
2025-11-01 10:40:23 +01:00
b09339a420 Split accumulator 3-Way
Squeeze a tiny bit more juice from the original idea in #6336 which this is on top of.

https://tests.stockfishchess.org/tests/view/68dddd85fa806e2e8393c0b9
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 156320 W: 40925 L: 40447 D: 74948
Ptnml(0-2): 427, 17330, 42172, 17800, 431

4-way doesn't look to be better than this.
https://tests.stockfishchess.org/tests/view/68dde19efa806e2e8393c0c1

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

No functional change

Co-authored-by: M Stembera <m_stembera@yahoo.com>
2025-10-05 09:33:23 +02:00
Timothy HerchenandJoost VandeVondele 9b164d9520 Shave some instructions off a hot loop in affine transform
On x86, GCC generates highly suboptimal code for this loop in its old form,
about 2x as many instructions as necessary. This decreases throughput
especially in an SMT setting. Clang does a better job but this change still has
some improvement. Note that the std::ptrdiff_t type is not optional; using an
unsigned type brings back the bad assembly. (Not sure why, but it seems
reliable on all the GCC versions I tested.)

passed STC:
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 44672 W: 11841 L: 11527 D: 21304
Ptnml(0-2): 165, 4625, 12415, 4993, 138
https://tests.stockfishchess.org/tests/view/68d8111efa806e2e8393b10e

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

No functional change
2025-09-28 21:04:29 +02:00