WIP: perf(lift): FRECPE and FRSQRTE read a constant table where the input and its estimate are normal #2068
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!2068
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/fp-estimate-table"
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
FRECPE and FRSQRTE (S and D, scalar and each vector lane) call
recomp_fp_estimatein the generateda64_suyu.c:suyu's body, which classifies the input, fills a table lazily from Arm's formula and works out the exponent, on every
call. This PR keeps that body as
recomp_fp_estimate_exactand puts a fast path in front of it(
nx2/suyu_rt_fixes.py): for a normal input whose estimate is normal (FRECPE with a biased exponent up to 252 / 2044,FRSQRTE of a positive number) the result is one read of a constant table that Python computes by the same formulas;
no flag is raised there, as in the body. Every other input goes to suyu's body.
A64_NO_EST_TABLEis read when the lift writesa64_suyu.c: unset (or0) the table;1suyu's body alone, thelift as before; any other value stops the lift with a message, so a typo cannot leave the table on unnoticed.
Changing it lifts the game again (it is in the lift key).
docs/dev/reference/build.mdhas its row.Pre-existing on
main, left for a separate change: suyu's body fills its lazy table (recomp_est_tab) with plainstores, so two guest threads reaching the same entry first at once both store it (the same value); that is a data race
in C's terms. This PR leaves the body as it is; with the table it is reached only by the inputs outside the table's
domain (NaNs, zeros, infinities, subnormals, FRSQRTE of a negative number, FRECPE's top three binades).
From the local branch
exp/x86-asm-sync(36d3d099, its table part). Main has nothing for these instructions.Read first:
ESTIMATE_C,est_table_onandpatch_cinnx2/suyu_rt_fixes.py;tests/test_fp_estimate.py.Testing
Tested: Windows 11, this PC (i7-9700, RTX 4060), llvm-mingw clang; the checks ran through the PC's job queue on this head (
b8984fe7, onmain@9dd41326). This change has NOT run in the game on this PC yet.tests/test_fp_estimate.py: passes ("fp estimate: pass in 14.1 s"): the switch's cases (unset and0: table;1: body;yes: "stop: A64_NO_EST_TABLE=yes: 1 (suyu's body alone) or 0 (the table)";1then0: body, then table), and the table against suyu's body, value and FPSR, at x86-64-v3 and x86-64-v2: the sweep "99090432 checks, 0 mismatches" and the random inputs "16000000 checks, 0 mismatches" at each level. Onmain@6e1521a7, the branch's earlier base, with this test copied in it failed, as it should, at the switch's cases: "A64_NO_EST_TABLE unset gives 'body', expected 'table'" (and likewise0,yes, and1then0).(380u - e) >> 1made(382u - e) >> 1innx2/suyu_rt_fixes.py) it fails, the sweep with 2731008 mismatches and the random inputs with 1986954 at both levels; with FRECPE's domain one binade wider (if (e - 1u < 252u)made< 253u) it fails, 21468 and 15664. Each ends "fp estimate: FAIL (x86-64-v3 sweep, x86-64-v3 random, x86-64-v2 sweep, x86-64-v2 random)".tests/run_all.py --strict --changed origin/mainon this head (the checks that read a changed file, 8 at once): 7passed, 1 timed out, 1 skipped. Passed:
test_fp_estimate.py,test_vfpx_elem.py,test_fpxkeep.py,test_fpx_sticky.py,test_fma_soft.py,byte_compile_tracked.py,test_doc_anchors.py. Skipped:nx2/test_leaf.py(needs the game's modules). Timed out:
tests/test_vbytes.pyat 600 s; it has not finished on this PC at all: alone itran past 20 minutes on
main@f1f2dc5band on this branch's earlier head 20aa0fa4 alike ("TIMED OUT at 20 min").Still to test:
main@9dd41326, this PR withA64_NO_EST_TABLE=1(suyu's body alone), and this PR as it is; each warmed once, theninterleaved, at least two runs each, the medians of fps and frame times compared; expecting the same game and
picture, no crash, and frame times with the table as
main's or better (by hand)python3 -I -B tests/test_fp_estimate.py, expecting the switch cases and 0 mismatches at bothlevels (by hand)
against
main(the PR's build lifts the game again), 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: micro-benchmark only, not measured in play yet: the table answers in 1.82 to 2.58 ns a call against 7.54
to 10.34 ns for suyu's body, 3.8x to 4.5x. That is the helper call alone, not a frame; the in-game A/B on this PC is in
Still to test.
A64_NO_EST_TABLEships at its default, unset: the table on (this change active);A64_NO_EST_TABLE=1is suyu's body alone.Setup: Windows 11, i7-9700, llvm-mingw clang,
tools/fpx_bench.py est 7at this headb8984fe7, one queue job alone onthe PC (run-alone timing mode); ns a call, the median of 7 interleaved rounds; micro-benchmark. Baseline: the Before
column is suyu's body (main's helper,
recomp_fp_estimate_exacthere) timed in the same benchmark process at thishead, not a separate build of
main.9dd41326(suyu's body)b8984fe7(the table)Risks
Float results: the table is checked against suyu's body (value and FPSR) on a sweep of every sign, exponent and top
nine fraction bits under the FPCR and FPSR states and on random inputs, at x86-64-v3 and x86-64-v2. A mistake would
show as wrong reciprocal and reciprocal square root estimates in the game. Off:
A64_NO_EST_TABLE=1(a new lift).Players notice nothing after updating; a build lifts again once.
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
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
Measurements: the micro-benchmark on this head (tools/fpx_bench.py, 7 interleaved rounds, one queue job alone on the PC) is in; figures and baseline in Measurements. Not measured in play yet (Still to test).
@Beanstalk This lifter change answers FRECPE and FRSQRTE (the reciprocal estimates) from a constant table in the lifted code (nx2), on by default (A64_NO_EST_TABLE unset; a lift-time switch), so this PR's build lifts the game again and its lifted C differs from main's by design. Please time the lift against main's; take a picture at a fixed point with no input right after the start save settles, with one main-against-itself picture; then, for frame times, play Kokiri Forest and Castle Town Market (from the market-entrance save), two minutes each; the PR against main on the same PC, on a Windows PC with an AMD processor, a Windows PC with an Intel processor, a Linux PC and the Steam Deck. The same game and picture within main's own noise, no crash or hang; frame time p99 equal to main's or better, within the run-to-run spread.
@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 66576 on this head, so that it follows the farm's picture and hardware rules. This lifter change answers FRECPE and FRSQRTE from a constant table where the input and its estimate are normal, in the lifted code (nx2), on by default (A64_NO_EST_TABLE=1 turns it off at lift time), so this PR's build lifts the game again and its lifted C differs from main's by design; the switch is read at lift time, which the farm cannot set, so please time each side's lift and compare the PR with main. Please start from the kokiri-start 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 Kokiri Forest for two minutes, and Castle Town Market for two minutes from the market-entrance save; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. 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 One correction to my request 69720 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.@Beanstalk This replaces my request 69720 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 lifter change answers FRECPE and FRSQRTE from a constant table where the input and its estimate are normal, in the lifted code (nx2), on by default (A64_NO_EST_TABLE=1 turns it off at lift time), so this PR's build lifts the game again and its lifted C differs from main's by design; the switch is read at lift time, which the farm cannot set, so please time each side's lift and compare the PR with main. Please start from the kokiri-start 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 Kokiri Forest for two minutes, and Castle Town Market for two minutes from the market-entrance save; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with a Ryzen 9 7900X, Windows with a Core i9-12900K, Linux with a Ryzen 5 5600X and the Steam Deck. 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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.