WIP: perf(lift): the lifted code's floats as host floats, without FPSR bookkeeping the game never reads (RX_FP_NATIVE) #2235

Draft
dyst wants to merge 3 commits from dyst/Longshot:perf/fp-native into main
Member

Summary

The lifter keeps every float result of the game bit for bit with Arm including FPSR's cumulative exception flags
(IOC, DZC, OFC, UFC, IXC, IDC). Each float op computes the native result and then proves it raised no flag FPSR lacks,
else runs a software body. The fast float regions (nx2/fastfp.py) run their ops as asm volatile inside an MXCSR
window, with a register snapshot and an exact copy of the whole region to fall back to. The vector forms (nx2/vecfp.py)
keep a lane only where it is provably Arm's. That is about 730,000 sites in the lifted code. It comes from the a64-kit and
suyu translator's standard, "registers + NZCV + V regs + FPSR + memory: 0 differences from Unicorn", which a general
translator needs because it cannot know whether a program reads FPSR.

This game doesn't read it during play:

  • Its FPSR reads (8, an MRS each) are in 6 functions: the C library's floating-point environment routines beside
    memcpy (f_8575d1d4, f_8575d1e4, f_8575d1fc, f_8575d214, f_857f71f0) and two others (f_851109b8,
    f_85110e58). None of them is in nx2/ran_funcs.txt, the coverage of a 100-minute play session (77,725 functions).
  • The host never reads it: it is only copied to a new fiber and printed in the thread dump (host/hos_thread.c).
  • FPSR is 0x9f in play, every flag set (#2036 found the same), so the bookkeeping keeps re-proving flags that stay set.

FPCR is different and is kept: the game sets flush-to-zero itself (f_8169d350, a setFlushToZero that play runs).

This PR compiles the lifted code against copies of the lift's two float headers (nx2/fp_native.py, written by
nx2/build.py and put ahead of the lift's on the include path) in which:

  • every FPX1 keep test and the vector keep tests are true, so each op is its plain host op;
  • the fast float regions' ops are plain intrinsics, with no MXCSR window, guard or exact copy;
  • the host thread's MXCSR follows FPCR.FZ (FTZ and DAZ): after every lifted MSR FPCR (through the RECOMP_FPX_INHIBIT
    token each such write ends with) and at a fiber's start, which inherits its creator's FPCR (fiber_main).

Conversions, min/max, compares and the FRECPE/FRSQRTE estimates keep their exact code. The translation itself doesn't
change (compile only, not in the lift key). RX_FP_NATIVE=0 builds the headers as before.

The result: Market +12% fps and Lake Hylia +7% on a Ryzen 9 3900X; the game's own loop is 10-22% shorter, and at the
lake the render chain then becomes the limit. The executable is 61 MB (10%) smaller.

Read first: nx2/fp_native.py, the hunks in nx2/build.py, fiber_main in host/hos_thread.c.

Related open work, which keeps FPSR exact and which this would change:

  • #2152 (float wrappers as leaves) and #2067 (FADDP and FSQRT fast paths) speed up the bookkeeping this removes.
  • #2068 (FRECPE/FRSQRTE table) is still needed: the estimates keep their exact code here.
  • #2036, #1910, #1904 (cloth, crowd and libm on host code) still gain from real SIMD and fewer context loads, but their
    FPSR handling (lanes kept for their flags, MXCSR read-backs, flag declines) and their gains against main would change.

No PR, issue or review found gives a reason FPSR must stay exact. Prior work searched: FPSR, fastfp, fpx, MXCSR,
"native float", vecfp, fpxkeep, "exact float".

Testing

Tested: Windows 11, Ryzen 9 3900X, RTX 3080 10 GB (NVIDIA 621.14), 3440x1440 window at 67% render resolution,
V-Sync off, uncapped. A/B by dev.py ab against the base of v3.1.1 (a2dc5385): the Market and Lake Hylia, 2 runs a side
each, interleaved (at 659c7ebe; the head only adds the fiber's MXCSR at its start), plus a 30 s smoke pair at the Market on the head, 388fa3cb (with the fiber change). Every run reached its scene and played its 60 s; no crash,
nothing wrong seen in the window. Played by hand at the Market for a few minutes, uncapped.

Still to test:

  • Proof that the FPSR readers never run: a build that logs once if any of the 6 functions runs, through long play
    sessions (all ages, cutscenes, minigames, saves and loads), expecting no line (by hand, then the Test Farm).
  • Linux (RADV and NVIDIA), the Steam Deck, an Intel CPU and an AMD GPU: @Beanstalk the Market and Lake Hylia A/B
    against main, expecting a gain of the same order and no crash.
  • 3 or more runs a side, and Hyrule Field, on this PC (by hand).
  • A clean build of main against this PR: build time and size (by hand).
  • A long play session (an hour or more, cutscenes and bosses) for anything a NaN's encoding could change, expecting
    nothing different from main (by hand).
  • mise run test (by hand).

Measurements

Verdict: +12% fps at the Market and +7% at Lake Hylia; every run of this PR beats every run of main in both scenes.
Two runs a side: the base drifts a few fps between sessions, so more runs are owed (Still to test).

Setup: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window, render resolution 67%, V-Sync off,
uncapped (HOS_FPS_MAX=1000), dev.py ab, 60 s measured after the warm-up, A1 B1 A2 B2. game_ms is the frame
trace's game loop.

Before: main @ a2dc5385 (v3.1.1) After: this PR @ 659c7ebe (smoke: 388fa3cb)
Market fps (2 runs) 52.7, 54.7 60.0, 60.0
Market median / p99 frame 18.11 / 42.51, 18.02 / 25.02 ms 16.33 / 23.62, 16.34 / 22.43 ms
Market 1% low 23.5, 40.0 fps 42.3, 44.6 fps
Market game_ms (median) 17.6, 17.6 15.8, 15.8
Lake Hylia fps (2 runs) 50.8, 52.6 55.3, 55.5
Lake Hylia median / p99 frame 19.03 / 29.93, 18.78 / 25.06 ms 17.72 / 25.04, 17.69 / 24.36 ms
Lake Hylia game_ms (median) 17.9, 17.6 14.2, 13.6
Lake Hylia GPU wait (mean) 0.50, 0.50 ms 1.79, 2.06 ms
longshot.exe 583,513,088 bytes 522,566,144 bytes
Market fps, smoke pair on the head (30 s) 52.4 60.0 (388fa3cb)

The Market's 60.0 is not a cap: 17% of this PR's frames there are under 15 ms. At Lake Hylia the game's loop is 22%
shorter but the frame only 7%: the wait for the GPU's previous frame grows, so the render chain holds the frame there.

Build: this PR's pack compiled all of the game code in 664 s (11:28 with the rest); a clean build of each side is
still to measure.

Risks

  • A path that reads FPSR gets the host's flags, not Arm's. Found nowhere in play (above); the proof build is owed.
  • NaN encodings follow x86: the default NaN is 0xFFC00000 (Arm 0x7FC00000), and which operand's NaN an op
    passes on can differ. Code that stores a NaN and then tests its sign bit would see a difference. Not seen.
  • Under FZ, a result that rounds up to exactly 2^-126 (x86 detects tininess after rounding, Arm before).
  • Host code a guest thread runs (a host call) sees its FTZ/DAZ while the game has FZ on.
  • Off: RX_FP_NATIVE=0 at build time builds the exact headers again. A player notices nothing after updating but the
    speed (the game is built again, as for any change to the game code).

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). Not run yet.
  • 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 switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
    RX_FP_NATIVE is a build switch, read by nx2/build.py: its row is in docs/dev/reference/build.md (as
    A64_FASTFP's), not switches.def. On by default from the first push.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows built; Linux not yet.
  • 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 The lifter keeps every float result of the game bit for bit with Arm **including FPSR's cumulative exception flags** (IOC, DZC, OFC, UFC, IXC, IDC). Each float op computes the native result and then proves it raised no flag FPSR lacks, else runs a software body. The fast float regions (`nx2/fastfp.py`) run their ops as `asm volatile` inside an MXCSR window, with a register snapshot and an exact copy of the whole region to fall back to. The vector forms (`nx2/vecfp.py`) keep a lane only where it is provably Arm's. That is about 730,000 sites in the lifted code. It comes from the a64-kit and suyu translator's standard, "registers + NZCV + V regs + FPSR + memory: 0 differences from Unicorn", which a general translator needs because it cannot know whether a program reads FPSR. This game doesn't read it during play: - Its FPSR reads (8, an MRS each) are in 6 functions: the C library's floating-point environment routines beside `memcpy` (`f_8575d1d4`, `f_8575d1e4`, `f_8575d1fc`, `f_8575d214`, `f_857f71f0`) and two others (`f_851109b8`, `f_85110e58`). None of them is in `nx2/ran_funcs.txt`, the coverage of a 100-minute play session (77,725 functions). - The host never reads it: it is only copied to a new fiber and printed in the thread dump (`host/hos_thread.c`). - FPSR is `0x9f` in play, every flag set (#2036 found the same), so the bookkeeping keeps re-proving flags that stay set. FPCR is different and is kept: the game sets flush-to-zero itself (`f_8169d350`, a setFlushToZero that play runs). This PR compiles the lifted code against copies of the lift's two float headers (`nx2/fp_native.py`, written by `nx2/build.py` and put ahead of the lift's on the include path) in which: - every FPX1 keep test and the vector keep tests are true, so each op is its plain host op; - the fast float regions' ops are plain intrinsics, with no MXCSR window, guard or exact copy; - the host thread's MXCSR follows FPCR.FZ (FTZ and DAZ): after every lifted MSR FPCR (through the `RECOMP_FPX_INHIBIT` token each such write ends with) and at a fiber's start, which inherits its creator's FPCR (`fiber_main`). Conversions, min/max, compares and the FRECPE/FRSQRTE estimates keep their exact code. The translation itself doesn't change (compile only, not in the lift key). `RX_FP_NATIVE=0` builds the headers as before. The result: Market +12% fps and Lake Hylia +7% on a Ryzen 9 3900X; the game's own loop is 10-22% shorter, and at the lake the render chain then becomes the limit. The executable is 61 MB (10%) smaller. Read first: `nx2/fp_native.py`, the hunks in `nx2/build.py`, `fiber_main` in `host/hos_thread.c`. Related open work, which keeps FPSR exact and which this would change: - #2152 (float wrappers as leaves) and #2067 (FADDP and FSQRT fast paths) speed up the bookkeeping this removes. - #2068 (FRECPE/FRSQRTE table) is still needed: the estimates keep their exact code here. - #2036, #1910, #1904 (cloth, crowd and libm on host code) still gain from real SIMD and fewer context loads, but their FPSR handling (lanes kept for their flags, MXCSR read-backs, flag declines) and their gains against main would change. No PR, issue or review found gives a reason FPSR must stay exact. Prior work searched: FPSR, fastfp, fpx, MXCSR, "native float", vecfp, fpxkeep, "exact float". ## Testing **Tested:** Windows 11, Ryzen 9 3900X, RTX 3080 10 GB (NVIDIA 621.14), 3440x1440 window at 67% render resolution, V-Sync off, uncapped. A/B by `dev.py ab` against the base of v3.1.1 (a2dc5385): the Market and Lake Hylia, 2 runs a side each, interleaved (at 659c7ebe; the head only adds the fiber's MXCSR at its start), plus a 30 s smoke pair at the Market on the head, 388fa3cb (with the fiber change). Every run reached its scene and played its 60 s; no crash, nothing wrong seen in the window. Played by hand at the Market for a few minutes, uncapped. **Still to test:** - Proof that the FPSR readers never run: a build that logs once if any of the 6 functions runs, through long play sessions (all ages, cutscenes, minigames, saves and loads), expecting no line (by hand, then the Test Farm). - Linux (RADV and NVIDIA), the Steam Deck, an Intel CPU and an AMD GPU: `@Beanstalk` the Market and Lake Hylia A/B against main, expecting a gain of the same order and no crash. - 3 or more runs a side, and Hyrule Field, on this PC (by hand). - A clean build of main against this PR: build time and size (by hand). - A long play session (an hour or more, cutscenes and bosses) for anything a NaN's encoding could change, expecting nothing different from main (by hand). - `mise run test` (by hand). ## Measurements **Verdict:** +12% fps at the Market and +7% at Lake Hylia; every run of this PR beats every run of main in both scenes. Two runs a side: the base drifts a few fps between sessions, so more runs are owed (Still to test). Setup: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window, render resolution 67%, V-Sync off, uncapped (`HOS_FPS_MAX=1000`), `dev.py ab`, 60 s measured after the warm-up, A1 B1 A2 B2. `game_ms` is the frame trace's game loop. | | Before: main @ a2dc5385 (v3.1.1) | After: this PR @ 659c7ebe (smoke: 388fa3cb) | |---|---|---| | Market fps (2 runs) | 52.7, 54.7 | 60.0, 60.0 | | Market median / p99 frame | 18.11 / 42.51, 18.02 / 25.02 ms | 16.33 / 23.62, 16.34 / 22.43 ms | | Market 1% low | 23.5, 40.0 fps | 42.3, 44.6 fps | | Market `game_ms` (median) | 17.6, 17.6 | 15.8, 15.8 | | Lake Hylia fps (2 runs) | 50.8, 52.6 | 55.3, 55.5 | | Lake Hylia median / p99 frame | 19.03 / 29.93, 18.78 / 25.06 ms | 17.72 / 25.04, 17.69 / 24.36 ms | | Lake Hylia `game_ms` (median) | 17.9, 17.6 | 14.2, 13.6 | | Lake Hylia GPU wait (mean) | 0.50, 0.50 ms | 1.79, 2.06 ms | | `longshot.exe` | 583,513,088 bytes | 522,566,144 bytes | | Market fps, smoke pair on the head (30 s) | 52.4 | 60.0 (388fa3cb) | The Market's 60.0 is not a cap: 17% of this PR's frames there are under 15 ms. At Lake Hylia the game's loop is 22% shorter but the frame only 7%: the wait for the GPU's previous frame grows, so the render chain holds the frame there. Build: this PR's pack compiled all of the game code in 664 s (11:28 with the rest); a clean build of each side is still to measure. ## Risks - **A path that reads FPSR** gets the host's flags, not Arm's. Found nowhere in play (above); the proof build is owed. - **NaN encodings** follow x86: the default NaN is `0xFFC00000` (Arm `0x7FC00000`), and which operand's NaN an op passes on can differ. Code that stores a NaN and then tests its sign bit would see a difference. Not seen. - **Under FZ**, a result that rounds up to exactly 2^-126 (x86 detects tininess after rounding, Arm before). - **Host code** a guest thread runs (a host call) sees its FTZ/DAZ while the game has FZ on. - Off: `RX_FP_NATIVE=0` at build time builds the exact headers again. A player notices nothing after updating but the speed (the game is built again, as for any change to the game code). ## 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. - [ ] `mise run test` passes (any failure that also fails on `main` is named). Not run yet. - [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 - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. `RX_FP_NATIVE` is a build switch, read by `nx2/build.py`: its row is in `docs/dev/reference/build.md` (as `A64_FASTFP`'s), not `switches.def`. On by default from the first push. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Windows built; Linux not yet. - [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)
The game reads FPSR in no function play runs and FPCR stays 0, so the FPX1 guards, the fast
float regions' MXCSR windows and exact copies, and the vector keep tests only keep flags nobody
reads. This builds native copies of the lift's two float headers ahead of the lift's own, to
measure what that layer costs. Not a product: NaN encodings and FPSR are no longer Arm's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The game sets FZ itself (f_8169d350, a setFlushToZero that play runs), so native float ops need
FTZ and DAZ where Arm flushes. Each lifted MSR FPCR now syncs MXCSR after the write, through the
RECOMP_FPX_INHIBIT token every such write ends with: no new lift.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
exp(lift): RX_FP_NATIVE sets a new fiber's MXCSR from the FPCR it inherits; its row in build.md
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 13s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Website build and checks (pull_request) Failing after 1m32s
388fa3cb02
A fiber takes its creator's FPCR (fiber_switch) but a float state of its own (FIBER_FLAG_FLOAT_SWITCH):
fiber_main now syncs MXCSR from FZ before the fiber's first instruction. The host files see the native
headers too, so the sync compiles only where RX_FP_NATIVE is on.

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

Tested in game: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window at 67%, V-Sync off, uncapped. dev.py ab against the v3.1.1 base (a2dc5385): Market 52.7/54.7 -> 60.0/60.0 fps and Lake Hylia 50.8/52.6 -> 55.3/55.5 fps (2 runs a side, at 659c7ebe), and a Market smoke pair on the head 388fa3cb: 52.4 -> 60.0 fps. Every run reached its scene and played through; no crash, nothing wrong seen in the window.

Tested in game: Windows 11, Ryzen 9 3900X, RTX 3080 (NVIDIA 621.14), 3440x1440 window at 67%, V-Sync off, uncapped. dev.py ab against the v3.1.1 base (a2dc5385): Market 52.7/54.7 -> 60.0/60.0 fps and Lake Hylia 50.8/52.6 -> 55.3/55.5 fps (2 runs a side, at 659c7ebe), and a Market smoke pair on the head 388fa3cb: 52.4 -> 60.0 fps. Every run reached its scene and played through; no crash, nothing wrong seen in the window.
Member

Possibly related, for context:

  • PR #1782 perf(lift): SSE fast paths for the float forms the translator does lane by lane (A64_VECFP) — Merged vector float fast paths with exact FPSR checks that this changes
  • PR #38 perf(lift): fast float regions, plain SSE checked once by MXCSR with the exact copy as fallback — Merged fast-float-region implementation whose exact guard and fallback this removes
Possibly related, for context: - PR #1782 perf(lift): SSE fast paths for the float forms the translator does lane by lane (A64_VECFP) — Merged vector float fast paths with exact FPSR checks that this changes - PR #38 perf(lift): fast float regions, plain SSE checked once by MXCSR with the exact copy as fallback — Merged fast-float-region implementation whose exact guard and fallback this removes
dazemc left a comment

The switch defaults on, but the FPCR side mirrors only FZ and the evidence that the game never depends on the rest is one 100-minute coverage file with no proof build.

RECOMP_FPX_OPEN used to require FPSR.IXC set and FPCR clear of everything in RECOMP_FPX_FPCR_MASK — rounding mode, DN, AHP, FZ16 and the trap bits — before an op took the fast path. nx2/fp_native.py forces that gate, and the KEEP/FIN/BIG/FZ* tests, to true. It mirrors only FPCR.FZ into MXCSR (FTZ/DAZ); it does not mirror FPCR.RMode or DN. The six functions that read FPSR (f_8575d1d4, f_8575d1e4, f_8575d1fc, f_8575d214, f_857f71f0, f_851109b8, f_85110e58) are the libc fenv routines — exactly the ones that can call fesetround/feholdexcept/fesetenv. Their absence from nx2/ran_funcs.txt is one 100-minute session, not a proof: a cutscene, minigame or save path that calls one of them, or a lifted block that reads FPSR, now sees the host's flags and rounding, not Arm's. The PR's own Still-to-test says the proof build is owed; until it runs, "the game never reads FPSR" is a coverage claim, not a demonstrated one.

NaN/denormal: the native path keeps x86 NaN encodings (default 0xFFC00000 vs Arm 0x7FC00000, and a different operand's NaN), and under FZ the x86 after-rounding tininess differs from Arm's before-rounding at exactly 2^-126; both are acknowledged and untested. The global FTZ/DAZ also reaches host code a guest thread runs, not just the float regions.

Test: there is no test for nx2/fp_native.py at all — not the header rewrites, not RX_FP_NATIVE=0, not a byte-identity check, not an FPSR-reader trap, not a NaN/denormal case; mise run test has not run. The regex patcher does fail if a header line moves, which is a guard, but it is not a test of the resulting semantics.

Off path: RX_FP_NATIVE=0 skips the copies and the host #ifdef; the generated headers should be the lift's own, but nothing checks them, and the build is not literally byte-identical to main because the changed host/hos_thread.c/nx2/build.py move the source fingerprint and version string. "Same headers" is the right claim; "byte-identical" is not demonstrated.

Measurements: the A/B is at 659c7ebe, not at this head 388fa3cb; the head only adds the fiber's MXCSR and has a single 30 s Market smoke pair. The before is current main a2dc5385 (post-#2174), which is right; the Lake Hylia A/B is not at the head.

No approval, no fix claim. The core idea may be sound for this game, but the default-on switch rests on a coverage snapshot and no game-free test of the semantics it removes.

**The switch defaults on, but the FPCR side mirrors only FZ and the evidence that the game never depends on the rest is one 100-minute coverage file with no proof build.** `RECOMP_FPX_OPEN` used to require `FPSR.IXC` set and `FPCR` clear of everything in `RECOMP_FPX_FPCR_MASK` — rounding mode, DN, AHP, FZ16 and the trap bits — before an op took the fast path. `nx2/fp_native.py` forces that gate, and the `KEEP`/`FIN`/`BIG`/`FZ*` tests, to true. It mirrors only `FPCR.FZ` into MXCSR (FTZ/DAZ); it does **not** mirror FPCR.RMode or DN. The six functions that read FPSR (`f_8575d1d4`, `f_8575d1e4`, `f_8575d1fc`, `f_8575d214`, `f_857f71f0`, `f_851109b8`, `f_85110e58`) are the libc fenv routines — exactly the ones that can call `fesetround`/`feholdexcept`/`fesetenv`. Their absence from `nx2/ran_funcs.txt` is one 100-minute session, not a proof: a cutscene, minigame or save path that calls one of them, or a lifted block that reads FPSR, now sees the host's flags and rounding, not Arm's. The PR's own Still-to-test says the proof build is owed; until it runs, "the game never reads FPSR" is a coverage claim, not a demonstrated one. **NaN/denormal:** the native path keeps x86 NaN encodings (default `0xFFC00000` vs Arm `0x7FC00000`, and a different operand's NaN), and under FZ the x86 after-rounding tininess differs from Arm's before-rounding at exactly 2^-126; both are acknowledged and untested. The global FTZ/DAZ also reaches host code a guest thread runs, not just the float regions. **Test:** there is no test for `nx2/fp_native.py` at all — not the header rewrites, not `RX_FP_NATIVE=0`, not a byte-identity check, not an FPSR-reader trap, not a NaN/denormal case; `mise run test` has not run. The regex patcher does fail if a header line moves, which is a guard, but it is not a test of the resulting semantics. **Off path:** `RX_FP_NATIVE=0` skips the copies and the host `#ifdef`; the generated headers should be the lift's own, but nothing checks them, and the build is not literally byte-identical to main because the changed `host/hos_thread.c`/`nx2/build.py` move the source fingerprint and version string. "Same headers" is the right claim; "byte-identical" is not demonstrated. **Measurements:** the A/B is at `659c7ebe`, not at this head `388fa3cb`; the head only adds the fiber's MXCSR and has a single 30 s Market smoke pair. The before is current main `a2dc5385` (post-#2174), which is right; the Lake Hylia A/B is not at the head. No approval, no fix claim. The core idea may be sound for this game, but the default-on switch rests on a coverage snapshot and no game-free test of the semantics it removes.
Contributor

Correction on the FPSR evidence: the description says the 8 FPSR reads are in "6 functions" but names seven: f_8575d1d4, f_8575d1e4, f_8575d1fc, f_8575d214, f_857f71f0, f_851109b8, f_85110e58. The proof build should name every one; the exact list matters to the claim that none runs in play.

**Correction on the FPSR evidence:** the description says the 8 FPSR reads are in "6 functions" but names seven: `f_8575d1d4`, `f_8575d1e4`, `f_8575d1fc`, `f_8575d214`, `f_857f71f0`, `f_851109b8`, `f_85110e58`. The proof build should name every one; the exact list matters to the claim that none runs in play.
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The default-on rewrite can return incorrect vector min/max results and breaks builds using supported lift switches. The performance results are promising on the tested Windows PC, but the final head and other affected systems need further runs.

The change removes much of the lifted code’s floating-point bookkeeping and reports a substantial speedup, at the cost of weaker Arm floating-point semantics and a new build switch. The rewrite also removes a guard needed for correct vector min/max results.

Blocking (2): must change before merging.

  1. L1 nx2/fp_native.py:60: Forcing a64_vx_none to succeed also disables the correctness guard for vector min/max, although those operations are meant to remain exact. (more on the line) Do: Keep the original bad-lane check for min/max, and restrict any unconditional acceptance to the arithmetic helpers whose behavior is intentionally changed. Add a game-free behavioral test covering NaNs and FZ subnormals.
  2. L2 nx2/fp_native.py:60: The patcher requires helpers that supported lift configurations deliberately omit. (more on the line) Do: Make rewrites conditional on the corresponding generated helper being present, while still rejecting unexpected partial or changed helper definitions; cover both supported off modes in a game-free test.

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

  • L3: The final head needs repeated performance and gameplay runs across the platforms affected by this default-on float rewrite. When: The two-scene A/B measurements precede the fiber MXCSR change, and Linux, Steam Deck and other CPU configurations have no reported run. The current evidence cannot show whether the final build works and retains its gain on those systems. Do: Run repeated interleaved A/B tests on the final head in the named scenes and exercise longer gameplay on Windows and Linux, including Steam Deck and the affected Tier 1 hardware.
  • L4: The assumption that gameplay never observes the removed FPSR bookkeeping needs the planned coverage run. When: The cited 100-minute coverage does not include all gameplay paths; if a later path reads FPSR, it observes flags that native operations no longer maintain. Do: Instrument all seven named FPSR-reading functions and exercise long play sessions including saves, loads, minigames, cutscenes and bosses. (@fix does its part first: Add the proposed one-time reader instrumentation so the run can identify an observed read.)

@fix can do L1, L2 and L4.

Checks: Failing on this head, which is behind its base, where they pass: Guide screenshots / Guide images and local UI source review (pull_request), CI / Website build and checks (pull_request). @rebase (or @fix) brings it up to date and runs them again; not held against it.

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

Does it help: Unproven on the final head across the affected systems. On Windows with a Ryzen 9 3900X and RTX 3080, the PR reports two interleaved runs per side at 659c7ebe: Market 52.7/54.7 to 60.0/60.0 fps and Lake Hylia 50.8/52.6 to 55.3/55.5 fps. The final head has only one 30-second Market smoke pair, 52.4 to 60.0 fps.

Other systems: The rewritten float operations run throughout the lifted game on Windows and Linux, across CPU vendors and GPUs. The reported runs cover Windows on one AMD CPU and NVIDIA GPU; Linux, Steam Deck, other CPUs and longer gameplay remain untested. The MXCSR change also affects host code called on guest threads.

Switches: RX_FP_NATIVE is added as a build-time switch, on by default, with an off setting documented in docs/dev/reference/build.md. Its default has promising measurements on one PC but needs broader validation; it also currently breaks builds combined with A64_FASTFP=0 or A64_VECFP=0.

Reviewed: 388fa3cb02 against a2dc538590: Read the supplied PR description, comments and review, repository rules and PR template, the complete diff and commit messages, nx2/fp_native.py, and relevant portions of the build, float generation, vector helpers, thread and fiber code. Skimmed docs/dev/reference/build.md and docs/dev/standards.md. The full nx2/build.py and host/hos_thread.c were not read; no recorded runs, translations or generated files were changed.; nothing run (a code review).

Checked and fine:

  • Each commit includes an AI-assistance trailer.
  • The diff adds no game-derived output or generated file.
  • The build-time switch is documented outside the runtime switch table.
  • CI reports no failure unique to this head.

Testing: No code or tests were run, as requested. The PR reports Windows gameplay and A/B results; its own test suite and Linux build remain outstanding.

Overlaps and merge order: The description identifies related open work: #2152 and #2067 optimize bookkeeping this change removes; #2068 remains relevant, while #2036, #1910 and #1904 would need their FPSR handling and gains reassessed.


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

**Recommendation: Request changes.** The default-on rewrite can return incorrect vector min/max results and breaks builds using supported lift switches. The performance results are promising on the tested Windows PC, but the final head and other affected systems need further runs. The change removes much of the lifted code’s floating-point bookkeeping and reports a substantial speedup, at the cost of weaker Arm floating-point semantics and a new build switch. The rewrite also removes a guard needed for correct vector min/max results. **Blocking (2)**: must change before merging. 1. **L1** `nx2/fp_native.py:60`: Forcing a64_vx_none to succeed also disables the correctness guard for vector min/max, although those operations are meant to remain exact. (more on the line) **Do:** Keep the original bad-lane check for min/max, and restrict any unconditional acceptance to the arithmetic helpers whose behavior is intentionally changed. Add a game-free behavioral test covering NaNs and FZ subnormals. 2. **L2** `nx2/fp_native.py:60`: The patcher requires helpers that supported lift configurations deliberately omit. (more on the line) **Do:** Make rewrites conditional on the corresponding generated helper being present, while still rejecting unexpected partial or changed helper definitions; cover both supported off modes in a game-free test. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3**: The final head needs repeated performance and gameplay runs across the platforms affected by this default-on float rewrite. *When:* The two-scene A/B measurements precede the fiber MXCSR change, and Linux, Steam Deck and other CPU configurations have no reported run. The current evidence cannot show whether the final build works and retains its gain on those systems. **Do:** Run repeated interleaved A/B tests on the final head in the named scenes and exercise longer gameplay on Windows and Linux, including Steam Deck and the affected Tier 1 hardware. - **L4**: The assumption that gameplay never observes the removed FPSR bookkeeping needs the planned coverage run. *When:* The cited 100-minute coverage does not include all gameplay paths; if a later path reads FPSR, it observes flags that native operations no longer maintain. **Do:** Instrument all seven named FPSR-reading functions and exercise long play sessions including saves, loads, minigames, cutscenes and bosses. *(`@fix` does its part first: Add the proposed one-time reader instrumentation so the run can identify an observed read.)* `@fix` can do L1, L2 and L4. **Checks:** Failing on this head, which is behind its base, where they pass: `Guide screenshots / Guide images and local UI source review (pull_request)`, `CI / Website build and checks (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs them again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven on the final head across the affected systems. On Windows with a Ryzen 9 3900X and RTX 3080, the PR reports two interleaved runs per side at 659c7ebe: Market 52.7/54.7 to 60.0/60.0 fps and Lake Hylia 50.8/52.6 to 55.3/55.5 fps. The final head has only one 30-second Market smoke pair, 52.4 to 60.0 fps. **Other systems:** The rewritten float operations run throughout the lifted game on Windows and Linux, across CPU vendors and GPUs. The reported runs cover Windows on one AMD CPU and NVIDIA GPU; Linux, Steam Deck, other CPUs and longer gameplay remain untested. The MXCSR change also affects host code called on guest threads. **Switches:** RX_FP_NATIVE is added as a build-time switch, on by default, with an off setting documented in docs/dev/reference/build.md. Its default has promising measurements on one PC but needs broader validation; it also currently breaks builds combined with A64_FASTFP=0 or A64_VECFP=0. **Reviewed:** 388fa3cb0278 against a2dc53859018: Read the supplied PR description, comments and review, repository rules and PR template, the complete diff and commit messages, nx2/fp_native.py, and relevant portions of the build, float generation, vector helpers, thread and fiber code. Skimmed docs/dev/reference/build.md and docs/dev/standards.md. The full nx2/build.py and host/hos_thread.c were not read; no recorded runs, translations or generated files were changed.; nothing run (a code review). **Checked and fine:** - Each commit includes an AI-assistance trailer. - The diff adds no game-derived output or generated file. - The build-time switch is documented outside the runtime switch table. - CI reports no failure unique to this head. **Testing:** No code or tests were run, as requested. The PR reports Windows gameplay and A/B results; its own test suite and Linux build remain outstanding. **Overlaps and merge order:** The description identifies related open work: #2152 and #2067 optimize bookkeeping this change removes; #2068 remains relevant, while #2036, #1910 and #1904 would need their FPSR handling and gains reassessed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -0,0 +57,4 @@
"_mm_sub_ps((a), (b)) : (ins)[0] == 'm' ? _mm_mul_ps((a), (b)) : _mm_div_ps((a), (b)))")
FN = r"static inline __attribute__\(\(always_inline\)\) "
FPX = [
(r"^(A64_VX int a64_vx_none\(__m128i bad, int k\)) \{.*\}$", r"\1 { (void)bad; (void)k; return 1; }", 1),
Member

L1 (blocking): Forcing a64_vx_none to succeed also disables the correctness guard for vector min/max, although those operations are meant to remain exact.

When: For a vector FMAX with a NaN in the first operand and a finite second operand, a64_vfpx_minmax32v now accepts the lane and selects the finite second operand instead of falling back to Arm's NaN handling. With FZ enabled, subnormal operands can likewise bypass the guard and produce the wrong selected bits.

Do: Keep the original bad-lane check for min/max, and restrict any unconditional acceptance to the arithmetic helpers whose behavior is intentionally changed. Add a game-free behavioral test covering NaNs and FZ subnormals.

**L1** (blocking): Forcing a64_vx_none to succeed also disables the correctness guard for vector min/max, although those operations are meant to remain exact. *When:* For a vector FMAX with a NaN in the first operand and a finite second operand, a64_vfpx_minmax32v now accepts the lane and selects the finite second operand instead of falling back to Arm's NaN handling. With FZ enabled, subnormal operands can likewise bypass the guard and produce the wrong selected bits. **Do:** Keep the original bad-lane check for min/max, and restrict any unconditional acceptance to the arithmetic helpers whose behavior is intentionally changed. Add a game-free behavioral test covering NaNs and FZ subnormals.
Member

L2 (blocking): The patcher requires helpers that supported lift configurations deliberately omit.

When: With A64_VECFP=0, vecfp.py does not append a64_vx_none, so the first FPX substitution matches zero times and the default RX_FP_NATIVE build exits. With A64_FASTFP=0, fastfp.py omits FASTFP_HEADER and the required fast-region substitutions similarly abort the build.

Do: Make rewrites conditional on the corresponding generated helper being present, while still rejecting unexpected partial or changed helper definitions; cover both supported off modes in a game-free test.

**L2** (blocking): The patcher requires helpers that supported lift configurations deliberately omit. *When:* With A64_VECFP=0, vecfp.py does not append a64_vx_none, so the first FPX substitution matches zero times and the default RX_FP_NATIVE build exits. With A64_FASTFP=0, fastfp.py omits FASTFP_HEADER and the required fast-region substitutions similarly abort the build. **Do:** Make rewrites conditional on the corresponding generated helper being present, while still rejecting unexpected partial or changed helper definitions; cover both supported off modes in a game-free test.
Member

🤖 A note on overlap with #2355 (WIP).

#2355 shortens one path inside today's lifted float handling: the lane routes (a64_vfpx_*32_lanes) for a quiet-NaN lane beside normal lanes. That's the Havok cloth's case, worth 83.14 → 90.24 fps in Lost Woods (child), 3 pairs, 5700X3D, main 0e32bc10. It's behind a lift-time switch, A64_FPXKEEP_QUICK, off by default.

If this PR replaces that handling, #2355 becomes unnecessary. #2355 changes only nx2/fpxkeep.py; a build with both should be checked if both move forward.

🤖 Generated with Claude Code

🤖 A note on overlap with #2355 (WIP). #2355 shortens one path inside today's lifted float handling: the lane routes (`a64_vfpx_*32_lanes`) for a quiet-NaN lane beside normal lanes. That's the Havok cloth's case, worth 83.14 → 90.24 fps in Lost Woods (child), 3 pairs, 5700X3D, main 0e32bc10. It's behind a lift-time switch, `A64_FPXKEEP_QUICK`, off by default. If this PR replaces that handling, #2355 becomes unnecessary. #2355 changes only `nx2/fpxkeep.py`; a build with both should be checked if both move forward. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Contributor

Steam Deck numbers for this change, from a player. The same bench is described in full on #2308.

Steam Deck LCD, SteamOS 3.9.5, RADV. Local builds of a2dc5385 + this PR for RX_MARCH=znver2, with RX_FP_NATIVE on (fpn) vs RX_FP_NATIVE=0 (base). Market entrance, standing still, headless, 3 interleaved runs a side, 60 s windows:

base fpn B-A (range of runs)
game_ms median 14.92 12.53 -2.39 ms (-16 %) [-2.85, -0.65]
process CPU ms/frame 155.4 132.4 -23.0 [-39.2, -6.7]
BaseProcExecutor* CPU ms/frame 57.8 45.7 -12.1 [-20.9, -4.5]
ModuleSystemWorker* CPU ms/frame 37.4 32.3 -5.1 [-7.9, -2.0]
avg fps 20.91 21.20 +0.29 [-0.41, +1.56]

On the Deck this is the bigger half of the #2235 + #2308 stack: the play profile on top added only -0.07 ms of game_ms there.

fps did not move because this bench ran headless at 2560x1440 (see the correction below), where render_ms (~30-34 ms) bounds the frame. I'm repeating it at the Deck's 1280x800.

Nothing looked wrong in play. I have not done a pixel check of fpn against base yet; that is part of the re-run.

Correction: the bench did not render at 1920x1080. That is only the size of its offscreen present image. With no screen, the game's output resolution falls back to 2560x1440 (oe: output resolution 2560x1440 (none chosen: the game's) in every run's log), 3.6x the pixels of the Deck's own 1280x800. The bench now sets HOS_OUTPUT_RES=1280x800; the re-run follows.

Assisted-by: Claude

Steam Deck numbers for this change, from a player. The same bench is described in full on #2308. Steam Deck LCD, SteamOS 3.9.5, RADV. Local builds of a2dc5385 + this PR for `RX_MARCH=znver2`, with `RX_FP_NATIVE` on (`fpn`) vs `RX_FP_NATIVE=0` (`base`). Market entrance, standing still, headless, 3 interleaved runs a side, 60 s windows: | | base | fpn | B-A (range of runs) | |---|---|---|---| | `game_ms` median | 14.92 | 12.53 | **-2.39 ms (-16 %)** [-2.85, -0.65] | | process CPU ms/frame | 155.4 | 132.4 | -23.0 [-39.2, -6.7] | | BaseProcExecutor* CPU ms/frame | 57.8 | 45.7 | -12.1 [-20.9, -4.5] | | ModuleSystemWorker* CPU ms/frame | 37.4 | 32.3 | -5.1 [-7.9, -2.0] | | avg fps | 20.91 | 21.20 | +0.29 [-0.41, +1.56] | On the Deck this is the bigger half of the #2235 + #2308 stack: the play profile on top added only -0.07 ms of `game_ms` there. fps did not move because this bench ran headless at 2560x1440 (see the correction below), where render_ms (~30-34 ms) bounds the frame. I'm repeating it at the Deck's 1280x800. Nothing looked wrong in play. I have not done a pixel check of `fpn` against `base` yet; that is part of the re-run. **Correction:** the bench did not render at 1920x1080. That is only the size of its offscreen present image. With no screen, the game's output resolution falls back to 2560x1440 (`oe: output resolution 2560x1440 (none chosen: the game's)` in every run's log), 3.6x the pixels of the Deck's own 1280x800. The bench now sets `HOS_OUTPUT_RES=1280x800`; the re-run follows. Assisted-by: Claude
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 7s
PR description / Description follows the template (pull_request_target) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 11s
CI / Workflow lint (actionlint) (pull_request) Successful in 11s
Third-party parts / As their notes say (pull_request) Successful in 13s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Website build and checks (pull_request) Failing after 1m32s
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/fp-native:dyst-perf/fp-native'
git switch 'dyst-perf/fp-native'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 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!2235
No description provided.