7177 Commits
Author SHA1 Message Date
f4bcd40409 Update nnue architecture to SFNNv16 and net nn-89cb98a217f7.nnue
Failed STC (https://tests.stockfishchess.org/tests/view/6a4f36355529b8472df7ff7e):
LLR: -2.94 (-2.94,2.94) <0.00,2.00>
Total: 144768 W: 38003 L: 38051 D: 68714
Ptnml(0-2): 521, 17154, 37050, 17170, 489

Passed LTC (https://tests.stockfishchess.org/tests/view/6a501dad5529b8472df80103):
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 189888 W: 49613 L: 48984 D: 91291
Ptnml(0-2): 122, 20406, 53256, 21041, 119

Passed VLTC (https://tests.stockfishchess.org/tests/view/6a52892c5529b8472df80481):
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 46124 W: 12156 L: 11865 D: 22103
Ptnml(0-2): 12, 4523, 13696, 4824, 7

Passed VVLTC (https://tests.stockfishchess.org/tests/view/6a566a285529b8472df80b84):
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 44698 W: 11805 L: 11507 D: 21386
Ptnml(0-2): 9, 3819, 14395, 4117, 9

This PR adds pawn pair features, a new set of features that is indexed by pairs of pawns occupying the same or adjacent files (hence "3-wide"). Because these are a superset of pawn–pawn interactions in threat inputs (including the recently added pawn-pusher inputs), those are removed. HalfKA features remain unchanged.

Pawn-pair features were invented by Jonathan for Pawnocchio, based on his observation that in a net trained on *all* pairs of pawns, the most important pawn pairs were those differing by at most one file.

sscg13 made the necessary changes to the trainer (https://github.com/official-stockfish/nnue-pytorch/pull/502) and initial changes to inference. The slowdown was originally far too large (some 10%); following major optimizations from Jonathan and a bit from me, the slowdown is small enough for a comfortable LTC pass; on my machine I get a 3.5% slowdown overall. I expect there are further "easy" speedups in the new code, so this gap should narrow a bit.

Nettest PR: https://github.com/vondele/nettest/pull/359

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

Bench: 2718396

Co-Authored-By: anematode <timothy.herchen@gmail.com>
Co-Authored-By: Jonathan Hallström <lmj.hallstrom@gmail.com>
stockfish-dev-20260720-f4bcd404
2026-07-20 11:06:41 +02:00
Syine MinetaandJoost VandeVondele 4d75fd4f70 Always use pthread
After a858defd33, the pthread implementation of `NativeThread` is always used (except MSVC), as:

1. `-DUSE_PTHREADS` is defined when `comp` is not `mingw`
2. the pthread implementation is used anyways because MinGW defines `__MINGW32__` or `__MINGW64__` macro

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

No functional change
2026-07-20 11:01:40 +02:00
mstemberaandJoost VandeVondele d70dec7d6f Optimize attacks
STC:  https://tests.stockfishchess.org/tests/view/6a57f12c5529b8472df80e2a
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 85856 W: 22400 L: 22037 D: 41419
Ptnml(0-2): 153, 8999, 24290, 9304, 182

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

No functional change
2026-07-20 10:59:45 +02:00
anematodeandJoost VandeVondele b4ea9205a6 Allow trailing whitespace in str_to_size_t
Fixes #6984, first reported by sqrmax on the Discord, causing incorrect detection of NUMA and L3 domains on Linux due to trailing whitespace when reading from sysfs.

This was introduced by #6844 which made `str_to_size_t` too strict, since `std::stoull` allows trailing characters (and leading whitespace, although this part is not relevant for us).

Before:
$ ./bins/stockfish.master speedtest
Stockfish dev-20260716-ebcea3ef by the Stockfish developers (see AUTHORS file)
info string Using 224 threads with NUMA node thread binding: 64/32:64/32:64/32:32/16

After:
$ ./stockfish speedtest
Stockfish dev-20260718-m-cb702902 by the Stockfish developers (see AUTHORS file)
info string Using 224 threads with NUMA node thread binding: 32/32:32/32:32/32:32/32:32/32:32/32:32/32

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

No functional change
2026-07-20 10:58:54 +02:00
FauziAkramandJoost VandeVondele ebcea3efe9 VVLTC parameters tweak
Passed VVLTC with stc bounds:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 91508 W: 24212 L: 23887 D: 43409
Ptnml(0-2): 6, 7863, 29690, 8190, 5
https://tests.stockfishchess.org/tests/view/6a522f515529b8472df803a4

Passed VVLTC with ltc bounds:
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 62296 W: 16446 L: 16117 D: 29733
Ptnml(0-2): 6, 5333, 20143, 5658, 8
https://tests.stockfishchess.org/tests/view/6a52d9e65529b8472df805a5

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

Bench: 2792255
2026-07-16 18:02:05 +02:00
mstemberaandJoost VandeVondele 86beb0f540 Remove some dead fused code
closes https://github.com/official-stockfish/Stockfish/pull/6971

No functional change
2026-07-16 08:28:24 +02:00
mstemberaandJoost VandeVondele 3e3ee33a75 Simplify HalfKAv2_hm::write_indices()
STC: https://tests.stockfishchess.org/tests/view/6a4b4b32f97ff95f78795de9
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 196064 W: 51063 L: 51020 D: 93981
Ptnml(0-2): 367, 21491, 54292, 21496, 386

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

No functional change
2026-07-16 08:28:24 +02:00
Guy VreulsandJoost VandeVondele 151e204cc8 Simplify bitboards
This PR:
- retires the unused distance() functions in bitboard.h including the 4K SquareDistance LUT,
- makes the 64K PopCnt16 LUT constexpr and only compiles it in if we don't use  a popcount intrinsic (we can't fully remove the LUT because it's faster than the intrinsic in the absence of a popcount machine instruction),
- retires Bitboards::init().

Passed STC:
https://tests.stockfishchess.org/tests/view/6a48e6d3f97ff95f78795a8f
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 162016 W: 42054 L: 41976 D: 77986
Ptnml(0-2): 383, 17375, 45454, 17373, 423

I didn't run LTC because the changes only really impact workers without popcount and there aren't any present on fishtest ATM. The correctness of the constexpr PopCnt16 LUT was verified locally with a x86-64 build; the build yields the same signature as master.

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

No functional change
2026-07-16 08:28:24 +02:00
Linmiao XuandJoost VandeVondele 1c384d3a87 AVX2 fused SqrClippedReLU + ClippedReLU
Speedup measured with profile-build x86-64-avx2:
```
Result of  50 runs
==================
base (./sf-master    ) =     777661  +/- 8102
test (./sf-fused     ) =     796739  +/- 9127
diff                   =     +19077  +/- 3164

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

CPU: 8 x AMD EPYC 7R13 Processor
```

Passed STC:
https://tests.stockfishchess.org/tests/view/6a5049335529b8472df8013c
LLR: 2.96 (-2.94,2.94) <0.00,2.00>
Total: 262624 W: 68444 L: 67815 D: 126365
Ptnml(0-2): 724, 28976, 71325, 29521, 766

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

No functional change
2026-07-16 08:28:24 +02:00
Linmiao XuandJoost VandeVondele 4c78ba8920 AVX-512 squared clipped ReLU
Passed STC:
https://tests.stockfishchess.org/tests/view/6a4dd1075529b8472df7fd5e
LLR: 3.44 (-2.94,2.94) <0.00,2.00>
Total: 327136 W: 84861 L: 84124 D: 158151
Ptnml(0-2): 692, 34323, 92827, 35008, 718

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

No functional change
2026-07-16 08:28:24 +02:00
mstemberaandJoost VandeVondele 8ddea72917 Add -fno-ipa-cp-clone for mingw
Add -fno-ipa-cp-clone for mingw just as we do for gcc.  I get about a 1% speedup.  My machine is pretty unreliable for bench so maybe someone can verify.

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

No functional change
2026-07-16 08:28:24 +02:00
mstemberaandJoost VandeVondele a255ad59e3 Optimize evasions in Position::pseudo_legal()
STC: https://tests.stockfishchess.org/tests/view/6a4be17d5529b8472df7fa60
LLR: 3.68 (-2.94,2.94) <0.00,2.00>
Total: 405888 W: 105701 L: 104837 D: 195350
Ptnml(0-2): 872, 42472, 115373, 43374, 853

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

No functional change
2026-07-16 08:28:21 +02:00
mstemberaandJoost VandeVondele 057e9bf4da Fix an MSVC debug break
With the latest master I started getting:
"A breakpoint instruction (__debugbreak() statement or a similar call) was executed in Stockfish.exe." when debugging in MSVC.

I don't really understand the issue but Fable fixed it and I verified it works.
Here is its summary:
Bug: Calling _get_wpgmptr() in CommandLine::get_binary_directory() triggered a debug CRT assertion failure (__debugbreak()) on Windows. The CRT only initializes the wide program name _wpgmptr when the application uses a wide entry point (wmain). Since Stockfish uses the narrow main(int, char**) entry point, _wpgmptr remains nullptr, and the debug CRT's parameter validation asserts when _get_wpgmptr is called.

Fix: Replaced _get_wpgmptr() with GetModuleFileNameW(), which queries the executable path directly from the OS and does not depend on the CRT entry point type. The implementation uses a grow-and-retry loop, so paths longer than MAX_PATH are handled correctly. If the API fails, the code falls back to the original argv0-based behavior. The #ifdef _MSC_VER guard was also removed, since the fix no longer relies on the MSVC CRT — non-MSVC Windows builds (e.g., MinGW) now benefit from the accurate path as well.

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

No functional change
2026-07-16 08:28:08 +02:00
ConKirbyandJoost VandeVondele ca11d43709 Remove dead code left over from earlier refactors
The following have zero references repo-wide:

    Move::to_sq_unchecked() (types.h): added in 542c30c2 for a
    branchless correction-history update; its only caller was removed
    in 5ae13d2b ("Remove Redundant Branchless Execution"), leaving the
    method unused.

    PipeDeleter (misc.h): the custom deleter for the std::unique_ptr<FILE,
    PipeDeleter> that wrapped popen("lscpu"). That pipe was removed in
    c8375c2f ("On linux use sysfs instead of lscpu"), so the struct has
    been unused since.

Dropping PipeDeleter also removes the last user of <cstdio> in misc.h, so that include is dropped as well.

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

No functional change
2026-07-16 08:16:29 +02:00
Joost VandeVondele 9a8dd81dd7 Revert "Scale Null Move Pruning reduction"
This reverts commit 9d4090e826.

causes very poor mate finding performance, ultimately causing a CI hang on a mate in 2

Testcase:

position fen k1B5/2p5/NbN5/P7/3p4/P2p4/P1prp3/2RbK3 b - - 0 1 setoption name Hash value 16
setoption name Threads value 4
go mate 2
ucinewgame

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

Bench: 2466447
2026-07-11 20:35:40 +02:00
Joost VandeVondele c18feef187 Enhance version string
Use sha and git diff-index status for full version string.

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

No functional change
2026-07-11 20:35:16 +02:00
FauziAkramandJoost VandeVondele 924d29d3ca Simplify Reduction formula for first picked move (ttMove)
Passed STC non-reg:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 124864 W: 32270 L: 32151 D: 60443
Ptnml(0-2): 273, 13766, 34278, 13799, 316
https://tests.stockfishchess.org/tests/view/6a44f4d9f97ff95f78795463

Passed LTC non-reg:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 335544 W: 87272 L: 87369 D: 160903
Ptnml(0-2): 157, 34355, 98852, 34244, 164
https://tests.stockfishchess.org/tests/view/6a46a188f97ff95f787956a1

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

Bench: 2890786
2026-07-10 20:19:33 +02:00
ayushthepiro11andJoost VandeVondele 9d4090e826 Scale Null Move Pruning reduction dynamically based on evaluation margin
This patch introduces a dynamic scaling factor for Null Move Pruning (NMP) reductions. By scaling the reduction depth relative to the static evaluation margin against beta, the engine can afford more aggressive reductions in positions that are overwhelmingly favorable, optimizing CPU cycle utilization without compromising search integrity.

Passed STC:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 85504 W: 22383 L: 22000 D: 41121
Ptnml(0-2): 225, 9855, 22218, 10220, 234
https://tests.stockfishchess.org/tests/view/6a4793daf97ff95f78795812

Passed LTC:
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 205800 W: 53879 L: 53224 D: 98697
Ptnml(0-2): 98, 21747, 58561, 22390, 104
https://tests.stockfishchess.org/tests/view/6a4b864ff97ff95f78795e52

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

Bench: 2513153
2026-07-10 20:19:02 +02:00
Linmiao XuandJoost VandeVondele fb1d777250 Split AVX-VNNI sparse affine accumulation two ways
Speedup measured by @anematode
```
Result of 100 runs
==================
base (...h.master.exe) = 1504448 +/- 15119
test (./stockfish.exe) = 1519239 +/- 15980
diff = +14791 +/- 4113

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

CPU: Intel Core Ultra 9 285H
```

Passed STC:
https://tests.stockfishchess.org/tests/view/6a4dc4c65529b8472df7fd56
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 48256 W: 12746 L: 12420 D: 23090
Ptnml(0-2): 144, 5310, 12913, 5598, 163

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

No functional change
2026-07-10 20:18:25 +02:00
tonyandJoost VandeVondele 93ed4b53c4 Dynamic root score ema2
Improves calculation of root move score averages by dynamically calculating weight based on effort

Passed STC
https://tests.stockfishchess.org/tests/view/6a4ada97f97ff95f78795d5a
```
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 157248 W: 41003 L: 40515 D: 75730
Ptnml(0-2): 419, 18320, 40644, 18836, 405
```

Passed LTC
```
LLR: 3.03 (-2.94,2.94) <0.50,2.50>
Total: 197460 W: 51626 L: 50982 D: 94852
Ptnml(0-2): 85, 20849, 56237, 21455, 104
```

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

Bench: 2388656
2026-07-10 20:17:55 +02:00
Miloslav MacůrekandJoost VandeVondele 9700f6f206 Fix crash with UCI_LimitStrength and tablebases at the root
`Skill::pick_best()` assumes the root moves are sorted by score in descending order:

```cpp
Value topScore = rootMoves[0].score;
int   delta    = std::min(topScore - rootMoves[multiPV - 1].score, int(PawnValue));
```

That does not have to be so with Syzygy tablebases at the root, where the moves are ordered by `tbRank` instead. `rootMoves[0]` is then not the highest score and `delta` can go negative. Since `delta * (rng.rand<unsigned>() % int(weakness))` is evaluated as unsigned, a negative `delta` wraps to a large value and the `int(...)` cast overflows, so the `score + push >= maxScore` check never passes and `best` stays `Move::none()`. The caller

```cpp
std::swap(rootMoves[0],
          *std::find(rootMoves.begin(), rootMoves.end(),
                     skill.best ? skill.best : skill.pick_best(rootMoves, multiPV)));
```

then dereferences `end()`. The result is a crash, or sometimes `bestmove (none)` / an illegal move, in tablebase endgames when `UCI_LimitStrength` is set (or `Skill Level` is below 20).

The fix computes the score range over the candidate moves directly, so `delta` stays non-negative and a valid move is always returned.

**To reproduce**:
```
setoption name UCI_LimitStrength value true
setoption name UCI_Elo value 2900
setoption name SyzygyPath value <syzygy tablebases path>
position fen 8/8/8/4k3/8/8/3BKN2/8 b - - 0 1
go wtime 250 btime 250 winc 100 binc 100
```

You need to call the go command a couple of times before crash, after which is ends with

```
bestmove a1e5 ponder (none)
```

and on the next `go wtime 250 btime 250 winc 100 binc 100` it crashes printing:

```
info string Available processors: 0-31
info string Using 1 thread
info string NNUE evaluation using nn-af1339a6dea3.nnue (106MiB, (83248, 1024, 31, 32, 1))
info string Network replica 1: Shared memory.
```

Bench is unchanged, since this code only runs under `UCI_LimitStrength` / `Skill Level`.

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

No functional change
2026-07-10 20:17:23 +02:00
Linmiao XuandJoost VandeVondele 2d239de460 Split NEON dense affine accumulation two ways
Speedup measured locally with apple-silicon M3 Pro:

```
Result of  50 runs
==================
base (./sf-master    ) =    1570076  +/- 27215
test (...-neon-2chain) =    1578923  +/- 29000
diff                   =      +8847  +/- 5700

speedup        = +0.0056
P(speedup > 0) =  0.9988

CPU: 11 x arm
Hyperthreading: off
```

Passed STC:
https://tests.stockfishchess.org/tests/view/6a49678cf97ff95f78795b38
LLR: 4.43 (-2.94,2.94) <0.00,2.00>
Total: 137696 W: 36041 L: 35477 D: 66178
Ptnml(0-2): 289, 14663, 38396, 15195, 305

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

No functional change
2026-07-10 20:16:42 +02:00
Timothy HerchenandJoost VandeVondele cd75d31127 Improve CLI error handling a bit
Reduce the number of *easy* ways to hit UB or an uncaught exception. This builds on Sopel's work on FEN validation.

Obviously SF is not and will never be a security boundary, but at least we can reduce the number of reports about uncaught `std::stoi` out of range, etc.

I also added a gentle fallback to `NumaConfig` specifically because that's something that (as a dev) I frequently set by hand in the CLI, but happy to revert if that's too annoying of a change.

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

No functional change
2026-07-10 20:16:02 +02:00
Robert NurnbergandJoost VandeVondele 48a9118251 Minor cleanups June 2026
In the spirit of previous such PRs, this PR proposes a collection of nonfunctional changes.

I am happy to incorporate changes from other devs, and revert some of the proposed changes if the maintainers ask me to.

Apart from trivial changes, the proposed changes so far include:

* A requested edit to `AUTHORS` and a resorting of all entries, following DIN 5007 for the treatment of any special characters.
* Exclude the two recent integer type renaming commits from git blame.
* Tightening of some static asserts in `history.h` to avoid overflows. (Note that rounding errors for floating point types could lead to the assert in `operator<<` triggering at run-time.)
* Re-instate the 0.5s maximal thinking time in case of a single legal move and reword the comment to make it clear that it should not be tuned.
* ~~A small refactoring of the network loading code thanks to @dubslow.~~
* A refactoring of the "dtz is dtm" code, also thanks to @dubslow.

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

No functional change
2026-07-10 20:12:38 +02:00
mstemberaandJoost VandeVondele eca43a97ef Remove unnecessary memset(), memcpy() from NetworkArcitecture::propagate()
Since https://github.com/official-stockfish/Stockfish/pull/6938 this is no longer needed.

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

No functional change
2026-07-06 11:38:27 +02:00
Linmiao XuandJoost VandeVondele 2cbf39f845 Split NEON sparse affine accumulation three ways
Speedup measured locally with apple-silicon M3 Pro:

```
Result of  50 runs
==================
base (./sf_master    ) =    1817788  +/- 4388
test (...on_sparse_3c) =    1839826  +/- 5482
diff                   =     +22039  +/- 3215

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

CPU: 11 x arm
Hyperthreading: off
```

Passed STC:
https://tests.stockfishchess.org/tests/view/6a496a49f97ff95f78795b3d
LLR: 2.92 (-2.94,2.94) <0.00,2.00>
Total: 44384 W: 11659 L: 11351 D: 21374
Ptnml(0-2): 86, 4673, 12406, 4901, 126

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

No functional change
2026-07-06 11:33:51 +02:00
Adrian LadoniandJoost VandeVondele 7da31a1f1d Simplify futility multiplier
this patch simplifies the Value futility multiplier and changes pruning behaviour

passed stc: https://tests.stockfishchess.org/tests/view/6a462265f97ff95f78795600
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 38112 W: 10071 L: 9758 D: 18283
Ptnml(0-2): 88, 4341, 9903, 4618, 106

passed ltc: https://tests.stockfishchess.org/tests/view/6a470bc5f97ff95f7879576a
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 67482 W: 17738 L: 17363 D: 32381
Ptnml(0-2): 36, 7061, 19164, 7452, 28

patch rebased to latest master

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

Bench: 2353997
2026-07-06 11:33:03 +02:00
Syine MinetaandJoost VandeVondele bc079c46a9 Fix Clang 22 codegen regression
Clang 22 apparently has a codegen regression in capture() and capture_stage() functions. GCC and the other versions of Clang also showed a marginal speedup which however could be due to noise.

Combined results of two STC tests:
https://tests.stockfishchess.org/tests/view/6a45b104f97ff95f78795570
https://tests.stockfishchess.org/tests/view/6a474aaff97ff95f787957a9

STC (clang++ 22):
LLR: 2.811 (-2.944,2.944) <0.00,2.00>
Ptnml(0-2): 67, 3094, 7975, 3306, 102

Non-regression STC (g++, clang++ ~21):
LLR: 6.617 (-2.944,2.944) <-1.75,0.25>
Ptnml(0-2): 428, 22211, 56555, 22553, 429

Local test results (Zen 4, x86-64-avx512icl, bench 512 1 16, 50 runs):

Clang (22.1.2): PASSED: speedup = +0.0169, P(speedup > 0) = 1.0000
GCC (15.2.0):   FAILED: speedup = +0.0031, P(speedup > 0) = 0.9597

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

No functional change
2026-07-06 11:32:15 +02:00
Timothy HerchenandJoost VandeVondele 4436524a3e add rbit fallback
GCC 12.2 added `__rbitll` intrinsic to `arm_acle.h`, so we can add a fallback for older versions

Clang 10 (our new minimum supported version) is unaffected by all this

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

No functional change
2026-07-06 11:31:28 +02:00
22548cb0c0 S人ving Privàte Ryän
Fixes problems with non-ASCII characters in paths. Fixes #3424.

Changes
- Bump the minimum supported Clang version to 11 to support std::filesystem
- Use std::optional for empty values instead of string sentinels like "None"
- Remove the FixedString class
- Move the EvalFile network path from the network struct to the engine
- Simplify parts of the command-line handling
- Remove the old dual-net logic from export_net
- And ofc we now support non-ascii paths for windows

Behavior Change
- Because the EvalFile is no longer part of the network, it won't be included in the hashing, thus the network sharing is no longer dependent on the EvalFile path
- As a result, if the binary version and network are the same, changing only the EvalFile location will now reuse the same shared network

This also fixes a master bug where:

```
export_net None
setoption name EvalFile value None
export_net None
Failed to export a net
```

would fail on the second export. With this patch, the second export succeeds.

Quick Fishtest Check that nets load like normal.
https://tests.stockfishchess.org/tests/view/6a455593f97ff95f787954da

<img width="833" height="1137" alt="image" src="https://github.com/user-attachments/assets/fffee63b-c63a-4d5e-b13d-87d58bc28c88" />

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

No functional change

Co-authored-by: anematode <timothy.herchen@gmail.com>
2026-07-06 11:30:51 +02:00
anematodeandJoost VandeVondele d5bbc6b67d [RfC] RISC-V port and universal binary
Performance on Spacemit K3, thanks @edolnx for testing

master:
Total time (ms) : 65200
Nodes searched  : 3493826
Nodes/second    : 53586

riscv-scalable-port:
Total time (ms) : 15834
Nodes searched  : 3493826
Nodes/second    : 220653

Also thanks to @camel-cdr for guidance on RVV programming, and https://cloud-v.co for supplying an RVV instance to test with

passed STC:
LLR: 2.81 (-2.94,2.94) <0.00,2.00>
Total: 1152 W: 527 L: 108 D: 517
Ptnml(0-2): 0, 17, 167, 348, 44
https://tests.stockfishchess.org/tests/view/6a39895b3036e45021aeb368

## Summary

We've had a `riscv64` target for a while, but haven't really optimized for it, in particular the vector extension (RVV).

RVV, like SVE, is based on a scalable vector system where the vector length ranges from 128 to 65536. In practice implementations are between 128 and 2048, and 256 bits is quite common (e.g. the Spacemit K3 system above). Unfortunately this doesn't fit well into the rest of our code which assumes a fixed vector length, so what I've done is bypass the `VECTOR` ifdef (which now basically means "FIXED_LENGTH_VECTOR") and just have RVV-specific paths.

The ability to explicitly control `vl` makes the code quite readable, in my opinion. We use LMUL>1 in most places to take advantage of multi-vector instructions. Generally the LMULs were chosen to best support a 256-bit vlen, which is very common, but by virtue of how the vlen control works, the code works with any vlen. In a couple places, i.e., `get_changed_pieces` and `AffineTransformSparseInput::propagate`, we have separate implementations depending on the vlen, because the optimal LMUL varies a lot between implementations.

One little wrinkle is that `load_as` is compiled to a sequence of byte loads, because although unaligned loads are legal in RVA23, the spec says that they *may* be extremely slow (even though they usually aren't, in actual hw), so compilers are conservative. Thus I aligned the relevant buffers and made the semantics of `load_as` that the operand is aligned, by adding a runtime assertion.

### Universal binary

Adding a universal binary is pretty easy and we can just cross-compile. There are two targets: baseline rv64gc and riscv64-rva23, which is actually a smaller subset of RVA23 that also works on some older processors that don't support the full thing. We use clang because GCC, until recently, has a nasty bug with LTO and RVV.

Like the universal ARM and x86 builds, we check all the builds in CI. In this case we run bench with multiple vlens, 128 through 1024.

In the meantime I deleted the existing broken and unused riscv64 tests.

### Follow-ups

- Optimizations
- zvdot4a8i path

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

No functional change
2026-07-03 20:29:50 +02:00
99489f57dd Simplify out pext attacks
Passed STC non-regression on avx512icl (https://tests.stockfishchess.org/tests/view/6a421b46f97ff95f78795061)
LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 81632 W: 21240 L: 21075 D: 39317
Ptnml(0-2): 184, 8907, 22464, 9082, 179

Passed STC non-regression on bmi2 (https://tests.stockfishchess.org/tests/view/6a41f6f9f97ff95f7879503e)
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 78112 W: 20411 L: 20245 D: 37456
Ptnml(0-2): 188, 8449, 21632, 8583, 204

After #6845 , pext attacks are slower or equal to parallel-hyperbola attacks which works on all architectures that pext supports. SVE2 supports pext/pdep in vector registers, but it's much slower than the `rbit`-based HQ that we have on ARM, so I don't foresee the code being useful there.

Ofc I don't think we should remove the `bmi2` build or anything, because it's nice for people to be able to freely use pext when testing ideas, and I'm sure we'll some day find another use for it!

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

No functional change

Co-authored-by: Dubslow <bunslow@gmail.com>
2026-07-03 20:27:33 +02:00
MFWandJoost VandeVondele 46428b9346 Allow cross-compilation of Android version on Mac
When compiling for Android (COMP=ndk) on macOS, the build fails because the
NDK's LLVM toolchain does not recognize the macOS-specific flags
-mdynamic-no-pic and -mmacosx-version-min.

This PR wraps these flags with ifneq ($(COMP),ndk) condition to skip them
during Android cross-compilation.

Please squash and merge this PR.

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

No functional change
2026-07-03 20:26:34 +02:00
DisservinandJoost VandeVondele 3e1e8e38a4 Fix Clang-Format Action Inputs
The inputs have a different name.. https://github.com/thollander/actions-comment-pull-request#action-inputs

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

No functional change
2026-07-03 20:25:35 +02:00
Robert Nurnberg @ elitebookandJoost VandeVondele 9449162d58 Simplify thread selection
The depth dependency in best thread selection no longer seems to gain sufficiently and so can be simplified away.

Passed non-reg STC SMP:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 437904 W: 111841 L: 112051 D: 214012
Ptnml(0-2): 485, 49454, 119332, 49148, 533
https://tests.stockfishchess.org/tests/view/6a3158590d5d4b19d08055cd

Passed non-reg LTC SMP:
LLR: 3.11 (-2.94,2.94) <-1.75,0.25>
Total: 484778 W: 123864 L: 124093 D: 236821
Ptnml(0-2): 121, 49237, 143920, 48972, 139
https://tests.stockfishchess.org/tests/view/6a377f3ba4f63d3271af0920

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

No functional change
2026-07-03 20:24:56 +02:00
mstemberaandJoost VandeVondele 32619a0294 Enable MoveSorter for AVX512
STC: https://tests.stockfishchess.org/tests/view/6a42f773f97ff95f7879518a
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 132992 W: 34679 L: 34248 D: 64065
Ptnml(0-2): 318, 14004, 37436, 14405, 333

No functional change

Credit to @anematode for the original PR!

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

No functional change
2026-07-03 20:24:27 +02:00
Syine MinetaandJoost VandeVondele 83514e4970 Filter invalid threat pairs early
Passed STC:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 246400 W: 63981 L: 63391 D: 119028
Ptnml(0-2): 612, 26055, 69299, 26599, 635
https://tests.stockfishchess.org/tests/view/6a3fafbf3036e45021aebaa0

Measured 1% speedup locally on x86-64-avx512icl build (bench 512 1 16, 50 runs):

PASSED: speedup = +0.0104, P(speedup > 0) = 1.0000

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

No functional change
2026-07-03 20:22:16 +02:00
Shawn XuandJoost VandeVondele d91c7f6eac Update main network to nn-0ee0657fb25e.nnue
Passed STC:
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 26976 W: 7185 L: 6883 D: 12908
Ptnml(0-2): 89, 3058, 6895, 3354, 92
https://tests.stockfishchess.org/tests/view/6a46dd46f97ff95f78795707

Passed LTC:
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 101394 W: 26460 L: 26009 D: 48925
Ptnml(0-2): 74, 10871, 28367, 11300, 85
https://tests.stockfishchess.org/tests/view/6a46eff2f97ff95f7879573b

fixes a potential overflow when rescaling network evals.

nettest: vondele/nettest#403

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

Bench: 2752030
2026-07-03 20:19:10 +02:00
e33bb26ee7 Update nnue-architecture to SFNNv15
Updating nnue to a new architecture including a newly trained net using recipe https://github.com/vondele/nettest/pull/395 and trainer https://github.com/official-stockfish/nnue-pytorch/pull/480.

The recipe contains many small improvements additionally the newly relabled data. Thus this is a combined effort.

Passed STC
https://tests.stockfishchess.org/tests/view/6a429fd8f97ff95f78795110
```
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 25312 W: 6725 L: 6422 D: 12165
Ptnml(0-2): 78, 2915, 6397, 3158, 108
```

Passed LTC
https://tests.stockfishchess.org/tests/view/6a434c4cf97ff95f78795235
```
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 32814 W: 8655 L: 8345 D: 15814
Ptnml(0-2): 17, 3469, 9132, 3765, 24
```

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

Bench: 2639962

Co-authored-by: anematode <anematode@users.noreply.github.com>
Co-authored-by: Joost VandeVondele <vondele@users.noreply.github.com>
Co-authored-by: xu-shawn <xu-shawn@users.noreply.github.com>
2026-07-03 20:07:49 +02:00
yl25946andJoost VandeVondele 6088838797 Yeet psqt weights
Simplifying the ratio in the eval between the psqt and the positional eval to a basic addition

Passed Nonreg STC:
https://tests.stockfishchess.org/tests/view/6a3eaac63036e45021aeb937
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 207392 W: 53521 L: 53489 D: 100382
Ptnml(0-2): 585, 24412, 53748, 24288, 663

Passed Nonreg LTC:
https://tests.stockfishchess.org/tests/view/6a423666f97ff95f7879508e
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 27198 W: 7200 L: 6989 D: 13009
Ptnml(0-2): 12, 2794, 7779, 2999, 15

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

Bench: 2067208
2026-06-30 06:22:29 +02:00
Shawn XuandJoost VandeVondele 4488343cf6 Update main network to nn-af1339a6dea3.nnue
This network is trained by adding the following binpacks, relabeled by @vondele and totaling 74B positions, to the distillation fine-tuning stage:
```
  - vondele/from_kaggle_1_relabel/leela96-filt-v2.min.split_0.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_1_relabel/leela96-filt-v2.min.split_1.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_1_relabel/leela96-filt-v2.min.split_2.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_1_relabel/leela96-filt-v2.min.split_3.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_1_relabel/leela96-filt-v2.min.split_4.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_2_relabel/T60T70wIsRightFarseerT60T74T75T76.split_0.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_2_relabel/T60T70wIsRightFarseerT60T74T75T76.split_1.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_2_relabel/T60T70wIsRightFarseerT60T74T75T76.split_2.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_2_relabel/T60T70wIsRightFarseerT60T74T75T76.split_3.relabel-BT4-tf13tune.binpack
  - vondele/from_kaggle_2_relabel/T60T70wIsRightFarseerT60T74T75T76.split_4.relabel-BT4-tf13tune.binpack
```

The relabeling effort has been completed during the testing of this patch, and a full training run is on the way. Thanks to @vondele, @anematode, @Disservin, @yl25946, and all who've contributed to the process.

Passed STC:
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 24512 W: 6500 L: 6201 D: 11811
Ptnml(0-2): 69, 2772, 6300, 3021, 94
https://tests.stockfishchess.org/tests/view/6a40b7083036e45021aebbd6

Passed LTC:
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 15708 W: 4232 L: 3960 D: 7516
Ptnml(0-2): 8, 1572, 4420, 1848, 6
https://tests.stockfishchess.org/tests/view/6a413d293036e45021aebc84

nettest PR: https://github.com/vondele/nettest/pull/388

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

Bench: 2102535

Co-authored-by: Joost VandeVondele <Joost.VandeVondele@gmail.com>
2026-06-29 06:32:19 +02:00
Shawn XuandDisservin 9d2ba2bed5 Update main network to nn-1b6a82263149.nnue
Add `test80-2024-01-jan-2tb7p.min-v2.v6.relabel.binpack` to the distillation fine tuning stage, an additional 3.5B (2.9B non-skipped) positions.

nettest PR: https://github.com/vondele/nettest/pull/375

Passed STC (vs #6924):
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 57952 W: 15000 L: 14656 D: 28296
Ptnml(0-2): 164, 6651, 15003, 6993, 165
https://tests.stockfishchess.org/tests/view/6a3cca103036e45021aeb6f8

Passed LTC:
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 81456 W: 21265 L: 20858 D: 39333
Ptnml(0-2): 52, 8630, 22958, 9035, 53
https://tests.stockfishchess.org/tests/view/6a3dbe203036e45021aeb828

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

Bench: 2703604
2026-06-27 15:30:39 +02:00
DavidandDisservin feb932533d Update bug report template
closes https://github.com/official-stockfish/Stockfish/pull/6926

No functional change
2026-06-27 15:30:23 +02:00
FauziAkramandJoost VandeVondele 47575ebd8b Deduplicating Color-Specific Piece Validation
Deduplicating Color-Specific Piece Validation.

The validation checks for the number of pawns and additional promoted pieces are duplicated for WHITE and BLACK. We can combine this logic into a single range-based for loop over both colors.

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

No functional change
2026-06-25 13:11:17 +02:00
Daniel MonroeandJoost VandeVondele 3c858c19e6 Two small simplifications
Passed simplification STC
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 206368 W: 52592 L: 52560 D: 101216
Ptnml(0-2): 537, 24201, 53669, 24247, 530
https://tests.stockfishchess.org/tests/view/6a2c5ab00d5d4b19d0805326

Passed simplification LTC
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 109944 W: 27839 L: 27709 D: 54396
Ptnml(0-2): 61, 11938, 30844, 12068, 61
https://tests.stockfishchess.org/tests/view/6a2dc6e70d5d4b19d08053aa

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

Bench: 2767133
2026-06-25 13:10:08 +02:00
zungurandJoost VandeVondele 782852b26a Clear capturedPiece in do_null_move
do_null_move copies the whole StateInfo from the previous state, which leaves capturedPiece holding the piece captured by the last real move, so inside the null-move subtree captured_piece() reports a stale capture. The priorCapture consumers in search are all guarded by prevSq != SQ_NONE or (ss-1)->currentMove.is_ok(), which are false at the null-move child, but the stalemate verification gate in qsearch reads captured_piece() unguarded and can be spuriously triggered by the stale value.

Clear the field, since a null move captures nothing.

Passed non-regression STC:
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 82784 W: 21172 L: 21011 D: 40601
Ptnml(0-2): 194, 8976, 22923, 9073, 226
https://tests.stockfishchess.org/tests/view/6a2b5b356b4aa63ddbf31518

Passed non-regression LTC:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 118134 W: 30007 L: 29891 D: 58236
Ptnml(0-2): 66, 11856, 35108, 11970, 67
https://tests.stockfishchess.org/tests/view/6a2c4c9c0d5d4b19d0805301

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

No functional change
2026-06-25 13:09:32 +02:00
zungurandJoost VandeVondele 5b87bc48cd Remove unused search-layer APIs
The following have zero call sites repo-wide:

    SearchManager:🆔 never read or written (also never initialized, nor was it ever used).
    Search::Worker::elapsed_time(): never called. PV output uses tm.elapsed_time() (TimeManager) directly. (removed callers on 25361e5)
    MovePicker::begin()/end(): unused private accessors. (removed callers on 8c2d21f)

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

No functional change
2026-06-25 13:09:03 +02:00
FauziAkramandJoost VandeVondele 1ece3c030d Simplify Evasion Logic
When the king is in check, a pseudo-legal move must be a valid evasion. Instead of duplicating the checking rules for king and non-king moves, we can leverage the existing MoveList<EVASIONS> class.

Passed non-reg STC:
LLR: 2.98 (-2.94,2.94) <-1.75,0.25>
Total: 187360 W: 47579 L: 47524 D: 92257
Ptnml(0-2): 418, 20266, 52263, 20309, 424
https://tests.stockfishchess.org/tests/view/6a28aa5b7c758d82accea13c

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

No functional change
2026-06-25 13:07:50 +02:00
9fcd47a717 Update main network to nn-f8a759c05f9f.nnue
This network is further trained on a new BT4 distillation stage, fine tuning on ~2 billion positions relabeled with the value head output of `BT4-tf13tune.pb.gz`. The dataset can be found at https://huggingface.co/datasets/xushawn/test80-bt4-relabel. A modified branch of lc0 was used to derive this data: https://github.com/xu-shawn/lc0/tree/relabel_dual_stream_test

2 billion positions represent a tiny subset of the total training data, and BT4 relabeling is inherently computationally expensive. I expect a lot more gains as more data are relabeled, but it will likely require coordinated community effort. Everyone is welcome to contribute, and yl25946 has made a spreadsheet to track progress: https://docs.google.com/spreadsheets/d/1yanofhusEzDg8ZnurAw799ikoTY6GcqsNMYfpswOIbw/edit.

Special thanks to Viren6, who performed policy/value distillation experiments on Monty, and created the lc0 distillation fork that the current relabeler is based on; yl25946 for proposing the idea of large network distillations back in February 2025, running distillation experiments on the HL4096 network, and working on fine tuning attempts; vondele for nettest and suggesting the fine-tuning approach; and many others on the knowledge distillation thread in the SF Discord #ideas channel.

nettest PR: https://github.com/vondele/nettest/pull/369

Ongoing STC:
 LLR: -0.01 (-2.94,2.94) <0.00,2.00>
Total: 72224 W: 18891 L: 18784 D: 34549
Ptnml(0-2): 336, 8437, 18332, 8798, 209
https://tests.stockfishchess.org/tests/view/6a3ae7913036e45021aeb4a0

Passed LTC:
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 25110 W: 6566 L: 6288 D: 12256
Ptnml(0-2): 27, 2625, 6957, 2935, 11
https://tests.stockfishchess.org/tests/view/6a3b73513036e45021aeb51e

Passed VLTC:
 LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 18544 W: 4924 L: 4658 D: 8962
Ptnml(0-2): 5, 1730, 5533, 2002, 2
https://tests.stockfishchess.org/tests/view/6a3bbe233036e45021aeb56e

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

Bench: 2710209

Co-authored-by: Li Ying <121075683+yl25946@users.noreply.github.com>
Co-authored-by: Viren6 <94880762+Viren6@users.noreply.github.com>
2026-06-25 13:06:10 +02:00
Michael ChalyandJoost VandeVondele d64835051e Do more aggressive probCut when improving.
If improving is true reduce depth of probCut search by 1.
Passed STC:
https://tests.stockfishchess.org/tests/view/6a2a6ceb17167cbe7100a909
LLR: 2.94 (-2.94,2.94) <0.00,2.00>
Total: 119136 W: 30591 L: 30158 D: 58387
Ptnml(0-2): 323, 13831, 30845, 14228, 341
Passed LTC:
https://tests.stockfishchess.org/tests/view/6a2d65a40d5d4b19d080537f
LLR: 2.96 (-2.94,2.94) <0.50,2.50>
Total: 186552 W: 47377 L: 46755 D: 92420
Ptnml(0-2): 89, 20047, 52395, 20643, 102

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

Bench: 2422062
2026-06-25 13:04:20 +02:00