perf(runtime): a correctly rounded FMA ahead of suyu's exact bodies on builds without FMA3 #1195

Merged
HumanBean merged 3 commits from brhode/Longshot:perf/fma-soft into main 2026-11-18 19:47:15 +00:00
Contributor

Type: perf · Risk: medium · Tested on: Linux (Ubuntu 24.04), RTX 3060, i7-3770 (no AVX2) · Needs: Windows, any CPU without AVX2

Why

A CPU without AVX2 (Ivy Bridge and older Intel, AMD before Excavator) gets an x86-64-v2 build, which has no hardware fused multiply-add. Every guest FMA there runs suyu's exact multi-word integer routine (recomp_fpe_fma64, about 180 ns a call, two 1 KB arrays zeroed on each), and on an i7-3770 that was 13.7 % of one core (4.5 ms of CPU a frame) in a sampled profile of rc.5. With this change the common case takes a correctly rounded fast path of a few nanoseconds with the same result and the same FPSR, and the game runs about 5 % faster on that CPU. Nothing changes on a CPU with AVX2 (the code is not compiled in).

What changed

The exact bodies stay as they are; a fast path in front of them handles the common case and hands everything else on. It exists only in a build without FMA3, so players on newer CPUs are not touched.

  • nx2/fma_soft.h (new): recomp_fma_soft64 / recomp_fma_soft32: a correctly rounded FMA (Veltkamp split and Dekker's exact product, TwoSum, rounding to odd, then one rounding to nearest; binary32 through binary64). It returns 0, meaning "take the exact body", for any FPCR control bit but FZ, a zero, subnormal, infinite or NaN operand, an exponent range where it could not prove the result, and a result near the range limits. It raises the inexact flag when the result is inexact. Compiled only where RECOMP_FPX_FMA64 is 0 on an x86-64 SSE2 host.
  • nx2/suyu_rt_fixes.py: wraps a64_rtgen.runtime_c the way it already wraps runtime_h: the header's text goes in after #include "a64.h" and an early exit at the top of recomp_fpe_fma32 / recomp_fpe_fma64, each substitution required to match exactly once. third_party/ is untouched.
  • tests/test_fma_soft.py, tests/fma_soft_test.c (new): the generated runtime built the way the lift builds it; the exact body (early exit off) against the early exit on the same operands and the same GuestContext, comparing the result and every byte of the context.
  • nx2/make_game.py: HOS_FMA_FAST in LIFT_ENV_NOT_OUTPUT (the switch is read by the generated C at play, as HOS_NO_FASTFP is), which tests/test_lift_cache.py requires of every variable a lift source names.
  • docs/development.md: the HOS_FMA_FAST=0 switch.
  • docs/tested/: two run files for the measurements below (separate commit).

rc.5's own float regions (#38) and a64_fpx_fma32_fma32 already handle most single-precision FMAs without FMA3 (in a double-precision product and sum with a midpoint check), so on current main this change acts mostly on the double-precision FMA: recomp_fpe_fma64 went from 13.7 % to 2.9 % of a core and recomp_fpe_fma32 from 2.6 % to 1.3 % (sampled profiles, three passes each).

Measurements

Verdict: about 5 % more frames a second on an i7-3770: the game's own fps counter went from a median of 29.55 to 31.0 (+4.9 %; +5.1 % by the mean) with the fast path on, in 4 of 4 alternated pairs of the same binary, every run on above every run off. The presented frames a second (RX_VK_FRAME_LOG, which counts frames frame generation shows too) rose by 1.9 % (+0.76 ± 0.27 fps, 95 %): the CPU saving shows in the frames the game computes, less in the frames the GPU adds. An earlier run of 3 pairs agreed in direction (+5.3 %, its 95 % interval just holds 0), and on rc.3 two independent same-binary comparisons gave +3.1 % and +4.5 % (6 of 6 pairs positive).

UPDATE: On rc.6 (v3.0.0-rc.6 with this change rebased on it, same PC and scene, 4 runs each ABBA, docs/tested/2026-11-17-fma-soft-brhode-run03.md): the game's own fps counter 29.95 -> 31.3 (+4.5 %, 4 of 4 pairs, +1.35 +- 0.28 fps); presented frames +1.24 +- 0.11 fps (+3.3 %). The effect holds on current code.

Hardware: Ubuntu 24.04.5 (kernel 6.8.0-149) in a Proxmox VM, RTX 3060 12 GB (driver 595.99.02), i7-3770 (4 cores, 8 threads; 7 vCPUs given to the VM), 28 GB DDR3, X11 at 1920x1080.
Scene: the Deku Tree autosave, a scripted walk of about 3 minutes, 1920x1080, HOS_FPS_MAX=240 (cap off), HOS_VCORES=0, RX_VK_WB_MAX_KB=1024; shaders prepared first.
Method: the game's "game fps avg" per run (the bench's reading of longshot_log.txt) and the per-present frame times (RX_VK_FRAME_LOG, the first 30 s of each run dropped); 4 runs of each variant alternated ABBA-style (off, on, on, off, off, on, on, off), the median; the 95 % intervals are Student's t over the runs. The executable is built from source with nx2/build.py --standalone (x86-64-v2) against the game's lifted code of v3.0.0-rc.5, so "off" is this PR's binary with HOS_FMA_FAST=0, the same code as main's path.
How to reproduce: build the game with make_game.py (a CPU without AVX2), then build the executable of this branch and of main against that folder's work folder and run the scene with and without HOS_FMA_FAST=0; the lab scripts and the raw lines are in docs/tested/2026-11-16-fma-soft-brhode-run01.md and run02.md.

Baseline: the "Before" column is v3.0.0-rc.5 as make_game.py built it (main e4d035e9, nine commits before 3e4e7cab; those commits are docs, the website, the launcher, the 30 fps cap (host/nn_vi.c, the menu), nx2/make_game.py, the job queue scripts and tests: nothing in the float runtime); the cleaner comparison for the same code is the "off" column. The two "After" columns pool the 3 pairs of the first job and the 4 pairs of the second (7 runs each).

Before: rc.5 stock @ e4d035e9 (3 runs) After, HOS_FMA_FAST=0: this PR @ 6027b7a7 (7 runs) After: this PR @ 6027b7a7 (7 runs)
game fps (median) 29.0 29.0 30.9
game fps (mean) 29.07 29.20 30.71
on-CPU in recomp_fpe_fma64 (sampled) 13.73 % of a core not sampled 2.85 % of a core
f5  (3 pairs)  rc5 stock 28.4 29.8 29.0 | on 29.9 30.1 31.0 | off 28.7 29.0 28.7        game fps avg
f5b (4 pairs)  off 28.9 30.0 29.5 29.6 | on 30.7 31.1 30.9 31.3                          game fps avg
f5b presents   v1 (off) 39.56 +- 0.36 [39.24-39.77]  v2 (on) 40.32 +- 0.21 [40.16-40.48]  paired +0.76 +- 0.27 fps
profile        rc.5 stock: total on-CPU 340 %, recomp_fpe_fma64 13.73 %, recomp_fpe_fma32 2.59 %
               this PR:    total on-CPU 346 %, recomp_fpe_fma64  2.85 %, recomp_fpe_fma32 1.26 %

Flags and settings

One switch is added.

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
HOS_FMA_FAST The correctly rounded FMA in front of suyu's exact bodies, off with 0 did not exist (the exact body every time) on, only in a build without FMA3 about 5 % more game frames a second on an i7-3770 helps x86-64-v2 builds (CPUs without AVX2); not in an x86-64-v3 build (the code is not compiled in), not on non-x86; Windows builds untested (the same C) on for everyone (the default); 0 is for comparisons

Testing

Tested: python -I -B tests/test_fma_soft.py: 10.3 M random and 8.2 M edge-sweep calls, 0 mismatches in the result and in the whole GuestContext, in both widths (the early exit is taken on about a quarter of the random calls, and the guard edges are drawn on purpose); the test fails when the inexact flag, the rounding to odd or the FPCR gate is taken out; python -I -B tests/run_all.py on main 71b1edd8 and on this branch: 25 failures on main (the Linux build-tool and game-file tests of a VM without the toolchain and the NUP cache) and the same 25 here, plus tests/test_lift_cache.py on the first run of this branch, which named HOS_FMA_FAST as a variable a lift source reads: it is in LIFT_ENV_NOT_OUTPUT now and that test passes (rerun alone; the full run was not repeated after that one line); tests/test_fpx_sticky.py and tests/test_fastfp_override.py pass with the new runtime; tests/test_tested_configurations.py passes. The measurements below are of this change on main 3e4e7cab, before the rebase onto 71b1edd8 (the 18 commits between are lift speed, the menu, the release scripts and renderer fixes, none in the float runtime), so the commit named in them is the unrebased one; the rebased tests above are the ones run on 71b1edd8. The branch was then rebased once more onto main 55e8fbd5 (6 commits: renderer changes, a lift memory change and run files; docs/development.md and docs/tested/ merged without a conflict), and tests/test_fma_soft.py, tests/test_lift_cache.py and tests/test_tested_configurations.py were run again: they pass; the full run was not repeated. In the game: the scene above with the fast path on and off, 14 runs of this binary on rc.5 (7 on, 7 off), no crash; on rc.3 an earlier build of the same change ran a soak of 8 runs with no crash.

Not tested: Windows (the C is the same and builds with the same flags; no run there); an x86-64-v3 machine running the test (the v3 build compiles with the early exit out, and the test's run is skipped on a CPU with AVX2); any scene other than the one measured. The operand exponent limits and the power-of-two exclusion are margins the test cannot show (the test's docstring says so).

Must be tested:

  • Windows, any CPU without AVX2 (Ivy Bridge or older): build the game, start a new file and walk in the Deku Tree for a minute with and without HOS_FMA_FAST=0, expecting the same game and no crash (by hand: a tester with such a CPU, or the Test Farm if it has a runner without AVX2: ask in a comment on the PR)

Risks

What could break: a wrong early-exit result would be a wrong float in the game's physics or animation, on CPUs without AVX2 only. It was tested bit for bit against the exact body, FPSR included, and everything outside the proven range falls through to the exact body. The rounding mode other than nearest, and every special value, take the exact body.

Turning it off: HOS_FMA_FAST=0, or revert the commit.

Compatibility: Nothing changes for a player's saves, options file or shader caches. The first update to a build with this change translates the game again on every PC, whatever the CPU: the generated runtime (a64_suyu.c) is written by the lift, and the lift key hashes nx2/suyu_rt_fixes.py and the new nx2/fma_soft.h (lift_key, lift_sources). I have not timed that re-translation on this PC. The executable is built again too. EDIT: Timed on the author's PC (i7-3770, 7 vCPUs, Ubuntu 24.04, 6 compile jobs; a built game folder, its kept work folder, make_game.py --update) with the code change in nx2/fma_soft.h, which is what this PR's first update is: 4 min 12 s in all, 191 s of translation and 37 s of compiling; 514 of the 517 compile units come from the object cache and 3 (a64_suyu.c, hos_main.c, vk_menu.cpp) are compiled again; the executable is linked again. (A comment-only change took 4 min 39 s with all 517 units cached.) Any release that changes a lift source costs the same, so a player who updates for another reason pays nothing extra. Not timed on Windows.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what
    can't be run by hand is in Testing's Not testable by hand, with why.
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and
    in Risks. UPDATE: Not ticked yet: Risks says the first-update re-translation on every PC was not timed.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named).
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A file in docs/tested/ for each new measured run (format in docs/tested-configurations.md).
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened (tests/test_lift_cache.py passes with HOS_FMA_FAST added to its list; no check was loosened).
  • Docs updated.
**Type:** perf · **Risk:** medium · **Tested on:** Linux (Ubuntu 24.04), RTX 3060, i7-3770 (no AVX2) · **Needs:** Windows, any CPU without AVX2 ## Why A CPU without AVX2 (Ivy Bridge and older Intel, AMD before Excavator) gets an x86-64-v2 build, which has no hardware fused multiply-add. Every guest FMA there runs suyu's exact multi-word integer routine (`recomp_fpe_fma64`, about 180 ns a call, two 1 KB arrays zeroed on each), and on an i7-3770 that was 13.7 % of one core (4.5 ms of CPU a frame) in a sampled profile of rc.5. With this change the common case takes a correctly rounded fast path of a few nanoseconds with the same result and the same FPSR, and the game runs about 5 % faster on that CPU. Nothing changes on a CPU with AVX2 (the code is not compiled in). ## What changed The exact bodies stay as they are; a fast path in front of them handles the common case and hands everything else on. It exists only in a build without FMA3, so players on newer CPUs are not touched. - `nx2/fma_soft.h` (new): `recomp_fma_soft64` / `recomp_fma_soft32`: a correctly rounded FMA (Veltkamp split and Dekker's exact product, TwoSum, rounding to odd, then one rounding to nearest; binary32 through binary64). It returns 0, meaning "take the exact body", for any FPCR control bit but FZ, a zero, subnormal, infinite or NaN operand, an exponent range where it could not prove the result, and a result near the range limits. It raises the inexact flag when the result is inexact. Compiled only where `RECOMP_FPX_FMA64` is 0 on an x86-64 SSE2 host. - `nx2/suyu_rt_fixes.py`: wraps `a64_rtgen.runtime_c` the way it already wraps `runtime_h`: the header's text goes in after `#include "a64.h"` and an early exit at the top of `recomp_fpe_fma32` / `recomp_fpe_fma64`, each substitution required to match exactly once. `third_party/` is untouched. - `tests/test_fma_soft.py`, `tests/fma_soft_test.c` (new): the generated runtime built the way the lift builds it; the exact body (early exit off) against the early exit on the same operands and the same `GuestContext`, comparing the result and every byte of the context. - `nx2/make_game.py`: `HOS_FMA_FAST` in `LIFT_ENV_NOT_OUTPUT` (the switch is read by the generated C at play, as `HOS_NO_FASTFP` is), which `tests/test_lift_cache.py` requires of every variable a lift source names. - `docs/development.md`: the `HOS_FMA_FAST=0` switch. - `docs/tested/`: two run files for the measurements below (separate commit). rc.5's own float regions (#38) and `a64_fpx_fma32_fma32` already handle most single-precision FMAs without FMA3 (in a double-precision product and sum with a midpoint check), so on current main this change acts mostly on the double-precision FMA: `recomp_fpe_fma64` went from 13.7 % to 2.9 % of a core and `recomp_fpe_fma32` from 2.6 % to 1.3 % (sampled profiles, three passes each). ## Measurements **Verdict:** about 5 % more frames a second on an i7-3770: the game's own fps counter went from a median of 29.55 to 31.0 (+4.9 %; +5.1 % by the mean) with the fast path on, in 4 of 4 alternated pairs of the same binary, every run on above every run off. The presented frames a second (RX_VK_FRAME_LOG, which counts frames frame generation shows too) rose by 1.9 % (+0.76 ± 0.27 fps, 95 %): the CPU saving shows in the frames the game computes, less in the frames the GPU adds. An earlier run of 3 pairs agreed in direction (+5.3 %, its 95 % interval just holds 0), and on rc.3 two independent same-binary comparisons gave +3.1 % and +4.5 % (6 of 6 pairs positive). UPDATE: On rc.6 (v3.0.0-rc.6 with this change rebased on it, same PC and scene, 4 runs each ABBA, docs/tested/2026-11-17-fma-soft-brhode-run03.md): the game's own fps counter 29.95 -> 31.3 (+4.5 %, 4 of 4 pairs, +1.35 +- 0.28 fps); presented frames +1.24 +- 0.11 fps (+3.3 %). The effect holds on current code. Hardware: Ubuntu 24.04.5 (kernel 6.8.0-149) in a Proxmox VM, RTX 3060 12 GB (driver 595.99.02), i7-3770 (4 cores, 8 threads; 7 vCPUs given to the VM), 28 GB DDR3, X11 at 1920x1080. Scene: the Deku Tree autosave, a scripted walk of about 3 minutes, 1920x1080, `HOS_FPS_MAX=240` (cap off), `HOS_VCORES=0`, `RX_VK_WB_MAX_KB=1024`; shaders prepared first. Method: the game's "game fps avg" per run (the bench's reading of `longshot_log.txt`) and the per-present frame times (`RX_VK_FRAME_LOG`, the first 30 s of each run dropped); 4 runs of each variant alternated ABBA-style (off, on, on, off, off, on, on, off), the median; the 95 % intervals are Student's t over the runs. The executable is built from source with `nx2/build.py --standalone` (x86-64-v2) against the game's lifted code of v3.0.0-rc.5, so "off" is this PR's binary with `HOS_FMA_FAST=0`, the same code as main's path. How to reproduce: build the game with `make_game.py` (a CPU without AVX2), then build the executable of this branch and of main against that folder's work folder and run the scene with and without `HOS_FMA_FAST=0`; the lab scripts and the raw lines are in docs/tested/2026-11-16-fma-soft-brhode-run01.md and run02.md. Baseline: the "Before" column is v3.0.0-rc.5 as `make_game.py` built it (main e4d035e9, nine commits before 3e4e7cab; those commits are docs, the website, the launcher, the 30 fps cap (`host/nn_vi.c`, the menu), `nx2/make_game.py`, the job queue scripts and tests: nothing in the float runtime); the cleaner comparison for the same code is the "off" column. The two "After" columns pool the 3 pairs of the first job and the 4 pairs of the second (7 runs each). | | Before: rc.5 stock @ e4d035e9 (3 runs) | After, `HOS_FMA_FAST=0`: this PR @ 6027b7a7 (7 runs) | After: this PR @ 6027b7a7 (7 runs) | |---|---|---|---| | game fps (median) | 29.0 | 29.0 | 30.9 | | game fps (mean) | 29.07 | 29.20 | 30.71 | | on-CPU in `recomp_fpe_fma64` (sampled) | 13.73 % of a core | not sampled | 2.85 % of a core | ``` f5 (3 pairs) rc5 stock 28.4 29.8 29.0 | on 29.9 30.1 31.0 | off 28.7 29.0 28.7 game fps avg f5b (4 pairs) off 28.9 30.0 29.5 29.6 | on 30.7 31.1 30.9 31.3 game fps avg f5b presents v1 (off) 39.56 +- 0.36 [39.24-39.77] v2 (on) 40.32 +- 0.21 [40.16-40.48] paired +0.76 +- 0.27 fps profile rc.5 stock: total on-CPU 340 %, recomp_fpe_fma64 13.73 %, recomp_fpe_fma32 2.59 % this PR: total on-CPU 346 %, recomp_fpe_fma64 2.85 %, recomp_fpe_fma32 1.26 % ``` ### Flags and settings One switch is added. | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `HOS_FMA_FAST` | The correctly rounded FMA in front of suyu's exact bodies, off with `0` | did not exist (the exact body every time) | on, only in a build without FMA3 | about 5 % more game frames a second on an i7-3770 | helps x86-64-v2 builds (CPUs without AVX2); not in an x86-64-v3 build (the code is not compiled in), not on non-x86; Windows builds untested (the same C) | on for everyone (the default); `0` is for comparisons | ## Testing **Tested:** `python -I -B tests/test_fma_soft.py`: 10.3 M random and 8.2 M edge-sweep calls, 0 mismatches in the result and in the whole `GuestContext`, in both widths (the early exit is taken on about a quarter of the random calls, and the guard edges are drawn on purpose); the test fails when the inexact flag, the rounding to odd or the FPCR gate is taken out; `python -I -B tests/run_all.py` on main 71b1edd8 and on this branch: 25 failures on main (the Linux build-tool and game-file tests of a VM without the toolchain and the NUP cache) and the same 25 here, plus `tests/test_lift_cache.py` on the first run of this branch, which named `HOS_FMA_FAST` as a variable a lift source reads: it is in `LIFT_ENV_NOT_OUTPUT` now and that test passes (rerun alone; the full run was not repeated after that one line); `tests/test_fpx_sticky.py` and `tests/test_fastfp_override.py` pass with the new runtime; `tests/test_tested_configurations.py` passes. The measurements below are of this change on main 3e4e7cab, before the rebase onto 71b1edd8 (the 18 commits between are lift speed, the menu, the release scripts and renderer fixes, none in the float runtime), so the commit named in them is the unrebased one; the rebased tests above are the ones run on 71b1edd8. The branch was then rebased once more onto main 55e8fbd5 (6 commits: renderer changes, a lift memory change and run files; `docs/development.md` and `docs/tested/` merged without a conflict), and `tests/test_fma_soft.py`, `tests/test_lift_cache.py` and `tests/test_tested_configurations.py` were run again: they pass; the full run was not repeated. In the game: the scene above with the fast path on and off, 14 runs of this binary on rc.5 (7 on, 7 off), no crash; on rc.3 an earlier build of the same change ran a soak of 8 runs with no crash. **Not tested:** Windows (the C is the same and builds with the same flags; no run there); an x86-64-v3 machine running the test (the v3 build compiles with the early exit out, and the test's run is skipped on a CPU with AVX2); any scene other than the one measured. The operand exponent limits and the power-of-two exclusion are margins the test cannot show (the test's docstring says so). **Must be tested:** - Windows, any CPU without AVX2 (Ivy Bridge or older): build the game, start a new file and walk in the Deku Tree for a minute with and without `HOS_FMA_FAST=0`, expecting the same game and no crash (by hand: a tester with such a CPU, or the Test Farm if it has a runner without AVX2: ask in a comment on the PR) ## Risks **What could break:** a wrong early-exit result would be a wrong float in the game's physics or animation, on CPUs without AVX2 only. It was tested bit for bit against the exact body, FPSR included, and everything outside the proven range falls through to the exact body. The rounding mode other than nearest, and every special value, take the exact body. **Turning it off:** `HOS_FMA_FAST=0`, or revert the commit. **Compatibility:** Nothing changes for a player's saves, options file or shader caches. The first update to a build with this change translates the game again on every PC, whatever the CPU: the generated runtime (`a64_suyu.c`) is written by the lift, and the lift key hashes `nx2/suyu_rt_fixes.py` and the new `nx2/fma_soft.h` (`lift_key`, `lift_sources`). ~~I have not timed that re-translation on this PC. The executable is built again too.~~ EDIT: Timed on the author's PC (i7-3770, 7 vCPUs, Ubuntu 24.04, 6 compile jobs; a built game folder, its kept work folder, make_game.py --update) with the code change in nx2/fma_soft.h, which is what this PR's first update is: **4 min 12 s in all,** 191 s of translation and 37 s of compiling; 514 of the 517 compile units come from the object cache and 3 (a64_suyu.c, hos_main.c, vk_menu.cpp) are compiled again; the executable is linked again. (A comment-only change took 4 min 39 s with all 517 units cached.) Any release that changes a lift source costs the same, so a player who updates for another reason pays nothing extra. **Not timed on Windows.** ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand, with why. - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. **UPDATE:** ~~Not ticked yet: Risks says the first-update re-translation on every PC was not timed.~~ - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Numbers from the same PC, scene and settings, at least 2 interleaved runs each, the median reported. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A file in `docs/tested/` for each new measured run (format in `docs/tested-configurations.md`). - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened (`tests/test_lift_cache.py` passes with `HOS_FMA_FAST` added to its list; no check was loosened). - [x] Docs updated.
Author
Contributor

Looking for a tester on Windows, or on any PC whose CPU has no AVX2 (Intel before Haswell, such as Ivy Bridge or Sandy Bridge; AMD before Excavator). That is the one item this PR could not cover: it has only been run on Linux, on an i7-3770.

What to do: build the game with make_game.py as usual, start a new file and walk around the Deku Tree for about a minute, once as it is and once with HOS_FMA_FAST=0 set. Expected: the same game both times and no crash; the game's own fps counter should read about 5 % higher without the switch (29.55 against 31.0 on the i7-3770).

If the Test Farm has a runner without AVX2, a pointer to the right tag would help; I don't know whether it has one.

Looking for a tester on Windows, or on any PC whose CPU has no AVX2 (Intel before Haswell, such as Ivy Bridge or Sandy Bridge; AMD before Excavator). That is the one item this PR could not cover: it has only been run on Linux, on an i7-3770. What to do: build the game with `make_game.py` as usual, start a new file and walk around the Deku Tree for about a minute, once as it is and once with `HOS_FMA_FAST=0` set. Expected: the same game both times and no crash; the game's own fps counter should read about 5 % higher without the switch (29.55 against 31.0 on the i7-3770). If the Test Farm has a runner without AVX2, a pointer to the right tag would help; I don't know whether it has one.
brhode force-pushed perf/fma-soft from 3590744e55
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 84a2d5996a
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-17 01:07:40 +00:00
Compare
TrashPanda left a comment

The fast path sits in front of the exact FMA bodies and only on a build without FMA3. I read head 84a2d599. It applies onto current main. This is not a merge yet.

A normal product and addend in the middle of the exponent range is rounded once, to nearest even, and the inexact flag is set only when the result differs. A zero, a subnormal, an infinity, a NaN, a result near the ends of the range, and any FPCR bit other than flush-to-zero stay on the exact body. The signs of a subtract or a negating multiply are already on the operands before that body is called, so the early exit sees the same bits. A multiply is the same body with a zero addend, and a zero addend is allowed through. HOS_FMA_FAST=0 turns it off. An AVX2 build does not compile it in.

The check compares the early exit with the exact body on the same operands and the same context. On the i7-3770 the game's own counter rose in every paired run.

Must be tested is still open: Windows, on a CPU without AVX2, a minute in the Deku Tree with the fast path and with HOS_FMA_FAST=0, the same game and no crash.

The fast path sits in front of the exact FMA bodies and only on a build without FMA3. I read head `84a2d599`. It applies onto current main. This is not a merge yet. A normal product and addend in the middle of the exponent range is rounded once, to nearest even, and the inexact flag is set only when the result differs. A zero, a subnormal, an infinity, a NaN, a result near the ends of the range, and any FPCR bit other than flush-to-zero stay on the exact body. The signs of a subtract or a negating multiply are already on the operands before that body is called, so the early exit sees the same bits. A multiply is the same body with a zero addend, and a zero addend is allowed through. `HOS_FMA_FAST=0` turns it off. An AVX2 build does not compile it in. The check compares the early exit with the exact body on the same operands and the same context. On the i7-3770 the game's own counter rose in every paired run. Must be tested is still open: Windows, on a CPU without AVX2, a minute in the Deku Tree with the fast path and with `HOS_FMA_FAST=0`, the same game and no crash.
Owner

Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).

  • Tested on my own PC: ticked: Testing and Measurements report in-game runs of this binary on the author's Ubuntu VM with an RTX 3060 and an i7-3770.
  • Nothing gets worse that I know of: not ticked: Risks says the first-update re-translation on every PC was not timed. Measure that cost and state it in Risks, then tick it.
Brought up to the [ready-for-review standard](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/CONTRIBUTING.md#ready-for-review-out-of-wip) (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know). - *Tested on my own PC*: ticked: Testing and Measurements report in-game runs of this binary on the author's Ubuntu VM with an RTX 3060 and an i7-3770. - *Nothing gets worse that I know of*: not ticked: Risks says the first-update re-translation on every PC was not timed. Measure that cost and state it in Risks, then tick it.
Author
Contributor

Thanks! Both boxes now match what I know.

"Nothing gets worse" is ticked now: Risks has the re-translation timed on my PC (4 min 12 s on an i7-3770: 191 s of translation, 37 s of compiling, 514 of 517 units from the object cache; the same cost as any release that changes a lift source).

I also added a run on rc.6 (docs/tested/2026-11-17-fma-soft-brhode-run03.md): the game's own fps +4.5 %, presented frames +3.3 %. The one open item is still "Must be tested": Windows on a CPU without AVX2; if the Test Farm has no such runner, a person with one is welcome/appreciated!

Thanks! Both boxes now match what I know. "Nothing gets worse" is ticked now: Risks has the re-translation timed on my PC (4 min 12 s on an i7-3770: 191 s of translation, 37 s of compiling, 514 of 517 units from the object cache; the same cost as any release that changes a lift source). I also added a run on rc.6 (docs/tested/2026-11-17-fma-soft-brhode-run03.md): the game's own fps +4.5 %, presented frames +3.3 %. The one open item is still "Must be tested": Windows on a CPU without AVX2; if the Test Farm has no such runner, a person with one is welcome/appreciated!
docs(tested): the FMA fast path on rc.6, an i7-3770, one run; the scene of run01 and run02 is the Hyrule Castle gardens, not the Deku Tree
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
31193308bd
HumanBean deleted branch perf/fma-soft 2026-11-18 19:47:17 +00:00
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
Some workflows are waiting to be reviewed.
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!1195
No description provided.