WIP: perf(lift): FPX1's float wrappers are leaves, and six of their fast paths are hand-written x86-64 #2152

Draft
siantm wants to merge 25 commits from siantm/Longshot:perf/fpx-leaf-asm into main
Contributor

Summary

Depends on #1947 (the asm kit); its commits show in this diff until it merges. This PR is its last commit,
"perf(lift): FPX1's float wrappers are leaves, and six of their fast paths ..."; review that one.

An experiment, off by default: without A64_FPX_LEAF=1 at lift time the lift writes a64_fpx.h exactly as main
does and the build neither compiles nor links fpx.S. Off by default as futondestroyer's review comments 67223 and
67225 ask (host and lifter experiments ship off unless set).

Lifted code calls an outlined helper, a64_fpx_<op> in the lift's a64_fpx.h, for most single- and double-precision
float operations outside a fast float region: it checks FPX1's gate, runs the native op, keeps the result where it is
provably Arm's, and otherwise runs the rescues (the kit's sticky-flag ones and, since #1905, A64_FPXKEEP's) and the
exact software body. All of that is one function, so clang saves and restores callee-saved registers for the rescues
on every call, before the fast path even runs.

  • nx2/fpx_helpers.py (new; wraps a64_lift.fpx_header, as nx2/suyu_rt_fixes.py wraps the runtime's generator):
    with A64_FPX_LEAF=1 (or true, on, yes, in any case) at lift time, each wrapper with a rescue or an assembly
    shape becomes the gate and the fast path alone, a leaf that tail-calls a64_fpx_rest_<op> (the rescues, then the
    exact body) where it cannot prove its result. The hot copies of those fall back to the rest directly. The fast path
    has no side effect, so the rest taking the gate again is the same op. A shape with neither (FDIV S, and FDIV D where
    a lift uses it; with A64_FPXKEEP=0 also FADD D, FSUB D, FMUL D and FMLA D, outside fpx.S; FSQRT S in a build with
    RX_FPX_ASM=0) is not split: it stays main's one function (the gate, the fast path, then the exact body; only the
    gate moves inside RECOMP_LIKELY). Unset or any other value: the header is returned unchanged, main's form (with
    fpxkeep's rescues). nx2/lift.py installs it after nx2/fpxkeep.py, so A64_FPXKEEP's rescues are in the rests;
    its install() stops the lift if fpxkeep's has not run (fpxkeep would find no wrapper of the kit's form to edit).

    "Leaf" here means the wrapper holds only the gate and the fast path: it reads c->fpcr and c->fpsr, writes only
    registers, and returns, or where it declines tail-calls (jumps to) the rest; the rescues, and the registers they made
    clang save, are in the rest (fpx.S's are frameless: no push, no stack use). It is not a leaf in the call-graph
    sense: through the rest it reaches the rescues and the exact body, which can write c->fpsr, as main's wrapper
    does. The lift treats a64_fpx_<op> as it treats main's wrapper.

  • host/asm/fpx.S, fpx.h: the fast paths of single-precision FMLA family, FADD, FSUB and FSQRT and
    double-precision FADD and FSUB in assembly (an SSE2 body and an AVX2+FMA body, by the build's CPU level, written with
    the kit's gpu/asm/lsasm.h), the C's tests in fewer instructions, tail-jumping to the C rest where they decline.
    They are frameless leaves (no push, no stack use), so their several rets and the tail jumps keep the unwind data
    the macros write valid. FMUL / FNMUL S, FDIV S and double FMUL / FNMUL and FMLA, which the local branch also had in
    fpx.S, are left to C (FMUL / FNMUL S and double FMUL / FNMUL and FMLA as C leaves; FDIV S, with no rescue, as
    main's one function): in the micro-benchmark under Measurements their assembly was no faster than the C, and
    double FMUL slower.

  • nx2/build.py: fpx_asm_on reads RX_FPX_ASM at each build, a sub-switch of the leaves: in the standalone build
    of a lift whose a64_fpx.h has all six wrappers as leaves (lifted with A64_FPX_LEAF=1), unset or any value but
    0, false, off, no (any case) or empty compiles the lifted code with -DA64_FPX_ASM and links fpx.S;
    RX_FPX_ASM=0 keeps the C leaves. Without the leaves it changes nothing: plan_modules leaves fpx.S out (its new
    leave_out). Compile only: nx2/make_game.py keeps the lift when it changes. a64_suyu.c defines the rests once
    (A64_FPX_IMPL, nx2/suyu_rt_fixes.py).

  • Tests: tests/test_fpx_asm.py (with fpx_asm_test.c, fpx_asm_ref.c; it generates the leaves itself),
    tests/test_fpx_asm_switch.py (new: A64_FPX_LEAF unset or off gives main's a64_fpx.h to the byte, on gives the
    leaves; RX_FPX_ASM), tests/test_asm_build.py (a kernel left out of the plan); tests/test_fpx_sticky.py runs
    its checks on both forms of the header. docs/dev/reference/build.md: both switches' rows.

Nothing is started at run time; the change is in the lifted code's calls and in what the build links, and only with
A64_FPX_LEAF=1.

From the local branch exp/x86-asm-sync (36d3d099, c4c8d297, 0b58b38d; fpx.S/fpx.h as committed there, less the
four kernels above). Main's
nx2/vecfp.py already has most of that branch's vector passes; FADDP and FSQRT (vector) and the FRECPE/FRSQRTE table
are PRs of their own.

Read first: nx2/fpx_helpers.py leaf_on, leaf and install, host/asm/fpx.S (FPX_GATE, FPX_KEEP),
fpx_asm_on in nx2/build.py, tests/test_fpx_asm.py.

Testing

Tested: Windows 11, this PC (i7-9700, x86-64-v3; RTX 4060), llvm-mingw clang 23.1.5; the checks ran through the PC's job queue. In the game: this head's code lifted with A64_FPX_LEAF=1 (leaves and fpx.S) against its base #1947 (cffa2f46, main's wrappers), Kokiri Forest, two sittings of 8 interleaved runs a side after a warm-up each; every run played and stopped cleanly (Measurements).

On this head (61fc4bec: b7bda95e rebased onto #1947's head 186fdb85, which is cffa2f46 plus one test commit to
tests/test_asm_build.py; on main @ 9dd41326; git range-diff: this PR's commit unchanged), the leaves opt-in
(A64_FPX_LEAF=1), one check at a time in one queue job:

  • tests/test_fpx_asm.py (it generates the leaves itself): "fpx asm: pass in 74.2 s", 99,531,018 checks a build,
    0 mismatches, at SSE2 and AVX2, each in the native and the System V convention, and clang's assemblies of fpx.S
    (ELF and COFF, both levels).
  • tests/test_fpx_asm_switch.py -v: "Ran 10 tests ... OK", among them A64_FPX_LEAF unset, 0, empty, 2, off,
    no and false giving main's a64_fpx.h to the byte, and 1, true, ON, " yes " the leaves.
  • tests/test_fpx_sticky.py: "fpx sticky: pass in 72.8 s", 0 mismatches in every set at x86-64-v3 and x86-64-v2,
    in main's form and in the leaf form.
  • tests/test_asm_build.py -v ("Ran 19 tests ... OK", #1947's two Linux-import checks among them),
    tests/test_fpxkeep.py ("fpxkeep: pass in 45.6 s", 0 mismatches), tests/test_fastfp_fma.py ("fastfp fma: pass in
    7.1 s") and tests/test_vecfp.py ("vecfp: pass in 11.6 s"; both use tests/test_fpx_sticky.py's generator,
    main's form by default) pass.
  • tests/test_lift_cache.py fails on this head as on main @ 9dd41326 (run there at b7bda95e), with the same output,
    "FAIL: ...and the others still by their code".
  • The switch test's Linux half, simulated on this PC, not run on Linux at this head: a wrapper (not in the repository)
    runs tests/test_fpx_asm_switch.py whole with its child forced onto the Linux build's path while nx2/build.py
    loads (toolchain.windows() false, as #1947's own import checks do; the child also asserts that build.LINUX is
    true and FFMPEG_LX None). At this head: "Ran 10 tests ... OK". At b7bda95e on cffa2f46: "FAILED (failures=14)",
    all 14 on the import's pkg-config --cflags libavcodec ... process, as on dazemc's Linux. Only the import's Linux
    branch is simulated; the rest of the system is Windows. The test itself needed no change.
  • Teeth at b7bda95e (same code as this head), each one fault in a git archive copy: A64_FPX_LEAF on by default
    (leaf_on's default made "1"): tests/test_fpx_asm_switch.py fails (2 failures: unset is no longer main's
    header); the rests without their rescues: tests/test_fpx_asm_switch.py fails (8 failures, one for each shape
    fpxkeep edits).

By a third party: dazemc, on Linux at b7bda95e (on cffa2f46), game-free, in his
review:
tests/test_fpx_asm.py 99,531,018 checks a level, 0 mismatches at SSE2 and AVX2; tests/test_fpx_sticky.py passes in
both header forms (x86-64-v3 and v2, 0 mismatches); tests/test_fpx_asm_switch.py: its 5 header, leaf and order tests
pass, its 14 build-switch checks failed in the child's import of tests/test_asm_build.py (the FFmpeg pkg-config
probe), which #1947's 186fdb85 answers. Not rerun on Linux at this head.

At earlier heads only, before the leaves were made opt-in (then on by default, off with a switch this head removes):

  • At fecf9557: the PR's new tests copied into #1947's head cffa2f46 and into main @ 9dd41326 fail there
    (tests/test_fpx_asm.py: no host/asm/fpx.S on cffa2f46, no tests/asm_kit.py on main;
    tests/test_fpx_asm_switch.py: no nx2/fpx_helpers.py; tests/test_asm_build.py: no fpx.S choice in
    plan_modules on cffa2f46, no asm_jobs on main). Teeth at fecf9557: nx2/lift.py installing fpx_helpers
    before fpxkeep: tests/test_lift_cache.py fails ("the lift's scripts import (fpx_helpers: install() before
    nx2/fpxkeep.py's ...)"); fpx_asm_on's test inverted: tests/test_fpx_asm_switch.py fails; plan_modules ignoring
    leave_out: tests/test_asm_build.py fails; at 34da225e: FPX_KEEP's bound in fpx.S made 0xfe000000:
    tests/test_fpx_asm.py fails (mismatches at SSE2). Since then only the switch changed (its name, its default, the
    tests that set it); fpx.S, the leaf form and the build's choice are as they were.
  • tests/run_all.py --strict --changed origin/main ran at 34da225e (on cffa2f46 on main @ 9dd41326): 786 passed,
    87 failed, 48 skipped. 85 of the failures fail on main @ 9dd41326 and on cffa2f46 too. The other 2,
    tests/test_audio_voice_biquad.py and tests/test_audio_wave_buffer_release.py, hit their own 30 s compile limit
    with 8 checks at once and passed when run alone at 34da225e. Not rerun at this head.

Still to test:

  • Windows 11, this PC (i7-9700, RTX 4060): Castle Town's market and Hyrule Field, 120 s each, three builds: #1947's
    head 186fdb85 (this PR's base: the kit without fpx.S, the wrappers in main's form), this PR lifted with
    A64_FPX_LEAF=1 and built with RX_FPX_ASM=0 (the C leaves, the same lift), and this PR lifted with
    A64_FPX_LEAF=1 (fpx.S); each warmed once, then interleaved (base, C leaves, fpx.S, fpx.S, C leaves, base), at
    least two runs each, the medians of fps, 1 % lows and frame times compared; expecting the same game and picture, no
    crash, and frame times with fpx.S as the base's or better (by hand)
  • Linux, x86-64, at this head: python3 -I -B tests/test_fpx_asm_switch.py -v, expecting "Ran 10 tests ... OK" (its
    build-switch half failed on the import at b7bda95e and passes here only on the simulated Linux path above); and
    tests/test_fpx_asm.py and tests/test_fpx_sticky.py, which passed on Linux at b7bda95e (by hand)
  • A CPU without AVX2 (an x86-64-v2 build): Castle Town's market, 60 s, this PR lifted with A64_FPX_LEAF=1 against
    RX_FPX_ASM=0, expecting the same play with the SSE2 body (by hand)
  • Linux and Windows with other CPUs (an AMD CPU) and the Steam Deck: Castle Town's market for two minutes, this PR
    lifted with A64_FPX_LEAF=1 against main, expecting the same game and picture, no crash and frame times
    as main's or better (@Beanstalk play Castle Town's market for two minutes on PCs with AMD CPUs and on the Steam
    Deck, this PR against main, comparing frame times and checking for crashes)

Measurements

Verdict: both switches' defaults leave the game as main builds it: A64_FPX_LEAF unset lifts the wrappers in
main's form, and RX_FPX_ASM matters only in a lift made with A64_FPX_LEAF=1 (then unset: the six fast paths in
fpx.S; 0: the C leaves from the same lift). In play, two sittings of 8 runs a side in Kokiri Forest against its base
#1947: the first leaned towards this PR (calm-stretch game time 10.00 against 10.22 ms, -2.2 %, p 0.01), the second is
level (9.84 against 9.86 ms, -0.2 %, p 0.97). Pooled, with the side labels swapped within each sitting: -1.2 %, p 0.35,
not shown (on means -1.5 %, 95 % interval -3.0 to -0.1 %; by medians -3.0 to +1.6 %). The frame rate, the game thread's
waiting time and the frame-time tails are not shown to differ in either sitting. So no difference in play is shown; the
first sitting's lean did not repeat, which is why one sitting was not called a gain. No further sitting is planned.

A throughput micro-benchmark of the wrapper call alone, not measured in play. It ran at b7bda95e (this head's code:
the rebase onto #1947's 186fdb85 added only that PR's test commit) on 2026-11-22: three programs, run in turn within
each of 7 rounds, for each of the ten FPX ops:

  • main's wrapper (A64_FPX_LEAF unset);
  • A64_FPX_LEAF=1, RX_FPX_ASM=0: the C leaves, except FDIV S and FSQRT S, which have no rescue and in this build no
    assembly, so each stays main's one function (only the gate moved inside RECOMP_LIKELY);
  • A64_FPX_LEAF=1, RX_FPX_ASM unset: fpx.S for six ops, the C leaf for FMUL S, FMUL D and FMLA D, and FDIV S
    still main's one function.

With A64_FPX_LEAF=1, nine of the ten ops are faster than main's wrapper. FDIV S is not split by this PR: its three
figures (2.29, 2.31 and 2.27 ns) are one function's, and show the benchmark's noise.

For five of the six ops in fpx.S the assembly is ahead of the C: FMLA S, FADD S, FSUB S and FSUB D against the C
leaf, FSQRT S against its one function (2.04 against 2.31 ns). FADD D is within the noise (see below). FMUL S, FMUL D
and FMLA D run the same C leaf in the second and third programs, and FDIV S the same one function, so their two
figures differ only by the benchmark's run-to-run noise: FMUL D 2.27 against 2.36 ns, FDIV S 2.31 against 2.27, FMUL S
2.39 against 2.28, FMLA D 2.52 against 2.34. Differences of up to about 0.2 ns between two programs are therefore no
difference measured.

FADD D's assembly (2.19 against the C leaf's 2.27) is within that noise at b7bda95e; it was ahead at fecf9557 (2.02
against 2.25).

Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; pr-work/tools/fpx_bench.py asm (not in the repository). Each wrapper
is called on normal operands with the gate open (independent calls, throughput). -O2 -march=x86-64-v3 -ffp-contract=off,
the median of the 7 rounds (the spread is not recorded). A timing-cpu queue job, no other queue job beside it. This PR @
b7bda95e on #1947 @ cffa2f46 on main @ 9dd41326.

ns a call (median of 7) @ b7bda95e main's wrapper (A64_FPX_LEAF unset) A64_FPX_LEAF=1, RX_FPX_ASM=0 (C leaves) A64_FPX_LEAF=1 (default RX_FPX_ASM) that op uses (default RX_FPX_ASM)
FMUL S 2.85 2.39 2.28 C leaf
FMLA S 3.03 2.73 2.56 fpx.S
FADD S 2.48 2.32 1.88 fpx.S
FSUB S 2.44 2.27 1.92 fpx.S
FDIV S 2.29 2.31 (main's one function) 2.27 (main's one function) main's one function (not split)
FSQRT S 2.26 2.31 (main's one function) 2.04 fpx.S
FADD D 3.11 2.27 2.19 fpx.S
FSUB D 2.99 2.25 2.05 fpx.S
FMUL D 3.71 2.27 2.36 C leaf
FMLA D 3.05 2.52 2.34 C leaf

The earlier run at fecf9557, before FMUL S, FDIV S, FMUL D and FMLA D left fpx.S, is why those four are left to C:
there their assembly was no faster than the C (FMUL S, FDIV S, FMLA D), and slower for FMUL D (2.51 against 2.24 ns).

In play: Kokiri Forest, this PR with A64_FPX_LEAF=1 against its base #1947, two sittings

Setup: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), run alone on the PC on 2026-11-23, 13:38 to 14:28 UTC (first sitting) and 17:32 to 18:18 UTC (second); Kokiri
Forest (child, the kokiri-start save, the teleport checked as taken: every run in the light load state), 60 s standing
and turning, frame cap off, window 800x600, output pinned at 2560x1440 (HOS_OUTPUT_RES), desktop 800x600 at 30 Hz
(swapchain 800x581), programs loaded when the game makes them (RX_VK_LOAD=create); a warm-up run a side, then 8
interleaved runs a side (base, this PR, this PR, base, four times), the GPU cooled to 70 °C before each run. None left
out (no run had the game window brought to the front or a commit-limit line).
Builds: the base is #1947 @ cffa2f46 (main's float wrappers); this PR is b7bda95e (this head's code: 61fc4bec adds
tests only) lifted with A64_FPX_LEAF=1, RX_FPX_ASM unset (the six fast paths in fpx.S, the other four as C leaves).
Checked before the counted runs: the lifted code is the same on both sides (the same object key); they differ by the
wrappers' header (gen/a64_fpx.h in its leaf form, which every lifted chunk includes), -DA64_FPX_ASM and fpx.S
(compiled in this PR's build only); both compiled the same 55 lifted chunks with the lighter passes; each warm-up ran
its own build. No counter in the game says how often the wrappers ran.
Calm-stretch game time: the measured 60 s in six 10 s windows, each window whose median game time is more than 20 % above
the run's lowest dropped (a burst), then the median game time of the frames left; blocked: the game thread's wait over
the same frames. p: the share of all 12,870 ways of swapping the side labels that give a difference of medians at least
as large.

First sitting, 13:38 to 14:28 UTC, desktop 800x600 at 30 Hz:

Kokiri Forest, 8 runs a side, median (range) Before: #1947 @ cffa2f46 (main's wrappers) After: this PR, A64_FPX_LEAF=1
calm-stretch game ms a frame 10.22 (9.85 to 10.52) 10.00 (9.88 to 10.12), -2.2 %, p 0.01
whole-run game ms a frame 10.22 (9.85 to 10.52) 10.00 (9.88 to 10.12)
game thread blocked, ms a frame 8.71 (8.51 to 9.08) 8.93 (8.27 to 9.14), p 0.44
fps 85.6 (83.5 to 88.3) 84.7 (83.7 to 90.1), p 0.53
p99 frame ms 18.1 (16.6 to 20.6) 18.1 (15.8 to 19.4), p 0.98

Second sitting, 17:32 to 18:18 UTC, desktop 800x600 at 30 Hz (swapchain 800x581), the same builds and settings, none left
out:

Kokiri Forest, 8 runs a side, median (range) Before: #1947 @ cffa2f46 (main's wrappers) After: this PR, A64_FPX_LEAF=1
calm-stretch game ms a frame 9.86 (9.53 to 10.43) 9.84 (9.41 to 10.68), -0.2 %, p 0.97
whole-run game ms a frame 9.89 (9.53 to 10.43) 9.93 (9.60 to 10.68), p 0.83
game thread blocked, ms a frame 8.52 (8.20 to 9.16) 8.75 (8.14 to 9.22), p 0.43
fps 87.2 (79.9 to 91.5) 85.6 (78.6 to 92.0), p 0.73
p99 frame ms 18.6 (14.9 to 35.4) 20.7 (15.2 to 41.1), p 0.78

Per run, calm-stretch game ms (in run order):

first sitting  base: 10.36, 10.09, 10.02, 10.24, 10.20, 10.52, 9.85, 10.34
               PR:   10.00, 9.89, 9.88, 10.00, 10.12, 9.99, 10.06, 10.12
second sitting base: 10.43, 10.11, 9.53, 9.80, 9.65, 9.98, 9.61, 9.91
               PR:   10.01, 9.41, 10.68, 9.67, 10.30, 9.60, 9.93, 9.75

In the first sitting the PR's side was lower in 51 of the 64 run pairs and tighter (standard deviation 0.09 ms against
0.21); in the second it is lower in 31 of 64 and spread wider (9.41 to 10.68). Pooled over both sittings (labels swapped
within each sitting only; both on the same desktop): calm-stretch game time -1.2 %, p 0.35; whole-run game time -0.8 %,
p 0.56; blocked +2.5 %, p 0.20; fps -1.5 %, p 0.58; p99 p 0.73. Nothing is shown to differ.

Risks

Off by default: without A64_FPX_LEAF=1 the lift's a64_fpx.h is main's to the byte (a test checks it) and
fpx.S is not built, so players and default builds see no change. With it, float results: every kernel is checked bit
for bit (value and FPSR) against the exact body and the C leaf at both levels and in both conventions, and must leave
its fast path exactly where the C does; the leaf is the same tests in another function, and its rest holds the kit's
and A64_FPXKEEP's rescues unchanged. A mistake would show as wrong maths in the game (physics, animation). Off again:
RX_FPX_ASM=0 at build time (the C leaves, no new lift) or A64_FPX_LEAF unset (main's wrappers, a new lift).

Other hosts: fpx.S is x86-64 only (A64_FPX_ASM_ON needs RECOMP_FPX_HOST == 2 on x86-64, not Emscripten). On an
ARM64 or wasm host, A64_FPX_LEAF=1 is the C split alone (the leaves and rests, no assembly), which this PR does not
test: every check above ran on x86-64, where the C leaves are the same C. Longshot's own build targets x86-64
(docs/dev/reference/build.md: its CPU levels, and every host/asm kernel linked into the game).

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.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • 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.
## Summary Depends on #1947 (the asm kit); its commits show in this diff until it merges. This PR is its last commit, "perf(lift): FPX1's float wrappers are leaves, and six of their fast paths ..."; review that one. An experiment, off by default: without `A64_FPX_LEAF=1` at lift time the lift writes `a64_fpx.h` exactly as `main` does and the build neither compiles nor links `fpx.S`. Off by default as futondestroyer's review comments 67223 and 67225 ask (host and lifter experiments ship off unless set). Lifted code calls an outlined helper, `a64_fpx_<op>` in the lift's `a64_fpx.h`, for most single- and double-precision float operations outside a fast float region: it checks FPX1's gate, runs the native op, keeps the result where it is provably Arm's, and otherwise runs the rescues (the kit's sticky-flag ones and, since #1905, `A64_FPXKEEP`'s) and the exact software body. All of that is one function, so clang saves and restores callee-saved registers for the rescues on every call, before the fast path even runs. - `nx2/fpx_helpers.py` (new; wraps `a64_lift.fpx_header`, as `nx2/suyu_rt_fixes.py` wraps the runtime's generator): with `A64_FPX_LEAF=1` (or `true`, `on`, `yes`, in any case) at lift time, each wrapper with a rescue or an assembly shape becomes the gate and the fast path alone, a leaf that tail-calls `a64_fpx_rest_<op>` (the rescues, then the exact body) where it cannot prove its result. The hot copies of those fall back to the rest directly. The fast path has no side effect, so the rest taking the gate again is the same op. A shape with neither (FDIV S, and FDIV D where a lift uses it; with `A64_FPXKEEP=0` also FADD D, FSUB D, FMUL D and FMLA D, outside `fpx.S`; FSQRT S in a build with `RX_FPX_ASM=0`) is not split: it stays `main`'s one function (the gate, the fast path, then the exact body; only the gate moves inside `RECOMP_LIKELY`). Unset or any other value: the header is returned unchanged, `main`'s form (with fpxkeep's rescues). `nx2/lift.py` installs it after `nx2/fpxkeep.py`, so `A64_FPXKEEP`'s rescues are in the rests; its `install()` stops the lift if fpxkeep's has not run (fpxkeep would find no wrapper of the kit's form to edit). "Leaf" here means the wrapper holds only the gate and the fast path: it reads `c->fpcr` and `c->fpsr`, writes only registers, and returns, or where it declines tail-calls (jumps to) the rest; the rescues, and the registers they made clang save, are in the rest (`fpx.S`'s are frameless: no push, no stack use). It is not a leaf in the call-graph sense: through the rest it reaches the rescues and the exact body, which can write `c->fpsr`, as `main`'s wrapper does. The lift treats `a64_fpx_<op>` as it treats `main`'s wrapper. - `host/asm/fpx.S`, `fpx.h`: the fast paths of single-precision FMLA family, FADD, FSUB and FSQRT and double-precision FADD and FSUB in assembly (an SSE2 body and an AVX2+FMA body, by the build's CPU level, written with the kit's `gpu/asm/lsasm.h`), the C's tests in fewer instructions, tail-jumping to the C rest where they decline. They are frameless leaves (no push, no stack use), so their several `ret`s and the tail jumps keep the unwind data the macros write valid. FMUL / FNMUL S, FDIV S and double FMUL / FNMUL and FMLA, which the local branch also had in `fpx.S`, are left to C (FMUL / FNMUL S and double FMUL / FNMUL and FMLA as C leaves; FDIV S, with no rescue, as `main`'s one function): in the micro-benchmark under Measurements their assembly was no faster than the C, and double FMUL slower. - `nx2/build.py`: `fpx_asm_on` reads `RX_FPX_ASM` at each build, a sub-switch of the leaves: in the standalone build of a lift whose `a64_fpx.h` has all six wrappers as leaves (lifted with `A64_FPX_LEAF=1`), unset or any value but `0`, `false`, `off`, `no` (any case) or empty compiles the lifted code with `-DA64_FPX_ASM` and links `fpx.S`; `RX_FPX_ASM=0` keeps the C leaves. Without the leaves it changes nothing: `plan_modules` leaves `fpx.S` out (its new `leave_out`). Compile only: `nx2/make_game.py` keeps the lift when it changes. `a64_suyu.c` defines the rests once (`A64_FPX_IMPL`, `nx2/suyu_rt_fixes.py`). - Tests: `tests/test_fpx_asm.py` (with `fpx_asm_test.c`, `fpx_asm_ref.c`; it generates the leaves itself), `tests/test_fpx_asm_switch.py` (new: `A64_FPX_LEAF` unset or off gives `main`'s `a64_fpx.h` to the byte, on gives the leaves; `RX_FPX_ASM`), `tests/test_asm_build.py` (a kernel left out of the plan); `tests/test_fpx_sticky.py` runs its checks on both forms of the header. `docs/dev/reference/build.md`: both switches' rows. Nothing is started at run time; the change is in the lifted code's calls and in what the build links, and only with `A64_FPX_LEAF=1`. From the local branch `exp/x86-asm-sync` (36d3d099, c4c8d297, 0b58b38d; `fpx.S`/`fpx.h` as committed there, less the four kernels above). Main's `nx2/vecfp.py` already has most of that branch's vector passes; FADDP and FSQRT (vector) and the FRECPE/FRSQRTE table are PRs of their own. Read first: `nx2/fpx_helpers.py` `leaf_on`, `leaf` and `install`, `host/asm/fpx.S` (`FPX_GATE`, `FPX_KEEP`), `fpx_asm_on` in `nx2/build.py`, `tests/test_fpx_asm.py`. ## Testing **Tested:** Windows 11, this PC (i7-9700, x86-64-v3; RTX 4060), llvm-mingw clang 23.1.5; the checks ran through the PC's job queue. In the game: this head's code lifted with `A64_FPX_LEAF=1` (leaves and `fpx.S`) against its base #1947 (cffa2f46, `main`'s wrappers), Kokiri Forest, two sittings of 8 interleaved runs a side after a warm-up each; every run played and stopped cleanly (Measurements). On this head (61fc4bec: b7bda95e rebased onto #1947's head 186fdb85, which is cffa2f46 plus one test commit to `tests/test_asm_build.py`; on `main` @ 9dd41326; `git range-diff`: this PR's commit unchanged), the leaves opt-in (`A64_FPX_LEAF=1`), one check at a time in one queue job: - `tests/test_fpx_asm.py` (it generates the leaves itself): "fpx asm: pass in 74.2 s", 99,531,018 checks a build, 0 mismatches, at SSE2 and AVX2, each in the native and the System V convention, and clang's assemblies of `fpx.S` (ELF and COFF, both levels). - `tests/test_fpx_asm_switch.py -v`: "Ran 10 tests ... OK", among them `A64_FPX_LEAF` unset, `0`, empty, `2`, `off`, `no` and `false` giving `main`'s `a64_fpx.h` to the byte, and `1`, `true`, `ON`, `" yes "` the leaves. - `tests/test_fpx_sticky.py`: "fpx sticky: pass in 72.8 s", 0 mismatches in every set at x86-64-v3 and x86-64-v2, in `main`'s form and in the leaf form. - `tests/test_asm_build.py -v` ("Ran 19 tests ... OK", #1947's two Linux-import checks among them), `tests/test_fpxkeep.py` ("fpxkeep: pass in 45.6 s", 0 mismatches), `tests/test_fastfp_fma.py` ("fastfp fma: pass in 7.1 s") and `tests/test_vecfp.py` ("vecfp: pass in 11.6 s"; both use `tests/test_fpx_sticky.py`'s generator, `main`'s form by default) pass. - `tests/test_lift_cache.py` fails on this head as on `main` @ 9dd41326 (run there at b7bda95e), with the same output, "FAIL: ...and the others still by their code". - The switch test's Linux half, simulated on this PC, not run on Linux at this head: a wrapper (not in the repository) runs `tests/test_fpx_asm_switch.py` whole with its child forced onto the Linux build's path while `nx2/build.py` loads (`toolchain.windows()` false, as #1947's own import checks do; the child also asserts that `build.LINUX` is true and `FFMPEG_LX` None). At this head: "Ran 10 tests ... OK". At b7bda95e on cffa2f46: "FAILED (failures=14)", all 14 on the import's `pkg-config --cflags libavcodec ...` process, as on dazemc's Linux. Only the import's Linux branch is simulated; the rest of the system is Windows. The test itself needed no change. - Teeth at b7bda95e (same code as this head), each one fault in a `git archive` copy: `A64_FPX_LEAF` on by default (`leaf_on`'s default made `"1"`): `tests/test_fpx_asm_switch.py` fails (2 failures: unset is no longer `main`'s header); the rests without their rescues: `tests/test_fpx_asm_switch.py` fails (8 failures, one for each shape fpxkeep edits). By a third party: dazemc, on Linux at b7bda95e (on cffa2f46), game-free, in his [review](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2152#issuecomment-72792): `tests/test_fpx_asm.py` 99,531,018 checks a level, 0 mismatches at SSE2 and AVX2; `tests/test_fpx_sticky.py` passes in both header forms (x86-64-v3 and v2, 0 mismatches); `tests/test_fpx_asm_switch.py`: its 5 header, leaf and order tests pass, its 14 build-switch checks failed in the child's import of `tests/test_asm_build.py` (the FFmpeg `pkg-config` probe), which #1947's 186fdb85 answers. Not rerun on Linux at this head. At earlier heads only, before the leaves were made opt-in (then on by default, off with a switch this head removes): - At fecf9557: the PR's new tests copied into #1947's head cffa2f46 and into `main` @ 9dd41326 fail there (`tests/test_fpx_asm.py`: no `host/asm/fpx.S` on cffa2f46, no `tests/asm_kit.py` on `main`; `tests/test_fpx_asm_switch.py`: no `nx2/fpx_helpers.py`; `tests/test_asm_build.py`: no `fpx.S` choice in `plan_modules` on cffa2f46, no `asm_jobs` on `main`). Teeth at fecf9557: `nx2/lift.py` installing `fpx_helpers` before `fpxkeep`: `tests/test_lift_cache.py` fails ("the lift's scripts import (fpx_helpers: install() before nx2/fpxkeep.py's ...)"); `fpx_asm_on`'s test inverted: `tests/test_fpx_asm_switch.py` fails; `plan_modules` ignoring `leave_out`: `tests/test_asm_build.py` fails; at 34da225e: `FPX_KEEP`'s bound in `fpx.S` made 0xfe000000: `tests/test_fpx_asm.py` fails (mismatches at SSE2). Since then only the switch changed (its name, its default, the tests that set it); `fpx.S`, the leaf form and the build's choice are as they were. - `tests/run_all.py --strict --changed origin/main` ran at 34da225e (on cffa2f46 on `main` @ 9dd41326): 786 passed, 87 failed, 48 skipped. 85 of the failures fail on `main` @ 9dd41326 and on cffa2f46 too. The other 2, `tests/test_audio_voice_biquad.py` and `tests/test_audio_wave_buffer_release.py`, hit their own 30 s compile limit with 8 checks at once and passed when run alone at 34da225e. Not rerun at this head. **Still to test:** - Windows 11, this PC (i7-9700, RTX 4060): Castle Town's market and Hyrule Field, 120 s each, three builds: #1947's head 186fdb85 (this PR's base: the kit without `fpx.S`, the wrappers in `main`'s form), this PR lifted with `A64_FPX_LEAF=1` and built with `RX_FPX_ASM=0` (the C leaves, the same lift), and this PR lifted with `A64_FPX_LEAF=1` (`fpx.S`); each warmed once, then interleaved (base, C leaves, `fpx.S`, `fpx.S`, C leaves, base), at least two runs each, the medians of fps, 1 % lows and frame times compared; expecting the same game and picture, no crash, and frame times with `fpx.S` as the base's or better (by hand) - Linux, x86-64, at this head: `python3 -I -B tests/test_fpx_asm_switch.py -v`, expecting "Ran 10 tests ... OK" (its build-switch half failed on the import at b7bda95e and passes here only on the simulated Linux path above); and `tests/test_fpx_asm.py` and `tests/test_fpx_sticky.py`, which passed on Linux at b7bda95e (by hand) - A CPU without AVX2 (an x86-64-v2 build): Castle Town's market, 60 s, this PR lifted with `A64_FPX_LEAF=1` against `RX_FPX_ASM=0`, expecting the same play with the SSE2 body (by hand) - Linux and Windows with other CPUs (an AMD CPU) and the Steam Deck: Castle Town's market for two minutes, this PR lifted with `A64_FPX_LEAF=1` against `main`, expecting the same game and picture, no crash and frame times as `main`'s or better (@Beanstalk play Castle Town's market for two minutes on PCs with AMD CPUs and on the Steam Deck, this PR against main, comparing frame times and checking for crashes) ## Measurements **Verdict:** both switches' defaults leave the game as `main` builds it: `A64_FPX_LEAF` unset lifts the wrappers in `main`'s form, and `RX_FPX_ASM` matters only in a lift made with `A64_FPX_LEAF=1` (then unset: the six fast paths in `fpx.S`; `0`: the C leaves from the same lift). In play, two sittings of 8 runs a side in Kokiri Forest against its base #1947: the first leaned towards this PR (calm-stretch game time 10.00 against 10.22 ms, -2.2 %, p 0.01), the second is level (9.84 against 9.86 ms, -0.2 %, p 0.97). Pooled, with the side labels swapped within each sitting: -1.2 %, p 0.35, not shown (on means -1.5 %, 95 % interval -3.0 to -0.1 %; by medians -3.0 to +1.6 %). The frame rate, the game thread's waiting time and the frame-time tails are not shown to differ in either sitting. So no difference in play is shown; the first sitting's lean did not repeat, which is why one sitting was not called a gain. No further sitting is planned. A throughput micro-benchmark of the wrapper call alone, not measured in play. It ran at b7bda95e (this head's code: the rebase onto #1947's 186fdb85 added only that PR's test commit) on 2026-11-22: three programs, run in turn within each of 7 rounds, for each of the ten FPX ops: - `main`'s wrapper (`A64_FPX_LEAF` unset); - `A64_FPX_LEAF=1`, `RX_FPX_ASM=0`: the C leaves, except FDIV S and FSQRT S, which have no rescue and in this build no assembly, so each stays `main`'s one function (only the gate moved inside `RECOMP_LIKELY`); - `A64_FPX_LEAF=1`, `RX_FPX_ASM` unset: `fpx.S` for six ops, the C leaf for FMUL S, FMUL D and FMLA D, and FDIV S still `main`'s one function. With `A64_FPX_LEAF=1`, nine of the ten ops are faster than `main`'s wrapper. FDIV S is not split by this PR: its three figures (2.29, 2.31 and 2.27 ns) are one function's, and show the benchmark's noise. For five of the six ops in `fpx.S` the assembly is ahead of the C: FMLA S, FADD S, FSUB S and FSUB D against the C leaf, FSQRT S against its one function (2.04 against 2.31 ns). FADD D is within the noise (see below). FMUL S, FMUL D and FMLA D run the same C leaf in the second and third programs, and FDIV S the same one function, so their two figures differ only by the benchmark's run-to-run noise: FMUL D 2.27 against 2.36 ns, FDIV S 2.31 against 2.27, FMUL S 2.39 against 2.28, FMLA D 2.52 against 2.34. Differences of up to about 0.2 ns between two programs are therefore no difference measured. FADD D's assembly (2.19 against the C leaf's 2.27) is within that noise at b7bda95e; it was ahead at fecf9557 (2.02 against 2.25). Setup: Windows 11, i7-9700, llvm-mingw clang 23.1.5; `pr-work/tools/fpx_bench.py asm` (not in the repository). Each wrapper is called on normal operands with the gate open (independent calls, throughput). `-O2 -march=x86-64-v3 -ffp-contract=off`, the median of the 7 rounds (the spread is not recorded). A `timing-cpu` queue job, no other queue job beside it. This PR @ b7bda95e on #1947 @ cffa2f46 on `main` @ 9dd41326. | ns a call (median of 7) @ b7bda95e | `main`'s wrapper (`A64_FPX_LEAF` unset) | `A64_FPX_LEAF=1`, `RX_FPX_ASM=0` (C leaves) | `A64_FPX_LEAF=1` (default `RX_FPX_ASM`) | that op uses (default `RX_FPX_ASM`) | |---|---|---|---|---| | FMUL S | 2.85 | 2.39 | 2.28 | C leaf | | FMLA S | 3.03 | 2.73 | 2.56 | `fpx.S` | | FADD S | 2.48 | 2.32 | 1.88 | `fpx.S` | | FSUB S | 2.44 | 2.27 | 1.92 | `fpx.S` | | FDIV S | 2.29 | 2.31 (`main`'s one function) | 2.27 (`main`'s one function) | `main`'s one function (not split) | | FSQRT S | 2.26 | 2.31 (`main`'s one function) | 2.04 | `fpx.S` | | FADD D | 3.11 | 2.27 | 2.19 | `fpx.S` | | FSUB D | 2.99 | 2.25 | 2.05 | `fpx.S` | | FMUL D | 3.71 | 2.27 | 2.36 | C leaf | | FMLA D | 3.05 | 2.52 | 2.34 | C leaf | The earlier run at fecf9557, before FMUL S, FDIV S, FMUL D and FMLA D left `fpx.S`, is why those four are left to C: there their assembly was no faster than the C (FMUL S, FDIV S, FMLA D), and slower for FMUL D (2.51 against 2.24 ns). **In play: Kokiri Forest, this PR with `A64_FPX_LEAF=1` against its base #1947, two sittings** Setup: Windows 11, i7-9700, RTX 4060 (NVIDIA 610.88), run alone on the PC on 2026-11-23, 13:38 to 14:28 UTC (first sitting) and 17:32 to 18:18 UTC (second); Kokiri Forest (child, the `kokiri-start` save, the teleport checked as taken: every run in the light load state), 60 s standing and turning, frame cap off, window 800x600, output pinned at 2560x1440 (`HOS_OUTPUT_RES`), desktop 800x600 at 30 Hz (swapchain 800x581), programs loaded when the game makes them (`RX_VK_LOAD=create`); a warm-up run a side, then 8 interleaved runs a side (base, this PR, this PR, base, four times), the GPU cooled to 70 °C before each run. None left out (no run had the game window brought to the front or a commit-limit line). Builds: the base is #1947 @ cffa2f46 (`main`'s float wrappers); this PR is b7bda95e (this head's code: 61fc4bec adds tests only) lifted with `A64_FPX_LEAF=1`, `RX_FPX_ASM` unset (the six fast paths in `fpx.S`, the other four as C leaves). Checked before the counted runs: the lifted code is the same on both sides (the same object key); they differ by the wrappers' header (`gen/a64_fpx.h` in its leaf form, which every lifted chunk includes), `-DA64_FPX_ASM` and `fpx.S` (compiled in this PR's build only); both compiled the same 55 lifted chunks with the lighter passes; each warm-up ran its own build. No counter in the game says how often the wrappers ran. Calm-stretch game time: the measured 60 s in six 10 s windows, each window whose median game time is more than 20 % above the run's lowest dropped (a burst), then the median game time of the frames left; blocked: the game thread's wait over the same frames. p: the share of all 12,870 ways of swapping the side labels that give a difference of medians at least as large. First sitting, 13:38 to 14:28 UTC, desktop 800x600 at 30 Hz: | Kokiri Forest, 8 runs a side, median (range) | Before: #1947 @ cffa2f46 (`main`'s wrappers) | After: this PR, `A64_FPX_LEAF=1` | |---|---|---| | calm-stretch game ms a frame | 10.22 (9.85 to 10.52) | 10.00 (9.88 to 10.12), -2.2 %, p 0.01 | | whole-run game ms a frame | 10.22 (9.85 to 10.52) | 10.00 (9.88 to 10.12) | | game thread blocked, ms a frame | 8.71 (8.51 to 9.08) | 8.93 (8.27 to 9.14), p 0.44 | | fps | 85.6 (83.5 to 88.3) | 84.7 (83.7 to 90.1), p 0.53 | | p99 frame ms | 18.1 (16.6 to 20.6) | 18.1 (15.8 to 19.4), p 0.98 | Second sitting, 17:32 to 18:18 UTC, desktop 800x600 at 30 Hz (swapchain 800x581), the same builds and settings, none left out: | Kokiri Forest, 8 runs a side, median (range) | Before: #1947 @ cffa2f46 (`main`'s wrappers) | After: this PR, `A64_FPX_LEAF=1` | |---|---|---| | calm-stretch game ms a frame | 9.86 (9.53 to 10.43) | 9.84 (9.41 to 10.68), -0.2 %, p 0.97 | | whole-run game ms a frame | 9.89 (9.53 to 10.43) | 9.93 (9.60 to 10.68), p 0.83 | | game thread blocked, ms a frame | 8.52 (8.20 to 9.16) | 8.75 (8.14 to 9.22), p 0.43 | | fps | 87.2 (79.9 to 91.5) | 85.6 (78.6 to 92.0), p 0.73 | | p99 frame ms | 18.6 (14.9 to 35.4) | 20.7 (15.2 to 41.1), p 0.78 | Per run, calm-stretch game ms (in run order): ``` first sitting base: 10.36, 10.09, 10.02, 10.24, 10.20, 10.52, 9.85, 10.34 PR: 10.00, 9.89, 9.88, 10.00, 10.12, 9.99, 10.06, 10.12 second sitting base: 10.43, 10.11, 9.53, 9.80, 9.65, 9.98, 9.61, 9.91 PR: 10.01, 9.41, 10.68, 9.67, 10.30, 9.60, 9.93, 9.75 ``` In the first sitting the PR's side was lower in 51 of the 64 run pairs and tighter (standard deviation 0.09 ms against 0.21); in the second it is lower in 31 of 64 and spread wider (9.41 to 10.68). Pooled over both sittings (labels swapped within each sitting only; both on the same desktop): calm-stretch game time -1.2 %, p 0.35; whole-run game time -0.8 %, p 0.56; blocked +2.5 %, p 0.20; fps -1.5 %, p 0.58; p99 p 0.73. Nothing is shown to differ. ## Risks Off by default: without `A64_FPX_LEAF=1` the lift's `a64_fpx.h` is `main`'s to the byte (a test checks it) and `fpx.S` is not built, so players and default builds see no change. With it, float results: every kernel is checked bit for bit (value and FPSR) against the exact body and the C leaf at both levels and in both conventions, and must leave its fast path exactly where the C does; the leaf is the same tests in another function, and its rest holds the kit's and `A64_FPXKEEP`'s rescues unchanged. A mistake would show as wrong maths in the game (physics, animation). Off again: `RX_FPX_ASM=0` at build time (the C leaves, no new lift) or `A64_FPX_LEAF` unset (`main`'s wrappers, a new lift). Other hosts: `fpx.S` is x86-64 only (`A64_FPX_ASM_ON` needs `RECOMP_FPX_HOST == 2` on x86-64, not Emscripten). On an ARM64 or wasm host, `A64_FPX_LEAF=1` is the C split alone (the leaves and rests, no assembly), which this PR does not test: every check above ran on x86-64, where the C leaves are the same C. Longshot's own build targets x86-64 (`docs/dev/reference/build.md`: its CPU levels, and every `host/asm` kernel linked into the game). ## Checklist ### Ready for review - [x] 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. - [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. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [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.
The ground the hand-written kernels stand on, without any kernel yet:

- gpu/asm/lsasm.h: a kernel is written once, in Intel syntax against the System V registers; the macros make the
  Win64 convention with its SEH unwind data on Windows (an epilogue laid out as Windows' unwinder recognises one:
  the vzeroupper and the frees before the pops) and the DWARF CFI on Linux, and LSASM_ABI for the declarations.
- tests/asm_kit.py: a kernel's check builds its fixture with the kernels at SSE2 and AVX2 (where the CPU has it),
  on Windows also the System V body through sysv_abi, and assembles every kernel with clang for ELF and COFF.
- tests/test_asm_abi.py with tests/asm_abi_probe.S: probes that use every part of the frame: six arguments arrive,
  every callee-saved register comes back, a fault inside one unwinds to the caller (Windows), and every single step
  of each probe is unwound by Windows' own unwinder to its caller.
- nx2/build.py asm_jobs: every .S of host/asm goes into the game, of gpu/vk/asm into the renderer, of gpu/asm into
  both, preprocessed with the build's CPU flags and keyed by the headers beside them and lsasm.h. No folder, no job.
- scripts/devtools/packs.py takes a .S as a source (it shows in its module's objects) and nx2/version.py counts it in
  the sources' fingerprint.
- tests/test_asm_build.py, tests/test_dev_packs.py: the jobs, their keys, the fingerprint and the packs' rules.

Assisted-by: Claude Code
tests/asm_abi_probe.S has three more probes that return rsp modulo 16 in their body: scratch alone, one push and
scratch, two pushes and the xmm saves, an even and an odd count of pushes in both conventions (Win64's LSASM_ARGS
pushes two). Win64 asks a function with a frame to keep rsp 16-byte aligned in its body, and LSASM_ALLOC's scratch
at [rsp] is aligned only so. On Windows each is stepped and unwound as the others are. tests/test_asm_abi.py also
assembles a kernel with LSASM_ALLOC 3072 (it must assemble) and 4096 (a page and a push: it must stop the assembly,
as the macros probe no stack page and its first store could skip Windows' guard page).

Both fail on this commit: lsasm.h leaves rsp at 8 modulo 16 with an even count of pushes, and takes any scratch size.

Assisted-by: Claude Code
Win64 asks a function with a frame to keep rsp 16-byte aligned in its body, and the macros did not: with an even
count of pushes (LSASM_ARGS's two included) the body ran at 8 modulo 16, so an aligned store to LSASM_ALLOC's
scratch could fault. The macros now count the pushes and take 8 bytes more below them where the count leaves rsp
misaligned, before the first xmm save or scratch (or at the prologue's end), in the SEH codes and the CFI alike; the
epilogue gives them back with its one add (Windows) or at the first pop (Linux). A push after the xmm saves or the
scratch stops the assembly, as the padding could not count it.

The macros probe no stack page, so a frame of more than a page could skip Windows' guard page with its first store:
LSASM_END_PROLOGUE stops the assembly of a frame (pushes, padding, xmm saves and scratch) over 4096 bytes.

The header also says what LSASM_ARGS maps: six integer or pointer arguments; a float argument is in another register
in each convention. The fifth and sixth stay loaded on every call: their slots lie inside the caller's own frame.

Assisted-by: Claude Code
tests/test_asm_build.py checks the kernels' object keys as compile_one names them: a header renamed with its contents or
removed changes the key (a clean compile of the kernel would fail), a .inc edit changes it, and a kernel whose depfile
exists is keyed by the headers it names (an edit to another header keeps it). A gpu/asm kernel's second job publishing
the same key after the first must leave the first job's object (the cache entry is a hard link to it) as it was. A
renderer file whose depfile names a gpu/asm declaration is keyed by it, through main()'s own vdeps_roots statement.

They fail on this commit: the key joins the folders' .h contents alone, cache_put copies over an entry that
os.link found there, and the renderer's roots leave gpu/asm out.

Assisted-by: Claude Code
asm_jobs keyed a kernel's object by the .h contents of its folder and gpu/asm joined: a header renamed with its
contents kept an object a clean compile no longer makes, and a .inc edit was not seen. A kernel is now compiled with
-MD and keyed as the host's and the back end's own files are (renderer_deps, DEPFILE_JOBS, rekey_depfiles): by the
names and contents of the headers its last compile read under its folder and gpu/asm, or by every header of the two
folders (tree_headers) before it has a depfile.

A gpu/asm kernel is compiled for each module with one key, and on a cold build both jobs could publish it: the second's
os.link failed on the first's entry, and its copyfile then wrote into that entry, a hard link to the first job's object.
cache_put leaves an entry it finds (FileExistsError), and a copy across volumes goes in whole by a rename.

The back end's own objects are keyed by gpu/asm's headers too (vdeps_roots), so a Vulkan caller of a shared kernel
compiles again when the kernel's declaration changes.

Assisted-by: Claude Code
tests/test_appimage_source_headers.py runs the AppImage script's copy block and checks that every file of gpu/asm
(lsasm.h, which every kernel includes) is carried and that every kernel's includes are, for host/asm, gpu/asm and
gpu/vk/asm (gpu/vk itself is copied whole after the block). tests/test_dev_packs.py routes the three kernel folders: a
host/asm kernel is the game's alone, so its pack builds the game without the renderer (renderer_untouched), a gpu/vk/asm
kernel builds the renderer alone, a gpu/asm kernel both.

They fail on this commit: the AppImage copies host/ and gpu/vk but not gpu/asm (a player's build with a host/asm kernel
stops listing it), and renderer_untouched takes only a host/ .c for the game's alone.

Assisted-by: Claude Code
scripts/linux/appimage.sh copied host/ and gpu/vk whole but not gpu/asm: a player's build with a host/asm kernel
stopped at asm_jobs listing the missing folder, and a gpu/asm kernel was left out of both modules. The source-copy
block now carries gpu/asm whole; tests/test_appimage_headers.py takes it for a host include of a kernel's declaration.

scripts/devtools/packs.py renderer_untouched took a host/ .c alone for the game's: a pack whose change was a host/asm
kernel, which only the game links, built and linked the renderer again. A host/asm .S is the game's alone now; a
header beside it, a gpu/asm kernel and a gpu/vk/asm kernel still build the renderer.

Assisted-by: Claude Code
tests/test_asm_kit.py records the commands tests/asm_kit.py would run, with no compiler: its CPU probe must read the
whole x86-64-v3 level (leaf 7, the extended leaf's LZCNT, the OS's ymm state through xgetbv) and a probe that crashed
must fail the check rather than read as a CPU without AVX2; two kernels of one name in two folders must be two
objects, natively and in the cross assembly, each linked once; a run with no clang found must fail instead of skipping
the cross assembly, an explicit clang must be the one used, and tests/test_asm_abi.py must take CXX without --cxx.

They fail on this commit: the probe reads AVX2, BMI2 and FMA alone and counts any exit but 0 as no AVX2, the objects
are named by the source's stem, a run without clang skips the cross assembly, and --cxx defaults to g++.

Assisted-by: Claude Code
tests/asm_kit.py ran the x86-64-v3 fixture where the CPU had AVX2, BMI2 and FMA, but a VM can mask MOVBE or LZCNT,
which the compiler emits at that level, and any exit of the probe but 0 read as no AVX2, a crash too. Its probe, built
for the baseline, now reads the whole level from CPUID (leaf 1, leaf 7, the extended leaf) and the OS's ymm state
(xgetbv), and an exit other than 0 or 1 fails the check.

The objects were named by the source's stem, so gpu/asm/hash.S and gpu/vk/asm/hash.S wrote one object and linked it
twice: each source's index is in its name now, natively and in the cross assembly.

Without clang on PATH the cross assembly (clang's assembler, the build's, for ELF and COFF) was skipped without a word,
and a CPU without AVX2 was then told its AVX2 bodies had been assembled. The clang is now the one given (--clang in
tests/test_asm_abi.py), else the one beside the compiler, else the one on PATH, and without one the check fails; its
PASS line names it. tests/test_asm_abi.py takes CXX when --cxx is not given. The unused os import is gone (Ruff F401).

Assisted-by: Claude Code
tests/test_asm_abi.py left the DWARF CFI unconsumed: removing the CFA adjustment after LSASM_ALLOC kept Linux green. A
Linux probe now stops in its body, with its scratch and padding in place, and calls the fixture, which unwinds from
there with the system's unwinder (_Unwind_Backtrace): the probe's frame must return to the harness's call, with rbx,
rbp and r12-r15 as the harness set them. A probe reads a table in LSASM_RODATA RIP-relative, so that macro is
assembled (ELF and COFF) and run.

On Windows each single step's unwind is now compared with the whole nonvolatile state of the entry: rsi, rdi and
xmm6-xmm15 as well in Win64, not the six other GPRs alone. A fault in a kernel is also taken by Windows' own dispatch
to a caller's __except, built with the game's -fms-extensions as guarded_copy is (clang; a gcc build says it skipped
this), besides the vectored handler that unwinds the one frame by hand.

Assisted-by: Claude Code
tests/asm_abi_probe.S calls a kernel of one argument on a stack that ends at its 32-byte home area, all a one-argument
Win64 call owes its callee, with the page above it left unreadable (tests/test_asm_abi.py, before any handler is set):
lsasm_probe_clobber and lsasm_probe_table must return their results there.

It fails on this commit: LSASM_ARGS reads the fifth and sixth slots on every call, so the first read lands in the
unreadable page.

Assisted-by: Claude Code
On Win64 LSASM_ARGS loaded the fifth and sixth arguments from the caller's stack on every call. A call of fewer owes
its callee the 32-byte home area alone, so the slots above it can lie past the stack's top. LSASM_ARGS now takes the
kernel's count of arguments (0 to 6; another count stops the assembly) and moves or loads only those: a one-argument
kernel reads no stack slot. The header says the mapping is for integer and pointer arguments; the probes give their
counts (6 for lsasm_probe_args, 1 for the others).

Assisted-by: Claude Code
tests/test_asm_build.py looked for asm_jobs' calls in main()'s text: it passed if a guard kept a call from running or
its jobs from a link list. main() now plans through plan_modules (nx2/build.py): the game's other jobs and the
renderer's in, the kernels joined (host/asm's and gpu/asm's to the game when it compiles the runtime, gpu/vk/asm's and
gpu/asm's to the renderer when it is built), RX_VK_ONLY's renderer-only jobs, and out the jobs and the two link lists
objs.rsp and vk_objs.rsp are written from. The build is the same as before; the kernels' jobs come after the game's
other jobs instead of after the runtime's files.

The test runs it on synthetic sources (two kernels in host/asm, one in gpu/asm, one of the same name in gpu/vk/asm)
and checks the compiled jobs and both modules' link inputs in full for a full build, a game-only build (no renderer
folder, as main() passes for RX_GAME_ONLY) and a renderer-only build (RX_VK_ONLY), and that main() plans and links
through it. tests/test_link_skip.py, test_renderer_depfiles.py and test_third_party_objects.py anchor on the planner's
line now, the lines they named being gone. docs/dev/reference/build.md names it.

Assisted-by: Claude Code
Importing nx2/build.py took the machine's build settings: RX_MARCH=native, or a CPU with x86-64-v3 and no RX_MARCH,
has clang say what -march=native is while the module loads, and RX_MARCH=native with no working clang stopped the
import before unittest started, in a check that says it runs no compiler. The test now imports it with the build's own
variables (RX_*, LONGSHOT_*, OOT_*) cleared and RX_MARCH=x86-64-v3, and with subprocess.Popen and os.system failing
while it loads: a process started by the import fails it instead of running. A test checks the CPU flags are the
fixed level's.

Assisted-by: Claude Code
hos_gpu_guest_ranges (host/nvdrv.c) sorts every GPU mapping's and native NVN pool's guest range by start before it
merges them, each time the mappings change: qsort with a comparison function call per compare. On x86-64 it now sorts
with host/asm/ranges.S's lsasm_sort_ranges, a hand-written merge sort on gpu/asm/lsasm.h: runs of 16 pairs by
insertion, then merges of runs twice as long a pass between the list and a second one (kept beside merged, grown with
it); two runs already in order (the mappings come mostly in address order) are copied, not merged, and the merge picks
its side with cmov, no branch. One body for both CPU levels: the pairs move in xmm registers. Other CPUs keep qsort
with cmp_range, under #if defined(__x86_64__). Both lists grow through hos_xrealloc (an allocation refused for 5 s
ends the run with the out-of-memory notice), where realloc's NULL was used as the list before.

It is stable where qsort is not: ranges that start together come out of qsort in any order, and the merge after the
sort makes the same ranges from any such order (one starts the merged range, the others only reach to their ends), so
the result is the same. No switch: the ranges merged are the same.

From 971f8074 on exp/x86-asm-sync, where the sort was collect.S's second kernel; here it is its own file. A
micro-benchmark there (i7-9700) found the kernel faster than qsort, more so in near order; not measured on this commit,
nor in play.

Test: tests/test_asm_ranges.py, through tests/asm_kit.py at SSE2 and AVX2, both conventions, clang ELF/COFF assembly:
the kernel against qsort with cmp_range (cut from the source) for 22 sizes around its runs and merges up to 10000 pairs
and 8 key patterns, between faulting pages: same order, stable, and hos_gpu_guest_ranges' merge makes the same ranges
from either order. The whole hos_gpu_guest_ranges, cut from the source, is compiled with its x86-64 test taken both
ways: the two give the same ranges for every case, one sorting with the kernel and the other with qsort, once a call.
scripts/profiling/cpu_functions.json describes lsasm_sort_ranges, and cmp_range as the other CPUs' comparison.

Assisted-by: Claude Code
The review asked for one shared kernel and one private kernel per module through a cold build, a cached rebuild after
an included file's rename, developer packs and the Linux AppImage's staging. tests/test_asm_end_to_end.py authors them
in a tree of its own (gpu/asm/e2e.S, host/asm/game.S, gpu/vk/asm/vk.S, each with an include, on the real lsasm.h) and
runs the build's own code on them with clang: plan_modules, plan_jobs with the hash record a build loads and saves,
compile_one on four threads (the shared kernel's two jobs at once), rekey_depfiles and main()'s own statements that
write the link lists. Each module's link list is linked with a caller and run, where this CPU runs x86-64-v3.

- a cold build compiles every kernel; a second build compiles nothing, nor does a new work folder made from its
  object cache (packs.link_objects), whose modules are the first's (module_changed);
- an include renamed while its kernel still names it compiles that kernel again and fails, as a clean build would; with
  the kernel naming the new file it compiles again, alone of the kernels;
- an include's edit compiles the kernels that read it, and its revert compiles nothing and links the cold build's
  objects, unchanged;
- packs one after another on one base (route, link_inputs_changed, renderer_untouched, link_objects, module_changed as
  cmd_pack runs them): a game kernel builds the game alone, a renderer kernel the renderer alone, a shared one both;
  each compiles the kernels that changed, and the base's objects and cache stay as they were;
- the AppImage's source-copy block, run with bash on the tree, carries the kernels and their includes, and a cold
  build of the staged tree compiles and links them.

nx2/build.py is imported as tests/test_asm_build.py imports it. The compiler is --cxx (CXX, else g++), clang beside it
(tests/asm_kit.py find_clang). The staging check needs bash: Git for Windows' on Windows, else it is skipped.

Assisted-by: Claude Code
compile_one hard-links each object into the object cache (cache_put), and links an object from the cache the same way;
a pack's work folder links the base's cache too (scripts/devtools/packs.py link_objects). clang's assembler, which
compiles the hand-written kernels (asm_jobs), writes its output in place (cc1as opens the -o path itself; clang's C and
C++ compiles write a temporary file and rename it over the object). A kernel compiled again therefore wrote through the
link: the cache's entry under the old key became the new object, and in a pack's work folder the base's cache entry and
its object did too. A build back at the old key (an edit reverted, a pack on that base) linked the edited kernel without
a word. compile_one now removes the object before it starts the compiler, so the compiler writes a new file and the
entries linked to the old one keep it. Every compile goes through it; for the C and C++ ones nothing changes, as their
compiler replaced the file anyway.

Test: tests/test_asm_end_to_end.py, which failed at the test commit: an include's edit and its revert linked the edited
kernel (the cache's entry under the cold build's key was the edited object), and a shared kernel's pack on a base wrote
into the base's objects and cache.

Assisted-by: Claude Code
The review: compile_one removes the old object but leaves its stamp (<object>.sha1) while clang's assembler writes the
new object in place. A build whose process tree is terminated during that write leaves part of an object under the old
stamp; once the edit is reverted the stamp matches the key again, and the first check (the object and its stamp) takes
the partial object before the object cache's valid entry is looked at.

tests/test_asm_end_to_end.py builds the kernels cold, edits the game kernel's include, and runs the next build with a
stand-in assembler for that kernel: a process that writes the first 64 bytes of the object at its own path and is
killed, and the build stops there (as its process tree terminated). The include is then reverted: the next build must
compile nothing and link the cold build's objects, unchanged, and the game's caller must give the cold build's values.

Assisted-by: Claude Code
The review: compile_one removed the object before it started the compiler but left its stamp (<object>.sha1). clang's
assembler, which compiles the hand-written kernels, writes its object in place, so a build whose process tree ended
during that write left part of an object under the old stamp. Once the edit was reverted the stamp matched the key
again, and the first check (the object and a stamp of its key) took the partial object before it looked in the object
cache, where the valid one is.

compile_one now removes the stamp as soon as it does not match: the object is replaced after that (linked from the
cache, or compiled), and only a finished one is stamped again. Without a stamp the next build links the cache's entry
or compiles again. The same holds for a link from the cache that stops before its stamp is written.

Test: tests/test_asm_end_to_end.py, test_a_stopped_replacement_and_its_revert, which failed at the test commit (the
revert linked the 64 bytes the stopped assembler had written).

Assisted-by: Claude Code
The review: main() sorts each compile's seconds into "renderer" or "host and game" by vk_job_objects, built from the
renderer's jobs before plan_modules joined the kernels to them (a new list), so a gpu/vk/asm or gpu/asm kernel of the
renderer was counted as host and game time.

tests/test_asm_build.py runs main()'s own statement (found in its syntax tree) on a plan of synthetic kernels: every
object the renderer links, its kernels included, is renderer time.

Assisted-by: Claude Code
vk_job_objects, by which main() counts each compile's seconds as renderer or host and game time, is now the set of the
renderer's link inputs plan_modules gives (vk_objs), its kernels included. It was built from the renderer's jobs before
the plan joined the kernels to them, so a renderer kernel was counted as host and game time.

Test: tests/test_asm_build.py, test_the_compile_time_breakdown_counts_the_renderer_kernels, which failed at the test
commit (vk_vk_draw.o alone was renderer time).

Assisted-by: Claude Code
The review: hos_gpu_guest_ranges grows the kernel's scratch list (one pair per range) through hos_xrealloc while it
holds the mapping lock. At the commit limit hos_xrealloc tries again for up to 5 s before the out-of-memory stop, and
every mapping change and lookup waits on the lock for as long.

tests/test_asm_ranges.py's fixture now holds a flag for the lock (LOCK, UNLOCK) and can refuse the scratch list: its
hos_xrealloc fails the check when asked for the sort's list while it is refused (the 5 s of tries), and the plain
realloc returns NULL. A call whose ranges outgrow every list the other cases grew, with the scratch refused, must sort
with qsort in place, not with the kernel, and leave the lock; the next call, with the scratch allowed, sorts with the
kernel, and both give the same ranges.

Assisted-by: Claude Code
fix(asm): a refused scratch list for the ranges' sort is not waited for with the mapping lock held
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 5s
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
CI / Website build and checks (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
cffa2f46ba
hos_gpu_guest_ranges grew lsasm_sort_ranges' scratch list (one pair per range) through hos_xrealloc with the mapping
lock held: refused at the commit limit, hos_xrealloc tries again for up to 5 s before the out-of-memory stop, and every
mapping change and lookup waited on the lock as long. The list is only the sort's; the ranges can be sorted without it.

It now grows through plain realloc, with a capacity of its own. When it is refused the call sorts with qsort and
cmp_range in place (as other CPUs do), and the next change of the mappings asks for it again. The merged list still
grows through hos_xrealloc: the call cannot go on without it (on main its realloc's NULL was used as the list).

Test: tests/test_asm_ranges.py, which failed at the test commit (the refused scratch went through hos_xrealloc's tries
with the lock held).

Assisted-by: Claude Code
perf(lift): FPX1's float wrappers are leaves, and six of their fast paths are hand-written x86-64
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 30s
beanstalk/approval waiting for a BigBean's 👍 on the request
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
CI / Website build and checks (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
b7bda95ed8
The kit's outlined FPX1 wrapper (a64_fpx_<op> in a64_fpx.h) is one function: the gate, the fast path, then the
sticky-flag rescues (and A64_FPXKEEP's, nx2/fpxkeep.py) and the exact body. The rescues' registers made clang save and
restore callee-saved registers on every call, before the fast path ran. nx2/fpx_helpers.py (new, wrapping
a64_lift.fpx_header as suyu_rt_fixes wraps the runtime's generator) makes the wrapper the gate and the fast path alone,
a leaf that tail-calls a64_fpx_rest_<op> (the rescues, the exact body) when it cannot prove its result; the hot copies
fall back to the rest directly. nx2/lift.py installs it after fpxkeep, whose rescues it moves into the rests;
install() stops if fpxkeep's has not run. An experiment, off by default (host and lifter experiments ship off unless
set): A64_FPX_LEAF=1 (or true, on, yes, in any case) at lift time turns the leaves on; unset or any other value lifts
a64_fpx.h exactly as main does.

host/asm/fpx.S and fpx.h (written with the asm kit's gpu/asm/lsasm.h): single-precision FMLA family, FADD, FSUB and
FSQRT and double-precision FADD and FSUB, the C's tests in fewer instructions, an SSE2 and an AVX2+FMA body,
tail-jumping to the C rest where the fast path declines. FMUL / FNMUL S, FDIV S and double FMUL / FNMUL and FMLA, which
the local branch also had in fpx.S, stay C leaves: in a micro-benchmark of the wrappers (i7-9700) their assembly was
no faster than the C leaf, and double FMUL slower. With all six wrappers as leaves in a lift's a64_fpx.h (lifted with
A64_FPX_LEAF=1), nx2/build.py builds the lifted code with -DA64_FPX_ASM and links fpx.S (RX_FPX_ASM, a sub-switch
read by each build in fpx_asm_on: on unless 0, false, off, no or empty; compile only, so in make_game's
COMPILE_ONLY_ENV); otherwise (main's wrappers, or RX_FPX_ASM=0) plan_modules leaves fpx.S out (its new leave_out).
a64_suyu.c defines the rests once (A64_FPX_IMPL, nx2/suyu_rt_fixes.py). Without it the same lift compiles the C
leaves.

tests/test_fpx_asm.py (with fpx_asm_test.c, fpx_asm_ref.c) generates the leaves (A64_FPX_LEAF=1) and checks every
kernel against the exact body and the C leaf, value and FPSR, at both levels (v3 where the CPU runs the whole level,
asm_kit.runs_v3) and in both conventions, and that it leaves its fast path exactly where the C does, and has clang
assemble fpx.S for ELF and COFF (a check without clang fails, as the kit's own);
test_fpx_sticky.py runs its checks on both forms of the header. tests/test_fpx_asm_switch.py: A64_FPX_LEAF unset and
its off values give main's a64_fpx.h to the byte and its on values the leaves; RX_FPX_ASM's values each in a fresh
process, read by each build, off without the assembly form, and fpxkeep's rescues in the rests;
tests/test_asm_build.py: a kernel left out of the plan.

From exp/x86-asm-sync 36d3d099, c4c8d297, 0b58b38d (fpx.S and fpx.h as committed at 6a4a8ec0, less the four kernels
above); its vector passes
are left out here (main's nx2/vecfp.py has most of them).

Assisted-by: Claude Code
Author
Contributor

@Beanstalk This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; the same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.

@Beanstalk This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (cffa2f46, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; the same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for b7bda95, and the PR has changed since (61fc4be), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `b7bda95`, and the PR has changed since (`61fc4be`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Author
Contributor

Measurements: the wrapper micro-benchmark ran again at this head (b7bda95e); its figures replace the fecf9557 table. Not measured in play yet: the in-game A/B is a held queue job.

Measurements: the wrapper micro-benchmark ran again at this head (b7bda95e); its figures replace the fecf9557 table. Not measured in play yet: the in-game A/B is a held queue job.
Author
Contributor

@Beanstalk One correction to my request 70166 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.

@Beanstalk One correction to my request 70166 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for b7bda95, and the PR has changed since (61fc4be), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `b7bda95`, and the PR has changed since (`61fc4be`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
dazemc left a comment

Read of b7bda95e (on #1947's cffa2f46, on main @ 9dd41326; WIP, not mergeable). Game-free checks only; no game run from me.

1. The six assembly kernels: no semantic difference from the C leaf that I can find.
The guards mirror the kit's macros exactly: FPX_GATE is RECOMP_FPX_OPEN (IXC set, no FPCR control bit but FZ); FPX_SUM is FIN32 then FZSUM32 (no subnormal operand, result big or zero); FPX_KEEP is BIG32 or a finite product of a zero; the FMA's FZ order, the SSE2 midpoint test and the fused AVX2 body; FSQRT's zero/positive-finite/FZ; the double FIN64/BIG64/SUBN64 and the zero result. The bounds are the C's (BIG32/64, SUBN, the midpoint), not off by one. No fast path writes FPSR — the gate's IXC is already set, and every exceptional result (NaN, inf, subnormal under FZ, tiny under FZ) goes to the rest, which is the same rescue + exact body as the C leaf. Rounding is the host's round-to-nearest (the gate rejects RMode), NaN/inf are declined, denormals are kept only under the C's conditions, and flags are left to the rest.

I ran tests/test_fpx_asm.py here: 99,531,018 checks a level, 0 mismatches at SSE2 and AVX2 — value and FPSR against the C leaf and recomp_fpe_*, and the fast path taken exactly where the C leaf takes it (the rest counted). tests/test_fpx_sticky.py passes in both header forms (v3 and v2, 8M/16M/150M checks, 0 mismatches). So the six match the interpreted wrappers as far as the kit's reference can say.

2. The "leaves" claim, and what a wrapper can do.

  • The assembly fast path is a frameless leaf: it reads c->fpsr and c->fpcr (observes memory), writes only registers, cannot throw, and tail-jumps to the rest. The function is not a leaf in the call-graph sense: the rest can write c->fpsr and calls the exact body, and the C leaf calls the rest on its slow path. If any tooling treated a64_fpx_<op> as pure/no-memory, that would be wrong; I found no such use (the hot copy inlines only the gate + fast path and falls back to the rest).
  • The hot copy now falls back to the rest instead of the wrapper. That only skips a second evaluation of the same fast path (which was just declined); the rest runs the same rescue and exact body. Equivalent.
  • fpx_helpers.leaf() does not split every wrapper: a shape with no rescue and no assembly (FDIV S; FDIV D if used) hits if not rescue: ... plain and stays main's one-function wrapper. The body's "each wrapper becomes the gate and the fast path alone" should say "each with a rescue or an assembly shape". The micro-benchmark's FDIV S "C leaf" figure is that same main wrapper (2.29 against 2.31 is one function's noise, not a leaf), so the table's only non-leaf entry is labelled as a leaf.

3. Other hosts and the default.
The assembly is x86-64 only (A64_FPX_ASM_ON requires RECOMP_FPX_HOST == 2, x86-64, not Emscripten); on ARM64/wasm the A64_FPX_LEAF=1 form is the C split (no fpx.S, no RX_FPX_ASM), which this PR does not test (the x86-64 C leaves cover the same code; the ARM64 host __builtin_fmaf/sqrt route is the kit's). A64_FPX_LEAF is off by default and in the lift key; RX_FPX_ASM is in COMPILE_ONLY_ENV, matters only in a standalone build of a leaf lift, and 0 gives the C leaves. The in-play effect is unmeasured: the micro-benchmark measures a wrapper call, not the game, and the PR's Still to test (this PC's areas, Linux, an x86-64-v2 CPU, AMD/Deck) is the evidence. The WIP checklist's "measured" is that micro-benchmark.

4. The test: the Linux half fails here, before testing the switch.
tests/test_fpx_asm_switch.py's 5 header/leaf tests pass here (main's header to the byte for the off values, the leaves for the on values, the install order). Its 14 build-switch tests fail on Linux: the child imports tests/test_asm_build.py, whose no_process guard rejects nx2/build.py's import-time pkg-config for FFmpeg (build.py:1163-1199). The base #1947's test_asm_build fails the same way on Linux, and the new test inherits it. The PR's Still to test lists Linux and this test; as written, the RX_FPX_ASM half cannot run there. Fix the new test's import (or let test_asm_build allow the FFmpeg query), then rerun; test_fpx_asm.py and test_fpx_sticky.py pass here.

5. Assembly and unwind. The kernels are assembled for ELF and COFF at both levels; the frameless leaves and the tail jumps keep the macros' unwind data. The runtime unwinder is not exercised (the tests do not throw), but no game-visible path throws, and fpx.h static-asserts the context offsets and gate mask.

No approval and no claim. The six paths look exact; the remaining items are the switch test on Linux, the in-play measurements, and the PR's own Still to test.

**Read of `b7bda95e` (on #1947's `cffa2f46`, on `main` @ `9dd41326`; WIP, not mergeable). Game-free checks only; no game run from me.** **1. The six assembly kernels: no semantic difference from the C leaf that I can find.** The guards mirror the kit's macros exactly: `FPX_GATE` is `RECOMP_FPX_OPEN` (IXC set, no FPCR control bit but FZ); `FPX_SUM` is `FIN32` then `FZSUM32` (no subnormal operand, result big or zero); `FPX_KEEP` is `BIG32` or a finite product of a zero; the FMA's FZ order, the SSE2 midpoint test and the fused AVX2 body; `FSQRT`'s zero/positive-finite/FZ; the double `FIN64`/`BIG64`/`SUBN64` and the zero result. The bounds are the C's (`BIG32`/`64`, `SUBN`, the midpoint), not off by one. No fast path writes FPSR — the gate's IXC is already set, and every exceptional result (NaN, inf, subnormal under FZ, tiny under FZ) goes to the rest, which is the same rescue + exact body as the C leaf. Rounding is the host's round-to-nearest (the gate rejects RMode), NaN/inf are declined, denormals are kept only under the C's conditions, and flags are left to the rest. I ran `tests/test_fpx_asm.py` here: **99,531,018 checks a level, 0 mismatches at SSE2 and AVX2** — value and FPSR against the C leaf and `recomp_fpe_*`, and the fast path taken exactly where the C leaf takes it (the rest counted). `tests/test_fpx_sticky.py` passes in both header forms (v3 and v2, 8M/16M/150M checks, 0 mismatches). So the six match the interpreted wrappers as far as the kit's reference can say. **2. The "leaves" claim, and what a wrapper can do.** - The **assembly fast path** is a frameless leaf: it reads `c->fpsr` and `c->fpcr` (observes memory), writes only registers, cannot throw, and tail-jumps to the rest. The **function** is not a leaf in the call-graph sense: the rest can write `c->fpsr` and calls the exact body, and the C leaf calls the rest on its slow path. If any tooling treated `a64_fpx_<op>` as pure/no-memory, that would be wrong; I found no such use (the hot copy inlines only the gate + fast path and falls back to the rest). - The **hot copy** now falls back to the rest instead of the wrapper. That only skips a second evaluation of the same fast path (which was just declined); the rest runs the same rescue and exact body. Equivalent. - `fpx_helpers.leaf()` does **not** split every wrapper: a shape with no rescue and no assembly (FDIV S; FDIV D if used) hits `if not rescue: ... plain` and stays **main's one-function wrapper**. The body's "each wrapper becomes the gate and the fast path alone" should say "each with a rescue or an assembly shape". The micro-benchmark's FDIV S "C leaf" figure is that same main wrapper (2.29 against 2.31 is one function's noise, not a leaf), so the table's only non-leaf entry is labelled as a leaf. **3. Other hosts and the default.** The assembly is x86-64 only (`A64_FPX_ASM_ON` requires `RECOMP_FPX_HOST == 2`, x86-64, not Emscripten); on ARM64/wasm the `A64_FPX_LEAF=1` form is the C split (no `fpx.S`, no `RX_FPX_ASM`), which this PR does not test (the x86-64 C leaves cover the same code; the ARM64 host `__builtin_fmaf`/sqrt route is the kit's). `A64_FPX_LEAF` is off by default and in the lift key; `RX_FPX_ASM` is in `COMPILE_ONLY_ENV`, matters only in a standalone build of a leaf lift, and `0` gives the C leaves. The **in-play** effect is unmeasured: the micro-benchmark measures a wrapper call, not the game, and the PR's Still to test (this PC's areas, Linux, an x86-64-v2 CPU, AMD/Deck) is the evidence. The WIP checklist's "measured" is that micro-benchmark. **4. The test: the Linux half fails here, before testing the switch.** `tests/test_fpx_asm_switch.py`'s 5 header/leaf tests pass here (main's header to the byte for the off values, the leaves for the on values, the install order). Its **14 build-switch tests fail on Linux**: the child imports `tests/test_asm_build.py`, whose `no_process` guard rejects `nx2/build.py`'s import-time `pkg-config` for FFmpeg (`build.py:1163-1199`). The base #1947's `test_asm_build` fails the same way on Linux, and the new test inherits it. The PR's Still to test lists Linux and this test; as written, the `RX_FPX_ASM` half cannot run there. Fix the new test's import (or let `test_asm_build` allow the FFmpeg query), then rerun; `test_fpx_asm.py` and `test_fpx_sticky.py` pass here. **5. Assembly and unwind.** The kernels are assembled for ELF and COFF at both levels; the frameless leaves and the tail jumps keep the macros' unwind data. The runtime unwinder is not exercised (the tests do not throw), but no game-visible path throws, and `fpx.h` static-asserts the context offsets and gate mask. No approval and no claim. The six paths look exact; the remaining items are the switch test on Linux, the in-play measurements, and the PR's own Still to test.
siantm force-pushed perf/fpx-leaf-asm from b7bda95ed8
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 30s
beanstalk/approval waiting for a BigBean's 👍 on the request
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
CI / Website build and checks (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 61fc4bec72
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 5s
2026-11-22 10:57:37 +00:00
Compare
Author
Contributor

The description now names head 61fc4bec: b7bda95e rebased onto #1947's head 186fdb85 (that PR's test commit for the Linux import), this PR's commit unchanged. Summary: which wrappers are split (each with a rescue or an assembly shape; a shape with neither stays main's one function) and what "leaf" means here. Testing: this head's checks, the switch test's Linux half (simulated on this PC, not run on Linux at this head), and dazemc's Linux runs as a third party's. Measurements: FDIV S, and FSQRT S in the RX_FPX_ASM=0 column, are labelled as main's one function, not a C leaf. Risks: the ARM64/wasm C split is untested.

The description now names head 61fc4bec: b7bda95e rebased onto #1947's head 186fdb85 (that PR's test commit for the Linux import), this PR's commit unchanged. Summary: which wrappers are split (each with a rescue or an assembly shape; a shape with neither stays `main`'s one function) and what "leaf" means here. Testing: this head's checks, the switch test's Linux half (simulated on this PC, not run on Linux at this head), and dazemc's Linux runs as a third party's. Measurements: FDIV S, and FSQRT S in the `RX_FPX_ASM=0` column, are labelled as `main`'s one function, not a C leaf. Risks: the ARM64/wasm C split is untested.
Author
Contributor

@dazemc, thank you for the read and the Linux runs.

  1. Nothing to change. Your Linux runs of tests/test_fpx_asm.py and tests/test_fpx_sticky.py at b7bda95e are now in Testing, as a third party's.

  2. Right, checked in leaf(): a shape with no rescue takes the if not rescue: branch and, unless it is one of fpx.S's six in an assembly build, stays one function: the gate, the fast path, then the exact body. With fpxkeep's default that is FDIV S and FDIV D; with A64_FPXKEEP=0 also FADD D, FSUB D, FMUL D and FMLA D outside fpx.S. One more: FSQRT S has no rescue either, so in the RX_FPX_ASM=0 build it is that one function too, and its 2.31 in the table's second column is main's form, as FDIV S's is. The Summary now says "each wrapper with a rescue or an assembly shape", names the ones that stay one function, and says what "leaf" means here (the function holds only the gate and the fast path and returns or tail-calls the rest; not a leaf in the call-graph sense, since the rest can write c->fpsr). The table labels FDIV S's two leaf-build figures and FSQRT S's RX_FPX_ASM=0 figure as main's one function. Description only, no code change.

  3. Added to Risks: fpx.S is x86-64 only, and on ARM64 or wasm A64_FPX_LEAF=1 is the C split, which this PR does not test (every check ran on x86-64).

  4. Pushed 61fc4bec: this PR's commit rebased onto #1947's 186fdb85 (your import patch, narrowed to FFmpeg's probe), unchanged (git range-diff). The new test needed no change of its own: its child imports tests/test_asm_build.py, which now answers the probe. Checked here by simulation only: tests/test_fpx_asm_switch.py run whole with its child forced onto the Linux build's path while nx2/build.py loads (toolchain.windows() false; the child asserts build.LINUX and FFMPEG_LX is None). At 61fc4bec: "Ran 10 tests ... OK". At b7bda95e: "FAILED (failures=14)", all 14 on the pkg-config --cflags libavcodec ... process, as on your Linux. It has not run on Linux at this head. The PR's own tests pass at 61fc4bec on this PC (Testing).

  5. Nothing to change. Thank you for checking the unwind data.

@dazemc, thank you for the read and the Linux runs. 1. Nothing to change. Your Linux runs of `tests/test_fpx_asm.py` and `tests/test_fpx_sticky.py` at b7bda95e are now in Testing, as a third party's. 2. Right, checked in `leaf()`: a shape with no rescue takes the `if not rescue:` branch and, unless it is one of `fpx.S`'s six in an assembly build, stays one function: the gate, the fast path, then the exact body. With fpxkeep's default that is FDIV S and FDIV D; with `A64_FPXKEEP=0` also FADD D, FSUB D, FMUL D and FMLA D outside `fpx.S`. One more: FSQRT S has no rescue either, so in the `RX_FPX_ASM=0` build it is that one function too, and its 2.31 in the table's second column is `main`'s form, as FDIV S's is. The Summary now says "each wrapper with a rescue or an assembly shape", names the ones that stay one function, and says what "leaf" means here (the function holds only the gate and the fast path and returns or tail-calls the rest; not a leaf in the call-graph sense, since the rest can write `c->fpsr`). The table labels FDIV S's two leaf-build figures and FSQRT S's `RX_FPX_ASM=0` figure as `main`'s one function. Description only, no code change. 3. Added to Risks: `fpx.S` is x86-64 only, and on ARM64 or wasm `A64_FPX_LEAF=1` is the C split, which this PR does not test (every check ran on x86-64). 4. Pushed 61fc4bec: this PR's commit rebased onto #1947's 186fdb85 (your import patch, narrowed to FFmpeg's probe), unchanged (`git range-diff`). The new test needed no change of its own: its child imports `tests/test_asm_build.py`, which now answers the probe. Checked here by simulation only: `tests/test_fpx_asm_switch.py` run whole with its child forced onto the Linux build's path while `nx2/build.py` loads (`toolchain.windows()` false; the child asserts `build.LINUX` and `FFMPEG_LX is None`). At 61fc4bec: "Ran 10 tests ... OK". At b7bda95e: "FAILED (failures=14)", all 14 on the `pkg-config --cflags libavcodec ...` process, as on your Linux. It has not run on Linux at this head. The PR's own tests pass at 61fc4bec on this PC (Testing). 5. Nothing to change. Thank you for checking the unwind data.
Author
Contributor

@Beanstalk This replaces my request 70166, made for the earlier head b7bda95e; this head is the same code rebased onto #1947's 186fdb85 (only #1947's tests/test_asm_build.py differs). This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (186fdb85, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between (a picture during the load's fade-in from black is not comparable), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.

@Beanstalk This replaces my request 70166, made for the earlier head b7bda95e; this head is the same code rebased onto #1947's 186fdb85 (only #1947's tests/test_asm_build.py differs). This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (186fdb85, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between (a picture during the load's fade-in from black is not comparable), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

@Beanstalk This replaces my request 72862 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (186fdb85, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.

@Beanstalk This replaces my request 72862 on this head and the corrections under it, in a form the farm can run: it cannot time a picture from the first frame that is not a uniform colour (its answer on #2131), so each picture here follows a fixed wait after the map event. This adds A64_FPX_LEAF, a lift-time switch off by default: with A64_FPX_LEAF=1 the lifted code's float maths goes through leaf wrappers and hand-written x86-64 routines (host/asm/fpx.S; RX_FPX_ASM=0 then keeps the C leaves). The farm cannot set a lift-time switch, so only the default build is to test here: unset, this PR's lift and its lifted C must be main's; the enabled build is measured outside the farm. It sits on #1947 (186fdb85, the asm kit), so its diff against its merge base includes that PR's commits and its build differs from main's by them; the farm cannot take #1947 as the comparison, so please compare with main. Please time the lift against main's and check the lifted C is the same; then start from the market-entrance save and take the picture 10 s (600 frames at 60 fps) after the map event that ends the load, a fixed wait with no input in between (the farm cannot time it from the first frame that is not a uniform colour), with a main-against-itself picture on the same PC from the same point; then, for frame times only, play Castle Town Market for two minutes; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Linux with a Ryzen 5 5600X and the Steam Deck. The same lifted C as main; The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL line, and no run may crash or hang.
Member

@siantm only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Author
Contributor

Testing and Measurements: the first in-game sitting has run: Kokiri Forest, this PR with A64_FPX_LEAF=1 against its base #1947, 8 interleaved runs a side. The game thread's time a frame was 2.2 % lower (p 0.01); fps, waiting time and frame-time tails were not shown to differ. That is one sitting and is not called a gain: a second sitting is queued, and both will be read together in a later update.

Testing and Measurements: the first in-game sitting has run: Kokiri Forest, this PR with `A64_FPX_LEAF=1` against its base #1947, 8 interleaved runs a side. The game thread's time a frame was 2.2 % lower (p 0.01); fps, waiting time and frame-time tails were not shown to differ. That is one sitting and is not called a gain: a second sitting is queued, and both will be read together in a later update.
Author
Contributor

Measurements: the second in-game sitting has run. The first sitting's lean (-2.2 %, p 0.01) did not repeat: the second is level (-0.2 %, p 0.97). Pooled over both, nothing is shown to differ (-1.2 %, p 0.35). The Verdict and the "In play" tables now cover both sittings, and the queued sitting is removed from Still to test. No further sitting is planned.

Measurements: the second in-game sitting has run. The first sitting's lean (-2.2 %, p 0.01) did not repeat: the second is level (-0.2 %, p 0.97). Pooled over both, nothing is shown to differ (-1.2 %, p 0.35). The Verdict and the "In play" tables now cover both sittings, and the queued sitting is removed from Still to test. No further sitting is planned.
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
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 5s
This pull request has changes conflicting with the target branch.
  • docs/dev/reference/build.md
  • nx2/build.py
Some workflows are waiting to be reviewed.
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/fpx-leaf-asm:siantm-perf/fpx-leaf-asm'
git switch 'siantm-perf/fpx-leaf-asm'
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!2152
No description provided.