perf: less game work a frame in Castle Town (registers as locals, vector rewrites) #1576
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
7 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1576
Loading…
Reference in a new issue
No description provided.
Delete branch "Veix/Longshot:perf/market-game-work"
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?
Type: perf · Risk: medium · Tested on: Windows 11, RTX 4070 SUPER · Needs: Windows on AMD and Intel GPUs; a CPU without SSSE3
Scope and title changed on 2026-11-18. This pull request was opened with six pieces, its title ending "(registers as locals, vector rewrites, unchanged texture data left alone)". After review it holds the two translator pieces that carry the gain. Taken out, each with nothing measurable on current main: the FMIN / FMAX fast path, the packaged-texture-data check, the identical-copy check and the capture-buffer worker. The numbers below are this head's.
TL;DR
In Castle Town's market the game's own work takes most of a 60 fps frame, so the frame rate dips. This PR makes the translated game code faster in two ways: a function keeps its hottest console registers in local variables, and five vector instruction forms become one processor instruction each. On a Ryzen 9 9900X the game's work per frame drops from 16.6 to 14.3 ms and the market runs at 61.1 instead of 56.5 fps with the cap lifted to 90. Checked with traced runs against main, each piece also by itself, with game-free tests for the rewritten instructions, and by a tester on a Steam Deck (+7 % where the game's code is the limit).
Breakdown
tests/test_vbytes.pyandtests/test_vfpx_elem.py.Why
In Castle Town's market the main thread's game work is about 16 ms of the 16.7 ms a 60 fps frame has, so every extra millisecond is a dropped frame. Part of that time is not the game's logic but how its code was translated: registers read from and written to memory around every instruction, and vector instructions spelled out byte by byte.
See #1020, #1560 (a rework of the place the locals hook into, in progress).
What changed
Two changes to how the game's code is written as C. Nothing in
third_party/is edited: both wrap the kit's functions fromnx2/.nx2/guest_locals.py,nx2/lift.py): the kit'sA64_LOCAL_REGS/A64_LOCAL_FLAGSon by default, six registers per function plus N, Z, C, V. A function the game's patches touch, one that holds an address they name, one with C spliced into it and one whose code starts below its entry (lift_fixesjumps to the entry from its head, over the place where the locals are loaded:keep_entered_below) keep the context:oot_patches.touchesanswers that per function, such a function is also written with the kit's context-flag text for every instruction (install_plain), andcheck_patched()stops the lift if a patched function has locals. The horse's jump blend and the moving floors' patches apply unchanged.nx2/fastvec.py): TBL with a one-register table (PSHUFB), EXT (PALIGNR or two shifts), 128-bit vector loads, DUP by element, FMUL by element. They were byte loops through the stack; TBL has 2,995 sites in the game and EXT 29,451.tests/test_vbytes.pyandtests/test_vfpx_elem.pyrun every rewritten form both ways against the kit's text;tests/test_entry_below_locals.pychecks that a function entered below its first block gets no locals;nx2/test_leaf.pycovers the locals.Measurements
Verdict: faster: 12-15 % less game work a frame, measured in Castle Town's market and on Death Mountain Trail; +15 % fps where the CPU is the limit (720p: 71.6 to 82.0 in the market), +8 % on the walked market route at 4K (56.5 to 61.1), little where the GPU is the limit. Each of the two pieces shows by itself: 1.4 ms for the locals, 1.2 ms for the vector rewrites.
Hardware: Windows 11 (26200), RTX 4070 SUPER 12 GB, NVIDIA 621.24, Ryzen 9 9900X, 64 GB
Scene: Castle Town market by day, the second visit of a recorded route (market, castle, market; 59.5 s); 4K output, DLSS Quality (1440p internal), V-Sync on, default settings, frame rate cap 90 (a measuring setup: above the game's 60, so that the fps can show the gain)
Method: fps and 1% low from present intervals (
HOS_PRESENT_TRACE); game work a frame fromRX_VK_FRAME_TRACE(game_ms+wait_main_ms, the median of the visit's frames); 2 runs a side; main's two were made 3 hours before this head's (the same build of main, the same settings), so not interleavedHow to reproduce: a save in Castle Town, the route above,
HOS_FPS_MAX=90Baseline: main @
430eef4f, the base these runs were made on. The head has since been rebased (main has had renderer and build-script changes, none in the code this PR writes) and changed after review in one way that reaches the game: 26 functions whose code starts below their entry keep the context. One run of it on this route gave 61.8 fps and 13.97 ms of game work a frame, so the numbers hold.430eef4fEach piece by itself (the same route and settings, one run each, on the earlier head
15c563a8, whose other pieces showed nothing measurable):A64_LOCAL_REGS=0,A64_LOCAL_FLAGS=0)A64_NO_VBYTES=1,A64_NO_VMOVES=1,A64_NO_VFPX_ELEM=1)Standing after a teleport to each place, 30 s measured, two runs a side in the order main, PR, main, PR. First with the GPU out of the way (1280x720 output, DLAA, uncapped, V-Sync off), then as played here (4K, DLSS Quality, cap 120):
430eef4fSo the gain is there at rest too, and how much of it shows as fps depends on what limits the frame: all of it where the CPU does (720p: the game never waits for the GPU), little or none where the GPU does (4K here: the game's wait for it grows from 0.5 to 1.7 ms a frame in the market, 1.5 to 2.2 ms on the trail).
A tester's Steam Deck OLED (Linux, RADV; both sides built all at
-O2; the earlier head, which had these two pieces and four more): Death Mountain Trail under the falling rocks 17.5 to 18.8 fps (+7 %), the frame less the replay 37.9 to 34.1 ms; Castle Town's market, where the Deck's GPU limits, no difference; 8 starts and a session in the Fire Temple without a fault.Works well together with
Three settings
mainalready has add to this change. This PR changes none of them.HOS_KEEP_FREED_PAGESon by default where the PC has the memory follows as a separate pull request. Whether the other two should become defaults is a question for the maintainers; their gain with this PR's code is shown here. The same route, walking, cap at 90, two runs each:RX_VK_FRAME_GATE=0andRX_VK_READBACK_LATE=3980,9b040,8b040,44b040,1b580HOS_KEEP_FREED_PAGES=1removes the frames in which the game's main thread is blocked for a whole frame while freed memory is given back to the system: 15 to 25 a market visit down to 0, the frames over 25 ms from 29-50 to 12. It costs 0.5 to 0.7 GB of memory in use.(The rows with the two settings and the third setting's numbers were measured with the earlier head, which had these two pieces and four that changed nothing measurable.)
Flags and settings
Five lift-time switches; two are the kit's own whose default changes, three are new. Each ships on.
A64_LOCAL_REGSA64_LOCAL_FLAGS=0off)A64_NO_VBYTES=1keeps TBL / EXT as byte loopsA64_NO_VMOVES=1keeps vector loads / DUP as the kit writes themA64_NO_VFPX_ELEM=1keeps FMUL by element as the kit writes itTesting
Tested: Windows 11, RTX 4070 SUPER, NVIDIA 621.24: the market route above with this head and with main; the build log shows the three gameplay patch sites applied and no warning. The same two pieces, with more on top, have been played by hand for over half an hour in Castle Town, the castle grounds and shops, no glitch seen.
python -I -B tests/run_all.py: 633 passed, 36 failed, 113 skipped; every failing check also fails without this change on this PC, none is new. A tester ran the earlier head on a Steam Deck OLED (Linux, RADV): it builds, 8 starts and a minute in the Fire Temple without a crash or a fault in the log.The Test Farm's first run (the earlier head
f862753, Linux, RTX 4070, one run a side) reported a fail on two rules: its picture was taken while Link ran, a few steps apart on the two sides (both pictures are a correct market street), and the 99th-percentile frame time of one 20 s window right after the arrival was 35.9 against 27.0 ms, the median the same (14.2 ms). No crash; its build timing is in Risks. The test asked for below stands still and runs twice a side.Not tested: Windows on AMD and Intel GPUs; a CPU without SSSE3 (the vector rewrites use PSHUFB and PALIGNR); areas beyond Castle Town and the castle grounds;
nx2/test_insn.pyandnx2/test_leaf.py --callson this base.Must be tested:
Market_Child, stand 30 s and measure; teleport toDeathMountainTrail_Child, stand 30 s and measure; uncapped, render resolution 50 %, the game's own upscaler, frame generation off; expecting no crash, the same picture as main, and a frame rate not below main's in both places: up to about 10 % above it where the CPU is the limit, about the same where the GPU is (Test Farm: @Beanstalk linux and windows)Risks
What could break: a lifted function that reads a register or a flag from the context while it lives in a local (the kit's context marks, the patched functions' rule and
check_patched()guard this); a vector rewrite on an operand form the tests do not cover.What it costs: the game's build takes longer, since the C with locals is more work for the lift and the compiler. The Test Farm timed it on an earlier head (Ryzen 7 5800X3D, 6 compile jobs, two builds a side in turn): 592.9 to 748.4 s (+26 %), the lift 74.6 to 95.5 s, the compile 500.0 to 634.7 s. Since then the lift's part is smaller (the plain text is made only for the functions that need it: 55 to 51 s here, 45 s without locals). A tester's Steam Deck: +16 %; here on 12 cores: +12 %. The cost is paid when the game code is built anew: every install takes it nearly in full once, at its first build with this change, and not again on updates that leave the game code as it is.
Turning it off: each piece by its switches above, at build time: the game's code is translated again.
Compatibility: the game's code is lifted and compiled again once after the update (the lift key holds the switches). Saves,
longshot_options.iniand the shader and pipeline caches are unchanged.Issues
See #1020
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (36 fail here with and without this change; the list is in the first comment.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).🤖 Generated with Claude Code
Tested in game: Windows 11, RTX 4070 SUPER (NVIDIA 621.24), Ryzen 9 9900X, 4K with DLSS Quality: Castle Town market, castle grounds and back on a recorded route, four traced runs of this branch at
15c563a8(two at default settings, two with RX_VK_FRAME_GATE=0 and RX_VK_READBACK_LATE set). No crash, no error in the log, both gameplay patches of main applied in the build; 61.7 fps against main's 56.5 with the cap at 90.Possibly related, for context:
@Beanstalk linux and windows amd: walk through Castle Town's market for a minute (the debug teleport to
Market_Child, then from the gate across the square to the far side and back), once with this PR's defaults and once withRX_VK_FRAME_GATE=0andRX_VK_READBACK_LATE=3980,9b040,8b040,44b040,1b580. Expecting no crash, the same picture as main, and a higher frame rate than main in both.Walking matters here: most of this change's gain, and all of the two switches' gain, shows in motion. If the farm can only stand, a standing run is still a useful check for crashes and picture differences, but its fps will say little.
(Edited: the first version asked for standing.)
@Veix only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@dyst approval of
f862753recorded. This diff touches sensitive paths, so a second member ofBigBeansmust approve it too.Beanstalk test farm · an earlier run: commit
f862753(the newer results are in a comment below)Commit
f862753· tier double-reviewed · approved by HumanBean, dyst (👍 on Veix's request) · dashboardWhat will be tested · AI plan (
gpt-6.1-terra)The farm will compare main and the PR in child Castle Town Market, including a return visit after Hyrule Castle and scripted movement before each measurement. It will measure standing frame times and FPS, compare screenshots, and time the lift and compile stages; the gameplay portion takes about 15 minutes per tester, apart from builds. A crash, significant visual difference, FPS drop over 10%, or p99 frame-time increase over 15% fails the plan. The standing measurements do not establish the claimed movement-related speedup or isolate the individual optimizations.
Started at 15:01 UTC.
Estimate: done in about 40 min, from the queue and the testers online now.
This diff touches sensitive paths, so it needs two members of
BigBeans:nx2/fastcmp.py,nx2/fastvec.py,nx2/lift.py,nx2/locals.py,nx2/oot_patches.py,nx2/test_leaf.pyNVIDIA GeForce RTX 4070, 615.71.9Measurements · any
Verdict: fail on any (1/1 report):
market-revisit screenshot.max_diff;market-revisit first-visit.frametime_p99_ms.max_delta_pct (+32.7%)failed.Hardware: 1: linux+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 4070, 615.71.9AMD Ryzen 7 5800X3D 8-Core Processor, 64 GB RAMScene: market-revisit, from a new save (frame_rate_cap=1, frame_generation=0); 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-revisit: 1 game start a side, first-visit 20 s after 5 s warm-up, return-visit 30 s after 5 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)430eef4f862753Build times (each a median of the timed builds; caches: lift = the lift again (no kept lift, main's compiled objects kept))
430eef4f862753Flags and settings
None: the plan varied no setting, switch or build option.
Markdown for the PR description
Farm readiness review for
f8627530: I’m holding the second approval. The PR still combines several translator and host changes with two renderer overrides, and the reported gain depends on movement. Please identify which pieces the Windows/Linux run is meant to validate, give the isolated evidence for each change or split the unrelated pieces, and specify a repeatable movement route and a pass condition. A standing run can provide crash and screenshot coverage.@Beanstalk
Steam Deck OLED (Linux, RADV): it builds, runs without a fault, and is about 7 % faster where the game's own code limits the frame. Where the replay and the GPU limit it, nothing moves. This PR @
f8627530against its base, main @430eef4f.Where the game's code limits: Death Mountain Trail, adult Link standing under the falling rocks (about 1,270 to 1,300 draws and 255 to 296 compute dispatches a frame), runs in the order main, PR, PR, main:
game_ms: no frame trace was taken), 37.9 to 34.1 ms (-10 %). Both runs of the PR are above both runs of main; two runs a side, and two runs of one side differ by up to 1 fps, so the direction is clearer than the size.Where the replay and the GPU limit: Castle Town's market, child Link, a fixed route (three visits a run by the debug teleport, 30 s of a walk with camera swings in each, about 2,100 to 2,250 draws):
No difference. A wide view of about 2,190 draws, standing: 24.9 fps on main, 24.7 with the PR, the same.
Build and run:
locals: 16 functions with spliced code kept in the context,locals: 58 functions that hold an address the patches name kept in the context,locals: 1 functions kept in the context for the patches; 32 patched functions checked in the written C.--jobs 4, 4 cores): 5,027 s against 4,329 s for main the same morning, 16 % longer.Hardware: Steam Deck OLED (AMD Custom APU 0932, Zen 2, 4 cores / 8 threads, AVX2; RADV VANGOGH, Mesa 26.2.0-devel), SteamOS 3.9.5, 16 GB, on the charger, the GPU at a manual 1600 MHz.
Builds: both built on the Deck by the Linux builder (
scripts/linux/appimage.sh, thenAppRun --cli --update), withLONGSHOT_CHUNK_OPT=alland a local hot list of 918 functions on both sides. So the lifted code is at-O2everywhere in both games, which is not the default build: the gain above is what the PR adds on top of that.Settings, the same on both sides: the handheld profile, a fixed 3D resolution of 1536x864 (
HOS_RES_LOG=1:3D scale 1.000in every run), the game's own upscaler, headless,HOS_FPS_MAX=1000; the player's switches:RX_VK_READBACK_LATE=newest,3980,RX_VK_LATE_DEFER=0,RX_VK_READBACK_EARLY_GAP=120,HOS_RESERVE_CORE=0,RX_VK_VRAM_MB=2800,RX_VK_TEX_MAX_DIM=1024,RX_VK_TEX_SKIP_MB=4,RX_VK_LOAD=create,RX_VK_LOW_SPEC=1,RX_VK_TEX_AHEAD=1,HOS_NATIVE_ZSTD=0. This PR's three run-time switches at their defaults (on).RX_VK_FRAME_GATEunset.Method: the two games are two sets of files swapped in one game folder, so the settings and the caches are the same files for both. Death Mountain: headless from a save, 720 presents measured once in play, the save copy put back before each run,
HOS_OOT_PROTECT_HEARTS=1on both sides (without it Link dies under the rocks about 20 s into the run and the scene changes: four runs made that way are left out). Market: every present taken from the control bridge'spresentevents; a visit's frames are the presents of 200 draws or more between the teleport's answer and the end of the walk.Limits:
-O2builds; a default build (-O1chunks) was not measured.Follow-up from play, as said above: a short session with this PR's game on the same Steam Deck OLED, in Game Mode (the log names the build,
v2.1.0-rc.3-806-gf8627530): the Fire Temple as adult Link, about a minute in play, 360 to 1,120 draws a frame. Nothing odd in the picture, no crash, 0 fatal lines in the log.That is one dungeon for one minute: it says the build plays there, not that every area was looked at. The frame rate is already good in that place, so no gain was looked for in this session; the numbers above stay the measurement.
f862753024cb7449eefcBeanstalk test farm
Commit
26c554e· tier untrusted · approved by nobody yet · dashboardThis diff touches sensitive paths, so it needs two members of
BigBeans:nx2/fastvec.py,nx2/guest_locals.py,nx2/lift.py,nx2/oot_patches.py,nx2/ran_funcs.txt,nx2/test_leaf.pyA member of
BigBeanscan review this commit and comment@Beanstalkto test it.WIP: perf: less game work a frame in Castle Town (registers as locals, vector rewrites, unchanged texture data left alone)to WIP: perf: less game work a frame in Castle Town (registers as locals, vector rewrites)Thanks for the review, all three points were fair.
One topic now. The head (
cb7449ee, on main876dc360) is the two translator changes only: registers and flags as C locals, and the vector rewrites. The two host checks, the capture-buffer worker and the FMIN / FMAX fast path are out.Each piece by itself (Castle Town market, the recorded route, default settings, cap lifted to 90):
430eef4fThe four pieces that left changed nothing measurable on current main (14.25 to 14.41 ms with any one of them off).
The gain does not depend on movement; that sentence of mine was wrong. Standing after a teleport: the market 13.65 to 11.73 ms of game work, Death Mountain Trail 9.15 to 8.17 ms.
The switches are out of the test and out of this PR. The description shows what they add to it.
The test is in the request below: two teleports, standing, a pass condition.
The farm's first run measured a moving, still-loading scene once a side: its picture was taken while Link ran (both pictures are correct, a few steps apart), and the median frame was the same. Its build timing is solid and in the description now: the build takes 26 % longer there with the locals (12 % here, 16 % on p0lux's Steam Deck; thanks for those runs).
Measured and written with the help of an AI coding agent.
@Beanstalk linux and windows: teleport to
Market_Child, stand 30 s and measure; then teleport toDeathMountainTrail_Child, stand 30 s and measure. Uncapped, render resolution 50 %, the game's own upscaler, frame generation off. Expecting no crash, the same picture as main, and a frame rate not below main's in both places: up to about 10 % above it where the CPU is the limit, about the same where the GPU is.@Veix 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 forcb7449e, and the PR has changed since (34e3d47), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.WIP: perf: less game work a frame in Castle Town (registers as locals, vector rewrites)to perf: less game work a frame in Castle Town (registers as locals, vector rewrites)Verdict: Request changes. The two translator pieces are well built and the gain is real and measured, but with locals on, the functions whose code starts below their entry skip their own register and flag loads:
lift_fixes' entry goto lands above the locals' declarations, so those functions run on whatever the stack holds.For a player this takes 12-15% off the game's own work per frame and up to +15% fps where the CPU limits the frame. It makes the code better on net: the vector rewrites are tight, exact and tested, and asking the patches which functions they touch is a clear improvement on keeping a list by hand. The costs are a build 12-26% longer, measured and stated, and the bug below.
Reviewed:
cb7449eeagainst its base876dc360. Read in full:nx2/locals.py,nx2/fastvec.py, the changes tonx2/lift.py,nx2/oot_patches.pyandnx2/test_leaf.py,nx2/lift_fixes.py'semit_function(unchanged here, but it wraps this PR's emit), the kit'slocalize_regs,recomp_ldp64anda64_vfpx_mul32, and the docstrings and word lists oftests/test_vbytes.pyandtests/test_vfpx_elem.py. Only skimmed:tests/vbytes_test.c,tests/vfpx_elem_test.c,docs/tested/. Nothing run: a code review.Fixed in this review: nothing.
Checked and fine:
a64_vfpx_mul32_vfast path and the samea64_vfpx_mul32_lanesfallback as the kit's 4-lane FMUL, with the element broadcast. TheKIT_MUL32text guard stops the lift if the kit changes.recomp_ldp64is two plain 8-byte loads ataanda + 8, so one 16-byte load reads the same bytes. DUP's widths and Q handling match.keep_mentionedcatches the patches that carry no(nx2/oot_patches.pymark, such as the dynamic-resolution branch, by their label's address;install_plaingives them the plain FCMP text, so the horse jump patch still findsa64_fcmp32(c,...);check_patchedstops the lift if a marked function got locals.A64_LOCAL_FLAGS=0now means off; the kit took any value as on.fastfp.localize_regsandfastfp.local_regs, imported by name, are both replaced, so fastfp's copy ofemit_functionfollows.Blocking (to change before merge)
nx2/lift.py:57-61:lift_fixes.install()runs afterlocal_regs.install()andinstall_plain(), so itsemit_functionwraps theirs.min(body) != e, 26 of them in a lift of OoT), it insertsgoto L_<entry>;right after the head (nx2/lift_fixes.py:134-137). Butlocalize_regshas already putuint64_t x19_ = c->x[19], ...;anduint8_t fn_ = c->n, ...;there. The goto jumps over those initialisers: legal C, but the locals are indeterminate.c->x[19] = x19_;write-back (before a call, or at its return) and hands its caller a garbage callee-saved register.nx2/test_leaf.pydoesn't build that shape, and the game may run through these functions rarely.lift_fixes'emit_functionto insert its goto after the locals' declaration lines (they start withuint64_t xoruint8_t fn_), or to put these functions inno_local. #1587 fixes the same bug for #1469 over #1560'snx2/emit.py: the head lines go in beforelocalize_regsdeclares the locals. A game-free test for it is in #1587 (tests/test_lift_entry_local_regs.py), and its idea fits here too: lift a function entered below its first block with locals on, and check that the declarations come before the goto.Suggestions (the author may take or leave)
install_plain'sop_textruns the kit'sop_texttwice for every instruction (the second time with local flags off), though only the ~75 functions inno_localever read the plain text. That likely accounts for most of the lift's +28% on the farm (74.6 → 95.5 s). Computing the plain text only when ano_localfunction asks for it (_Plain.__getitem__callingop_textwith flags off on the raw text) would give most of it back.nx2/locals.py, imported aslocal_regs, sits next toa64_lift.local_regs(), a function, and a module namedlocalsreads like the builtin. Something likenx2/guest_locals.pywould be clearer.nx2/test_leaf.pyno longer compares x9-x15 with locals on. That matches the kit's write-back (the scratch registers aren't stored at a return) and the AAPCS64. A comment saying it rests on no caller reading x9-x15 after a call would keep the next reader from treating it as a bug.Questions
f862753failed on p99, 35.9 ms against 27.0 (+33%), and on a picture difference (Linux, RTX 4070, Ryzen 7 5800X3D). The explanation, a scene still loading and a picture a few steps apart, is plausible but not shown. Your Windows 1% lows are fine. Will the farm's run on this head be the answer before this is called ready?Testing: Windows RTX 4070 SUPER and Ryzen 9 9900X runs by the author, traced, 2 a side and each piece alone; p0lux's Steam Deck OLED, +7% where the game's code limits, with
-O2builds on both sides; the farm's earlier run (above). Missing: the farm on this head, AMD and Intel GPUs on Windows, and a CPU without SSSE3 (the fallbacks look right on reading). For what it's worth, on a Ryzen 9 3900X here, #1469's registers alone, without the flags, were within noise (+0.2% and +1.6% over 3 rounds), which is consistent with your split: the flags carry a good part of the locals' 1.4 ms.Overlaps and merge order:
emit_functionwith hook points, and conflicts with this PR's wrappers. Whichever merges second ports onto the other; #1560's lift is byte-identical, so porting this onto it is mechanical.@ -51,2 +54,4 @@insn.install()fastvec.install() # (around the kit's vectorize_fpx, op_text and fpx_header)fastfp.install() # (before lift_fixes and poll wrap emit_function: theirs go around this one)local_regs.install(oot_patches.touches) # (around fastfp's emit_function and the kit's localize_regs; the defaults; the patches asked)lift_fixes.install() runs after this, so its emit_function wraps the locals': its entry goto (lift_fixes.py:137) lands right after the head, above localize_regs' declarations, and the 26 functions entered below their first block skip their register and flag loads. See the review.
cb7449eefc34e3d4769fThanks for the careful review. The blocking point is fixed and the suggestions are taken; head
34e3d476, on mainc507b98c.Blocking: the entry goto over the locals' loads. Confirmed here: 26 functions in the lifted code had the goto right above their declarations. A function whose code starts below its entry now keeps the context (
keep_entered_below()innx2/guest_locals.py, intono_local), solift_fixesstays as it is. After it, a scan of all 294,522 lifted functions finds none with a load behind the goto, and the Market route is unchanged (61.8 fps, 13.97 ms of game work).tests/test_entry_below_locals.pychecks the rule without the game, and that it is the same conditionlift_fixeswrites its goto under.Build time. Your suggestion is in: the plain text is made only when a
no_localfunction asks. The lifted C is byte-identical and the lift step went from 55 to 51 s here. Most of the cost is the compile and stays. It is paid when the game code is built anew: every install takes it nearly in full once, at its first build with this change, and not again on updates that leave the game code as it is. The hot list that is being looked at for-O2could later serve lifter changes like this one too: locals only for the functions that run often would keep most of the gain for a fraction of the compile.Name and comment.
nx2/locals.pyisnx2/guest_locals.py;test_leaf.pysays why x9-x15 are not compared.The farm. Yes: its run on this head is meant to be the answer. The farm request, posted again for this head since a push voids the earlier one, asks for a standing test, two runs a side, so that neither the picture nor a single window decides it.
Measured and written with the help of an AI coding agent.
@Beanstalk linux and windows: teleport to
Market_Child, stand 30 s and measure; then teleport toDeathMountainTrail_Child, stand 30 s and measure. Uncapped, render resolution 50 %, the game's own upscaler, frame generation off. Expecting no crash, the same picture as main, and a frame rate not below main's in both places: up to about 10 % above it where the CPU is the limit, about the same where the GPU is.@Veix 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 for34e3d47, and the PR has changed since (26c554e), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Verdict: Request changes. The below-entry fix addresses the earlier review. The current head still has a packed-flags correctness case and test runners that fail to cover the claimed Linux and baseline x86-64 paths.
Reviewed
34e3d476againstc507b98c, including the new lifter paths, the entry exclusion, vector fixtures, and performance records. No source changes pushed.nx2/guest_locals.py:125. InheritedA64_PACKED_FLAGS=1now conflicts with local flags enabled by default. The kit folds CMP's writes intoa64_set_nzcv(c, …)before localizing, so the helper updates the context while the following B.EQ can read the entry value of local Z. With incoming Z clear and equal operands, it can miss the branch. Preserve the explicit packed mode by keeping flags in the context when it is selected, or update the localized flags correctly. Add an actual emitted CMP/B.EQ case.tests/vbytes_test.c:11andtests/vfpx_elem_test.c:15include Win32 headers and use Win32 APIs unconditionally, while the scripts are discovered on Linux x86-64. Make those fixtures portable. Also gate the x86-64-v2 and v3 binaries on the host ISA before executing them. The vector runner currently runs those variants before the SSE2 baseline.nx2/test_leaf.py:66. This validation path installs the existing hooks but misses the newfastvecand guest-local passes and their entry exclusion. Share the production emission setup, or correct what the test claims and provide an emitted-function differential result from the production path.Independent Windows checks: the four entry tests, the vector differential test with 1,000 random cases per instruction, and the FMUL differential sweep and random checks passed at the exact head. The compiler exercised native, x86-64-v3, and x86-64-v2 on a CPU that supports them. This host has no Linux test environment. The results do not cover the packed-flags combination or a CPU without SSSE3.
Performance evidence: please add a warm interleaved Market comparison at this exact head and publish p99 alongside game work per frame. The headline pair is from earlier commits, and the previous farm run had a p99 and image regression on an earlier head. Keep those results attached to their revisions when evaluating the current change.
PR #1560 changes the same emitter hook structure. The second branch to land needs to recheck the wrappers and their order.
@ -0,0 +122,4 @@return_installed = Trueimport fastfpa64_lift.local_regs = fastfp.local_regs = local_regsPacked NZCV updates the context, while a later conditional branch can read the stale local flags. Please gate packed mode or localize its update too.
@ -0,0 +8,4 @@#include "a64.h"#include <stdio.h>#include <stdlib.h>#include <windows.h>This fixture is auto-discovered on Linux x86-64 and needs a non-Win32 path.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.