Commit Graph
16 Commits
Author SHA1 Message Date
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
cf559b2c17 speed up update_piece_threats after SFNNv12
with the removal of all king-related threats in SFNNv12 we can avoid some work in update_piece_threats

STC for anematode's swan:
https://tests.stockfishchess.org/tests/view/6986b920b0f3ca5200aaf80a
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 262880 W: 68379 L: 67747 D: 126754
Ptnml(0-2): 808, 29001, 71223, 29567, 841

STC of further speedups on top of swan:
https://tests.stockfishchess.org/tests/view/698d7f8362a8f472da3a8a35
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 65920 W: 17126 L: 16781 D: 32013
Ptnml(0-2): 186, 7084, 18105, 7369, 216

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

No functional change

Co-Authored-By: Timothy Herchen <timothy.herchen@gmail.com>
2026-02-18 05:58:44 +01:00
Carlos EsparzaandDisservin f4244e13e4 Some more work on FullThreats::make_index
[Passed STC](https://tests.stockfishchess.org/tests/live_elo/691fc321acb6dbdf23d07e4b):

```
LLR: 2.95 (-2.94,2.94) <0.00,2.00>
Total: 215360 W: 55651 L: 55108 D: 104601
Ptnml(0-2): 520, 22399, 61290, 22960, 511
```

This PR is on top of ces42's work so I'll rebase if that PR changes.
Essentially, it comprises my adjustments to `make_index` that remained
unmerged before threat inputs was finalized.

The unsigned intermediate variables let us skip a bunch of useless sign
extensions (because Square and Piece inherit from `int8_t`, and C/C++
semantics require narrow integers to be promoted to `int` before doing
arithmetic on them). Additionally, by removing the special usage of
`offsets[][64]` and `[65]` the indexing becomes more efficient. (This
usage was a temporary hack from sscg anyway, so I think he'll like that
it's gone.) Finally, the `sf_assume` condition was fixed so that it
actually makes a difference to the compiler.

The speedup is fairly nice locally (combining both ces42's and these changes):

```
Result of 100 runs
==================
base (...kfish.master) =    1691982  +/- 1907
test (./stockfish    ) =    1714349  +/- 1789
diff                   =     +22367  +/- 2465

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

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

No functional change
2025-11-30 21:45:14 +01:00
Carlos EsparzaandJoost VandeVondele 2084d94266 inline make_index() and avoid templating perspective
combination of two patches.

pass perspective as argument
passed STC:
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 52832 W: 13725 L: 13528 D: 25579
Ptnml(0-2): 154, 5756, 14412, 5927, 167
https://tests.stockfishchess.org/tests/view/69162e307ca8781852331c6a

inline make_index
passed STC:
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 68768 W: 17786 L: 17607 D: 33375
Ptnml(0-2): 187, 7591, 18694, 7680, 232
https://tests.stockfishchess.org/tests/view/6916859e7ca8781852331d36

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

No functional change
2025-11-17 13:34:45 +01:00
Carlos EsparzaandJoost VandeVondele e9674a7888 simplify make_index()
passed non-regression STC: https://tests.stockfishchess.org/tests/view/68fdb409637acd2a11e72f11
LLR: 3.08 (-2.94,2.94) <-1.75,0.25>
Total: 95008 W: 24837 L: 24677 D: 45494
Ptnml(0-2): 268, 10024, 26775, 10154, 283

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

no functional change
2025-11-01 11:34:54 +01:00
Carlos EsparzaandJoost VandeVondele 11ab4cde07 Avoid unnecessary allocations in AccumulatorStack
replacing the vector with an array resulted in a .45+-.10 % speedup.

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

no functional change
2025-11-01 11:12:03 +01:00
Carlos EsparzaandJoost VandeVondele 5695486db9 Fix outdated comment
closes https://github.com/official-stockfish/Stockfish/pull/6108

No functional change
2025-06-02 21:40:13 +02:00
Carlos EsparzaandDisservin 63c6f22627 Simplify DirtyPiece
Simplifies the DirtyPiece struct.

passed STC: https://tests.stockfishchess.org/tests/view/68054c9798cd372e3aea05d7
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 36608 W: 9641 L: 9437 D: 17530
Ptnml(0-2): 89, 3630, 10668, 3822, 95

passed LTC: https://tests.stockfishchess.org/tests/view/6805514598cd372e3aea0783
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 127620 W: 31993 L: 31894 D: 63733
Ptnml(0-2): 42, 10983, 41665, 11074, 46

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

No functional change
2025-05-13 20:30:22 +02:00
Carlos EsparzaandDisservin f0de8dc034 Simplify move ordering bonuses for putting piece en prise and escaping capture
Now there is also a penalty for exposing knights and bishops to capture by a pawn.

Passed STC:
https://tests.stockfishchess.org/tests/view/68074379878abf56f9a0d5b1
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 96512 W: 24841 L: 24687 D: 46984
Ptnml(0-2): 294, 11336, 24835, 11504, 287

Passed LTC:
https://tests.stockfishchess.org/tests/view/6808954a878abf56f9a0d76d
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 221328 W: 56271 L: 56255 D: 108802
Ptnml(0-2): 131, 24149, 62071, 24199, 114

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

Bench: 1778227
2025-04-27 19:42:06 +02:00
Carlos EsparzaandDisservin fda269a299 Introduce double incremental accumulator updates
when we need to update an accumulator by two moves and the second move
captures the piece moved in the first move, we can skip computing the
middle accumulator and cancel a feature add with a feature remove to
save work.

Passed STC
https://tests.stockfishchess.org/tests/view/67f70b1c31d7cf8afdc45f51
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 72800 W: 18878 L: 18529 D: 35393
Ptnml(0-2): 160, 7711, 20374, 7930, 225

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

No functional change
2025-04-27 19:27:18 +02:00
Carlos EsparzaandDisservin e407a4f269 Simplify risk_tolerance + avoid overflow
passed simplification STC:
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 73984 W: 19058 L: 18879 D: 36047
Ptnml(0-2): 232, 8735, 18866, 8940, 219
https://tests.stockfishchess.org/tests/view/67c269a38200cf1034c9baf9

passed simplification LTC:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 39288 W: 10033 L: 9833 D: 19422
Ptnml(0-2): 14, 4168, 11086, 4356, 20
https://tests.stockfishchess.org/tests/view/67c34f8c8200cf1034c9bda1

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

Bench: 2050046
2025-03-21 11:09:27 +01:00
Carlos EsparzaandDisservin e9997afb1c Replace hint_common_parent_position() by backwards accumulator updates
Only calls to `evaluate()` now trigger NNUE accumulator updates. To make
sure that we are likely to find parent positions from which to update
the accumulators we perform a backwards NNUE update whenever we compute
the accumulator from scratch for some position.

passed STC
LLR: 2.93 (-2.94,2.94) <0.00,2.00>
Total: 39680 W: 10474 L: 10164 D: 19042
Ptnml(0-2): 171, 4068, 11042, 4398, 161
https://tests.stockfishchess.org/tests/view/67a27f26eb183d11c65945be

passed LTC
LLR: 2.94 (-2.94,2.94) <0.50,2.50>
Total: 337308 W: 86408 L: 85550 D: 165350
Ptnml(0-2): 276, 30551, 106126, 31441, 260
https://tests.stockfishchess.org/tests/view/67a287efeb183d11c65945ee

then simplified:
STC
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 28608 W: 7641 L: 7413 D: 13554
Ptnml(0-2): 132, 3036, 7744, 3256, 136
https://tests.stockfishchess.org/tests/view/67a4703719f522d3866d3345

LTC
LLR: 2.96 (-2.94,2.94) <-1.75,0.25>
Total: 200226 W: 51026 L: 50990 D: 98210
Ptnml(0-2): 170, 18468, 62799, 18508, 168
https://tests.stockfishchess.org/tests/view/67a4f255229c1a170cc08964

The version in this PR is a bit different from the simplified version,
but it's compile-time changes only.

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

No functional change
2025-02-24 19:01:23 +01:00
Carlos EsparzaandDisservin e089f723d8 Remove two xors by setting the hash keys for unreachable squares to zero
performance before:
3.6714 +- 0.20%  Gcycles
3.6620 +- 0.12%  Gcycles
3.6704 +- 0.26%  Gcycles
3.6602 +- 0.27%  Gcycles
3.6799 +- 0.37%  Gcycles

after:
3.6540 +- 0.30%  Gcycles
3.6388 +- 0.25%  Gcycles
3.6557 +- 0.17%  Gcycles
3.6449 +- 0.15%  Gcycles
3.6460 +- 0.26%  Gcycles

(every line is a different `profile-build` and shows the number of
cycles needed for `./stockfish bench`, measured with `perf stat -r 10`)

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

No functional change
2025-02-13 19:44:53 +01:00
Carlos EsparzaandDisservin 7684b6e4d8 Don't increase rule50 when doing null moves
also prefetch a bit earlier while we're at it

passed STC: https://tests.stockfishchess.org/tests/view/678c0860f4dc0a8b4ae8cf58
LLR: 2.95 (-2.94,2.94) <-1.75,0.25>
Total: 67328 W: 17608 L: 17418 D: 32302
Ptnml(0-2): 256, 7905, 17156, 8087, 260

passed LTC: https://tests.stockfishchess.org/tests/view/678c1a56f4dc0a8b4ae8cfb1
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 340896 W: 86577 L: 86685 D: 167634
Ptnml(0-2): 291, 38325, 93332, 38201, 299

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

Bench: 1910281
2025-02-02 13:35:48 +01:00
Carlos EsparzaandJoost VandeVondele aaafaaecf2 prefetch in do_move()
this allows removing Position::key_after()

STC
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 24960 W: 6556 L: 6336 D: 12068
Ptnml(0-2): 59, 2554, 7056, 2730, 81

LTC
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 115080 W: 29319 L: 29204 D: 56557
Ptnml(0-2): 51, 10736, 35864, 10825, 64

STC with 2MB hash
LLR: 3.04 (-2.94,2.94) <-1.75,0.25>
Total: 182176 W: 46998 L: 46932 D: 88246
Ptnml(0-2): 526, 19711, 50544, 19785, 522

LTC with 8MB hash
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 441180 W: 111557 L: 111746 D: 217877
Ptnml(0-2): 229, 39698, 140929, 39501, 233

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

bench: 1379150
2025-01-18 20:19:53 +01:00
Carlos EsparzaandDisservin 1f9404434d Simplify picking of evasion moves
Sort evasions before we start returning them in next_move() (just like
every other kind of move) instead of looking for the biggest element on
every call to next_move(). The bench number changes because the old
method is not equivalent to a stable sort.

Passed STC:
LLR: 2.93 (-2.94,2.94) <-1.75,0.25>
Total: 132064 W: 34318 L: 34204 D: 63542
Ptnml(0-2): 392, 15522, 34106, 15604, 408
https://tests.stockfishchess.org/tests/view/6743fee086d5ee47d953f9ca

Passed LTC:
LLR: 2.94 (-2.94,2.94) <-1.75,0.25>
Total: 97542 W: 24899 L: 24757 D: 47886
Ptnml(0-2): 63, 10646, 27193, 10824, 45
https://tests.stockfishchess.org/tests/view/674509cd86d5ee47d953fb96

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

Bench: 1094825
2024-12-08 19:54:18 +01:00