Commit Graph
6921 Commits
Author SHA1 Message Date
FauziAkramandJoost VandeVondele 7bd32a51f5 Replacing the futility margin static value with a continuous transition
Smooth the futility margin by interpolating the multiplier based on depth, replacing the previous static value with a continuous transition between depth 1 and 10.

Passed STC:
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 208448 W: 53891 L: 53324 D: 101233
Ptnml(0-2): 629, 24426, 53574, 24939, 656
https://tests.stockfishchess.org/tests/view/69e232206f344a19176002f3

Passed LTC:
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 208938 W: 53432 L: 52765 D: 102741
Ptnml(0-2): 105, 22531, 58550, 23158, 125
https://tests.stockfishchess.org/tests/view/69e8b5d00e9667dd5a7656c6

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

Bench: 2661424
2026-05-04 08:30:28 +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
Ryan Hirsch rhirsch123andJoost VandeVondele 0e78190b72 Speed up find_nnz on neon (Refactored)
Passed STC:
LLR: 2.97 (-2.94,2.94) <0.00,2.00>
Total: 349568 W: 90131 L: 89393 D: 170044
Ptnml(0-2): 725, 37712, 97280, 38234, 833
https://tests.stockfishchess.org/tests/view/69e470510e9667dd5a765046

This is a refactor of https://github.com/official-stockfish/Stockfish/pull/6766 so we don't have to include nnue_architecture.h
It also includes the fix in https://github.com/official-stockfish/Stockfish/pull/6769 which was needed to make this work.
mstembera made rhirsch123 the author.  credits also to anematode.

[Edit] Also fixes a bug where _mm512_packus_epi32 was being used instead of the correct _mm512_packs_epi32 for the IceLake version.

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

No functional change
2026-04-26 09:41:09 +02:00
mstemberaandJoost VandeVondele 692d90bd74 Simplify FullThreats::append_active_indices()
Also add an else to FullThreats::append_changed_indices() because dp2removed
can't be equal to both from and to simultaneously.

passed STC
https://tests.stockfishchess.org/tests/view/69e71a490e9667dd5a76549f
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 210688 W: 54362 L: 54335 D: 101991
Ptnml(0-2): 613, 23246, 57593, 23285, 607

Thanks to ces42 for an improvement suggestion.

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

No functional change
2026-04-26 09:37:18 +02:00
FauziAkramandJoost VandeVondele c787509663 Simplify time management reduction logic
Simplify the time management reduction logic by replacing the previous sigmoid
function with the linear interpolate function introduced in #6729 , resulting
in a cleaner and more efficient calculation of move stability that avoids
unnecessary exponential operations.

Passed STC non-reg:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 161856 W: 41933 L: 41852 D: 78071
Ptnml(0-2): 418, 18137, 43792, 18108, 473
https://tests.stockfishchess.org/tests/view/69e117a46f344a1917600148

Passed LTC non-reg:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 108726 W: 27819 L: 27692 D: 53215
Ptnml(0-2): 59, 11084, 31942, 11227, 51
https://tests.stockfishchess.org/tests/view/69e563c00e9667dd5a7652ac

This is a follow-up for #6091  #6729

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

No functional change
2026-04-26 09:35:37 +02:00
mstemberaandJoost VandeVondele 767dcfe48d Fix Universal build on Windows
TRACKED_TOP previously used a shell pipeline (xargs, awk, sort) to extract
unique top-level directory/file names from SRCS and HEADERS. When invoking make
from cmd.exe on Windows, $(shell ...) uses cmd.exe rather than sh.exe, so the
pipeline fails because cmd.exe does not support Unix pipe syntax. Other MSYS2
tools (e.g. the compiler) work fine because they are invoked directly as
commands, not through a shell pipeline. This caused TRACKED_TOP to be empty, so
ln -s never ran and the per-arch temp_builds subdirectories were left without a
Makefile symlink, breaking the universal build with: "No rule to make target
'universal-object-nopgo'". Fixed by replacing the shell pipeline with pure GNU
make built-in functions (sort, foreach, firstword, subst) which have no shell
or PATH dependencies and work identically on Windows, Linux and macOS.

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

No functional change
2026-04-26 09:33:03 +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
Robert Nurnberg @ elitebookandJoost VandeVondele 86853a60ce [bugfix] Send correct search depth in final UCI info line
For quite some time SF has reported a too low final search depth in rare cases
(in multi-threaded search if a non-main thread was selected). Unfortunately,
the recent refactoring in #6704 means that this now happens for almost every
stopped search.

This PR fixes this issue, which was first spotted and reported by joergoster,
by ensuring that `rootDepth` always holds the last depth for which a search was
started.

Fixes #6756.

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

No functional change.
2026-04-26 09:28:54 +02:00
FauziAkramandJoost VandeVondele 38d887ac64 Reuse Promotion Type Natively
Piece promotion is generated, and then type_of(promotion) is used to retrieve
the underlying type. The class Move provides .promotion_type() natively,
meaning we can cache the type directly and avoid extracting it indirectly
afterward.  By extracting pt = m.promotion_type(); up front, we don't need to
call type_of(promotion) iteratively inside the assertions or conditions below.

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

No functional change
2026-04-26 09:25:45 +02:00
Robert NurnbergandJoost VandeVondele 50e8ff1e23 multiPV: protect mated-ins and allow thread selection
This PR is a replacement for #6652 and takes into account the changes made to this part of the code since then.

In multiPV analysis master may suppress genuine proven mated-in scores, if the iteration for a secondary PV line is aborted. In very rare cases, it may also evict a proven mated-in score from the best PV line with a score from an incomplete iteration of a secondary PV line. This PR avoids both.

In addition, we allow best thread selection in multithreaded multiPV searches. This was originally disabled in #524.

Single PV searches are not affected by this patch at all.

Fixes #6642.

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

No functional change.
2026-04-26 09:24:34 +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
FauziAkramandJoost VandeVondele ed651aab54 Replacing std::clamp with std::min
No functional change

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

No functional change
2026-04-20 17:45:03 +02:00
FauziAkramandJoost VandeVondele 7faecd75ac Combine duplicated - tb.plies subtraction logic
closes https://github.com/official-stockfish/Stockfish/pull/6752

No functional change
2026-04-20 17:44:01 +02:00
DisservinandJoost VandeVondele 583e0c1c75 cleanup feature detection code
makes the main dispatch logic more easy to follow and possibly update

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

No functional change
2026-04-20 17:42:47 +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
FauziAkramandJoost VandeVondele ce7848f7cc Remove the Redundant ply Variables in Benchmark Calculations
In setup_benchmark, the variables evaluating the current ply simply mirror the
exact iterative progress of the string arrays loop (since ply just increments
by 1 with every pass). We can delete the separate integer assignment and
execute it securely within the loop declaration.

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

No functional change
2026-04-19 07:23:25 +02:00
FauziAkramandJoost VandeVondele c66acdac99 Restructure Futility pruning
to a simpler and cleaner version

Passed non-reg test:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 175648 W: 45156 L: 45091 D: 85401
Ptnml(0-2): 459, 19228, 48383, 19297, 457
https://tests.stockfishchess.org/tests/view/69d8d9263ca80bdf151d454a

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

No functional change
2026-04-19 07:21:27 +02:00
Maxim MasiutinandJoost VandeVondele 40ac93b8f8 Fix MultiArray::at(); use operator[] on hot paths
Fix MultiArray::at() which was marked noexcept despite delegating to
std::array::at() that throws on out-of-range. Per review feedback, at() now
keeps standard bounds-checking semantics (only noexcept removed), and
operator[] gains an assert for debug-mode safety.

All eight correction history lookups in search.cpp (correction_value and
update_correction_history) are switched from .at(us) to [us].

Passed STC:
https://tests.stockfishchess.org/tests/view/69de7a735c67bee7d241ff92
LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 77536 W: 20031 L: 19860 D: 37645
Ptnml(0-2): 221, 8411, 21338, 8572, 226

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

No functional change
2026-04-19 07:19:23 +02:00
FauziAkramandJoost VandeVondele cc4637b52b Remove Redundant Cast in MovePicker
closes https://github.com/official-stockfish/Stockfish/pull/6735

No functional change
2026-04-19 07:18:02 +02:00
FauziAkramandJoost VandeVondele 95f3680080 Replace constant LMR history divisor with depth-based array
Passed STC:
LLR: 2.97 (-2.94,2.94) <0.00,2.00>
Total: 677344 W: 175301 L: 174041 D: 328002
Ptnml(0-2): 2018, 79669, 174166, 80673, 2146
https://tests.stockfishchess.org/tests/view/69cfae021668971c9da23b80

Passed LTC:
LLR: 2.95 (-2.94,2.94) <0.50,2.50>
Total: 46470 W: 11988 L: 11651 D: 22831
Ptnml(0-2): 37, 4877, 13055, 5244, 22
https://tests.stockfishchess.org/tests/view/69dcd13c3ca80bdf151d4ab5

Passed VLTC (non-reg.):
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 58986 W: 15120 L: 14947 D: 28919
Ptnml(0-2): 7, 5835, 17636, 6008, 7
https://tests.stockfishchess.org/tests/view/69debc6c5c67bee7d241ffe9

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

Bench: 2723949
2026-04-19 07:15:43 +02:00
sscg13andJoost VandeVondele de7b0cd7a6 Update trace eval
Updates the information printed in the "eval" command. Removes piece value estimation, and adds both small and big net eval information.

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

No functional change
2026-04-19 07:10:20 +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
rn5f107s2andJoost VandeVondele b1fb50ae69 Simplify away the special case for en passant in the legality check
Since as of 94175524b1 the en passant square is
only set if there is a legal en passant capture, the special handling is
redundant

Passed Non-Regression STC:
https://tests.stockfishchess.org/tests/view/696ffb6512ee1f6231b96fe8
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 79072 W: 20380 L: 20210 D: 38482.

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

No functional change
2026-04-15 20:35:32 +02:00
DisservinandJoost VandeVondele 45711fceb4 Add PVMoves Struct
Use a dedicated struct for keeping track of the pv moves.

anematode pointed out that we can use the ValueList for this as well, left that open for a future patch.

Passed Non Regression
https://tests.stockfishchess.org/tests/view/69d399cfec2dc6794cf18376
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 267264 W: 68895 L: 68927 D: 129442
Ptnml(0-2): 790, 29238, 73566, 29290, 748

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

No functional change
2026-04-15 20:30:00 +02:00
87andJoost VandeVondele 4bdeb6352c Remove unnecessary use of _mm512_zextsi256_si512
[Some build environments](https://tests.stockfishchess.org/actions?max_count=400&sort=time&order=desc&action=failed_task&user=gaster319&text=executing) do not have this intrinsic.

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

No functional change.
2026-04-15 20:26:21 +02:00
FauziAkramandJoost VandeVondele 0694742a31 Remove redundant std::skipws from fresh string streams
In C++, all standard input streams (including std::istringstream) are initialized with the skipws format flag enabled by default. Because these stream objects are scoped locally and freshly constructed on each loop iteration, we are guaranteed that skipws is already active.

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

No functional change
2026-04-15 20:26:10 +02:00
J. OsterandJoost VandeVondele 5f3dcb92ee Simplify stalemate detection in qsearch.
Conditions for no pawn pushes, non-pawn material and last captured piece are already such restrictive that we don't need to artificially set checkers bitboard for legal move generation.
Also moving the check for available pawn pushes at first place, as it should already filter about 90% of cases.

Passed STC and LTC non-regression tests.
 LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 171232 W: 44202 L: 44131 D: 82899
Ptnml(0-2): 466, 18809, 47023, 18824, 494
https://tests.stockfishchess.org/tests/view/69d3623b61a12cebe17ededa

LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 55662 W: 14424 L: 14247 D: 26991
Ptnml(0-2): 38, 5479, 16609, 5678, 27
https://tests.stockfishchess.org/tests/view/69d64cada07a818b0a25f95e

And also neutral on 10k fixed games test with custom stalemate book.
 Elo: 0.24 ± 0.9 (95%) LOS: 69.9%
Total: 10000 W: 4681 L: 4674 D: 645
Ptnml(0-2): 0, 87, 4819, 94, 0
nElo: 1.81 ± 6.8 (95%) PairsRatio: 1.08
https://tests.stockfishchess.org/tests/view/69d7e4183ca80bdf151d43b8

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

Bench: 2984258
2026-04-15 20:15:36 +02:00
DubslowandJoost VandeVondele 3cce652564 Simplify relative_age and its constants
STC: https://tests.stockfishchess.org/tests/view/69cf29ed1668971c9da23a5a
LLR: 3.47 (-2.94,2.94) <-1.75,0.25>
Total: 193760 W: 50142 L: 50051 D: 93567
Ptnml(0-2): 534, 21375, 52980, 21448, 543

* Simplify retval and arithmetic semantics
* Remove mixing of int and uint8_t

I find this overall much easier to reason about

(Also rename a DEPTH constant per mstembera's suggestion https://github.com/official-stockfish/Stockfish/pull/5766#issuecomment-2586449296)

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

No functional change
2026-04-15 20:13:22 +02:00
DisservinandJoost VandeVondele 9bdf2f8d4c Update main network to nn-f68ec79f0fe3.nnue
Trained with the following yaml definition https://github.com/Disservin/nettest/blob/8da0a21503adb341bc89ca20b4e2f166c7c9720d/threats.yaml

and the following trainer change
https://github.com/official-stockfish/nnue-pytorch/commit/d87c248fbed584d08df59820ae0dd309e9b35c85

Initially I saw a lot of weird 0 scores in the binpack, since then @linrock has explained to me/us their meaning and mentioned that they are actually mostly skipped.. except a very small percentage, however it seems this change was still beneficial.

Passed STC:
https://tests.stockfishchess.org/tests/view/69db95f43ca80bdf151d4913
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 106272 W: 27916 L: 27489 D: 50867
Ptnml(0-2): 420, 12533, 26841, 12884, 458

Passed LTC:
https://tests.stockfishchess.org/tests/view/69ddd9003ca80bdf151d4c4d
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 29748 W: 7775 L: 7470 D: 14503
Ptnml(0-2): 24, 3136, 8247, 3445, 22

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

Bench: 3108996
2026-04-15 20:06:17 +02:00
mstemberaandJoost VandeVondele 7959885747 Interpolate highBestMoveEffort
STC: https://tests.stockfishchess.org/tests/view/69d586a64088e069540a22aa
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 63520 W: 16579 L: 16233 D: 30708
Ptnml(0-2): 138, 7179, 16825, 7435, 183

LTC: https://tests.stockfishchess.org/tests/view/69d6ddd79ffee997bab13a98
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 227100 W: 58279 L: 57591 D: 111230
Ptnml(0-2): 95, 23435, 65828, 24071, 121

Transition highBestMoveEffort smoothly instead of abruptly. May also be more amenable to future tuning.

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

Bench: 2923401
2026-04-15 20:03:49 +02:00
Ryan LefkowitzandJoost VandeVondele bb5f0100b0 fix syzygy crash on Apple Silicon by unrolling tbprobe adjustment loop
A bit tricky to identify, but in `apple-silicon` builds, specifying a value for
`SyzygyPath` could still lead to crashes at certain depths from a
SIGBUS/SIGSEGV.

This PR replaces the `std::count_if()` adjustment in `tbprobe.cpp`'s
`do_probe_table()` with an annotated handwritten loop, avoiding the clang/LTO
miscompilation behind the crash.

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

No functional change.
2026-04-15 19:05:14 +02:00
Shawn XuandJoost VandeVondele b63bd7b78e Fix assert
the assert checks for `bestThreadDecisive && newThreadDecisive`. However `newThreadDecisive` is not guaranteed at this point, leading to assertion failures. This PR rearranges the conditions to ensure correctness.

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

No functional change
2026-04-15 19:01:06 +02:00
Linmiao XuandDisservin bb4eb04a50 Don't store stand pat return value in TT
Passed non-regression STC:
https://tests.stockfishchess.org/tests/view/69d2d3de61a12cebe17ede38
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 68384 W: 17646 L: 17459 D: 33279
Ptnml(0-2): 200, 8058, 17496, 8231, 207

Passed non-regression LTC:
https://tests.stockfishchess.org/tests/view/69d4293433584dad27b3c8cb
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 37290 W: 9582 L: 9380 D: 18328
Ptnml(0-2): 18, 3915, 10579, 4113, 20

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

Bench: 2923401
2026-04-09 21:56:05 +02:00
Robert Nurnberg @ elitebookandDisservin 9db77822bd Simplify best thread selection
For some time now we can trust the threads' exact win/loss scores. This
allows for some simplification in the best thread selection code.

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

No functional change
2026-04-09 21:56:05 +02:00
FauziAkramandDisservin 5ae13d2bd4 Remove Redundant Branchless Execution
Passed STC non-reg:
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 102272 W: 26553 L: 26411 D: 49308
Ptnml(0-2): 269, 11212, 28036, 11346, 273
https://tests.stockfishchess.org/tests/view/69d0f1c5e2b443cb2670b710

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

No functional change
2026-04-09 21:56:05 +02:00
Robert Nurnberg @ elitebookandDisservin d3a4587fe8 Simplify uci pv output logic
The uci pv suppression and PV roll-back logic in master is a bit
convoluted, which makes it hard to reason about the code. In fact,
subtle bugs that led to wrong mated-in scores in game play or a mismatch
between bestmove and first PV move were only recently fixed. Moreover,
in master the uci pv output through `pv()` is called in four different
places.

This PR proposes to simplify this logic. In this patch, the PV is sent
to the GUI from within `iterative_deepening()` only (a) for fail
highs/lows or (b) when an iteration for a root move is completed. All
other PV outputs are now handled by `start_searching()`, just before the
bestmove extraction. This easily ensures that bestmove (and ponder move)
will always be in sync with the final PV output.

The only noticeable change to master is for multi-threaded searches that
do not involve `limits.depth`. Here master would show both the PV from
the aborted search in main thread, as well as the new PV from the
selected best thread. This patch would only show the latter.

While at it, we also remove the requirement to finish at least a depth 1
search and simplify the logic around stalemates/checkmates at root and
in particular avoid any PVs that start with `Move::none()`.

Passed STC non-reg:
LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 72416 W: 18784 L: 18609 D: 35023
Ptnml(0-2): 200, 7762, 20127, 7901, 218
https://tests.stockfishchess.org/tests/view/69d3ef0c33584dad27b3c85a

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

No functional change
2026-04-09 21:56:05 +02:00
Carlos EsparzaandDisservin df01cb7ed3 Avoid branching before ValueList::push_back
Instead of checking whether a threat index is valid and then writing to
a vector if it isn't, we can instead always write to the buffer of the
vector, and only increase the size of the vector if the index is valid.

This saves some branch mispredictions.

passed STC:
https://tests.stockfishchess.org/tests/view/69ceb1689f7a7e3fdfc9a44b
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 205760 W: 53109 L: 52561 D: 100090
Ptnml(0-2): 603, 22552, 56076, 22992, 657

local speedtest shows
```
Result of 100 runs (cycles)
===========================
base (...ockfish.orig) =     296886  +/- 1645
test (...kfish.df0822) =     298862  +/- 1662
speedup %              =      +0.67  +/- 0.19
                         [95% CI; t-statistic]

p(speedup > 0)   =  1.0000
p(speedup > .5%) =  0.9562

CPU: 16 x Intel(R) Core(TM) Ultra 9 185H
Hyperthreading: on
```

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

No functional change
2026-04-09 21:56:05 +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
FauziAkramandDisservin ef27b4db7b Using the already existing pawn_single_push_bb
Using the already existing pawn_single_push_bb helper which encapsulates
the exact same logic.

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

No functional change
2026-04-09 21:53:08 +02:00
Niklas FiekasandDisservin 20b61d2fd4 Fix shell escaping in misc.o rule
After 415f2ef1. Now works again with CXX paths like `A:\path\to\g++`
under MSYS2. The cache files are no longer read in the rule itself and
only used as markers for change detection.

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

No functional change
2026-04-09 21:53:08 +02:00
Linmiao XuandDisservin a42d328f21 Fix compilation errors on macOS
```
clang++: error: unknown argument: '-fno-ipa-cp-clone'
clang++: error: unknown argument: '-fno-ipa-cp-clone'
make[1]: *** [bitboard.o] Error 1
```

The flag is unsupported by Clang, which pretends to be GCC on macOS, so
only passing -fno-ipa-cp-clone to real GCC fixes macOS builds.

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

No functional change
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
mstemberaandDisservin 969542e4f0 Simplify HalfKAv2_hm::write_indices()
https://tests.stockfishchess.org/tests/view/69bb1fafd7d60419badf31a3
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 116544 W: 30024 L: 29895 D: 56625
Ptnml(0-2): 317, 12875, 31729, 13064, 287

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

No functional change
2026-04-09 21:53:01 +02:00
FauziAkramandDisservin 82908e0fd6 Simplify mtg in time management
Passed Stc:
LLR: 3.05 (-2.94,2.94) <-1.75,0.25>
Total: 289088 W: 74727 L: 74773 D: 139588
Ptnml(0-2): 903, 30974, 80841, 30918, 908
https://tests.stockfishchess.org/tests/view/699d9093eaae015cd278eda3

Passed Ltc:
LLR: 3.02 (-2.94,2.94) <-1.75,0.25>
Total: 144438 W: 36859 L: 36766 D: 70813
Ptnml(0-2): 62, 13391, 45235, 13454, 77
https://tests.stockfishchess.org/tests/view/699f02913ece4c464328a264

Passed Sudden death:
LLR: 2.99 (-2.94,2.94) <-1.75,0.25>
Total: 53406 W: 13960 L: 13753 D: 25693
Ptnml(0-2): 265, 5848, 14253, 6089, 248
https://tests.stockfishchess.org/tests/view/69a47548a70d5f3736be6482

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

No functional change
2026-04-09 21:48:51 +02:00
FauziAkramandDisservin 19dec05602 Update a few outdated wrong comments
closes https://github.com/official-stockfish/Stockfish/pull/6525

No functional change
2026-04-09 21:48:40 +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
Linmiao XuandDisservin 8a1b0f8b04 Reorder NNUE accumulator evals
Makes eval calls more cache-friendly on a hot path.

Hints of a speedup found locally:
```
Result of  30 runs
==================
base (...ockfish-base) =    1754124  +/- 2887
test (...h-eval-order) =    1757848  +/- 2412
diff                   =      +3724  +/- 1368

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

CPU: 16 x arm
Hyperthreading: off
```

Passed STC:
https://tests.stockfishchess.org/tests/view/69c84f3cf40d95b975597c21
LLR: 3.36 (-2.94,2.94) <0.00,2.00>
Total: 335840 W: 87022 L: 86257 D: 162561
Ptnml(0-2): 932, 36760, 91816, 37435, 977

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

No functional change
2026-04-02 20:32:43 +02:00
Linmiao XuandDisservin 171afd2b4d NEON: simplify updates in NNUE accumulator
Reduce # instructions using widening add/sub calls on AArch64.
Add shims for 32-bit ARM.

Passed non-regression STC:
https://tests.stockfishchess.org/tests/view/69c093d3f690a4b7f5fb0d6e
LLR: 5.15 (-2.94,2.94) <-1.75,0.25>
Total: 338624 W: 86931 L: 86853 D: 164840
Ptnml(0-2): 667, 35888, 96079, 36056, 622

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

No functional change
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