WIP: perf(lift): FADDP and FSQRT (vector) get SSE fast paths beside nx2/vecfp.py's other forms #2067
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2067
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/fpx-vec-addp-sqrt"
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 translator writes FADDP (vector) and FSQRT (vector), 4S and 2S, as one call of the scalar float helper a lane
(its gate, its native op, its keep test).
nx2/vecfp.py(A64_VECFP, #1782) already puts the other lane-by-lanefloat forms behind one SSE op; these two were not among them. This PR adds them as two more vecfp groups:
addp: the pairs' first elements gathered into one vector and their second into another (lane j adds pair j: n'spairs, then m's), one
ADDPSin Arm's operand order, kept where FPX1 keeps a sum (finite; under FZ no subnormaloperand and a result big or zero);
sqrt: oneSQRTPS, kept where FPX1 keeps a root (a zero, itself; else a positive finite operand, under FZ notsubnormal).
As for the other groups, the helper writes the destination only when every lane is provably Arm's; otherwise the
instruction's own C runs as before, and in a fast float region the helper runs as it is with its lanes' scalar
helpers the region's own.
A64_VECFPis read while the lift translates: unset (or1), both groups are on with theothers;
A64_VECFP=elem,vec,minmax,fcvtlifts these two instructions as before;0lifts as without vecfp; a valueit does not know (a misspelt group) stops the lift with a message. Changing it lifts the game again (it is in the lift
key).
docs/dev/reference/build.md's row says so.tests/test_vecfp.pygets the six words,A64_VECFP's cases with the new groups (each in a Python process of its ownwith its environment set explicitly), and a CPU check in its C driver: the driver ran its x86-64-v3 build without
asking the CPU; now its main first asks (
__builtin_cpu_supports: AVX2, FMA3, BMI2, which for the AVX ones includesthe OS saving their state; SSE4.2 and POPCNT for x86-64-v2) and a level the CPU lacks is skipped.
From the local branch
exp/x86-asm-sync(c4c8d297 FADDP, 0b58b38d vector FSQRT), where they were rewrites of thelane loops in
nx2/fpx_helpers.py; here they follow main's vecfp. That branch's other vector paths (FMLA/FMLS,FMUL by element, FMIN/FMAX) main already has in vecfp and fastvec.
Read first:
a64_vfpx_addp32,a64_vfpx_sqrt32vandfast_callinnx2/vecfp.py;check_switchand the words intests/test_vecfp.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 (
eeeaa721, onmain@9dd41326). This change has NOT run in the game on this PC yet.tests/test_vecfp.py: passes ("vecfp: pass in 43.6 s"): "A64_VECFP's cases passed, each in a process of its own", and every word 0 mismatches at x86-64-v3 and x86-64-v2, the six new ones with the fast path on 20000 of 20000 normal cases. Onmain@6e1521a7, the branch's earlier base, with this test copied in it failed, as it should: "vecfp: no fast path for faddp v28.4s, v1.4s, v2.4s"._mm_and_si128(a64_vx_fz(c), fzbad)made_mm_setzero_si128()innx2/vecfp.py) it fails, FADDP 4S, 2S and in place with 1644, 1998 and 1698 mismatches at both levels; with FSQRT's taken out (_mm_and_si128(a64_vx_fz(c), a64_vx_subn(a))made_mm_setzero_si128()) it fails, FSQRT 4S, 2S and in place with 378, 828 and 378 at both levels. Each ends "vecfp: FAIL (x86-64-v3, x86-64-v2)".tests/test_lift_cache.pyfails on this head and onmain@9dd41326with the same message, "FAIL: ...and the others still by their code": it also fails on main.tests/run_all.py --strict --changed origin/mainon this head (the checks that read a changed file, 8 at once): 4passed (
test_vecfp.py,test_function_ends.py,test_doc_anchors.py,byte_compile_tracked.py), 1 failed:test_lift_cache.py, the failuremain@9dd41326has too (above); none fails on this branch alone.Still to test:
main@9dd41326, this PR withA64_VECFP=elem,vec,minmax,fcvt(the two groups off), and this PR as it is; each warmedonce, then interleaved, 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 groups on as
main's or better (by hand)python3 -I -B tests/test_vecfp.py, expecting the switch cases and every word with 0 mismatchesat both levels (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 new SSE forms take 4.30 ns (FADDP 4S) to 2.78 ns
(FSQRT 2S) a guest instruction against 4.96 to 9.71 ns for main's lane-by-lane forms, from 1.2x (FADDP 2S) to 3.3x
(FSQRT 4S). That is the instruction alone, not a frame; the in-game A/B on this PC is in Still to test.
A64_VECFPships at its default, unset: every group on,
addpandsqrtincluded (this change active);A64_VECFP=elem,vec,minmax,fcvtturns the two off.Setup: Windows 11, i7-9700, llvm-mingw clang,
tools/fpx_bench.py vec 7at this headeeeaa721, one queue job alone onthe PC (run-alone timing mode); ns a guest instruction, the median of 7 interleaved rounds; micro-benchmark. Baseline:
the Before column is main's lane-by-lane form as this head builds it with the two groups off, timed in the same
benchmark process, not a separate build of
main.9dd41326(lane by lane)eeeaa721(vecfp)Risks
Float results: each word is checked against the same word translated with FPX off (the exact integer bodies) on
60,000 cases a word, lifted, hot and as a region, at x86-64-v3 and x86-64-v2. A mistake would show as wrong maths in
the game. Off:
A64_VECFP=elem,vec,minmax,fcvt(a new lift). Players notice nothing after updating; a build liftsagain 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
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.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 gives FADDP and FSQRT vector instructions fast paths in the lifted code (nx2), on by default (A64_VECFP 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 66573 on this head, so that it follows the farm's picture and hardware rules. This lifter change gives FADDP and FSQRT (vector) SSE fast paths in the lifted code (nx2/vecfp.py), on by default (A64_VECFP=0 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 69718 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 69718 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 gives FADDP and FSQRT (vector) SSE fast paths in the lifted code (nx2/vecfp.py), on by default (A64_VECFP=0 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.