perf(builder): a float operation with a NaN lane and no subnormal lane is answered inline by default (LONGSHOT_FP_NAN_MID=0 turns it off) #2684

Merged
HumanBean merged 23 commits from klimovich008/Longshot:perf/fp-nan-mid into main 2026-11-28 03:59:55 +00:00
Member

Summary

Why: where the game's float vectors carry a NaN in one lane (the cloth keeps one in its vectors' fourth lane: Lost Woods first), every add, multiply or subtract on them leaves the fast path for the exact helper, a noinline cold call. In Lost Woods child that helper was 6 % of the process's CPU samples. This answers most of those operations inline, on by default; LONGSHOT_FP_NAN_MID=0 at build time turns it off.

What changed: by default (LONGSHOT_FP_NAN_MID unset, or 1), the slow path of a float add, subtract, multiply, divide, FMULX or fused multiply-add in a hot unit (lifted_hot_*) gets a middle path. When a lane is a NaN and no operand lane and no lane of the fast value is subnormal, every flush in the exact semantics is the identity, so the exact result is the host's operation with Arm's NaN choice applied. That is computed inline. A subnormal lane still takes the full helper, as today. With LONGSHOT_FP_NAN_MID=0, the emitted IR and the lift keys are byte-identical to main's.

Files, in reading order:

  • builder/crates/sem/src/fpfast.rs: nan_mid (and the hidden nan_mid_broken for the negative control). The test classifies each f32/f64 operand lane and each lane of the fast value as subnormal or not. The value is the helper's own Sem::exact (farith/fmulx/fmuladd with the same nan_fix) with FZ held clear and DN read from FPCR, so the NaN choice (a signalling operand first, in operand order, quieted; the addend first for fused; the default NaN for an invalid operation or under DN) matches the helper by construction.
  • builder/crates/mir/src/lib.rs, mir/src/verify.rs: Helper.mid: Option<Box<Mid>> (the middle path belongs to the helper, so no Op::Checked pattern changes); the verifier checks its signatures, names, pure bodies, and refuses a table lookup inside one, a test and value with the same name, or two same-named helpers with different bodies.
  • builder/crates/llvm/src/lib.rs: the slow path calls the test and branches (the full helper weighted unlikely) to the inline value or the helper; a three-input phi joins them. The test reads its values through an empty asm "", "=x,0" so LLVM keeps the cold test's classifications apart from the fast path's merged check. A third counter, lifter_mid_checks, beside LONGSHOT_COUNT_CHECKS's two. Off, nothing new is written.
  • builder/crates/lift/src/whole/mod.rs: LiftOptions::fp_nan_mid, applied to hot units only, minus the skip list; in each hot unit's key (the switch and the skip entries among that unit's own functions) and in the whole lift's key, never in the other units' keys, so turning it on or off moves only the hot units' keys (BeanBot L1; 122 of 386 in the whole game); the log line counts the fast paths given a middle path.
  • builder/crates/build-driver/src/stages.rs, build.rs: the switches, read by value (build_core::switch: unset or any value but an off word is on); a malformed skip list stops the lift and a compile alone the same way.
  • builder/crates/longshot-builder/src/dev/{words,lift_cmd}.rs: dev words --fp-nan-mid / --fp-nan-mid-broken, dev lift with the middle path by default, as a build; --no-fp-nan-mid lifts without it, --fp-nan-mid-skip leaves functions out (--fp-nan-mid is kept and is the default).
  • tests/test_lifter_semantics.py, tests/lifter_semantics_rt.c: fixed NaN cases (always, CI included), --fp-nan-mid, --march.
  • Unit tests in sem/src/tests.rs, llvm/src/tests.rs, lift/src/whole/tests.rs; docs in docs/dev/reference/builder.md and build.md.

Flags and settings:

  • LONGSHOT_FP_NAN_MID: build time, on by default, read by value as the builder's other switches (build_core::switch): 0, off, no, false or empty turn it off (the kill switch: the IR and keys are main's); unset, 1 or any other value is on. On, it is in each hot unit's key and the whole lift's key, not in the other units' keys.
  • LONGSHOT_FP_NAN_MID_SKIP=f_<hex>,...: a developer's list of functions left out of it (hex, f_ or 0x prefixes). A malformed or non-Unicode list with the switch on (the default) stops the build; with it off, the list is not read. A change to the list moves only the keys of the hot units whose functions it adds or removes.
  • Both are builder switches, documented under build switches, so not in switches.def. The launcher sets neither.
  • On by default, since the builder's owner (HumanBean, #2286) asked on this PR whether to enable it by default and the maintainers chose to. Its costs are below. Every player's hot units lift and compile once again on the update that ships it (their keys move; every other unit keeps its key and its object).

Vectors only, an offer: of the 66,397 middle paths in the hot units, 36.8 % are on vectors and 63.2 % on scalars. The cloth's NaN lane is a vector lane. A vectors-only variant would drop about 60 % of the added code and most of the extra compile CPU, probably at little cost to the gain. Not measured: the counters don't split scalars from vectors. I can add it if the builder's owner prefers that shape.

Testing

The default flip itself was not retested. Every measurement and game run below is of a build with LONGSHOT_FP_NAN_MID=1, which the default now gives (the unit tests below check that unset reads as 1 does, and 0 as off). No whole-game lift, game run or second-opinion review was done on the flip.

Tested: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2. The game runs used a build from this branch's first round (a03c59a6e) on main 09dea503. The head's emitted IR is byte-identical to that commit's in every mode, so those runs stand for the head (see "Exactness" below).

  • In the game with the switch on: Lost Woods child, Market child, Kokiri Forest (Link's cap and tunic hang as on main), Fire Temple. Pictures normal. Across 8 runs a side, no error line appeared only with the switch on.
  • A diagnostic build with the counters, Lost Woods child: 13.8 % of fast-path runs took the slow path, and 94.5 % of those took the middle path.
  • A sampled Lost Woods run per arm: the exact helpers went from 6.00 % to 0.61 % of samples; the middle path's own code is about 1.6 %.

Exactness:

  • tests/test_lifter_semantics.py against Unicorn (Windows port of the test, default sizes): passes off and on, --march x86-64-v2 and v3, at -O1, and on at -O2 with -ffp-contract=off as hot units ship. Each run: 126,846 single-word runs, 2,988 edge states, 11,066 sequence runs, and 1,408 fixed NaN-case runs (352 cases under all four FZ/DN settings; 952 slow, 724 middle path). The NaN cases cover each kind in each shape (vector .4s/.2s/.2d, by-element, scalar s/d/h): one quiet NaN lane beside finite ones, NaNs in both operands (payload order, the addend first), a signalling NaN behind a quiet one, a NaN in the second lane alone of either operand, invalid operations with no NaN operand (inf×0, inf−inf, inf/inf, 0/0, FMULX's ±2, a quiet-NaN addend with inf×0), signed zeros, subnormals beside a NaN lane (operand and result). The test fails unless the fast, middle and full paths all ran.
  • Negative controls: the broken variant (operand lanes untested) differs in 56 runs, all under FZ, and the test requires that. Mutants that each fail: operands swapped in the middle value (108 cases), DN not read (304), the fast value not tested (20). Each fix from review, put back one at a time, makes its named unit test fail.
  • LONGSHOT_FP_NAN_MID=0 is byte-identical to main (measured with the switch off on the earlier head, when off was the default): dev words over 118,829 words, 4,000 sequences and the 32 NaN-case words gives the same 73,557,937 bytes plain and 74,390,314 with --count-checks as main's builder. A whole-game lift with the switch off: 386 of 386 units with the same content as main's. On: 114 of 122 hot units change, no other unit.
  • Rust, on the default flip (head 0b01c7a9d, merged with main 20bedc6da; Windows, Rust 1.99.1), the tests it edits or adds only: cargo test -p lift 48 passed; build-driver's stages:: tests 3 passed (new: the_float_middle_path_is_on_when_its_switch_is_unset_and_off_when_it_is_0); longshot-builder's dev lift test 1 passed (new). Each fails when the default is put back to off, four ways (the switch's rule, the skip list's Unicode check, LiftOptions::new, dev lift's start). cargo clippy --locked -p build-driver -p lift -p longshot-builder -p sem --all-targets -- -D warnings clean (the crates the flip touches; workspace clippy not run); cargo fmt --all --check clean; mise run lint passes every hook. The crates' full suites were not run again.
  • On the head before the flip (the merge with main 699405ecb): cargo test --locked --no-fail-fast -p mir -p sem -p llvm -p lift: 81 passed, 0 failed, all middle-path tests among them.
  • tests/run_all.py --jobs 4 (Windows, llvm-mingw 20261104) on the merge with main 2e02c0d66 and on that main (before #2680 landed, which changes the builder's progress reports only): 719 passed, 14 failed, 128 skipped on both. The same 14 files fail on both (Windows-environment tests: test_longshot_ctl, test_job_queue, test_dev_ab, test_parity_gates, test_run_all_mingw and others; none touches the builder's lifter). One extra sub-check in test_parity_gates failed on the merge only, "path is on mount 'E:', start on mount 'C:'": the merge's checkout was on another drive than the temp folder, main's was not. test_lifter_semantics.py is skipped on Windows by design; the matrix above ran through a Windows port of it.
  • A second-opinion review (gpt-6.2-sol) through eleven rounds; the last found no regression in the renderer-only, dry-run or third-party compiles and no lifter output that trips the new verifier checks.

Still to test:

  • Linux: tests/test_lifter_semantics.py with and without --fp-nan-mid, expecting a pass as on Windows (CI's Linux job runs the default mode; --fp-nan-mid by hand).
  • A CPU with AVX-512 (the game builds at -march=native): build with LONGSHOT_FP_NAN_MID=1 and play Lost Woods child, expecting the cloth as on main and no new error line (by hand; here the asm was only compiled for x86-64-v4, not run).
  • x86-64-v2 in the game: a build with LONGSHOT_FP_NAN_MID=1 RX_MARCH=x86-64-v2 in Lost Woods child and Market child, expecting the cloth as on main and Market not slower (by hand; the semantics test passes at v2).
  • The Kokiri children's cloth with the switch on, expecting it to move as on main (by hand; no Kokiri child came into view in the runs above).

Measurements

Verdict: with the switch on, Lost Woods child: CPU per frame −3.2 % and fps +4.5 % (best estimate about −3 % CPU over both sessions); Market child: not worse. All "diagnostic" (under 5 % with 3 pairs).

Setup: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2; claude-perf/std_test.py, uncapped (HOS_FPS_MAX=240), 16:9, render thread on, 3 alternating pairs, the median; game clock 0.993–1.011 on every reading. Before: main 09dea503 built as a player's build. After: the same with this branch (a03c59a6e, whose IR the head reproduces byte for byte) built with LONGSHOT_FP_NAN_MID=1. Switch off, the build is main's.

Lost Woods child, session 2 Before: main @ 09dea503 After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e
CPU ms (median) 42.153 40.808 (−3.2 %; per pair −3.3 / −2.2 / −5.3 %)
fps (median) 116.29 121.54 (+4.5 %; higher in every pair)
p99 frame ms 11.45 11.03
frames over 50 / 100 / 250 ms 0 / 0 / 0 0 / 0 / 0
Other sessions Before: main @ 09dea503 After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e
Lost Woods child, session 1 (the PC ran about 20 % slow, cause not found), CPU ms 49.894 49.162 (−1.5 %)
Lost Woods child, session 1, fps 98.84 100.19 (+1.4 %)
Market child (PC partly slow), CPU ms 50.394 48.688 (inside the noise)
Market child, fps 91.69 93.09 (inside the noise)

Fps was higher with the switch in all 6 Lost Woods pairs over both sessions. An earlier run by the implementer gave −5.6 % CPU; the checker did not reproduce it.

Why these numbers still hold on current main: they were taken on main 09dea503. Since then main has not changed the lifter (builder/crates/{sem,mir,llvm,lift,passes}, third_party/a64-kit), and this head's builder emits byte-identical IR to the measured commit's, off and on. Main's other changes since (the mutex lookups of #2665, a renderer fix for GCN, startup reporting, a game fix in game/) apply to both arms alike. Not measured again on current main.

No Test Farm run. With the default on, a farm comparison of this PR against main would measure the LONGSHOT_FP_NAN_MID=1 build above; none was run.

Costs, with the switch on (now the default; stated plainly):

Before: main @ 09dea503 After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e
hot units' compile, CPU-s (8 jobs, native -O2, ABBA) 492 669 (+36 %; wall at 8 jobs 65 → 85 s)
hot units' objects, .text bytes 42,098,404 58,976,135 (+40 %)
whole exe, .text bytes 753,248,822 770,126,390 (+2.24 %)
callee-saved XMM saves in the 1,470 hot functions (native, Zen 3) 7,418 7,445 (14 functions save more, 1 fewer)

Non-hot units are byte-identical either way. The extra register saves are on the fast path's prologue; Market showed no slowdown from them on this CPU, and v2 was not measured in the game. A full cold build was not timed.

Risks

  • On by default: every player's hot units lift and compile once again on the update that ships it (122 of 386 units in the whole game here; their compile about a third longer, as measured above, and on every later compile of them). Every other unit keeps its key and its object. With LONGSHOT_FP_NAN_MID=0 the IR and keys are main's.
  • On: a wrong middle path would give a wrong float result where a NaN lane meets no subnormal lane. The semantics test checks it against Unicorn state for state under every FZ/DN setting; LONGSHOT_FP_NAN_MID=0 turns it off for a build, the skip list for single functions. Linux, AVX-512 and x86-64-v2 in the game are still untested (Still to test). The inline asm is x86-64 ("=x,0"); the builder has no other host target.
  • Cost when on: compile time, code size and a few extra register saves, as measured above.
  • Rollback: LONGSHOT_FP_NAN_MID=0 for a build; or revert (no data or format depends on it).

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary **Why:** where the game's float vectors carry a NaN in one lane (the cloth keeps one in its vectors' fourth lane: Lost Woods first), every add, multiply or subtract on them leaves the fast path for the exact helper, a `noinline cold` call. In Lost Woods child that helper was 6 % of the process's CPU samples. This answers most of those operations inline, **on by default**; `LONGSHOT_FP_NAN_MID=0` at build time turns it off. **What changed:** by default (`LONGSHOT_FP_NAN_MID` unset, or `1`), the slow path of a float add, subtract, multiply, divide, FMULX or fused multiply-add in a hot unit (`lifted_hot_*`) gets a middle path. When a lane is a NaN and no operand lane and no lane of the fast value is subnormal, every flush in the exact semantics is the identity, so the exact result is the host's operation with Arm's NaN choice applied. That is computed inline. A subnormal lane still takes the full helper, as today. With `LONGSHOT_FP_NAN_MID=0`, the emitted IR and the lift keys are byte-identical to main's. Files, in reading order: - `builder/crates/sem/src/fpfast.rs`: `nan_mid` (and the hidden `nan_mid_broken` for the negative control). The **test** classifies each f32/f64 operand lane and each lane of the fast value as subnormal or not. The **value** is the helper's own `Sem::exact` (`farith`/`fmulx`/`fmuladd` with the same `nan_fix`) with FZ held clear and DN read from FPCR, so the NaN choice (a signalling operand first, in operand order, quieted; the addend first for fused; the default NaN for an invalid operation or under DN) matches the helper by construction. - `builder/crates/mir/src/lib.rs`, `mir/src/verify.rs`: `Helper.mid: Option<Box<Mid>>` (the middle path belongs to the helper, so no `Op::Checked` pattern changes); the verifier checks its signatures, names, pure bodies, and refuses a table lookup inside one, a test and value with the same name, or two same-named helpers with different bodies. - `builder/crates/llvm/src/lib.rs`: the slow path calls the test and branches (the full helper weighted unlikely) to the inline value or the helper; a three-input phi joins them. The test reads its values through an empty `asm "", "=x,0"` so LLVM keeps the cold test's classifications apart from the fast path's merged check. A third counter, `lifter_mid_checks`, beside `LONGSHOT_COUNT_CHECKS`'s two. Off, nothing new is written. - `builder/crates/lift/src/whole/mod.rs`: `LiftOptions::fp_nan_mid`, applied to hot units only, minus the skip list; in each hot unit's key (the switch and the skip entries among that unit's own functions) and in the whole lift's key, never in the other units' keys, so turning it on or off moves only the hot units' keys (BeanBot L1; 122 of 386 in the whole game); the log line counts the fast paths given a middle path. - `builder/crates/build-driver/src/stages.rs`, `build.rs`: the switches, read by value (`build_core::switch`: unset or any value but an off word is on); a malformed skip list stops the lift and a compile alone the same way. - `builder/crates/longshot-builder/src/dev/{words,lift_cmd}.rs`: `dev words --fp-nan-mid` / `--fp-nan-mid-broken`, `dev lift` with the middle path by default, as a build; `--no-fp-nan-mid` lifts without it, `--fp-nan-mid-skip` leaves functions out (`--fp-nan-mid` is kept and is the default). - `tests/test_lifter_semantics.py`, `tests/lifter_semantics_rt.c`: fixed NaN cases (always, CI included), `--fp-nan-mid`, `--march`. - Unit tests in `sem/src/tests.rs`, `llvm/src/tests.rs`, `lift/src/whole/tests.rs`; docs in `docs/dev/reference/builder.md` and `build.md`. **Flags and settings:** - `LONGSHOT_FP_NAN_MID`: build time, **on by default**, read by value as the builder's other switches (`build_core::switch`): `0`, `off`, `no`, `false` or empty turn it off (the kill switch: the IR and keys are main's); unset, `1` or any other value is on. On, it is in each hot unit's key and the whole lift's key, not in the other units' keys. - `LONGSHOT_FP_NAN_MID_SKIP=f_<hex>,...`: a developer's list of functions left out of it (hex, `f_` or `0x` prefixes). A malformed or non-Unicode list with the switch on (the default) stops the build; with it off, the list is not read. A change to the list moves only the keys of the hot units whose functions it adds or removes. - Both are builder switches, documented under [build switches](docs/dev/reference/build.md#build-switches), so not in `switches.def`. The launcher sets neither. - **On by default**, since the builder's owner (HumanBean, #2286) asked on this PR whether to enable it by default and the maintainers chose to. Its costs are below. **Every player's hot units lift and compile once again** on the update that ships it (their keys move; every other unit keeps its key and its object). **Vectors only, an offer:** of the 66,397 middle paths in the hot units, 36.8 % are on vectors and 63.2 % on scalars. The cloth's NaN lane is a vector lane. A vectors-only variant would drop about 60 % of the added code and most of the extra compile CPU, probably at little cost to the gain. Not measured: the counters don't split scalars from vectors. I can add it if the builder's owner prefers that shape. ## Testing **The default flip itself was not retested.** Every measurement and game run below is of a build with `LONGSHOT_FP_NAN_MID=1`, which the default now gives (the unit tests below check that unset reads as `1` does, and `0` as off). No whole-game lift, game run or second-opinion review was done on the flip. **Tested:** Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2. The game runs used a build from this branch's first round (a03c59a6e) on main 09dea503. The head's emitted IR is byte-identical to that commit's in every mode, so those runs stand for the head (see "Exactness" below). - In the game with the switch on: Lost Woods child, Market child, Kokiri Forest (Link's cap and tunic hang as on main), Fire Temple. Pictures normal. Across 8 runs a side, no error line appeared only with the switch on. - A diagnostic build with the counters, Lost Woods child: 13.8 % of fast-path runs took the slow path, and 94.5 % of those took the middle path. - A sampled Lost Woods run per arm: the exact helpers went from 6.00 % to 0.61 % of samples; the middle path's own code is about 1.6 %. Exactness: - `tests/test_lifter_semantics.py` against Unicorn (Windows port of the test, default sizes): passes off and on, `--march x86-64-v2` and `v3`, at -O1, and on at -O2 with `-ffp-contract=off` as hot units ship. Each run: 126,846 single-word runs, 2,988 edge states, 11,066 sequence runs, and 1,408 fixed NaN-case runs (352 cases under all four FZ/DN settings; 952 slow, 724 middle path). The NaN cases cover each kind in each shape (vector .4s/.2s/.2d, by-element, scalar s/d/h): one quiet NaN lane beside finite ones, NaNs in both operands (payload order, the addend first), a signalling NaN behind a quiet one, a NaN in the second lane alone of either operand, invalid operations with no NaN operand (inf×0, inf−inf, inf/inf, 0/0, FMULX's ±2, a quiet-NaN addend with inf×0), signed zeros, subnormals beside a NaN lane (operand and result). The test fails unless the fast, middle and full paths all ran. - Negative controls: the broken variant (operand lanes untested) differs in 56 runs, all under FZ, and the test requires that. Mutants that each fail: operands swapped in the middle value (108 cases), DN not read (304), the fast value not tested (20). Each fix from review, put back one at a time, makes its named unit test fail. - `LONGSHOT_FP_NAN_MID=0` is byte-identical to main (measured with the switch off on the earlier head, when off was the default): `dev words` over 118,829 words, 4,000 sequences and the 32 NaN-case words gives the same 73,557,937 bytes plain and 74,390,314 with `--count-checks` as main's builder. A whole-game lift with the switch off: 386 of 386 units with the same content as main's. On: 114 of 122 hot units change, no other unit. - Rust, on the default flip (head 0b01c7a9d, merged with main 20bedc6da; Windows, Rust 1.99.1), the tests it edits or adds only: `cargo test -p lift` 48 passed; build-driver's `stages::` tests 3 passed (new: `the_float_middle_path_is_on_when_its_switch_is_unset_and_off_when_it_is_0`); longshot-builder's `dev lift` test 1 passed (new). Each fails when the default is put back to off, four ways (the switch's rule, the skip list's Unicode check, `LiftOptions::new`, `dev lift`'s start). `cargo clippy --locked -p build-driver -p lift -p longshot-builder -p sem --all-targets -- -D warnings` clean (the crates the flip touches; workspace clippy not run); `cargo fmt --all --check` clean; `mise run lint` passes every hook. The crates' full suites were not run again. - On the head before the flip (the merge with main 699405ecb): `cargo test --locked --no-fail-fast -p mir -p sem -p llvm -p lift`: 81 passed, 0 failed, all middle-path tests among them. - `tests/run_all.py --jobs 4` (Windows, llvm-mingw 20261104) on the merge with main 2e02c0d66 and on that main (before #2680 landed, which changes the builder's progress reports only): 719 passed, 14 failed, 128 skipped on both. The same 14 files fail on both (Windows-environment tests: `test_longshot_ctl`, `test_job_queue`, `test_dev_ab`, `test_parity_gates`, `test_run_all_mingw` and others; none touches the builder's lifter). One extra sub-check in `test_parity_gates` failed on the merge only, "path is on mount 'E:', start on mount 'C:'": the merge's checkout was on another drive than the temp folder, main's was not. `test_lifter_semantics.py` is skipped on Windows by design; the matrix above ran through a Windows port of it. - A second-opinion review (gpt-6.2-sol) through eleven rounds; the last found no regression in the renderer-only, dry-run or third-party compiles and no lifter output that trips the new verifier checks. **Still to test:** - Linux: `tests/test_lifter_semantics.py` with and without `--fp-nan-mid`, expecting a pass as on Windows (CI's Linux job runs the default mode; `--fp-nan-mid` by hand). - A CPU with AVX-512 (the game builds at `-march=native`): build with `LONGSHOT_FP_NAN_MID=1` and play Lost Woods child, expecting the cloth as on main and no new error line (by hand; here the asm was only compiled for x86-64-v4, not run). - x86-64-v2 in the game: a build with `LONGSHOT_FP_NAN_MID=1 RX_MARCH=x86-64-v2` in Lost Woods child and Market child, expecting the cloth as on main and Market not slower (by hand; the semantics test passes at v2). - The Kokiri children's cloth with the switch on, expecting it to move as on main (by hand; no Kokiri child came into view in the runs above). ## Measurements **Verdict:** with the switch on, Lost Woods child: CPU per frame −3.2 % and fps +4.5 % (best estimate about −3 % CPU over both sessions); Market child: not worse. All "diagnostic" (under 5 % with 3 pairs). Setup: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2; `claude-perf/std_test.py`, uncapped (`HOS_FPS_MAX=240`), 16:9, render thread on, 3 alternating pairs, the median; game clock 0.993–1.011 on every reading. Before: main 09dea503 built as a player's build. After: the same with this branch (a03c59a6e, whose IR the head reproduces byte for byte) built with `LONGSHOT_FP_NAN_MID=1`. Switch off, the build is main's. | Lost Woods child, session 2 | Before: main @ 09dea503 | After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e | |---|---|---| | CPU ms (median) | 42.153 | 40.808 (−3.2 %; per pair −3.3 / −2.2 / −5.3 %) | | fps (median) | 116.29 | 121.54 (+4.5 %; higher in every pair) | | p99 frame ms | 11.45 | 11.03 | | frames over 50 / 100 / 250 ms | 0 / 0 / 0 | 0 / 0 / 0 | | Other sessions | Before: main @ 09dea503 | After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e | |---|---|---| | Lost Woods child, session 1 (the PC ran about 20 % slow, cause not found), CPU ms | 49.894 | 49.162 (−1.5 %) | | Lost Woods child, session 1, fps | 98.84 | 100.19 (+1.4 %) | | Market child (PC partly slow), CPU ms | 50.394 | 48.688 (inside the noise) | | Market child, fps | 91.69 | 93.09 (inside the noise) | Fps was higher with the switch in all 6 Lost Woods pairs over both sessions. An earlier run by the implementer gave −5.6 % CPU; the checker did not reproduce it. **Why these numbers still hold on current main:** they were taken on main 09dea503. Since then main has not changed the lifter (`builder/crates/{sem,mir,llvm,lift,passes}`, `third_party/a64-kit`), and this head's builder emits byte-identical IR to the measured commit's, off and on. Main's other changes since (the mutex lookups of #2665, a renderer fix for GCN, startup reporting, a game fix in `game/`) apply to both arms alike. Not measured again on current main. **No Test Farm run.** With the default on, a farm comparison of this PR against main would measure the `LONGSHOT_FP_NAN_MID=1` build above; none was run. **Costs, with the switch on** (now the default; stated plainly): | | Before: main @ 09dea503 | After, LONGSHOT_FP_NAN_MID=1: this PR @ a03c59a6e | |---|---|---| | hot units' compile, CPU-s (8 jobs, native -O2, ABBA) | 492 | 669 (+36 %; wall at 8 jobs 65 → 85 s) | | hot units' objects, `.text` bytes | 42,098,404 | 58,976,135 (+40 %) | | whole exe, `.text` bytes | 753,248,822 | 770,126,390 (+2.24 %) | | callee-saved XMM saves in the 1,470 hot functions (native, Zen 3) | 7,418 | 7,445 (14 functions save more, 1 fewer) | Non-hot units are byte-identical either way. The extra register saves are on the fast path's prologue; Market showed no slowdown from them on this CPU, and v2 was not measured in the game. A full cold build was not timed. ## Risks - **On by default: every player's hot units lift and compile once again** on the update that ships it (122 of 386 units in the whole game here; their compile about a third longer, as measured above, and on every later compile of them). Every other unit keeps its key and its object. With `LONGSHOT_FP_NAN_MID=0` the IR and keys are main's. - **On:** a wrong middle path would give a wrong float result where a NaN lane meets no subnormal lane. The semantics test checks it against Unicorn state for state under every FZ/DN setting; `LONGSHOT_FP_NAN_MID=0` turns it off for a build, the skip list for single functions. Linux, AVX-512 and x86-64-v2 in the game are still untested (Still to test). The inline asm is x86-64 (`"=x,0"`); the builder has no other host target. - **Cost when on:** compile time, code size and a few extra register saves, as measured above. - Rollback: `LONGSHOT_FP_NAN_MID=0` for a build; or revert (no data or format depends on it). ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A vector with a NaN in one lane (the cloth keeps one in its fourth) sends every operation of it to the exact helper:
flush(operands), the operation, Arm's NaN choice, flush(result). With no subnormal operand lane and no subnormal lane
of the fast value, every flush is the identity whatever FZ says, so the helper's value is the same semantics with FZ
read as clear. sem::nan_mid gives the helpers of FPAdd, FPSub, FPMul, FPDiv, FPMulX and FPMulAdd a middle path
(mir::Mid: a test helper and a value helper): the slow path tests the operands and the fast value for a subnormal lane
(through an empty asm, so LLVM does not share the classifications with the fast path's and split its merged check), then
takes the value inline (alwaysinline) or the helper as before.

Off by default (build time, read by value); on, only in the hot units' functions, LONGSHOT_FP_NAN_MID_SKIP leaves
functions out, and the option is in every unit's key. Off, the IR is byte-identical to the base's. dev words
--fp-nan-mid / --fp-nan-mid-broken and dev lift --fp-nan-mid(-skip) for the checks; count_checks counts the middle
path's runs (lifter_mid_checks). test_lifter_semantics.py: fixed NaN cases without it, with it and with a wrong test
(the operands untested), which must fail under FZ; --fp-nan-mid and --march.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- build-driver: lift_options is a Result, and both the lift and a compile alone (lift_texts, longshot-builder compile)
  take the switch from it, so a malformed LONGSHOT_FP_NAN_MID_SKIP stops both instead of compiling with the option off.
- llvm: the operands a middle path tests are sliced only for a middle path (a fast path whose helper takes no
  arguments was a panic, the switch off too).
- mir verify: a middle path's helper body is verified before its result's type is read.
- lift: the log counts the fast paths of the functions given the middle path, says so, and is written when every
  function is left out too.
Tests for each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- lift: the log says the skip list's entries (a cold function on it is counted as an entry, not as a hot function left
  out); the whole-lift test reads the line with nothing, a cold function and the hot one on the list.
- build-driver: lift_texts reads the switch through lift_texts_from, and the test checks that a compile alone's texts
  are refused for a bad list.
- test_lifter_semantics.py: a case with the first operand's second lane NaN alone (the by-element forms broadcast the
  second operand's element, so the other single-lane case gives them a NaN in every lane).
- docs: a skip-list change makes every unit's text again; a unit whose IR is unchanged reuses its object.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- build-driver: compile_only makes the units' texts (and so reads, and refuses, the lift's switches) only for the game
  (Game, GameOnly); the renderer alone, a dry run and the third-party set do not. Its texts are noted as the build's are
  (LiftTexts::note: the count's line, then units.txt). clippy: expect_err in the stages test.
- lift: the count's line says how many units were made now (cached ones are not in it).
- mir verify: a middle path's helper may not look up a table (the writer writes them inline, reading no memory). Test.
- docs: a unit whose IR is unchanged reuses its object where the work folder or the store has it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge branch 'main' into perf/fp-nan-mid
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / What the change needs (pull_request) Successful in 19s
CI / Third-party parts and guide screenshots (pull_request) Failing after 26s
PR description / Title and description (pull_request_target) Successful in 34s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 3m10s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m59s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m8s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m24s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m15s
CI / Website build and checks (pull_request) Successful in 2m54s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Successful in 11m7s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
238c600160
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2, a build of this branch's first round (a03c59a6e, whose emitted IR this head reproduces byte for byte) on main 09dea503 with LONGSHOT_FP_NAN_MID=1: Lost Woods child and Market child (3 alternating pairs each against main, uncapped), Kokiri Forest (Link's cap and tunic hang as on main), Fire Temple. Pictures normal; no error line appeared only with the switch on (8 runs a side). The Kokiri children's cloth was not seen.

Tested in game: Windows 11, Ryzen 7 5700X3D, RX 9070 XT, AMD 26.11.2, a build of this branch's first round (a03c59a6e, whose emitted IR this head reproduces byte for byte) on main 09dea503 with LONGSHOT_FP_NAN_MID=1: Lost Woods child and Market child (3 alternating pairs each against main, uncapped), Kokiri Forest (Link's cap and tunic hang as on main), Fire Temple. Pictures normal; no error line appeared only with the switch on (8 runs a side). The Kokiri children's cloth was not seen.
Author
Member
@review
BeanBot left a comment

Recommendation: Request changes. The opt-in path shows a Lost Woods gain on the tested Windows PC, but its cache key invalidates units whose output cannot change. The enabled path also needs the outstanding Linux and CPU-target runs before merge.

The builder can inline the NaN slow path in hot units when explicitly enabled. The reported gain comes with a 36% increase in hot-unit compile CPU time and a 40% increase in their object text size.

Blocking (1): must change before merging.

  1. L1 builder/crates/lift/src/whole/mod.rs:198: The option and entire skip list enter the base key shared by every unit, including units whose generated text cannot change. (more on the line) Do: Put the effective option and the relevant skipped entries into each affected unit's key, leaving unaffected units' keys unchanged.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 builder/crates/llvm/src/lib.rs:1333: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. (more on the line) Do: Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.
  • L3 builder/crates/lift/src/whole/mod.rs:560: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. (more on the line) Do: Measure clean and one-function-change build time and size against the base with the switch enabled. (@fix does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)

@fix can do L1 and L3.

Checks: Failing on this head, which is behind its base, where it passes: CI / Third-party parts and guide screenshots (pull_request). @rebase (or @fix) brings it up to date and runs it again; not held against it. Still running: 9 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes, on the reported Windows Ryzen 7 5700X3D run: three alternating pairs in Lost Woods showed median CPU time per frame falling from 42.153 to 40.808 ms and fps rising from 116.29 to 121.54. The earlier session showed a smaller gain; current main and other CPU targets have not been measured in game.

Other systems: The default is off. When enabled, the generated floating-point path can affect Windows and Linux and different x86-64 CPU targets. The reported Windows semantics and game runs cover one CPU; Linux, x86-64-v2 in game, AVX-512 execution and the Kokiri children's cloth remain untested.

Switches: LONGSHOT_FP_NAN_MID defaults off and enables the path only for value 1. LONGSHOT_FP_NAN_MID_SKIP defaults to an empty list and excludes named functions when enabled. The developer commands also add --fp-nan-mid, --fp-nan-mid-broken and --fp-nan-mid-skip. The off default limits the unmeasured costs while the remaining runs are outstanding.

Reviewed: 238c600160 against 699405ecba: Read AGENTS.md, CONTRIBUTING.md, the pull request template and standards; inspected the diff, focusing on the changed semantics, LLVM emission, verifier, lift cache, driver options and test changes. The full changed files and all surrounding callers were not read in full; the full diff output was truncated. The review checklist file was absent. No generated files or translations changed. Commit history was skimmed.; nothing run (a code review).

Checked and fine:

  • The reported fixed NaN cases compare the enabled and disabled paths with Unicorn and include a negative control.
  • The new builder switches are documented, and the launcher does not enable them.
  • The provided CI results list no failure unique to this head.

Testing: No commands from the pull request, builds or tests were run, as requested. The assessment uses the author's reported runs and the supplied CI status.

Overlaps and merge order: Not checked; network access was unavailable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The opt-in path shows a Lost Woods gain on the tested Windows PC, but its cache key invalidates units whose output cannot change. The enabled path also needs the outstanding Linux and CPU-target runs before merge. The builder can inline the NaN slow path in hot units when explicitly enabled. The reported gain comes with a 36% increase in hot-unit compile CPU time and a 40% increase in their object text size. **Blocking (1)**: must change before merging. 1. **L1** `builder/crates/lift/src/whole/mod.rs:198`: The option and entire skip list enter the base key shared by every unit, including units whose generated text cannot change. (more on the line) **Do:** Put the effective option and the relevant skipped entries into each affected unit's key, leaving unaffected units' keys unchanged. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `builder/crates/llvm/src/lib.rs:1333`: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. (more on the line) **Do:** Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base. - **L3** `builder/crates/lift/src/whole/mod.rs:560`: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. (more on the line) **Do:** Measure clean and one-function-change build time and size against the base with the switch enabled. *(`@fix` does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)* `@fix` can do L1 and L3. **Checks:** Failing on this head, which is behind its base, where it passes: `CI / Third-party parts and guide screenshots (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Still running: 9 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes, on the reported Windows Ryzen 7 5700X3D run: three alternating pairs in Lost Woods showed median CPU time per frame falling from 42.153 to 40.808 ms and fps rising from 116.29 to 121.54. The earlier session showed a smaller gain; current main and other CPU targets have not been measured in game. **Other systems:** The default is off. When enabled, the generated floating-point path can affect Windows and Linux and different x86-64 CPU targets. The reported Windows semantics and game runs cover one CPU; Linux, x86-64-v2 in game, AVX-512 execution and the Kokiri children's cloth remain untested. **Switches:** LONGSHOT_FP_NAN_MID defaults off and enables the path only for value 1. LONGSHOT_FP_NAN_MID_SKIP defaults to an empty list and excludes named functions when enabled. The developer commands also add --fp-nan-mid, --fp-nan-mid-broken and --fp-nan-mid-skip. The off default limits the unmeasured costs while the remaining runs are outstanding. **Reviewed:** 238c6001608f against 699405ecba97: Read AGENTS.md, CONTRIBUTING.md, the pull request template and standards; inspected the diff, focusing on the changed semantics, LLVM emission, verifier, lift cache, driver options and test changes. The full changed files and all surrounding callers were not read in full; the full diff output was truncated. The review checklist file was absent. No generated files or translations changed. Commit history was skimmed.; nothing run (a code review). **Checked and fine:** - The reported fixed NaN cases compare the enabled and disabled paths with Unicorn and include a negative control. - The new builder switches are documented, and the launcher does not enable them. - The provided CI results list no failure unique to this head. **Testing:** No commands from the pull request, builds or tests were run, as requested. The assessment uses the author's reported runs and the supplied CI status. **Overlaps and merge order:** Not checked; network access was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.</sub>
@ -189,0 +195,4 @@
let mut text =
format!("{:?} mark_each={} no_simplify={} split={:?}", o.codegen, o.mark_each, o.no_simplify, o.split);
if let Some(skip) = &o.fp_nan_mid {
text.push_str(&format!(" fp_nan_mid=1 skip={skip:?}"));
Member

L1 (blocking): The option and entire skip list enter the base key shared by every unit, including units whose generated text cannot change. This breaks the repository's rule that a unit's cache key contains only inputs that change its output.

When: Enabling the option or changing one skipped function invalidates every unit's lift key, so even non-hot units and unrelated hot units have their texts made again.

Do: Put the effective option and the relevant skipped entries into each affected unit's key, leaving unaffected units' keys unchanged.

**L1** (blocking): The option and entire skip list enter the base key shared by every unit, including units whose generated text cannot change. This breaks the repository's rule that a unit's cache key contains only inputs that change its output. *When:* Enabling the option or changing one skipped function invalidates every unit's lift key, so even non-hot units and unrelated hot units have their texts made again. **Do:** Put the effective option and the relevant skipped entries into each affected unit's key, leaving unaffected units' keys unchanged.
@ -507,6 +557,9 @@ impl Session {
if !self.o.no_simplify {
simplified += passes::simplify(f);
}
if mid {
Member

L3 (should fix): The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes.

When: With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown.

Do: Measure clean and one-function-change build time and size against the base with the switch enabled.

**L3** (should fix): The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. *When:* With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. **Do:** Measure clean and one-function-change build time and size against the base with the switch enabled.
@ -1255,0 +1330,4 @@
let b = self.temp();
self.line(format!("{b} = bitcast {t} {v} to {carrier}"));
v = b;
}
Member

L2 (should fix): The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding.

When: A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there.

Do: Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.

**L2** (should fix): The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. *When:* A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. **Do:** Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.
Author
Member

Thanks. Point by point:

L1 (lift key): agreed, it will be fixed. docs/dev/standards.md says a cache key holds exactly what changes its output, and today codegen_text puts the switch and the whole skip list into base_key, which every unit's key starts from, while only the hot units' text changes. The fix: take fp_nan_mid out of codegen_text. A lifted_hot_* unit's key gets the switch when it is on, plus the skip-list entries among that unit's own functions. Every other unit's key stays as it is with the switch off. The whole lift's key (whole_key) must still change when the switch flips or the list changes, so that an unchanged gen/ isn't taken for the new lift. The tests in lift/src/whole/tests.rs that now assert "on moves every key" will change to match: on, only the hot unit's key moves and the cold unit's stays; a skip entry moves only its own unit's key; off again gives the first keys. This is a change to the cache keys, so it goes back through our implementer and checker with its own second-opinion review before I push it. I'll ask for a review again on that commit. Off (the default), no key changes either way, so a player's build is unaffected meanwhile.

L2 (Linux, AVX-512, x86-64-v2 in game): open, and listed under Still to test. Not run yet. The switch stays off by default until they have run. Turning it on would be a separate change, and these runs are a precondition for it.

L3 (whole-build and one-function-change cost): not measured, and said so. What was measured: the hot units' compile CPU (+36 %, ABBA, same load), their .text (+40 %) and the whole exe's .text (+2.24 %). Non-hot units' text is byte-identical. A clean build and an incremental build with the switch on were not timed; I won't estimate them here. I'll time a clean build and a one-function edit against main before anyone proposes turning it on, along with the vectors-only variant offered in the description, which should cut most of that cost.

Checks: Third-party parts and guide screenshots fails on this head, which is one commit behind main (#2683). I haven't read its log yet; the L1 commit will be pushed on current main and I'll look at that check again there. CI's Rust job should stop at clippy for the reason below. Separately, clippy on the merge stops at main's own three needless_borrow errors in builder/crates/build-driver/src/play.rs (503, 521, 522); this PR doesn't touch that file.

No Test Farm request on this PR: off by default, its build is main's, so the farm would see no difference.

Thanks. Point by point: **L1 (lift key): agreed, it will be fixed.** `docs/dev/standards.md` says a cache key holds exactly what changes its output, and today `codegen_text` puts the switch and the whole skip list into `base_key`, which every unit's key starts from, while only the hot units' text changes. The fix: take `fp_nan_mid` out of `codegen_text`. A `lifted_hot_*` unit's key gets the switch when it is on, plus the skip-list entries among that unit's own functions. Every other unit's key stays as it is with the switch off. The whole lift's key (`whole_key`) must still change when the switch flips or the list changes, so that an unchanged gen/ isn't taken for the new lift. The tests in `lift/src/whole/tests.rs` that now assert "on moves every key" will change to match: on, only the hot unit's key moves and the cold unit's stays; a skip entry moves only its own unit's key; off again gives the first keys. This is a change to the cache keys, so it goes back through our implementer and checker with its own second-opinion review before I push it. I'll ask for a review again on that commit. Off (the default), no key changes either way, so a player's build is unaffected meanwhile. **L2 (Linux, AVX-512, x86-64-v2 in game): open, and listed under Still to test.** Not run yet. The switch stays off by default until they have run. Turning it on would be a separate change, and these runs are a precondition for it. **L3 (whole-build and one-function-change cost): not measured, and said so.** What was measured: the hot units' compile CPU (+36 %, ABBA, same load), their `.text` (+40 %) and the whole exe's `.text` (+2.24 %). Non-hot units' text is byte-identical. A clean build and an incremental build with the switch on were not timed; I won't estimate them here. I'll time a clean build and a one-function edit against main before anyone proposes turning it on, along with the vectors-only variant offered in the description, which should cut most of that cost. **Checks:** `Third-party parts and guide screenshots` fails on this head, which is one commit behind main (#2683). I haven't read its log yet; the L1 commit will be pushed on current main and I'll look at that check again there. CI's Rust job should stop at clippy for the reason below. Separately, clippy on the merge stops at main's own three `needless_borrow` errors in `builder/crates/build-driver/src/play.rs` (503, 521, 522); this PR doesn't touch that file. **No Test Farm request** on this PR: off by default, its build is main's, so the farm would see no difference.
The switch and its whole skip list were in the options every unit's key holds, so turning it on or off, or any change
of the list, moved every unit's key although only the hot units' text changes (docs/dev/standards.md: a cache key holds
exactly what changes its output). Now:
- codegen_text no longer holds it;
- each lifted_hot_ unit's key holds the switch and the skip entries among its own functions (units::plan_with);
- the lift's whole key holds the switch and the list, so a lift made with another setting is never kept as this one's.
Off, every key is as before. The whole-lift test: on moves the lift's key and the hot unit's alone (the cold unit is
kept, key and text); a cold function on the list moves no unit's key; the hot one on it moves its unit's key alone;
off again gives the first keys. Docs say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
test(builder): LONGSHOT_FP_NAN_MID: a hot unit of two functions, one left out then both: its key holds which
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / What the change needs (pull_request) Successful in 13s
CI / Third-party parts and guide screenshots (pull_request) Failing after 15s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 1m38s
PR description / Title and description (pull_request_target) Successful in 7s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 3m5s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m40s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 2m32s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 3m30s
CI / Website build and checks (pull_request) Successful in 2m29s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Successful in 13m45s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 27m9s
c35216ebe8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

🤖 L1 (the option in every unit's key): fixed in e87e3d3be, a9fbea091, d27b46a9d and c35216ebe (head c35216ebe).

What changed

  • codegen_text no longer holds LONGSHOT_FP_NAN_MID or its skip list, so the key every unit starts from is the same with the option on or off.
  • Each lifted_hot_* unit's key holds the switch and the skip-list entries among its own functions (units::plan_with). A hot unit whose functions are all on the list keeps the key it has without the option, as its text is the same.
  • The lift's whole key holds the switch and the list, so unchanged(), the lift store and Texts::text's check never take a lift made with another setting for this one.
  • Off, every key and every text are as before.
  • The docs (build.md, builder.md) now say which keys move: the hot units' when the switch flips, only the affected hot units' when the list changes, no other unit's.

Whole game (longshot-builder dev lift of the same image, off and then on): 122 of 386 unit keys move, exactly the 122 hot units. 114 unit texts change, all hot; no other unit's key or text moves. The off lift's 386 unit texts are byte-identical to the base build's (09dea503), 386 of 386.

IR: dev words over 118,829 words, 4,000 sequences and the 32 NaN-case words gives byte-identical output to the PR's first commit's builder in all 5 modes: plain, --count-checks, --fp-nan-mid, --count-checks --fp-nan-mid, --count-checks --fp-nan-mid-broken.

Tests (builder/crates/lift/src/whole/tests.rs)

  • the_float_middle_path_is_off_by_default_in_the_hot_units_and_their_keys_only:

    • codegen_text is the same on and off;
    • turning the option on moves the lift's key and the hot unit's alone, and the cold unit is kept with its key and text;
    • a cold function on the skip list moves no unit's key;
    • the hot function on it brings that unit back to its key and text without the option;
    • a fresh lift with the option on makes the cold unit's text the same as off;
    • off again gives the first lift's keys.
  • a_hot_unit_s_key_holds_which_of_its_functions_the_middle_path_leaves_out, one hot unit of two functions:

    • one function skipped gives a new unit key and one middle path;
    • both skipped gives the unit key and text without the option, while the lift's whole key still differs from off's.

    It fails when the hot unit's key leaves out which functions are skipped (mutant run here).

Results:

  • cargo test -p lift: 48 passed, 0 failed.
  • cargo fmt --check is clean and mise run lint passes.
  • Workspace clippy stops only at main's three needless_borrow errors in build-driver/src/play.rs. With that lint allowed, clippy on the touched crates is clean.
  • A gpt-6.2-sol review of the key change found nothing, on d27b46a9d, the commit before the test-only c35216ebe.
🤖 **L1 (the option in every unit's key): fixed** in `e87e3d3be`, `a9fbea091`, `d27b46a9d` and `c35216ebe` (head `c35216ebe`). **What changed** - `codegen_text` no longer holds `LONGSHOT_FP_NAN_MID` or its skip list, so the key every unit starts from is the same with the option on or off. - Each `lifted_hot_*` unit's key holds the switch and the skip-list entries among its own functions (`units::plan_with`). A hot unit whose functions are all on the list keeps the key it has without the option, as its text is the same. - The lift's whole key holds the switch and the list, so `unchanged()`, the lift store and `Texts::text`'s check never take a lift made with another setting for this one. - Off, every key and every text are as before. - The docs (`build.md`, `builder.md`) now say which keys move: the hot units' when the switch flips, only the affected hot units' when the list changes, no other unit's. **Whole game** (`longshot-builder dev lift` of the same image, off and then on): **122 of 386 unit keys move, exactly the 122 hot units**. 114 unit texts change, all hot; no other unit's key or text moves. The off lift's 386 unit texts are byte-identical to the base build's (09dea503), 386 of 386. **IR:** `dev words` over 118,829 words, 4,000 sequences and the 32 NaN-case words gives **byte-identical output** to the PR's first commit's builder **in all 5 modes**: plain, `--count-checks`, `--fp-nan-mid`, `--count-checks --fp-nan-mid`, `--count-checks --fp-nan-mid-broken`. **Tests** (`builder/crates/lift/src/whole/tests.rs`) - `the_float_middle_path_is_off_by_default_in_the_hot_units_and_their_keys_only`: - `codegen_text` is the same on and off; - turning the option on moves the lift's key and the hot unit's alone, and the cold unit is kept with its key and text; - a cold function on the skip list moves no unit's key; - the hot function on it brings that unit back to its key and text without the option; - a fresh lift with the option on makes the cold unit's text the same as off; - off again gives the first lift's keys. - `a_hot_unit_s_key_holds_which_of_its_functions_the_middle_path_leaves_out`, one hot unit of two functions: - one function skipped gives a new unit key and one middle path; - both skipped gives the unit key and text without the option, while the lift's whole key still differs from off's. It fails when the hot unit's key leaves out which functions are skipped (mutant run here). Results: - `cargo test -p lift`: 48 passed, 0 failed. - `cargo fmt --check` is clean and `mise run lint` passes. - Workspace clippy stops only at main's three `needless_borrow` errors in `build-driver/src/play.rs`. With that lint allowed, clippy on the touched crates is clean. - A gpt-6.2-sol review of the key change found nothing, on `d27b46a9d`, the commit before the test-only `c35216ebe`.
Author
Member
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The cache-key fix addresses the blocking item, but the enabled path still needs the outstanding platform runs and build-cost measurements. Recommend approval; not approved on the forge.

The opt-in builder switch handles eligible NaN float operations inline. The key change limits invalidation to affected hot units; enabling the feature still increases generated code and compile work.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 builder/crates/llvm/src/lib.rs:1333: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. When: A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. Do: Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.
  • L3 builder/crates/lift/src/whole/mod.rs:560: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. When: With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. Do: Measure clean and one-function-change build time and size against the base with the switch enabled. (@fix does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)

@fix can do L3.

Since the last review (on 238c600160)
Resolved: L1 (The option and entire skip list enter the base key shared by every unit, including units w…)
Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…)

Checks: Failing on this head, which is behind its base, where it passes: CI / Third-party parts and guide screenshots (pull_request). @rebase (or @fix) brings it up to date and runs it again; not held against it. Still running: 8 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes, on the measured Windows system: the reported Lost Woods session showed median CPU time per frame falling 3.2% and FPS rising 4.5% over three alternating pairs. Hot-unit compile CPU rose 36% and object text size 40%; clean and incremental build costs remain unmeasured.

Other systems: The enabled path has Windows game and semantics-test evidence. Linux, AVX-512 and an x86-64-v2 game build remain untested; the default-off path is reported byte-identical to main.

Switches: LONGSHOT_FP_NAN_MID defaults off and enables the optimization only when set to 1. LONGSHOT_FP_NAN_MID_SKIP defaults to empty and excludes named functions when the optimization is enabled. Keeping the optimization off by default is appropriate pending the outstanding runs.

Reviewed: c35216ebe8 against 699405ecba: Read AGENTS.md, CONTRIBUTING.md, the changes since the ledger, whole/units.rs, and the cache-key and unit-generation paths in whole/mod.rs. Skimmed the test and documentation changes, commit list, reported runs and remaining changed-file inventory; the other changed code files were not read in full.; nothing run (a code review).

Checked and fine:

  • A fully skipped hot unit receives its off key, matching the unit-generation condition.
  • The whole-lift key distinguishes enabled settings, including skip-list changes, before unchanged or store reuse.
  • The added tests cover off, enabled, partial skip, full skip and restoration to off.

Testing: No commands that build, run tests or execute project code were run. The author reports passing lift tests and Windows game and semantics runs; CI is still running.

Overlaps and merge order: none found


Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The cache-key fix addresses the blocking item, but the enabled path still needs the outstanding platform runs and build-cost measurements. Recommend approval; not approved on the forge. The opt-in builder switch handles eligible NaN float operations inline. The key change limits invalidation to affected hot units; enabling the feature still increases generated code and compile work. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `builder/crates/llvm/src/lib.rs:1333`: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. *When:* A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. **Do:** Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base. - **L3** `builder/crates/lift/src/whole/mod.rs:560`: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. *When:* With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. **Do:** Measure clean and one-function-change build time and size against the base with the switch enabled. *(`@fix` does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)* `@fix` can do L3. **Since the last review** (on 238c6001608f) Resolved: L1 (The option and entire skip list enter the base key shared by every unit, including units w…) Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…) **Checks:** Failing on this head, which is behind its base, where it passes: `CI / Third-party parts and guide screenshots (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Still running: 8 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes, on the measured Windows system: the reported Lost Woods session showed median CPU time per frame falling 3.2% and FPS rising 4.5% over three alternating pairs. Hot-unit compile CPU rose 36% and object text size 40%; clean and incremental build costs remain unmeasured. **Other systems:** The enabled path has Windows game and semantics-test evidence. Linux, AVX-512 and an x86-64-v2 game build remain untested; the default-off path is reported byte-identical to main. **Switches:** LONGSHOT_FP_NAN_MID defaults off and enables the optimization only when set to 1. LONGSHOT_FP_NAN_MID_SKIP defaults to empty and excludes named functions when the optimization is enabled. Keeping the optimization off by default is appropriate pending the outstanding runs. **Reviewed:** c35216ebe8d5 against 699405ecba97: Read AGENTS.md, CONTRIBUTING.md, the changes since the ledger, whole/units.rs, and the cache-key and unit-generation paths in whole/mod.rs. Skimmed the test and documentation changes, commit list, reported runs and remaining changed-file inventory; the other changed code files were not read in full.; nothing run (a code review). **Checked and fine:** - A fully skipped hot unit receives its off key, matching the unit-generation condition. - The whole-lift key distinguishes enabled settings, including skip-list changes, before unchanged or store reuse. - The added tests cover off, enabled, partial skip, full skip and restoration to off. **Testing:** No commands that build, run tests or execute project code were run. The author reports passing lift tests and Windows game and semantics runs; CI is still running. **Overlaps and merge order:** none found </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.</sub>
Owner

Should we enable by default?

Should we enable by default?
Co-Authored-By: Claude Opus 5.5 <[email protected]>
perf(builder): LONGSHOT_FP_NAN_MID on by default; 0 (or off, no, false, empty) turns it off
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / What the change needs (pull_request) Successful in 28s
CI / Third-party parts and guide screenshots (pull_request) Failing after 44s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 47s
PR description / Title and description (pull_request_target) Successful in 28s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
0b01c7a9d6
The hot units' float slow paths get their middle path by default: unset or any value but an off word
(build_core::switch) is on, and LONGSHOT_FP_NAN_MID=0 lifts as before, the IR and keys main's. The skip
list is read whenever it is on, so with the switch unset too. LiftOptions::new and `dev lift` start on, as
a build does; `dev lift --no-fp-nan-mid` lifts without it (`--fp-nan-mid` is kept). Every player's hot
units get new keys and lift and compile once again on the update that ships this.

Tests: unset reads as 1 and 0 as off, in the lift's options and a compile alone; `dev lift`'s default and
--no-fp-nan-mid; the lift crate's default lift gives the hot unit the middle path, the cold one not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
klimovich008 changed title from WIP: perf(builder): LONGSHOT_FP_NAN_MID=1, a float operation with a NaN lane and no subnormal lane is answered inline, not by the exact helper (off by default) to WIP: perf(builder): a float operation with a NaN lane and no subnormal lane is answered inline by default (LONGSHOT_FP_NAN_MID=0 turns it off) 2026-11-28 01:10:19 +00:00
Author
Member

@HumanBean Yes: it is now on by default, in 0b01c7a9d (head 0b01c7a9d, merged with main 20bedc6da).

  • LONGSHOT_FP_NAN_MID unset (or 1) gives the hot units' float slow paths the middle path. LONGSHOT_FP_NAN_MID=0 (or off, no, false, empty, read by build_core::switch like the builder's other switches) is the kill switch: the IR and the lift keys are main's again. LONGSHOT_FP_NAN_MID_SKIP still leaves single functions out.
  • LiftOptions::new and longshot-builder dev lift start with it on, as a build does. dev lift --no-fp-nan-mid lifts without it.
  • Every player's hot units get new keys, so they lift and compile once again on the update that ships this. Every other unit keeps its key and its object.
  • Tests: unset reads as 1 and 0 reads as off, for the lift and for a compile alone (the_float_middle_path_is_on_when_its_switch_is_unset_and_off_when_it_is_0), plus dev lift's default and the lift crate's default lift. Each one fails when the default is put back to off, which I checked four ways. The edited tests pass, as do clippy on the touched crates, fmt and mise run lint.
  • The flip itself was not retested in the game or with a whole-game lift. The measurements in the description are of LONGSHOT_FP_NAN_MID=1 builds, which is what the default now gives. Linux, AVX-512 and x86-64-v2 in the game are still open (L2), and so are the clean and one-function build times (L3).
@HumanBean Yes: it is now on by default, in `0b01c7a9d` (head `0b01c7a9d`, merged with main 20bedc6da). - `LONGSHOT_FP_NAN_MID` unset (or `1`) gives the hot units' float slow paths the middle path. `LONGSHOT_FP_NAN_MID=0` (or `off`, `no`, `false`, empty, read by `build_core::switch` like the builder's other switches) is the kill switch: the IR and the lift keys are main's again. `LONGSHOT_FP_NAN_MID_SKIP` still leaves single functions out. - `LiftOptions::new` and `longshot-builder dev lift` start with it on, as a build does. `dev lift --no-fp-nan-mid` lifts without it. - Every player's hot units get new keys, so they lift and compile once again on the update that ships this. Every other unit keeps its key and its object. - Tests: unset reads as `1` and `0` reads as off, for the lift and for a compile alone (`the_float_middle_path_is_on_when_its_switch_is_unset_and_off_when_it_is_0`), plus `dev lift`'s default and the lift crate's default lift. Each one fails when the default is put back to off, which I checked four ways. The edited tests pass, as do clippy on the touched crates, fmt and `mise run lint`. - The flip itself was not retested in the game or with a whole-game lift. The measurements in the description are of `LONGSHOT_FP_NAN_MID=1` builds, which is what the default now gives. Linux, AVX-512 and x86-64-v2 in the game are still open (L2), and so are the clean and one-function build times (L3).
Author
Member
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The enabled path shows a Lost Woods gain on one Windows system, but its Linux, AVX-512 and x86-64-v2 game coverage and its whole-build costs remain unmeasured. Those runs matter now that the path is on by default. Recommend approval; not approved on the forge.

The builder handles eligible NaN float operations inline in hot units, reducing exact-helper calls at the cost of larger generated code and longer compilation. The latest change enables that path by default.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 builder/crates/llvm/src/lib.rs:1333: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. When: A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. Do: Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.
  • L3 builder/crates/lift/src/whole/mod.rs:560: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. When: With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. Do: Measure clean and one-function-change build time and size against the base with the switch enabled. (@fix does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)

@fix can do L3.

Since the last review (on c35216ebe8)
Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…)

Checks: Failing on this head, which is behind its base, where it passes: CI / Third-party parts and guide screenshots (pull_request). @rebase (or @fix) brings it up to date and runs it again; not held against it. Cancelled on this head (no result): PR description / Title and description (pull_request_target). Still running: 8 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes, on the measured Windows system: three alternating Lost Woods pairs showed median CPU time per frame falling 3.2% and fps rising 4.5%; a second, slower session showed 1.5% and 1.4% respectively. Hot-unit compile CPU rose 36%, and whole-executable text grew 2.24%.

Other systems: The emitted code affects Windows and Linux x86-64 builds and CPUs using different instruction levels. Windows on Zen 3 was tested; enabled Linux semantics, AVX-512 gameplay and x86-64-v2 gameplay remain outstanding. Kokiri children's cloth was not observed.

Switches: LONGSHOT_FP_NAN_MID is added and now defaults on; 0, off, no, false or empty disable it. LONGSHOT_FP_NAN_MID_SKIP defaults to an empty list and excludes named functions when enabled. Both are documented builder switches; the default's broader correctness and build costs remain to be measured.

Reviewed: 0b01c7a9d6 against 20bedc6da1: Read AGENTS.md, CONTRIBUTING.md and the pull request template; inspected the default-flip commit, relevant lift and switch paths, the diff statistics, commits, description and comments. The full changed code files, referenced standards and remaining full diff were not read; the review checklist file is absent.; nothing run (a code review).

Checked and fine:

  • The build and compile-alone paths use the same switch parsing, with unset enabling the path and off values disabling it.
  • The developer lift command defaults on and rejects combining its off option with the on or skip options.
  • The reported semantics tests include negative controls and all four FZ/DN settings.

Testing: No commands from the project or tests were run. The author reports Windows game and semantics runs; CI is still running.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The enabled path shows a Lost Woods gain on one Windows system, but its Linux, AVX-512 and x86-64-v2 game coverage and its whole-build costs remain unmeasured. Those runs matter now that the path is on by default. Recommend approval; not approved on the forge. The builder handles eligible NaN float operations inline in hot units, reducing exact-helper calls at the cost of larger generated code and longer compilation. The latest change enables that path by default. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `builder/crates/llvm/src/lib.rs:1333`: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. *When:* A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. **Do:** Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base. - **L3** `builder/crates/lift/src/whole/mod.rs:560`: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. *When:* With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. **Do:** Measure clean and one-function-change build time and size against the base with the switch enabled. *(`@fix` does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)* `@fix` can do L3. **Since the last review** (on c35216ebe8d5) Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…) **Checks:** Failing on this head, which is behind its base, where it passes: `CI / Third-party parts and guide screenshots (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Cancelled on this head (no result): `PR description / Title and description (pull_request_target)`. Still running: 8 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes, on the measured Windows system: three alternating Lost Woods pairs showed median CPU time per frame falling 3.2% and fps rising 4.5%; a second, slower session showed 1.5% and 1.4% respectively. Hot-unit compile CPU rose 36%, and whole-executable text grew 2.24%. **Other systems:** The emitted code affects Windows and Linux x86-64 builds and CPUs using different instruction levels. Windows on Zen 3 was tested; enabled Linux semantics, AVX-512 gameplay and x86-64-v2 gameplay remain outstanding. Kokiri children's cloth was not observed. **Switches:** LONGSHOT_FP_NAN_MID is added and now defaults on; 0, off, no, false or empty disable it. LONGSHOT_FP_NAN_MID_SKIP defaults to an empty list and excludes named functions when enabled. Both are documented builder switches; the default's broader correctness and build costs remain to be measured. **Reviewed:** 0b01c7a9d6b2 against 20bedc6da146: Read AGENTS.md, CONTRIBUTING.md and the pull request template; inspected the default-flip commit, relevant lift and switch paths, the diff statistics, commits, description and comments. The full changed code files, referenced standards and remaining full diff were not read; the review checklist file is absent.; nothing run (a code review). **Checked and fine:** - The build and compile-alone paths use the same switch parsing, with unset enabling the path and off values disabling it. - The developer lift command defaults on and rejects combining its off option with the on or skip options. - The reported semantics tests include negative controls and all four FZ/DN settings. **Testing:** No commands from the project or tests were run. The author reports Windows game and semantics runs; CI is still running. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.</sub>
klimovich008 changed title from WIP: perf(builder): a float operation with a NaN lane and no subnormal lane is answered inline by default (LONGSHOT_FP_NAN_MID=0 turns it off) to perf(builder): a float operation with a NaN lane and no subnormal lane is answered inline by default (LONGSHOT_FP_NAN_MID=0 turns it off) 2026-11-28 01:12:36 +00:00
Author
Member

Out of WIP at 0b01c7a9d, as the maintainer asked: on by default, LONGSHOT_FP_NAN_MID=0 turns it off. The edited tests pass (lift 48, build-driver stages 3, dev lift default 1), and four ways of putting the default back to off each fail one of them. fmt, clippy on the touched crates and mise run lint are clean. Not retested in the game: the measurements are from =1 builds. CI was still running when I took it out of WIP. The guide screenshot check fails on main's head too, on 7 menu files changed by #1349 and #2708 without a review.

🤖 Generated with Claude Code

Out of WIP at 0b01c7a9d, as the maintainer asked: on by default, `LONGSHOT_FP_NAN_MID=0` turns it off. The edited tests pass (lift 48, build-driver stages 3, dev lift default 1), and four ways of putting the default back to off each fail one of them. fmt, clippy on the touched crates and `mise run lint` are clean. Not retested in the game: the measurements are from `=1` builds. CI was still running when I took it out of WIP. The guide screenshot check fails on main's head too, on 7 menu files changed by #1349 and #2708 without a review. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Merge branch 'main' into perf/fp-nan-mid
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
PR description / Title and description (pull_request_target) Successful in 37s
CI / What the change needs (pull_request) Successful in 41s
CI / Third-party parts and guide screenshots (pull_request) Failing after 57s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 34s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
23e79ee39f
Merge branch 'main' into perf/fp-nan-mid
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
PR description / Title and description (pull_request_target) Successful in 9s
CI / What the change needs (pull_request) Successful in 13s
CI / Third-party parts and guide screenshots (pull_request) Failing after 16s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 17s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 4m18s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 2m10s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 5m46s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 5m42s
CI / Website build and checks (pull_request) Failing after 1m18s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 27m17s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 37m46s
2be149afee
Main d05a0daba, with #2700 (the hot units' never-run blocks leave the hot code by default, LONGSHOT_HOT_SPLIT=0 turns
it off). Both switches kept as each PR made them, each on when unset and off at 0, each with its own skip list:

- stages.rs: lift_options_from reads both switches from the same env (the middle path's Result and Unicode check,
  #2700's hot_split and its skip list); lift() logs and refuses a bad hot-split list as #2700 does, then lifts with
  lift_options()?; check_hot_split_as kept.
- build.rs compile_only: #2700's check of gen/lift.key's hot_split line first, then the texts only where the lifted
  units are compiled (Game, GameOnly), as #2684 made it.
- lift whole_key: both options in the whole key; the hot units' keys carry both (hot_split in each hot function's
  key, the middle path in each hot unit's); codegen_text holds neither; lift.key keeps the hot_split skip line.
- dev lift: --fp-nan-mid, --no-fp-nan-mid, --fp-nan-mid-skip and --hot-split, --no-hot-split, --hot-split-skip.
- dev words and test_lifter_semantics.py: --fp-nan-mid, --fp-nan-mid-broken, --count-checks and --hot-flags,
  --hot-split; build() lifts with both modes' flags and compiles as compile_flags says (the NaN cases' modules too).
- lift tests: every test of both kept; a new one lifts the four settings and checks that the whole key and the hot
  unit's key differ in each, the cold unit's never moves, and each skip list moves the hot unit's key on its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Merged main d05a0daba into the branch, which brings in #2700 (the hot split, on by default). Head is now 2be149afe, a fast-forward over 23e79ee39. The merge had seven conflicts (build.rs, stages.rs, lift whole/mod.rs and tests.rs, dev lift, dev words, test_lifter_semantics.py), all resolved by keeping both sides. Main has moved six renderer and profile commits since d05a0daba; they merge cleanly and are not in this merge.

How the two switches combine

  • LONGSHOT_FP_NAN_MID and LONGSHOT_HOT_SPLIT are each on when unset and off at 0/off/no/false/empty, independently. Each has its own skip list. Both are read in lift_options_from.
  • A hot unit's key carries both. The hot split's part is in each hot function's key (hot_split / hot_split left out). The middle path's part is in the unit's key (fp_nan_mid=1 left_out=[...], or nothing when every function is left out).
  • Non-hot units' keys carry neither, and codegen_text holds neither.
  • The whole lift key holds both options with both full lists.
  • gen/lift.key keeps the hot_split skip line. longshot-builder compile on its own still checks it before making texts, and makes texts only for Game/GameOnly.
  • dev lift has both sets of flags. dev words and the semantics test have both modes, and the test's NaN-case modules are built with --hot-flags and --hot-split too.
  • New lift test the_middle_path_and_the_hot_split_are_each_in_the_hot_units_keys_on_their_own:
    • it lifts all four on/off settings: four different whole keys and four different hot-unit keys, and the cold unit's key never changes;
    • leaving the hot unit's function out of the middle path's list gives the key of the middle path off with the hot split on;
    • leaving it out of the hot split's list gives a key of its own.

What ran (Windows 11, Rust 1.99.1, llvm-mingw clang 23.1.5; no game runs and no whole-game lift)

  • cargo fmt --all --check: clean.
  • cargo clippy --workspace --all-targets -D warnings: clean.
  • cargo test --no-fail-fast of lift, llvm, build-compile, build-driver and longshot-builder, including tests/hot_split.rs (6/6):
    • 18 failures on the branch and 19 on main d05a0daba, with nothing failing only on the branch;
    • they are the Windows path and toolchain tests that fail on main too;
    • main's 19th, a_lifted_unit_s_text_made_on_demand_compiles_…, passed on the branch;
    • every middle-path and hot-split test passed, including lift 50/50.
  • tests/run_all.py test_lifter_semantics:
    • it doesn't run on Windows (lifter_semantics_rt.c needs sys/mman.h, and the check is marked Linux-only);
    • I ran the merged test with a local Windows runtime instead (VirtualAlloc for the window page), all ok: default; --fp-nan-mid; and --fp-nan-mid --hot-flags --hot-split;
    • with the hot flags, 3,163 regions were outlined in the words module and 30 to 32 in each NaN-case module;
    • the 352 NaN cases gave 724 middle-path runs, and the broken control differed in 56.
  • mise run lint: passes.

🤖 Generated with Claude Code

Merged main d05a0daba into the branch, which brings in #2700 (the hot split, on by default). Head is now `2be149afe`, a fast-forward over `23e79ee39`. The merge had seven conflicts (build.rs, stages.rs, lift `whole/mod.rs` and `tests.rs`, `dev lift`, `dev words`, `test_lifter_semantics.py`), all resolved by keeping both sides. Main has moved six renderer and profile commits since d05a0daba; they merge cleanly and are not in this merge. **How the two switches combine** - `LONGSHOT_FP_NAN_MID` and `LONGSHOT_HOT_SPLIT` are each on when unset and off at `0`/`off`/`no`/`false`/empty, independently. Each has its own skip list. Both are read in `lift_options_from`. - A hot unit's key carries both. The hot split's part is in each hot function's key (`hot_split` / `hot_split left out`). The middle path's part is in the unit's key (`fp_nan_mid=1 left_out=[...]`, or nothing when every function is left out). - Non-hot units' keys carry neither, and `codegen_text` holds neither. - The whole lift key holds both options with both full lists. - `gen/lift.key` keeps the `hot_split skip` line. `longshot-builder compile` on its own still checks it before making texts, and makes texts only for Game/GameOnly. - `dev lift` has both sets of flags. `dev words` and the semantics test have both modes, and the test's NaN-case modules are built with `--hot-flags` and `--hot-split` too. - New lift test `the_middle_path_and_the_hot_split_are_each_in_the_hot_units_keys_on_their_own`: - it lifts all four on/off settings: four different whole keys and four different hot-unit keys, and the cold unit's key never changes; - leaving the hot unit's function out of the middle path's list gives the key of the middle path off with the hot split on; - leaving it out of the hot split's list gives a key of its own. **What ran** (Windows 11, Rust 1.99.1, llvm-mingw clang 23.1.5; no game runs and no whole-game lift) - `cargo fmt --all --check`: clean. - `cargo clippy --workspace --all-targets -D warnings`: clean. - `cargo test --no-fail-fast` of lift, llvm, build-compile, build-driver and longshot-builder, including `tests/hot_split.rs` (6/6): - 18 failures on the branch and 19 on main d05a0daba, with nothing failing only on the branch; - they are the Windows path and toolchain tests that fail on main too; - main's 19th, `a_lifted_unit_s_text_made_on_demand_compiles_…`, passed on the branch; - every middle-path and hot-split test passed, including lift 50/50. - `tests/run_all.py test_lifter_semantics`: - it doesn't run on Windows (`lifter_semantics_rt.c` needs `sys/mman.h`, and the check is marked Linux-only); - I ran the merged test with a local Windows runtime instead (VirtualAlloc for the window page), all ok: default; `--fp-nan-mid`; and `--fp-nan-mid --hot-flags --hot-split`; - with the hot flags, 3,163 regions were outlined in the words module and 30 to 32 in each NaN-case module; - the 352 NaN cases gave 724 middle-path runs, and the broken control differed in 56. - `mise run lint`: passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Member
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The reported Windows measurements show a Lost Woods improvement, but the outstanding platform runs and full-build costs remain unknown. CI is also still running. Recommend approval; not approved on the forge.

The builder answers eligible NaN-containing float operations inline in hot units. The reported gain is accompanied by larger generated code and longer hot-unit compilation.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 builder/crates/llvm/src/lib.rs:1333: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. When: A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. Do: Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base.
  • L3 builder/crates/lift/src/whole/mod.rs:560: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. When: With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. Do: Measure clean and one-function-change build time and size against the base with the switch enabled. (@fix does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)

@fix can do L3.

Since the last review (on 0b01c7a9d6)
Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…)

Checks: Failing on this head, which is behind its base, where it passes: CI / Third-party parts and guide screenshots (pull_request). @rebase (or @fix) brings it up to date and runs it again; not held against it. Still running: 7 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes on the measured Windows system: median Lost Woods CPU time fell 3.2% and fps rose 4.5% over three alternating pairs; another session showed a 1.5% CPU reduction. Hot-unit compile CPU rose 36% and whole-executable text size rose 2.24%, according to the pull request.

Other systems: The emitted code affects Windows and Linux and multiple x86 CPU levels. Windows semantics and game runs are reported; Linux, AVX-512 and x86-64-v2 game coverage remain outstanding. The merged hot-split interaction has a reported Windows semantics run.

Switches: LONGSHOT_FP_NAN_MID defaults on; off words disable it. LONGSHOT_FP_NAN_MID_SKIP excludes selected functions when enabled. The default has a measured benefit on one Windows system, but its broader platform coverage and build costs remain open.

Reviewed: 2be149afee against d05a0dabae: Read AGENTS.md, CONTRIBUTING.md, the pull request template and the diff since the ledger head. Skimmed the reported runs and changes relative to base; did not read every changed code file in full or all referenced repository rules.; nothing run (a code review).

Checked and fine:

  • The reported merged-head semantics run exercised the middle path together with hot splitting.
  • The new key test covers both switches independently and their skip-list interaction.

Testing: No commands that build or run project code were executed. The reported merged-head Windows tests pass the middle-path and hot-split cases; CI is still running.

Overlaps and merge order: None established from the supplied information.


Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The reported Windows measurements show a Lost Woods improvement, but the outstanding platform runs and full-build costs remain unknown. CI is also still running. Recommend approval; not approved on the forge. The builder answers eligible NaN-containing float operations inline in hot units. The reported gain is accompanied by larger generated code and longer hot-unit compilation. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `builder/crates/llvm/src/lib.rs:1333`: The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game run is still outstanding. *When:* A developer enabling the switch on these supported configurations relies on newly emitted inline assembly and floating-point code that has not yet been exercised there. **Do:** Run the semantics test on Linux and the specified Lost Woods and Market game checks on x86-64-v2 and an AVX-512 CPU; compare the cloth and error logs with the base. - **L3** `builder/crates/lift/src/whole/mod.rs:560`: The reported compile cost covers hot units, not a clean game build or an incremental build after one function changes. *When:* With the switch enabled, the measured hot-unit compile CPU rises from 492 to 669 seconds, but its effect on the complete build and incremental workflow is unknown. **Do:** Measure clean and one-function-change build time and size against the base with the switch enabled. *(`@fix` does its part first: Restricting the middle path to vector operations could reduce generated code and compile work; its effect needs measurement.)* `@fix` can do L3. **Since the last review** (on 0b01c7a9d6b2) Still open: L2 (The enabled path has not been run on Linux or on an AVX-512 CPU, and the x86-64-v2 game ru…); L3 (The reported compile cost covers hot units, not a clean game build or an incremental build…) **Checks:** Failing on this head, which is behind its base, where it passes: `CI / Third-party parts and guide screenshots (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs it again; not held against it. Still running: 7 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes on the measured Windows system: median Lost Woods CPU time fell 3.2% and fps rose 4.5% over three alternating pairs; another session showed a 1.5% CPU reduction. Hot-unit compile CPU rose 36% and whole-executable text size rose 2.24%, according to the pull request. **Other systems:** The emitted code affects Windows and Linux and multiple x86 CPU levels. Windows semantics and game runs are reported; Linux, AVX-512 and x86-64-v2 game coverage remain outstanding. The merged hot-split interaction has a reported Windows semantics run. **Switches:** LONGSHOT_FP_NAN_MID defaults on; off words disable it. LONGSHOT_FP_NAN_MID_SKIP excludes selected functions when enabled. The default has a measured benefit on one Windows system, but its broader platform coverage and build costs remain open. **Reviewed:** 2be149afee9f against d05a0dabaedd: Read AGENTS.md, CONTRIBUTING.md, the pull request template and the diff since the ledger head. Skimmed the reported runs and changes relative to base; did not read every changed code file in full or all referenced repository rules.; nothing run (a code review). **Checked and fine:** - The reported merged-head semantics run exercised the middle path together with hot splitting. - The new key test covers both switches independently and their skip-list interaction. **Testing:** No commands that build or run project code were executed. The reported merged-head Windows tests pass the middle-path and hot-split cases; CI is still running. **Overlaps and merge order:** None established from the supplied information. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch perf/fp-nan-mid 2026-11-28 03:59:56 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2684
No description provided.