WIP: perf(lift): FPX1's float wrappers are leaves, and six of their fast paths are hand-written x86-64 #2152
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2152
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/fpx-leaf-asm"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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=1at lift time the lift writesa64_fpx.hexactly asmaindoes and the build neither compiles nor links
fpx.S. Off by default as futondestroyer's review comments 67223 and67225 ask (host and lifter experiments ship off unless set).
Lifted code calls an outlined helper,
a64_fpx_<op>in the lift'sa64_fpx.h, for most single- and double-precisionfloat 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 theexact 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; wrapsa64_lift.fpx_header, asnx2/suyu_rt_fixes.pywraps the runtime's generator):with
A64_FPX_LEAF=1(ortrue,on,yes, in any case) at lift time, each wrapper with a rescue or an assemblyshape becomes the gate and the fast path alone, a leaf that tail-calls
a64_fpx_rest_<op>(the rescues, then theexact 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=0also FADD D, FSUB D, FMUL D and FMLA D, outsidefpx.S; FSQRT S in a build withRX_FPX_ASM=0) is not split: it staysmain's one function (the gate, the fast path, then the exact body; only thegate moves inside
RECOMP_LIKELY). Unset or any other value: the header is returned unchanged,main's form (withfpxkeep's rescues).
nx2/lift.pyinstalls it afternx2/fpxkeep.py, soA64_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->fpcrandc->fpsr, writes onlyregisters, 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-graphsense: through the rest it reaches the rescues and the exact body, which can write
c->fpsr, asmain's wrapperdoes. The lift treats
a64_fpx_<op>as it treatsmain's wrapper.host/asm/fpx.S,fpx.h: the fast paths of single-precision FMLA family, FADD, FSUB and FSQRT anddouble-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 datathe 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, asmain's one function): in the micro-benchmark under Measurements their assembly was no faster than the C, anddouble FMUL slower.
nx2/build.py:fpx_asm_onreadsRX_FPX_ASMat each build, a sub-switch of the leaves: in the standalone buildof a lift whose
a64_fpx.hhas all six wrappers as leaves (lifted withA64_FPX_LEAF=1), unset or any value but0,false,off,no(any case) or empty compiles the lifted code with-DA64_FPX_ASMand linksfpx.S;RX_FPX_ASM=0keeps the C leaves. Without the leaves it changes nothing:plan_modulesleavesfpx.Sout (its newleave_out). Compile only:nx2/make_game.pykeeps the lift when it changes.a64_suyu.cdefines the rests once(
A64_FPX_IMPL,nx2/suyu_rt_fixes.py).Tests:
tests/test_fpx_asm.py(withfpx_asm_test.c,fpx_asm_ref.c; it generates the leaves itself),tests/test_fpx_asm_switch.py(new:A64_FPX_LEAFunset or off givesmain'sa64_fpx.hto the byte, on gives theleaves;
RX_FPX_ASM),tests/test_asm_build.py(a kernel left out of the plan);tests/test_fpx_sticky.pyrunsits 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.has committed there, less thefour kernels above). Main's
nx2/vecfp.pyalready has most of that branch's vector passes; FADDP and FSQRT (vector) and the FRECPE/FRSQRTE tableare PRs of their own.
Read first:
nx2/fpx_helpers.pyleaf_on,leafandinstall,host/asm/fpx.S(FPX_GATE,FPX_KEEP),fpx_asm_oninnx2/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 andfpx.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:b7bda95erebased onto #1947's head186fdb85, which iscffa2f46plus one test commit totests/test_asm_build.py; onmain@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 themA64_FPX_LEAFunset,0, empty,2,off,noandfalsegivingmain'sa64_fpx.hto the byte, and1,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 in7.1 s") and
tests/test_vecfp.py("vecfp: pass in 11.6 s"; both usetests/test_fpx_sticky.py's generator,main's form by default) pass.tests/test_lift_cache.pyfails on this head as onmain@9dd41326(run there atb7bda95e), with the same output,"FAIL: ...and the others still by their code".
runs
tests/test_fpx_asm_switch.pywhole with its child forced onto the Linux build's path whilenx2/build.pyloads (
toolchain.windows()false, as #1947's own import checks do; the child also asserts thatbuild.LINUXistrue and
FFMPEG_LXNone). At this head: "Ran 10 tests ... OK". Atb7bda95eoncffa2f46: "FAILED (failures=14)",all 14 on the import's
pkg-config --cflags libavcodec ...process, as on dazemc's Linux. Only the import's Linuxbranch is simulated; the rest of the system is Windows. The test itself needed no change.
b7bda95e(same code as this head), each one fault in agit archivecopy:A64_FPX_LEAFon by default(
leaf_on's default made"1"):tests/test_fpx_asm_switch.pyfails (2 failures: unset is no longermain'sheader); the rests without their rescues:
tests/test_fpx_asm_switch.pyfails (8 failures, one for each shapefpxkeep edits).
By a third party: dazemc, on Linux at
b7bda95e(oncffa2f46), game-free, in hisreview:
tests/test_fpx_asm.py99,531,018 checks a level, 0 mismatches at SSE2 and AVX2;tests/test_fpx_sticky.pypasses inboth header forms (x86-64-v3 and v2, 0 mismatches);
tests/test_fpx_asm_switch.py: its 5 header, leaf and order testspass, its 14 build-switch checks failed in the child's import of
tests/test_asm_build.py(the FFmpegpkg-configprobe), which #1947's
186fdb85answers. 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):
cffa2f46and intomain@9dd41326fail there(
tests/test_fpx_asm.py: nohost/asm/fpx.Soncffa2f46, notests/asm_kit.pyonmain;tests/test_fpx_asm_switch.py: nonx2/fpx_helpers.py;tests/test_asm_build.py: nofpx.Schoice inplan_modulesoncffa2f46, noasm_jobsonmain). Teeth at fecf9557:nx2/lift.pyinstallingfpx_helpersbefore
fpxkeep:tests/test_lift_cache.pyfails ("the lift's scripts import (fpx_helpers: install() beforenx2/fpxkeep.py's ...)");
fpx_asm_on's test inverted:tests/test_fpx_asm_switch.pyfails;plan_modulesignoringleave_out:tests/test_asm_build.pyfails; at 34da225e:FPX_KEEP's bound infpx.Smade 0xfe000000:tests/test_fpx_asm.pyfails (mismatches at SSE2). Since then only the switch changed (its name, its default, thetests that set it);
fpx.S, the leaf form and the build's choice are as they were.tests/run_all.py --strict --changed origin/mainran at 34da225e (oncffa2f46onmain@9dd41326): 786 passed,87 failed, 48 skipped. 85 of the failures fail on
main@9dd41326and oncffa2f46too. The other 2,tests/test_audio_voice_biquad.pyandtests/test_audio_wave_buffer_release.py, hit their own 30 s compile limitwith 8 checks at once and passed when run alone at 34da225e. Not rerun at this head.
Still to test:
head
186fdb85(this PR's base: the kit withoutfpx.S, the wrappers inmain's form), this PR lifted withA64_FPX_LEAF=1and built withRX_FPX_ASM=0(the C leaves, the same lift), and this PR lifted withA64_FPX_LEAF=1(fpx.S); each warmed once, then interleaved (base, C leaves,fpx.S,fpx.S, C leaves, base), atleast 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.Sas the base's or better (by hand)python3 -I -B tests/test_fpx_asm_switch.py -v, expecting "Ran 10 tests ... OK" (itsbuild-switch half failed on the import at
b7bda95eand passes here only on the simulated Linux path above); andtests/test_fpx_asm.pyandtests/test_fpx_sticky.py, which passed on Linux atb7bda95e(by hand)A64_FPX_LEAF=1againstRX_FPX_ASM=0, expecting the same play with the SSE2 body (by hand)lifted with
A64_FPX_LEAF=1againstmain, expecting the same game and picture, no crash and frame timesas
main's or better (@Beanstalk play Castle Town's market for two minutes on PCs with AMD CPUs and on the SteamDeck, this PR against main, comparing frame times and checking for crashes)
Measurements
Verdict: both switches' defaults leave the game as
mainbuilds it:A64_FPX_LEAFunset lifts the wrappers inmain's form, andRX_FPX_ASMmatters only in a lift made withA64_FPX_LEAF=1(then unset: the six fast paths infpx.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
186fdb85added only that PR's test commit) on 2026-11-22: three programs, run in turn withineach of 7 rounds, for each of the ten FPX ops:
main's wrapper (A64_FPX_LEAFunset);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 noassembly, so each stays
main's one function (only the gate moved insideRECOMP_LIKELY);A64_FPX_LEAF=1,RX_FPX_ASMunset:fpx.Sfor six ops, the C leaf for FMUL S, FMUL D and FMLA D, and FDIV Sstill
main's one function.With
A64_FPX_LEAF=1, nine of the ten ops are faster thanmain's wrapper. FDIV S is not split by this PR: its threefigures (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.Sthe assembly is ahead of the C: FMLA S, FADD S, FSUB S and FSUB D against the Cleaf, 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.02against 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 wrapperis 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-cpuqueue job, no other queue job beside it. This PR @b7bda95eon #1947 @cffa2f46onmain@9dd41326.b7bda95emain's wrapper (A64_FPX_LEAFunset)A64_FPX_LEAF=1,RX_FPX_ASM=0(C leaves)A64_FPX_LEAF=1(defaultRX_FPX_ASM)RX_FPX_ASM)fpx.Sfpx.Sfpx.Smain's one function)main's one function)main's one function (not split)main's one function)fpx.Sfpx.Sfpx.SThe 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=1against its base #1947, two sittingsSetup: 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-startsave, the teleport checked as taken: every run in the light load state), 60 s standingand 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 8interleaved 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 isb7bda95e(this head's code:61fc4becaddstests only) lifted with
A64_FPX_LEAF=1,RX_FPX_ASMunset (the six fast paths infpx.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.hin its leaf form, which every lifted chunk includes),-DA64_FPX_ASMandfpx.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:
cffa2f46(main's wrappers)A64_FPX_LEAF=1Second sitting, 17:32 to 18:18 UTC, desktop 800x600 at 30 Hz (swapchain 800x581), the same builds and settings, none left
out:
cffa2f46(main's wrappers)A64_FPX_LEAF=1Per run, calm-stretch game ms (in run order):
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=1the lift'sa64_fpx.hismain's to the byte (a test checks it) andfpx.Sis not built, so players and default builds see no change. With it, float results: every kernel is checked bitfor 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=0at build time (the C leaves, no new lift) orA64_FPX_LEAFunset (main's wrappers, a new lift).Other hosts:
fpx.Sis x86-64 only (A64_FPX_ASM_ONneedsRECOMP_FPX_HOST == 2on x86-64, not Emscripten). On anARM64 or wasm host,
A64_FPX_LEAF=1is the C split alone (the leaves and rests, no assembly), which this PR does nottest: 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 everyhost/asmkernel linked into the game).Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.@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.@siantm only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was forb7bda95, and the PR has changed since (61fc4be), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.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.@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.
@siantm only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was forb7bda95, and the PR has changed since (61fc4be), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Read of
b7bda95e(on #1947'scffa2f46, onmain@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_GATEisRECOMP_FPX_OPEN(IXC set, no FPCR control bit but FZ);FPX_SUMisFIN32thenFZSUM32(no subnormal operand, result big or zero);FPX_KEEPisBIG32or 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 doubleFIN64/BIG64/SUBN64and 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.pyhere: 99,531,018 checks a level, 0 mismatches at SSE2 and AVX2 — value and FPSR against the C leaf andrecomp_fpe_*, and the fast path taken exactly where the C leaf takes it (the rest counted).tests/test_fpx_sticky.pypasses 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.
c->fpsrandc->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 writec->fpsrand calls the exact body, and the C leaf calls the rest on its slow path. If any tooling treateda64_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).fpx_helpers.leaf()does not split every wrapper: a shape with no rescue and no assembly (FDIV S; FDIV D if used) hitsif not rescue: ... plainand 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_ONrequiresRECOMP_FPX_HOST == 2, x86-64, not Emscripten); on ARM64/wasm theA64_FPX_LEAF=1form is the C split (nofpx.S, noRX_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_LEAFis off by default and in the lift key;RX_FPX_ASMis inCOMPILE_ONLY_ENV, matters only in a standalone build of a leaf lift, and0gives 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 importstests/test_asm_build.py, whoseno_processguard rejectsnx2/build.py's import-timepkg-configfor FFmpeg (build.py:1163-1199). The base #1947'stest_asm_buildfails the same way on Linux, and the new test inherits it. The PR's Still to test lists Linux and this test; as written, theRX_FPX_ASMhalf cannot run there. Fix the new test's import (or lettest_asm_buildallow the FFmpeg query), then rerun;test_fpx_asm.pyandtest_fpx_sticky.pypass 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.hstatic-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.
b7bda95ed861fc4bec72The description now names head
61fc4bec:b7bda95erebased onto #1947's head186fdb85(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 staysmain'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 theRX_FPX_ASM=0column, are labelled asmain's one function, not a C leaf. Risks: the ARM64/wasm C split is untested.@dazemc, thank you for the read and the Linux runs.
Nothing to change. Your Linux runs of
tests/test_fpx_asm.pyandtests/test_fpx_sticky.pyatb7bda95eare now in Testing, as a third party's.Right, checked in
leaf(): a shape with no rescue takes theif not rescue:branch and, unless it is one offpx.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; withA64_FPXKEEP=0also FADD D, FSUB D, FMUL D and FMLA D outsidefpx.S. One more: FSQRT S has no rescue either, so in theRX_FPX_ASM=0build it is that one function too, and its 2.31 in the table's second column ismain'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 writec->fpsr). The table labels FDIV S's two leaf-build figures and FSQRT S'sRX_FPX_ASM=0figure asmain's one function. Description only, no code change.Added to Risks:
fpx.Sis x86-64 only, and on ARM64 or wasmA64_FPX_LEAF=1is the C split, which this PR does not test (every check ran on x86-64).Pushed
61fc4bec: this PR's commit rebased onto #1947's186fdb85(your import patch, narrowed to FFmpeg's probe), unchanged (git range-diff). The new test needed no change of its own: its child importstests/test_asm_build.py, which now answers the probe. Checked here by simulation only:tests/test_fpx_asm_switch.pyrun whole with its child forced onto the Linux build's path whilenx2/build.pyloads (toolchain.windows()false; the child assertsbuild.LINUXandFFMPEG_LX is None). At61fc4bec: "Ran 10 tests ... OK". Atb7bda95e: "FAILED (failures=14)", all 14 on thepkg-config --cflags libavcodec ...process, as on your Linux. It has not run on Linux at this head. The PR's own tests pass at61fc4becon this PC (Testing).Nothing to change. Thank you for checking the unwind data.
@Beanstalk This replaces my request 70166, made for the earlier head
b7bda95e; this head is the same code rebased onto #1947's186fdb85(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.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@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.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Testing and Measurements: the first in-game sitting has run: Kokiri Forest, this PR with
A64_FPX_LEAF=1against 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.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.
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.