Commit Graph
7166 Commits
Author SHA1 Message Date
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
Dalton HanawayandJoost VandeVondele 6f97594eda prefetch the TT entry as soon as the move is known
Worker::do_move computes the successor hash key via the new
Position::key_after(m) and prefetches the TT entry one full do_move
earlier than the existing prefetch in Position::do_move. key_after does
not model castling, en passant or promotion keys exactly; for rare
moves the prefetch lands on an unused line.

`key_after` has been around since 2014 (https://github.com/official-stockfish/Stockfish/commit/82d065b0) and was removed in (https://github.com/official-stockfish/Stockfish/pull/5770). Adding back `prefetch_key` helps in common, normal moves at the cost of extra compute.

Speedup (PGO vs PGO, interleaved paired bench, n=48 pairs, Apple M2
Pro / apple-silicon): +0.69% [0.47, 0.91]

Passed STC:
https://tests.stockfishchess.org/tests/view/6a291f8d7c758d82accea17f
LLR: 4.24 (-2.94,2.94) <0.00,2.00>
Total: 473504 W: 121250 L: 120228 D: 232026
Ptnml(0-2): 1112, 51137, 131251, 52121, 1131

No functional change

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

No functional change
2026-06-25 13:03:44 +02:00
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
Robert Nurnberg @ elitebookandDisservin 74a0a73715 Final fix for MultiPV mate PV corner cases
This PR fixes the remaining corner cases in the treatment of MultiPV
mated-in PVs, as well as an oversight in #6886. See the discussion in

In particular:
1. `previousScore` and `previousPV` can only be trusted, if that
   rootmove was indeed fully searched in the previous iteration.
2. A move beyond `pvIdx` (that was hence not fully searched) may have an
   exact loss score that cannot be trusted. So if a MultiPV search gets
   aborted while searching `pvIdx`, we mark all the following loss
   scores as bounds.
3. The forgotten mate logic also got broken in #6886, because the
   `previousPV` of the forgotten mate's bestmove can only be trusted if
   that move was fully searched in the previous iteration, something
   that is not guaranteed. So we now store both `lastBestMoveScore` and
   `lastBestMovePV`.

Here some scenarios for MultiPV = 8 that explain how master was broken:
1. Move A with an inexact mated-in-2 score from the previous iteration
   (so outside the top8 moves) gets flushed into the top8 moves for the
   current iteration, because the previous top8 move B is now scored as
   a mated-in-1. Hence we cannot trust `previousScore` or `previousPV`
   for move A, if the search gets aborted while it is being searched.
2. In the scenario above, move B has `Score != -VALUE_INFINITE` and a
   mated-in-1 score, which cannot be trusted as it was not fully
   searched.
3. Iteration N has bestmove A with mated-in-10, which gets recorded in
   `lastBestMoveScore` (renamed from `lastIterationScore`). Iteration 11
   forgets the mate and has bestmove B with a cp score, move A may have
   an incomplete PV, and may even have a non-mate score. Iteration 12
   gets aborted, and in trying to remember the forgotten mate, master
   recovers the `previousScore` and `previousPV` of move A, which may be
   neither mate nor complete.

Passed STC non-reg:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 69728 W: 17748 L: 17573 D: 34407
Ptnml(0-2): 143, 7571, 19274, 7720, 156
https://tests.stockfishchess.org/tests/view/6a2c40c60d5d4b19d08052f2

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

No functional change
2026-06-14 09:58:13 +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
zungurandDisservin f9beec5fa5 Reuse computed ray bitboard in update_piece_threats
Reuse the already-computed ray instead of calling ray_pass_bb a second time with identical arguments.

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

No functional change
2026-06-14 09:58:13 +02:00
zungurandDisservin ed8e35d759 Remove unused code from the post NNUE accumulator merge
After merging the HalfKA and Threats accumulators (7c7fe322) and the
subsequent removal of the double-incremental/fused update, a number of
NNUE helpers and fields became unreachable. Each was verified to have
zero callers/readers across the source tree:

- FusedUpdateData logic in FullThreats: the fused-update branch of
  append_changed_indices and the FusedUpdateData parameter are unused;
  the accumulator update no longer passes fused data.
- FullThreats::requires_refresh: never called. The live king-bucket
  refresh check is HalfKAv2_hm::requires_refresh (PSQFeatureSet), used
  in nnue_accumulator.
- HalfKAv2_hm::append_active_indices: never called. The live
  active-index builder is FullThreats::append_active_indices
  (ThreatFeatureSet).
- DirtyThreats::us, prevKsq and ksq: written in do_move but only read by
  the now-removed FullThreats::requires_refresh. Removing them also
  drops three stores from the do_move path.
- Unused feature Name constants and the unused FtOneVal / HiddenMaxVal
  constants in nnue_common.h.
- Two stale feature-header banner comments.

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

No functional change
2026-06-14 09:58:13 +02:00
Disservin 6e4e03fd28 Replace Remaining Types
Somehow a few size_t slipped through https://github.com/official-stockfish/Stockfish/pull/6874

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

No functional change
2026-06-14 09:58:13 +02:00
Disservin 718a001e6a Fixup RelaxedAtomic operator Types
As pointed out in
https://github.com/official-stockfish/Stockfish/commit/0111d11e2356147bad21c1f890b271a30d10a580#r188197707,
the parameter type should be `T` not `int`

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

No functional change
2026-06-14 09:58:13 +02:00
Joost VandeVondeleandDisservin 0dc19b61ae More stable matetrack CI
This version handles aborting engine processes more gracefully. This
also test the engine prior to use, as the process is nevertheless not
fully robust.

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

No functional change
2026-06-14 09:58:05 +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
zungurandJoost VandeVondele 5595cb20ea Fix FEN validation of pawns on first or eighth rank
The FEN validation check intended to reject pawns on the first or eighth rank uses the `Rank` enum values in a bitwise OR operation:

`if (pieces(PAWN) & (RANK_1 | RANK_8))`

`RANK_1 | RANK_8` evaluates to the integer `0 | 7 == 7` instead of a bitboard, so the expression only tests squares A1, B1 and C1. As a result, unsupported positions with pawns elsewhere on the first or eighth rank are silently accepted. For instance, `position fen 3P3k/8/8/8/8/8/8/3K4 w - - 0 1` is accepted even though the pawn on d8 makes the position unsupported.

Use the `Rank1BB | Rank8BB` bitboard constants so any pawn on the first or eighth rank are correctly rejected.

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

No functional change
2026-06-10 12:44:57 +02:00