perf(lift): keep NaN and infinite operands and exact-zero multiply-adds off the software float bodies (A64_FPXKEEP) #1905
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1905
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:perf/fpx-fallbacks-pr"
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
The translated game code does each float operation with the PC's instruction when it can prove the result is Arm's (the fast path) and otherwise calls an exact software routine (
recomp_fpe_*, multi-word integer code of about 180 ns a call). In a Market profile those software routines took 1.895 % of the game's code time, and the lane-by-lane route of the vector operations that end in them another 1.3 % (3.2 % together). Two cases cause most of it, and neither needs the software routine: the Havok cloth's particle positions carry a quiet NaN in their unused fourth lane, so every 4-lane FMUL, FADD and FSUB on them failed the vector fast check and went lane by lane to the software routines (2,000 captured bend-pass calls: 6.7 million software calls, 100 % a quiet NaN operand); and the game'spowfcomputesz * invc - 1with an FMADD that cancels to exactly +0 whenever x is a power of two, which the fast path does not keep and binary64 had no rescue for (one software call per suchpowf; the cloth damping callspowf(1 + ..., 60 dt)).This PR adds three rules, each proven exact, that keep those results without the software routine:
How:
nx2/fpxkeep.pyedits the helpers the translator writes intoa64_fpx.h, not the lifted functions: the eight outlined scalar wrappers (a64_fpx_{add,sub}{32,64}_*,a64_fpx_{mul,fma}{32,64}_fma*) get one rescue after the fast path and the kit's rescues, before the software routine, inside the float gate; the kit's lane routes (a64_vfpx_add32_lanes,_sub32_lanes,a64_vfpx_mul32_lanes, whichnx2/fastvec.py's by-element FMUL also takes) get a head that computes the NaN and infinite lanes on SSE from their bits, runs the vector operation again with zeros in those lanes, and merges the two; with no such lane the lanes run one by one as before. The inline fast paths, the hot copies and the vector fast checks are unchanged, so the common case costs what it did and the lifted functions' C text is the same.A64_FPXKEEPis a lift-time switch (anA64_variable, so in the lift key): unset or1on,0writesa64_fpx.has main does, byte for byte. Each edit must match the kit's text exactly once, or the lift stops with a message.Where it meets #1782 (
A64_VECFP, merged): no shared lines and no shared symbols. Both add an import and an install tonx2/lift.py(vecfp's beside fastvec's, this one aftersuyu_rt_fixes) and a row todocs/dev/reference/build.md(vecfp's afterA64_FASTFP, this one afterRX_MARCH); the branch was cut from a main without #1782 and moved onto current main with no conflict. They meet at run time: when one of vecfp's SSE forms (FMLA / FMLS, FMUL 2S, by-element FMLA, FDIV) declines a lane, the old per-lane C runs, and its scalar wrappers now take rules N, I and Z. vecfp's own SSE helpers do not take NaN lanes themselves (a follow-up could give them the same head). Its helpers area64_vfpx_<form>/a64_vx_*, this PR'sa64_fpxk_*.The graphics settings guide also states when the Custom HUD placement controls and reset action are shown. The website settings parser recognizes that condition and the registered reset action, with coverage in
website/tests/graphics-settings.test.ts; these changes do not alter the game's settings behavior.Read first:
nx2/fpxkeep.py(its docstring states the rules and their proofs),tests/test_fpxkeep.pywithtests/fpxkeep_test.c, the two lines innx2/lift.py, the row indocs/dev/reference/build.md.Testing
Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game: this change (69b6326a, cherry-picked) lifted into a test tree with nine rewrite branches on main
068fb8eb(test/rewrites@ e614ef49), withA64_FPXKEEPon and no run-time switch: three runs in the Market at a 60 fps cap in the CPU measurement below, every run held 60. That tree is on main068fb8eb, before #1782 was merged: the two together have not been built into a game. This head is not built or played.Exactness, game-free:
tests/test_fpxkeep.pychecks each rule against the software routinesrecomp_fpe_*(the value and FPSR), with FPCR random over FZ, DN, the rounding modes and the other bits and FPSR states chosen for the earlier fixtures, in an x86-64-v3 build and an x86-64-v2 build (no FMA): 16,000,000 random scalar checks (kept by N 3,114,660, by I 1,260,858 at v3 and 1,411,761 at v2, by Z 55,973 binary64 at v3 and 103,433 binary32 at v2); a sweep of every pair and triple of 30 binary32 and 26 binary64 special values with Z's exponent edge built in (1,048,032 checks); 16,000,000 cancelling multiply-adds (Z kept 770,485 binary64 at v3, 497,777 binary32 at v2); 4,000,000 vector operations (2- and 4-lane FADD, FSUB, FMUL, FMUL by element) against each lane's software routine (2,330,657 kept by the new lane head). 0 mismatches in every run; no rule keeps a result under a closed gate. Sixteen deliberately broken rules (the NaN order, IOC, IDC, the default-NaN case, FSUB negating a NaN, inf - inf kept, inf * 0 kept, a flushed subnormal beside an infinity, Z's binary64 edge at 1075, Z's binary32 test in binary32, and in the lane head: two lanes taken as four, the NaN order, IOC, IDC, FSUB's infinite operand, inf * a flushed subnormal): every one fails. WithA64_FPXKEEP=0the header is main's byte for byte. These runs preceded the fixture changes; the revised tests still need to be run.Together with #1782:
tests/test_vecfp.pypasses at this head, and so does a copy of it run withnx2/suyu_rt_fixes.pyandnx2/fpxkeep.pyinstalled after vecfp, innx2/lift.py's order (vecfp's forms against their lanes, with this PR's edits in the samea64_fpx.h, at x86-64-v3 and v2): every vecfp form 0 mismatches at both levels, the header compiled with both.Game-free checks:
tests/test_fpxkeep.pypassed at1ce24477, before the fixture changes; the revised test has not been run. At1ce24477,test_fpx_sticky,test_fma_soft,test_vfpx_elem,test_fastfp_fma,test_fastfp_regions,test_fastfp_override,test_vecfp,test_switch_table,test_doc_anchorsand the other tests that readnx2/lift.py, the float headers ordocs/dev/reference/build.md: 29 of 35 pass. The other six fail here and on maina104182balike:test_dev_packs,test_libc_hooks,test_lift_cache(its "...and the others still by their code" check),test_linux_preflight,test_make_game_ngx,test_sdiv_overflow.test_vbytes(TBL / EXT, not touched here) was not run: it did not finish in 50 minutes on the branch's first base.tests/run_all.pywas not run. Note for CI:ruffreportsglobimported and unused innx2/lift.pyon maina104182bitself; this PR changes that file in two other lines.Still to test:
A64_FPXKEEPon) in the child Market and in Hyrule Field by day for a few minutes each; the game's CPU seconds with the frame rate capped at 60, and the frame times uncapped. Expecting less CPU time on the main executor threads, the same frame rate or better, and the picture as on main, cloth included (@Beanstalk linux).Measurements
Verdict: less CPU work: with
A64_FPXKEEPon, the game's process used 0.8 % less CPU standing and 0.9 % less turning in the Market at a 60 fps cap, and the executor threads 1.7 % and 2.2 % less, against plain main068fb8eb. That build also carries nine rewrite branches' hooks with every run-time switch off, which measured at no cost on their own (-0.3 % / -0.2 %, inside the runs' spread).Baseline: main
068fb8eb(#1802), against the test treetest/rewrites@ e614ef49 (main068fb8ebwith nine rewrite branches: the seven maths units, the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the six-channel reverb, and the solver; the cloth and particle effect rewrites, the two- and four-channel reverb and later pieces of other branches are not among them, and this change cherry-picked), lifted withA64_FPXKEEPon and no run-time switch set; beside it the same tree lifted withA64_FPXKEEP=0(the hooks alone). Not this PR alone on current main: the tree is on068fb8eb, before #1782 and 27 other commits.Setup: Windows 11, Ryzen 9 5900X, RTX 3090, 3840x2160; the child Market, hands-free; frame rate capped at 60 (all 15 runs of the measurement held 60); each run 30 s standing, then 30 s turning the camera; five variants interleaved over three rounds, the PC otherwise idle. CPU seconds per second of play (cores busy on average), from the processor's cycle counter; the median of three runs (the three in brackets for the process).
068fb8ebA64_FPXKEEP=0, the hooks off: test/rewrites @ e614ef49A64_FPXKEEPon, the hooks off: test/rewrites @ e614ef49BaseProcExecutor1..), standing, coresWith the nine branches' run-time switches on as well, it took another 1.0 % standing and 0.6 % turning off the process (it and those rewrites overlap on
powf). The process includes the renderer's threads (about 1.4 cores standing), which this change does not touch.Offline, cost a call (
bench_fpxkeep, -O1 -march=native as the build compiles lifted code, the runtime -O2; Ryzen 9 5900X with other jobs running, best of 5 rounds of 7; FPCR FZ):powfat x a power of two)From the Market profile and these costs the estimate was about 2.1 % of the game's code time (
powf's software calls 0.55 %, the lane routes 1.6 %). The route profiles (Kakariko, Death Mountain Trail) had no samples in the software routines.The switch
A64_FPXKEEP(new, lift time, indocs/dev/reference/build.md; not ingpu/vk/switches.def, which lists what the game reads): on unless set to0, as the measurement above chose.A64_FPXKEEP=0writesa64_fpx.has main does, byte for byte. It is in the lift key, so changing it lifts again.Risks
What could break: a float result that differs from Arm's in the cases the rules keep (a NaN's payload or sign, a flag in FPSR, the sign of a cancelled zero); every rule is checked against the software routines on 37 million cases a build with sixteen broken versions caught. A refreshed a64-kit or fastvec that moves the text these edits match stops the lift with a message rather than writing a wrong header. Rounding modes other than nearest, default-NaN mode and the other FPCR bits close the gate as before. Not taken: made-up NaNs (inf - inf, 0 * inf), binary64 tiny or overflowing results with the flag already set, FDIV, FRECPS / FRSQRTS; none was seen in the classified data. Inside a fast float region (
nx2/fastfp.py) a NaN still sends the region to its exact copy, which then takes these paths.Turning it off: build with
A64_FPXKEEP=0(a new lift).After updating: the next build lifts the game again (the lift key changes); saves,
longshot_options.iniand the caches do not change otherwise.Checklist
Ready for review
main; the title is a Conventional Commit.068fb8eb, without #1782; this head is not built or played.)mise run testpasses (any failure that also fails onmainis named). (29 of the 35 related tests pass, the six failures are main's; the whole suite not run.)main, or Measurements says why there is nothing to measure. (Against main068fb8eb, in a tree that also carries other branches' hooks, off.)third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened. (tests/test_fpxkeep.py, new.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Lifted with A64_FPXKEEP on into a test tree of nine merged rewrite branches on main
068fb8eb(before #1782) and run three times in the Market at a 60 fps cap in a 15-run CPU measurement (Windows, RTX 3090; every run held 60; -0.8 % / -0.9 % of the process's CPU against main); this head, with #1782, is not built or played.@Beanstalk linux: main against this branch (it changes the translator: A64_FPXKEEP is on by default, so the branch's build is the "on" side; no run-time switch), each in the child Market for a few minutes and in Hyrule Field by day for a few minutes. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), standing and turning the camera, per thread if you can (the BaseProcExecutor threads are where it should show), and the frame times uncapped. Expect less CPU time, the same frame rate or better, and the picture as on main, the characters' cloth included.
@snaildev99 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 for13f6786, and the PR has changed since (9a51e1f), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Recommendation: Request changes. The new lane fallback adds work to operations it cannot rescue, and its cost in affected scenes is unmeasured. The reported game-level gain is also too small and noisy to establish that the default-on change helps on its current base.
The change keeps certain NaN, infinity and exactly cancelling float operations out of software routines, potentially reducing CPU work in cloth-heavy scenes. It adds classification work to other slow float paths and substantially expands generated helpers; the net game and build costs remain unmeasured.
Does it help: Unproven. The PR reports 0.8% and 0.9% lower process CPU in the Market over three interleaved runs on Windows, but the ranges overlap and the tested tree includes other branches on an older base. The targeted executor-thread medians fell 1.7% and 2.2%, without per-run spreads. Microbenchmarks show faster selected cases, but this head has no comparable game measurement, uncapped frame times or 1% lows.
Other systems: The helpers affect scalar and vector float operations throughout the translated game, including vecfp fallbacks and fastvec's by-element multiply. The author reports combined game-free vecfp checks, but no game run of this head; Linux, AMD, Steam Deck and other Tier 1 coverage remain outstanding. No clean build-time or size comparison is reported for the expanded generated header. Saves, audio and input are not directly changed, though game logic using float results can affect them.
Switches: A64_FPXKEEP is new, lift-time, default on; 0 disables the edits and is included in the lift key. It is documented in the build-variable table, appropriately outside the runtime switch table. The default's benefit and costs are not yet established across supported systems.
Reviewed:
13f67869f7againsta104182b40: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the full diff and commit, nx2/fpxkeep.py, nx2/lift.py, tests/test_fpxkeep.py and tests/fpxkeep_test.c in full. Read the relevant kit vector and wrapper generation, fastvec and lift-key code; skimmed related vecfp paths and reported runs. docs/review-checklist.md and the adjacent Tooling AGENTS.md were absent; network access was unavailable. No translations or generated files are changed.; nothing run (a code review).Checked and fine:
Blocking (to change before merge)
Suggestions (the author may take or leave)
Testing: Read-only review: no code, tests, builds or project scripts were run. The author reports 29 of 35 related checks passing, six failures also on main, and no full suite run.
Overlaps and merge order: The PR identifies merged #1782 as a runtime interaction; combined game-free checks are reported, but the combined head has not been played. Other open pull requests could not be checked with the network closed.
Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.
@ -0,0 +51,4 @@SUM_LANES_NEW = ("static inline __attribute__((always_inline)) void a64_vfpx_##name(Ctx *c, uint64_t *d, const uint64_t *n, ""const uint64_t *m, int k); \\\n" + SUM_LANES +" { uint64_t _ka[2], _kb[2], _kt[2]; a64_fpxk_v128 _ks, _kr; uint32_t _kf; \\\n"" if (a64_fpxk_vspecial(c, n, m, k, #name[0] == 's', _ka, _kb, &_ks, &_kr, &_kf)) { \\\n"Finite subnormal lanes under FZ can reach this fallback with no NaN or infinity, so they pay the new classification and then still run the old scalar route. The ordinary no-NaN benchmark remains on the vector fast path. Please measure this fallback and affected scenes against the base, and reduce any material regression.
@ -0,0 +284,4 @@_installed = Falsedef install():This default-on edit expands the generated shared header and can increase compilation work. Please compare clean build time and output size against the base and address any material increase.
@fix
I changed this pull request by bringing it up to date: the new head is
9a51e1f8f1. I rebased it ontomain(a764653726).Left for the author
Nothing was built or run: check the change. It will be reviewed again.
Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
13f67869f79a51e1f8f1Recommendation: Request changes. The new helpers speed up selected float operations, but add work to finite fallbacks that they cannot rescue. The reported game runs leave the net gain on this head unproven, and the new test fails when run with the documented opt-out set.
The lifter keeps certain NaN, infinity and exact-zero results out of software float routines. That can reduce CPU work in cloth-heavy scenes, at the cost of more generated code and extra checks on other scalar and vector fallbacks.
Does it help: Unproven. On an older Windows test tree with nine other branches, three interleaved Market runs at a 60 fps cap showed 0.8% and 0.9% less process CPU versus main, with overlapping run ranges. Executor medians were 1.7% and 2.2% lower, with no per-run spread reported. The microbenchmarks show FMA64 cancellation going from 179.7 to 2.1 ns and four-lane FMUL with a NaN going from 21.7 to 10.4 ns. There is no current-base game A/B, uncapped frame-time comparison or 1% low result.
Other systems: The change runs on the CPU across GPU vendors, including on Steam Deck. It affects scalar wrappers, fastvec by-element FMUL, vecfp lane fallbacks and the exact copies of fast float regions. The author reports v2 and v3 result-bit and FPSR checks and a combined vecfp header check. Windows and Linux game runs on this head, including affected Tier 1 hardware, are outstanding. There are no direct changes to renderer APIs, saves, audio, input or persistent game formats. The generated header changes the game build and invalidates the lift cache.
Switches: A64_FPXKEEP is new, lift-time and on by default. 0 disables the edits and changes the lift key. The build table is the right place to document it. The current measurements do not establish that the default pays off across supported systems. No runtime switch changes.
Reviewed:
9a51e1f8f1againsta764653726: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, standards, the full diff and commit, and all five changed files. Read the relevant kit wrapper and lane generation, host FP contract, fastvec and suyu runtime hooks, lift ordering, header regeneration, lift key and test discovery. Skimmed vecfp and fastfp integration, CI and the reported runs. The checkout has no docs/review-checklist.md or adjacent Tooling checkout. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Blocking (to change before merge)
Waiting on the author (a run, a measurement or a decision; no edit does it)
9a51e1f8f1againsta764653726in the Market and a representative heavy scene, with matched builds and settings and interleaved warmed runs. Report per-run CPU, uncapped average and 1% low FPS, median and p99 frame times, and in-game correctness including cloth on Windows and Linux across affected Tier 1 hardware. Use those results to justify the default and update the Measurements verdict.Suggestions (the author may take or leave)
Testing: Read-only review. No builds or tests run. The author reports zero result-bit and FPSR mismatches in v2 and v3, all 16 fault injections caught, and 29 of 35 related checks passing before the rebase. The six named failures also occurred on the earlier main tested. The full suite, current-head CI and current-head game runs are unverified. The farm request was for an older commit and produced no run.
Overlaps and merge order: #1782 is already merged into the base. Its vecfp fallbacks can use the changed scalar wrappers. The author reports a combined header check before the rebase. The rewrite branches used in the older benchmark overlap on powf workload. No merge-order dependency was identified in the supplied material.
Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@ -60,6 +60,7 @@ Read by the build, not the game, so they are not in `switches.def`.| `LONGSHOT_SPLIT_DIRECT=0` | The pieces of a `LONGSHOT_SPLIT_GIANTS` function go through its dispatch loop only, as before this switch: each goto into another piece returns to the loop, which calls the piece that owns the label. On by default, the pieces jump to each other themselves (`musttail`, with clang's `preserve_none` calling convention, the function's guest registers and flags as arguments in registers), and come back to the loop only for a guest return or tail call; a compiler without those attributes builds the loop either way. A function with guest locals (`nx2/guest_locals.py`) is split in both modes: its locals cross a cut as the pieces' arguments, or through a struct of the loop's in this mode. Compile-time; the objects of each mode are kept apart (the flag names it) || `LONGSHOT_LIGHT_PASSES=0` | Compile small chunks with every module pass (light passes need LLVM 22+) || `RX_MARCH=<level>` | CPU level || `A64_FPXKEEP=0` | Without `nx2/fpxkeep.py`: float ops with a NaN or infinite operand, and multiply-adds that cancel exactly, go to the software bodies as before (on by default: their exact results are kept from the operands' bits). A lift-time switch: it changes the lift key |Qualify this row to cover eligible operations. The gate and invalid cases still fall back, and binary64 cancellation needs host FMA.
@ -0,0 +4,4 @@large, or a sum, or a product of a zero; a64_lift.py's wrappers add rescues when the flags an op could raise are alreadyset (a64_fpx_sticky32, a64_fpx_fz_add32). Everything else runs the exact body (recomp_fpe_*), multi-word integer code of~180 ns a call (a few ns for a NaN). In a Market profile the bodies took 1.9 % of game code and the lane route of thevector ops that end in them another 2.3 %; the cases measured there are the first and the third below:The docstring says the lane route took 2.3% of game code time, while the PR summary says 1.3%. Reconcile the two figures.
@ -0,0 +147,4 @@} \rule = 1; \} else { \if (!(a & ~(SIGN)) || !(b & ~(SIGN)) || (fz && (sa || sb || sz))) return 0; \FMUL passes a signed-zero addend, so nonzero multiplicands cannot cancel. Skip this cancellation check for multiply wrappers and measure finite scalar misses.
@ -0,0 +202,4 @@const __m128i kmask = k == 4 ? _mm_set1_epi32(-1) : _mm_set_epi32(0, 0, -1, -1);const __m128i fzm = _mm_set1_epi32(-(int)(RECOMP_FPX_FZ(c) != 0));const __m128i aa = _mm_and_si128(a, absm), ab = _mm_and_si128(b, absm); /* (0 .. 0x7fffffff: signed compares) */const __m128i nana = _mm_cmpgt_epi32(aa, inf), nanb = _mm_cmpgt_epi32(ab, inf);Measure the FZ fallback with finite subnormal inputs. It now classifies every lane before using the original loop. The no-NaN fast-path benchmark misses this overhead.
@ -0,0 +268,4 @@def keep_wrappers(text):"""a64_fpx.h's text with HEADER after the kit's FPX_FZ_HEADER and the rescues in the wrappers of WRAPPED"""text = _once(text, a64_lift.FPX_FZ_HEADER, a64_lift.FPX_FZ_HEADER + HEADER, "the kit's FPX_FZ_HEADER")The larger header is compiled across lifted chunks. Report clean player build time and output size for this head against its base.
@ -0,0 +270,4 @@"""a64_fpx.h's text with HEADER after the kit's FPX_FZ_HEADER and the rescues in the wrappers of WRAPPED"""text = _once(text, a64_lift.FPX_FZ_HEADER, a64_lift.FPX_FZ_HEADER + HEADER, "the kit's FPX_FZ_HEADER")out = []for line in text.split("\n"):A changed declaration prefix bypasses the once-only check entirely. Validate the edit count for each wrapper expected from the requested shapes.
@ -0,0 +95,4 @@finally:fpxkeep._installed = Falseif saved is None:del os.environ["A64_FPXKEEP"]With A64_FPXKEEP=0 inherited, the second install also runs off and the test fails. Control the switch for both generations and restore it afterward.
@fix
I changed this pull request where the review's points could be done here (the rest needs runs, measurements or decisions): the new head is
1ce24477c3. I rebased it ontomain(fc4a6769fd).Changed
Left for the author
Still for the author (from the review)
9a51e1f8f1againsta764653726in the Market and a representative heavy scene, with matched builds and settings and interleaved warmed runs. Report per-run CPU, uncapped average and 1% low FPS, median and p99 frame times, and in-game correctness including cloth on Windows and Linux across affected Tier 1 hardware. Use those results to justify the default and update the Measurements verdict.Nothing was built or run: check the change. It will be reviewed again.
Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
9a51e1f8f11ce24477c3Recommendation: Request changes. The follow-up fixes the opt-out test and validates requested wrappers. Finite float fallbacks still do extra work, and current-base measurements are needed to establish whether the default-on change pays off in play and how much it costs to build.
The lifter avoids software float routines for selected NaN, infinity and exact-zero multiply-add results. This can reduce CPU work in cloth-heavy scenes. The follow-up removes the unnecessary cancellation check from multiply wrappers and makes the header edits fail fast when requested wrappers are missing or duplicated. Remaining costs include extra work on finite misses and a larger generated header.
Since the last review (on
9a51e1f8f1)Resolved:
Still open:
9a51e1f8f1againsta764653726in the Market and a representative heavy scene, with matched builds and settings and interleaved warmed runs. Report per-run CPU, uncapped average and 1% low FPS, median and p99 frame times, and in-game correctness including cloth on Windows and Linux across aff (The reported game runs use an older Windows test tree. A matched comparison of1ce24477c3againstfc4a6769fdand affected Tier 1 correctness runs are still missing.)Does it help: Unproven. On the older Windows Market test tree, three interleaved runs at a 60 fps cap showed 0.8% and 0.9% lower process CPU versus main, with overlapping run ranges. Executor CPU medians fell 1.7% and 2.2%, with no per-run spread reported. The PR's microbenchmarks report FMA64 cancellation falling from 179.7 to 2.1 ns and four-lane FMUL with a NaN falling from 21.7 to 10.4 ns. There is no matched game comparison for this head, no uncapped frame-time or 1% low result, and no clean-build comparison.
Other systems: The CPU-side changes reach scalar wrappers, fastvec by-element FMUL, vecfp lane fallbacks and the exact copies of fast float regions. The author reports earlier result-bit and FPSR checks with and without host FMA and a combined vecfp header check. Windows and Linux game runs on this head, including affected NVIDIA and AMD systems and Steam Deck, remain outstanding. The shared header affects lifted-code compilation and the lift cache key. Renderer APIs, save formats, audio and input interfaces have no direct changes.
Switches: A64_FPXKEEP is a new lift-time A/B switch, on by default. Setting it to 0 bypasses the header edits, and the value participates in the lift key. The build-variable table is the right place for it. The evidence for enabling it by default across supported systems is still incomplete.
Reviewed:
1ce24477c3againstfc4a6769fd: Read the base AGENTS.md, CONTRIBUTING.md, Forgejo PR template, standards and clean-build procedure. Compared the earlier and current commit ranges and read the changed code in all five PR files, including the full new Python and C files and lift.py. Read the kit wrapper generator, fastvec header hook and chunk header regeneration. Skimmed the lift-key and test-discovery paths, build reference, vecfp integration and reported runs. The checkout has no docs/review-checklist.md or adjacent Tooling checkout. No translations or generated files are in the diff.; nothing run (a code review).Checked and fine:
Waiting on the author (a run, a measurement or a decision; no edit does it)
1ce24477c3withfc4a6769fdin the Market and a representative heavy scene using matched builds and settings and interleaved, warmed runs. Report per-run CPU, uncapped average and 1% low FPS, median and p99 frame times, and in-game correctness including cloth on Windows and Linux across affected Tier 1 hardware. Use the results to justify the default and update the Measurements verdict.fc4a6769fd.Testing: Read-only review. No builds or tests were run. The author reports earlier v2 and v3 exactness checks, sixteen caught deliberate faults, combined vecfp header checks and 29 of 35 related checks passing, with six failures reproduced on the older main. BeanBot reports no runs for the follow-up. The earlier Linux Test Farm request went stale and supplies no results.
Overlaps and merge order: #1782 is already merged. Its vecfp lane fallbacks can reach these scalar rescues. The author reports earlier combined game-free checks, with in-game coverage for the combination still outstanding. No merge-order dependency was found in the supplied record.
Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@ -0,0 +147,4 @@} \rule = 1; \} else { \if (mul || !(a & ~(SIGN)) || !(b & ~(SIGN)) || (fz && (sa || sb || sz))) return 0; \FMUL now skips cancellation. Measure the remaining finite scalar miss overhead against the base, including on hosts without FMA.
@ -0,0 +202,4 @@const __m128i kmask = k == 4 ? _mm_set1_epi32(-1) : _mm_set_epi32(0, 0, -1, -1);const __m128i fzm = _mm_set1_epi32(-(int)(RECOMP_FPX_FZ(c) != 0));const __m128i aa = _mm_and_si128(a, absm), ab = _mm_and_si128(b, absm); /* (0 .. 0x7fffffff: signed compares) */const __m128i nana = _mm_cmpgt_epi32(aa, inf), nanb = _mm_cmpgt_epi32(ab, inf);Finite subnormal fallbacks under FZ still pay for this classification. Measure those misses and their frequency in play against the base.
@ -0,0 +268,4 @@def keep_wrappers(text, used):"""a64_fpx.h's text with HEADER after the kit's FPX_FZ_HEADER and the rescues in the wrappers of WRAPPED"""text = _once(text, a64_lift.FPX_FZ_HEADER, a64_lift.FPX_FZ_HEADER + HEADER, "the kit's FPX_FZ_HEADER")The helper block still expands every generated float header. Measure clean player build time and output size against the base.
@fix
@Beanstalk
Beanstalk test farm · an earlier run: commit
1ce2447(the newer results are in a comment below)Commit
1ce2447· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm does not measure individual float fallback frequencies, executor-thread CPU, clean-build output size, or run the game-free correctness suite in this plan.
⚠️ Note: The lift-cache timing measures lift and incremental compilation, not a clean player build; screenshots sample cloth visually but do not prove bit-exact float results.
Started at 07:33 UTC.
Estimate: done in about 2 h 15 min, from the queue and the testers online now.
anymarket· frame time p99 (ms), main → PR at each levelframe_rate_cap=0(reference)frame_rate_cap=6anyfield· frame time p99 (ms), main → PR at each levelframe_rate_cap=0(reference)frame_rate_cap=6anyCouldn't be judged: the tester's PC could not finish the test. The farm tries another PC, or the same one after a fix; it says nothing about the PR on its own.
any, report 1:the main base failed (exit 1): build.py stopped (exit status 1): fatal error: too many errors emitted, stopping now [-ferror-limit=]What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main and the PR in the child Market and Hyrule Field, using capped and uncapped frame rates to exercise cloth-heavy and general gameplay. It measures process CPU time and frame times, compares pictures, and fails on crashes, substantial performance regressions, or picture differences. Two timed lift builds per side also check build costs and whether lifted C remains unchanged. Gameplay takes about 20–25 minutes per tester; timed builds are additional.
0or6.market-entrance, then teleport to Market, move the stick, take the picture market to compare with main, measure market for 60 s (after 10 s warm-up); 1 run on each side for each of 2 cells (1 game start a run).kokiri-start, then teleport to Hyrule Field, take the picture field to compare with main, measure field for 60 s (after 10 s warm-up); 1 run on each side for each of 2 cells (1 game start a run).Measurements on `any`, for the PR description
Verdict: running on any (1 report).
Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMScene: market, from the repository's save market-entrance; field, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market: 1 game start a side, market 60 s after 10 s warm-up; field: 1 game start a side, field 60 s after 10 s warm-up; timed builds: main and this PR each built 2 times a cache, alternating, each a whole build in a fresh folder (lift; shader preparation not timed); each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))
fc4a6761ce2447Flags and settings
frame_rate_cap0,6As Markdown for the PR description:
The testers' hardware
anyAMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMI changed this pull request where an edit could (the rest needs runs, measurements or decisions): the new head is
5d13b806cb. I rebased it ontomain(7486869e64). I edited the pull request's description too (5 edits).Changed
1ce24477for test_fpxkeep.py and distinguish the revised fixture tests.Brought up to date
Already done
Still for the author (no edit does these)
tests/test_fpxkeep.py:173: Run the revised exactness and mutation tests on supported v2 and v3 hosts. The fixture and CPU-gating changes have not been run, so the earlier passing results do not verify these revisions.Nothing was built or run: check the change. It will be reviewed again.
Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
1ce24477c35d13b806cbBeanstalk test farm
Commit
545e03c· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Recommendation: Wait. The reported CPU savings come from an older test tree with nine other branches, and this head has not been built or played. The gain and correctness of the enabled-by-default change therefore remain unproven on the code proposed for merge.
The change keeps some NaN, infinity and exactly cancelling floating-point operations out of software routines. It adds specialized scalar and vector code and a lift-time switch; its measured benefit on the current code and its build-time cost are not yet established.
@fixwill do (3)nx2/lift.py:68: Reduce generated or compiled helper code if the clean-build comparison shows a material cost.tests/test_fpxkeep.py:135: The generated reference runtime inherits HOS_FMA_FAST from the environment. (more on the line)For the author (3) (a run, a measurement or a decision)
nx2/fpxkeep.py:45: Measure current main against this head in the target and heavy scenes, including uncapped frame times and 1% lows. (more on the line)nx2/lift.py:68: Measure clean game build time and output size against the base. (more on the line)tests/test_fpxkeep.py:154: Run the revised tests and build and play this head with vecfp on Windows and Linux, including the requested cloth-heavy scenes. (more on the line)More: does it help, other systems, switches, what was read
Does it help: Unproven. On Windows, an older modified tree measured 0.8–0.9% less process CPU and 1.7–2.2% less executor CPU against its main baseline over three interleaved runs. The runs are not this PR against its merge base, and the process results overlap the reported run spread. Uncapped frame times and 1% lows are missing.
Other systems: The helpers affect translated game code, including vector lanes and scalar fallbacks from vecfp, on Windows and Linux. The current head has not been played with vecfp; Linux, Steam Deck and other affected Tier 1 configurations remain untested. The change also alters generated headers and may affect lift and compile time.
Switches: A64_FPXKEEP is added at lift time, on by default and off with 0; its build reference row and lift-key coverage are present. The default's benefit on this head and across supported systems is not yet measured.
Reviewed:
5d13b806cbagainst7486869e64: Read AGENTS.md, CONTRIBUTING.md, the PR template, the applicable standards, all six changed files and the commits. Read the surrounding float gate, generated wrappers, vector lane routes, test compiler helpers and lift installation order. Skimmed related vecfp, fastvec, runtime and build references. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. The full large lift driver, generated output, translations and recorded runs were not read.; nothing run (a code review).Checked and fine:
Testing: No code, tests or project scripts were run, as requested. The PR reports earlier game-free runs, but says the revised fixtures have not been run.
Overlaps and merge order: The description identifies merged PR #1782 as interacting at runtime; its combined game build remains to be tested. No other overlapping pull requests were available in the supplied context.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
@ -0,0 +42,4 @@import a64_lift# (each edit below must match exactly once: a refreshed a64-kit or fastvec that moved these lines stops the lift here)WRAPPED = {("add32", "add32"): "a64_fpxk_sum32(c, a0, a1, 0, &v)", ("sub32", "sub32"): "a64_fpxk_sum32(c, a0, a1, 1, &v)",L1 (minor): Measure current main against this head in the target and heavy scenes, including uncapped frame times and 1% lows. The existing CPU runs include nine other branches and predate vecfp, so they cannot establish this head's gain or its effect on frame pacing.
@ -64,6 +65,7 @@ walk.install()lift_fixes.install()entry_hooks.install() # (host/*.c's ENTRY_HOOK_SYM hooks at the entry of their SDK functions: add() below)suyu_rt_fixes.install()fpxkeep.install() # (after fastvec's: it edits the kit's lane routes and wraps fpx_header around fastvec's)L2 (minor): Measure clean game build time and output size against the base. The added generated helper code is compiled with the lift, and the existing measurements do not show its cost to players building the game.
@ -0,0 +132,4 @@raise SystemExit("fpxkeep: missing or duplicated wrapper accepted")try:a64_rtgen.write(tmp)finally:L4 (minor): The generated reference runtime inherits HOS_FMA_FAST from the environment. On a v2 build, its default-enabled early exit can answer reference FMA calls before the integer software body, so the claimed oracle and coverage vary with the caller's environment. Force HOS_FMA_FAST=0 for the driver runs, or explicitly test both modes while using the unmodified body as the reference.
@ -0,0 +151,4 @@return exedef main():L3 (minor): Run the revised tests and build and play this head with vecfp on Windows and Linux, including the requested cloth-heavy scenes. The recorded exactness runs precede the fixture changes, and the game run predates vecfp, so neither verifies the final combination.
Recommendation: Request changes. I read the rules and they look exact, and the fast path is unchanged. Two things have to change before merge: the description describes website and settings-guide changes that aren't in the diff, and nobody has measured what this lifter change costs players' game build. On top of that, the game-level gain on this code is still Unproven.
For a player, this cuts CPU time in scenes with Havok cloth and in the game's
powf. Float ops with a NaN or infinite operand, and multiply-adds that cancel to exactly zero, now get Arm's result from the operands' bits instead of the ~180 ns software bodies. The common case costs the same, because the inline fast paths and the vector fast checks are not touched. The cost is a biggera64_fpx.hand bigger outlined wrappers in every lifted chunk that uses them.Does it help: Unproven on this head. The in-game numbers come from a Windows test tree on main
068fb8ebwith nine other branches in it, from before #1782. Process CPU dropped 0.8 % standing and 0.9 % turning, but the three runs overlap: before [5.144 5.156 5.161], after [5.177 5.115 5.106]. Executor threads dropped 1.7 % and 2.2 % on medians, with no per-run spread given. There are no uncapped frame times or 1 % lows. The per-call microbenchmarks are clear: an FMA64 that cancels goes from 179.7 to 2.1 ns, a 4-lane FMUL with a NaN lane from 21.7 to 10.4 ns, and the ordinary paths are unchanged (1.67 ns, 1.95 ns).Other systems: This runs on the CPU only, so the GPU vendor doesn't matter.
RECOMP_FPX_HOST == 2).RECOMP_FPX_HOST == 1) gets the scalar rules, and the lane head compiles to0, so its lanes run as before.Lifter.write, not throughfpx_header, so the two don't edit the same text. Its declined lanes now reach these rescues. That has been checked game-free (per the description) but not in a game.nx2/chunks.py'sfill_fpxcalls the wrappedfpx_header(set())andfpx_header(used).keep_wrappersaccepts an empty shape set, so that path holds.Switches:
A64_FPXKEEP: new, lift time, default on, and0writes main's header byte for byte. As anA64_variable it is inLIFT_ENV_PREFIXES, so it changes the lift key. It is documented indocs/dev/reference/build.mdand correctly left out ofgpu/vk/switches.def, because the game doesn't read it. On is the right default for a rule that is exact and only ever replaces a slow body with a cheaper exact answer, provided the revised tests pass and the build-time cost turns out small. Once that's shown, the switch could go away.Reviewed:
5d13b806cagainst7486869e6(its base):nx2/fpxkeep.py,nx2/lift.py(the two lines),docs/dev/reference/build.md,tests/test_fpxkeep.py,tests/fpxkeep_test.candtests/fpxkeep_cpu.c, all in full. I also read the code they depend on: the kit'sfpx_header,VFPX_HEADER,VFPX_MUL_HEADER,FPX_FZ_HEADERandvectorize_fpx;RECOMP_FPX_OPENand the FPX macros inarm64_to_c.h;nx2/fastvec.py's install and its by-element FMUL;chunks.fill_fpx; vecfp's install. I skimmedHOS_FMA_FASTinfma_soft.h. Nothing run (a code review).Fixed in this review: nothing pushed. The push to
snaildev99/Longshotwas refused, so the fix is offered as a suggestion. Locally I rebased the three commits one by one onto mainb62932a96with no conflicts, and addeddocs(lift), which moves theA64_FPXKEEProw next to the otherA64_switches, says what stays with the bodies, and changes the docstring's 2.3 % to the description's 1.3 %. The stale base is why "Guide screenshots" fails: the base lacks main's newer screenshot assets.Checked and fine:
__builtin_fmaonly whenRECOMP_FPX_FMA64is set. Multiply wrappers skip Z.RECOMP_FPX_OPEN, which needs IXC set and no FPCR control bits other than FZ (DN, RMode and traps all close it). They run after the fast path and the kit's rescues, so they only ever replace a call to the body.kmaskkeeps the top lanes out of the 2-lane forms, anda64_vst_lo64writes all 16 bytes with the top half zeroed, so_ktis fully set. Recursion stops after one level: zeroed lanes are no longer special, and the lanes that stay non-special (cancelling infinities, inf × 0) stay non-special. 0 + 0, 0 − 0 and 0 × 0 pass the vector fast check.powfstep (z * invc - 1) is described in words only.third_party/, and AI assistance is recorded in the trailers.Blocking (to change before merge)
website/tests/graphics-settings.test.ts". This PR changes none of those files. The six files arenx2/fpxkeep.py,nx2/lift.py,docs/dev/reference/build.mdand the three test files. That paragraph came from an automated description edit. Remove it so the description matches the diff.nx2/lift.py:68: the lifter runs on players' PCs, and this change makes their game build bigger and slower by an amount nobody has measured.HEADERadds about 180 lines of C toa64_fpx.h, which every lifted chunk parses. The eightstatic noinlinewrappers are compiled in every chunk that uses them, and the lane routes are bigger. The Beanstalk build timing failed on its main base, so it gives no number. Measure a clean game build (time and output size) of this head against its base on one PC, asdocs/dev/developing.mddescribes, and put it in Measurements. If the cost is material, a way to cut it is to emitHEADER's scalar part only when a wrapped shape is inused.Suggestions (the author may take or leave)
545e03c62locally, but couldn't push it.docs/dev/reference/build.md:66: put the row next toA64_VECFPand say what still goes to the bodies (inf − inf, inf × 0, the closed gate, binary64 without a host FMA).nx2/fpxkeep.py:7: the docstring says the lane route took 2.3 %, but the description says 1.3 % (1.9 + 1.3 = 3.2).tests/test_fpxkeep.py: run the driver withHOS_FMA_FAST=0, so the oracle is always the plain integer body.fma_softclaims the same results either way, but the test shouldn't depend on that claim.Testing: The game ran on Windows (RTX 3090) in an older test tree. This head has not been built or played, and it hasn't been played together with vecfp. The revised fixtures and the CPU probe have not been run. The full suite has not been run, and this head has no CI Python run, because those jobs were skipped. Still needed: the revised
tests/test_fpxkeep.pyat v2 and v3; this head against its base in the Market and one heavy area (per-run CPU, uncapped frame times, 1 % lows), with the cloth checked visually on Windows and Linux; and the clean build time.Overlaps and merge order: No files are shared with the siblings: this PR doesn't touch
switches.def,oot_patches.py,build.pyorrtgen.py. Its gains do overlap, though. #2036 (cloth on host code) would take away the cloth NaN lanes that rule N targets. #1904 and #1911 (hostpowf, and its memo) would take away thepowfcancellations that rule Z targets. Measure this PR on main as it is when it merges, and if those siblings merge first, say what is left for these rules.@ -63,6 +63,7 @@ Read by the build, not the game, so they are not in `switches.def`.| `LONGSHOT_SPLIT_DIRECT=0` | The pieces of a `LONGSHOT_SPLIT_GIANTS` function go through its dispatch loop only, as before this switch: each goto into another piece returns to the loop, which calls the piece that owns the label. On by default, the pieces jump to each other themselves (`musttail`, with clang's `preserve_none` calling convention, the function's guest registers and flags as arguments in registers), and come back to the loop only for a guest return or tail call; a compiler without those attributes builds the loop either way. A function with guest locals (`nx2/guest_locals.py`) is split in both modes: its locals cross a cut as the pieces' arguments, or through a struct of the loop's in this mode. Compile-time; the objects of each mode are kept apart (the flag names it) || `LONGSHOT_LIGHT_PASSES=0` | Compile small chunks with every module pass (light passes need LLVM 22+) || `RX_MARCH=<level>` | CPU level || `A64_FPXKEEP=0` | Without `nx2/fpxkeep.py`: float ops with a NaN or infinite operand, and multiply-adds that cancel exactly, go to the software bodies as before (on by default: their exact results are kept from the operands' bits). A lift-time switch: it changes the lift key |Nit: this row would sit better next to
A64_VECFPwith the otherA64_switches. It could also say what still goes to the bodies: the closed gate, inf - inf, inf * 0, and binary64 Z without a host FMA.@ -0,0 +4,4 @@large, or a sum, or a product of a zero; a64_lift.py's wrappers add rescues when the flags an op could raise are alreadyset (a64_fpx_sticky32, a64_fpx_fz_add32). Everything else runs the exact body (recomp_fpe_*), multi-word integer code of~180 ns a call (a few ns for a NaN). In a Market profile the bodies took 1.9 % of game code and the lane route of thevector ops that end in them another 2.3 %; the cases measured there are the first and the third below:Nit: the docstring says 2.3 % here, but the description says 1.3 % (1.9 + 1.3 = 3.2 %).
@ -64,6 +65,7 @@ walk.install()lift_fixes.install()entry_hooks.install() # (host/*.c's ENTRY_HOOK_SYM hooks at the entry of their SDK functions: add() below)suyu_rt_fixes.install()fpxkeep.install() # (after fastvec's: it edits the kit's lane routes and wraps fpx_header around fastvec's)This lifter change grows
a64_fpx.h(~180 lines in every chunk) and the eight outlined wrappers every chunk compiles. Please measure a clean game build (time and size) of this head against its base on one PC (docs/dev/developing.md). If the cost is material, emit HEADER's scalar part only when a wrapped shape is used.@ -0,0 +182,4 @@continueexe = compile_driver(cc, tmp, march, fma, tmp, march)for args in runs:r = fs.run([exe] + args, timeout=3600)Suggestion: run the driver with
HOS_FMA_FAST=0, so the v2 oracle is always the plain integer body and the test doesn't depend on fma_soft's claim that both modes give the same results.5d13b806cb545e03c629Pushed to this branch from the review (head
545e03c62): rebased onto mainb62932a96with no conflicts, which should clear the stale-base Guide screenshots failure; and545e03c6docs(lift): A64_FPXKEEP's row beside the other A64_ switches, with what still goes to the software routines, and the docstring's 1.3 %. The description and build-time points still stand.WIP: perf(lift): keep NaN and infinite operands and exact-zero multiply-adds off the software float bodies (A64_FPXKEEP)to perf(lift): keep NaN and infinite operands and exact-zero multiply-adds off the software float bodies (A64_FPXKEEP)