WIP: test(lift): A64_PIN_REGS, guest registers in host registers across calls, kept as a game-free experiment apart from the build (measured no-go) #1981
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!1981
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/lift-pin-regs"
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
An experiment kept for the record, apart from the game's build:
nx2/pin_regs.py, a pass over lifted C that makesevery lifted function clang's
preserve_noneand hands up to 10 guest registers (A64_PIN_REGS) from call to call inhost registers, with a game-free fixture and a write-up. Measured as a no-go on the branch it comes from (342422dd): a
synthetic workload 2-4 % faster at best, within its spread. Nothing of the game's build runs it: the lift does not
import it and
nx2/rtgen.pyis main's, so a default build lifts and compiles exactly asmain(the pinned runtime ispin_regs.write_rt's, for the fixture only). With the review (futondestroyer, BeanBot): the build integration of thefirst commit is taken out again, the pass checks its switches and every file before it writes,
A64_PIN_ABI'sa64_runkeeps what a call keeps, and the doc no longer carries figures taken over the game's lifted code.Read first:
nx2/pin_regs.py,tests/test_pin_regs.py,docs/dev/reference/pin-regs.md.Testing
Tested: Windows 11, i7-9700, RTX 4060, llvm-mingw clang 23.1.5 (the Builder's, found through
LONGSHOT_MINGW, no--cc), Python 3.14.7 (the Builder's); game-free checks only, each in a hidden console of its own, through the PC's jobqueue, on this branch rebased onto
main@f1f2dc5b:python -I -B tests/test_pin_regs.pyon the head (01cd59d8, queue job fb2-1981-2): exit 0, "all passed": the isolation, the switches' values andrefusals (each in a folder of its own, left as it was), and seeds 1 to 3, any and AAPCS64 callees, O1 and O2, each
set of pinned registers (x0; x0 sp; x0-x3 x19 x29 x30 sp; ten; ABI four; ABI ten): the same digest plain and pinned
(e.g. "seed 3, AAPCS64 callees, O2, ABI ten: plain adaef4a828ee7dfb, pinned adaef4a828ee7dfb").
dfb8e913, the review's cases before their fix, same queue job): exit 1, 26 failed: the12
A64_PIN_ABIbuilds (seeds 1 to 3, O1 and O2, ABI four and ABI ten; e.g. "seed 3, AAPCS64 callees, O2, ABIfour: plain adaef4a828ee7dfb, pinned a234a6e4ec7a62d6": the lowered SP read again after a site's miss), the gameplay
HUD wrapper, a setjmp call in a later file and main's locals left on (not refused, or the folder rewritten), five
A64_PIN_REGSvalues (31-0,5-3,0-, non-ASCII digits) and fourA64_PIN_ABIvalues (0taken as ABI;yes,true,2not refused). Its exact builds and the spliced function pass there.make_game.lift_keyover one fixed made-up exefs and work folder,lift_sources()andrtgen.write'sa64.handa64_rt.c, frommain@f1f2dc5band from this branch (4cd8a394, which differs from thehead by one line of
tests/test_pin_regs.py): the same lift key (8509d8c7a558...), the same 49 lift sources(
pin_regs.pynone of them), the samea64.handa64_rt.c(sha256 48c4a0f6b44c... and 3baf0ecb3403...). Thebranch's diff against
mainisdocs/dev/reference/pin-regs.md,nx2/pin_regs.pyandtests/test_pin_regs.py,and no other file names them.
python -I -B tests/run_all.py --strict --changed origin/main(3 files changed) on 4cd8a394 (queue job fb2-1981-1;the head differs from it by one line of
tests/test_pin_regs.py, a FAIL message printed withascii()): 2 passed(
test_pin_regs.py,byte_compile_tracked.py), 0 failed, 0 skipped.Still to test:
python3 -I -B tests/test_pin_regs.py, expecting it to pass (by hand)Measurements
Verdict: a no-go, kept out of the game's build: a default build is
main's (the table), so there is nothing tomeasure in play; the only performance figures are the branch's synthetic ones (342422dd, in the doc and Summary), and a
pinned game cannot be built.
Setup: Windows 11, i7-9700; the lift key and the generated runtime computed from each tree through the PC's job queue
(
make_game.lift_keyover one made-up exefs,rtgen.write)f1f2dc5ba64.h,a64_rt.c(sha256)Risks
None for the game: no file the build reads changes, so the lift key and every object key stay
main's, and aninstallation updated to it translates and compiles nothing again because of it. The pass and its pinned runtime run
only in
tests/test_pin_regs.py. Nothing a player keeps (saves,longshot_options.ini, caches) changes.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.Possibly related, for context:
Recommendation: Close. The experiment has no demonstrated gameplay gain, cannot build the supported game with pinning on, and invalidates the lifted-object cache with pinning off. Keep the synthetic findings in a docs-only change and leave the experimental ABI out of the production build.
The pass moves selected guest registers into host registers across lifted calls. It adds a second calling convention, runtime dispatch paths, and compiler requirements without giving players a usable improvement.
@fixwill do (19)nx2/rtgen.py:143: Keep the experiment out of the default lift and runtime generator so their output and cache inputs stay stable.nx2/rtgen.py:123: ABI mode can corrupt SP or x19 on an indirect call. (more on the line)nx2/lift.py:255: The normal Builder accepts the option and starts translating the supported game, then fails at the known setjmp callers. (more on the line)nx2/rtgen.py:82: Header discovery alone activates the pinned ABI in every consumer. (more on the line)nx2/rtgen.py:152: Disabling host lookup sends ordinary NVN calls througha64_call_miss. (more on the line)nx2/rtgen.py:90: An older Clang can ignorepreserve_nonewhile the build and fixture suppress its warning. (more on the line)nx2/pin_regs.py:76: The parser materializes a range before checking its endpoints. (more on the line)nx2/pin_regs.py:199: The pass rewrites chunks before validating later ones. (more on the line)nx2/pin_regs.py:84:A64_PIN_ABI=0selects ABI mode and drops exact return state. (more on the line)tests/test_pin_regs.py:151: The conflicting-switch check points the mutating pass at the system temporary directory. (more on the line)tests/test_pin_regs.py:40: The suite forces--cc clang, bypassing the script'sCCandLONGSHOT_MINGWselection. (more on the line)tests/test_pin_regs.py:325: The test inherits lift settings outside the four variables cleared byenv(). (more on the line)tests/test_pin_regs.py:398: The off comparison appliespin_dirto output that was already emitted without importingguest_localsor usinglift.py. (more on the line)tests/test_lift_cache.py:51: Both cases compare to the unpinned key, so the ABI case still passes if the key ignoresA64_PIN_ABI. (more on the line)docs/dev/reference/pin-regs.md:94: The hot-function tables are sampled outputs from compiled game code, and the following paragraph includes a game trace. (more on the line)docs/dev/reference/pin-regs.md:65: The measurement setup says every build used exact mode, but both timing tables include ABI variants. (more on the line)docs/dev/reference/build.md:70: Remove the production build integration and switch entries. Keep a compliant record of the synthetic experiment.For the author (3) (a run, a measurement or a decision)
nx2/rtgen.py:143: With pinning unset, an update from main still discards reuse of every lifted object. (more on the line)docs/dev/reference/build.md:70: The production build carries an opt-in ABI whose reported gain is within noise and whose enabled mode cannot build the game. (more on the line)Checks: Still running:
CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request),Website / Website on Cloudflare (pull_request).More: does it help, other systems, switches, what was read
Does it help: Unproven on this PR. On predecessor 342422dd, the best synthetic timings were roughly 2–4% faster within run-to-run spread. Exact ten-register pinning was 12.9% slower in the hot synthetic run. Windows digest matches on the earlier PR head establish equivalence for the exercised fixtures. There are no comparable gameplay or build timings against
6e1521a70a.Other systems: Both Windows and Linux rebuild cached lifted objects after the generated header changes. Pinning would also affect NVN host dispatch, guest thread state and crash diagnostics, the emulator DLL ABI, and Linux Tracy instrumentation. The renderer interface, shader formats, save code, audio, and input code are outside the diff. No Tier 1 gameplay run was reported, including on Steam Deck.
Switches: A64_PIN_REGS is unset by default. A64_PIN_ABI is unset for exact mode, but any nonempty value currently enables ABI mode, including 0. A nonblank register list changes the defaults of A64_LOCAL_REGS from six to zero and A64_LOCAL_FLAGS from on to off. Leaving pinning unset is the only usable game default. These are lift-time options documented in the build table and covered by the lift key's A64_ prefix. They do not belong in the game's runtime switch table.
Reviewed:
5b3b49fc3fagainst6e1521a70a: Read all nine changed files in full and revisited each. Read AGENTS.md, CONTRIBUTING.md, the standards, the Forgejo template, and the commit message and trailers. No local review checklist or adjacent Tooling checkout was present. Read relevant sections of the build, cache, chunking, emitter, runtime, host, profiling, test runner, and CI code. Two unrelated recorded-run sets and the rest of the unchanged tree were outside the review. No translations or generated files changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review.
git diff --checkwas clean. The author reports passing Windows synthetic digests on the earlier rebased head. Seven named failures were reproduced on its base, and one check skipped. Exact-head CI was pending. Linux fixture execution and in-game testing were unverified.Overlaps and merge order: No overlapping open pull request was identified in the supplied review data or local refs. The merged giant-splitting work in #1727 shares the calling-convention technique and is already in the base.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -67,6 +67,7 @@ Read by the build, not the game, so they are not in `switches.def`.| `LONGSHOT_THIRD_PARTY_OBJECTS=0` or `<dir>` | The prebuilt third-party objects a release ships (`0`: compile them) || `LONGSHOT_TRACY=1` | A Tracy build ([profiling](profiling.md#tracy)) || `LONGSHOT_NGX_SDK=<dir>`, `LONGSHOT_FSR=1` | Build with NVIDIA DLSS, AMD FSR 4 ([setup](../setup.md#upscaler-sdks-optional)) || `A64_PIN_REGS=<regs>`, `A64_PIN_ABI=1` | An experiment, off, measured as a no-go: lifted functions take the context and up to 10 guest registers (`0,31`, `0-7,30,31`: numbers, ranges, `sp`) in host registers, clang's `preserve_none`, and hand them on in calls and tail calls (`nx2/pin_regs.py`, a pass after the lift's last edit; [pinned registers](pin-regs.md)). It turns the default locals off. The game cannot be built with it yet ([what it still needs](pin-regs.md#what-a-full-integration-still-needs)). Off, the lifted C is byte for byte as before. Lift-time switches: they change the lift key |L18: The production build carries an opt-in ABI whose reported gain is within noise and whose enabled mode cannot build the game. It also bypasses pinned hot-call grouping and giant splitting, and the Linux Tracy wrappers still assume the plain signature. Preserve the findings without enrolling the production lifter and runtime in the experiment.
@ -0,0 +62,4 @@These are the measurements of the branch this comes from (exp/x86-asm-sync, 342422dd), not repeated on main; that branchhad no locals by default then, and `A64_LOCAL_REGS` below is its earlier hot-list form. 2026-11-17, Windows, clang22.1.8 (`--target=x86_64-w64-windows-gnu -march=native`, the build's lifted-code flags), another PC (RX 9070 XT), nogame run. Every build below is exact: against Unicorn on a synthetic workload (`work/lift-probe`, a scratch harness notL16 (minor): The measurement setup says every build used exact mode, but both timing tables include ABI variants. It also says the experiment is kept so the measurements can be repeated, while the measured harnesses are absent. Label the variant contracts accurately and identify which results the committed fixture can reproduce.
@ -0,0 +91,4 @@pinning live guest registers gives part of it back: every one a function keeps live across a call is spilled(`preserve_none` preserves nothing), and Win64 returns the second register through memory.The game's 46 hottest functions under 150 KB of C (the head of `hot_funcs.txt`, 2.8 MB of real lifted C copied out ofL15: The hot-function tables are sampled outputs from compiled game code, and the following paragraph includes a game trace. The repository rule covers these derived outputs. Remove them and the corresponding derived figures from the commit message. Keep the synthetic results and use an authored fixture for instruction and spill comparisons.
@ -251,6 +252,11 @@ def main():L.stats["locals_kept_for_patches"], local_regs.check_patched(gen)))took("locals check")print("\n".join(chunks.end_side(side, tables)), flush=True)pinned = pin_regs.pin_dir(gen) # (A64_PIN_REGS: after the last edit of the C, whose patches anchor on its plain text)L3: The normal Builder accepts the option and starts translating the supported game, then fails at the known setjmp callers. Removing that refusal alone still leaves direct host calls such as
host/oot_voice.c:61using the old signature. Keep the option in the standalone fixture or reject it at the build entry before translating. Exposing it for play requires both setjmp handling and host caller conversion.@ -0,0 +73,4 @@lo, _, hi = part.lower().replace("sp", "31").replace("x", "").partition("-")if not lo.isdigit() or (hi and not hi.isdigit()):raise SystemExit("A64_PIN_REGS=%s: registers are numbers, ranges or sp (0-7,29-31)" % v)out += range(int(lo), int(hi or lo) + 1)L7: The parser materializes a range before checking its endpoints.
0-1000000000attempts a huge allocation. A reversed range such as31-0gives an empty pin set while its nonblank value still disables the usual locals. Validate ASCII endpoints and ascending order before expansion, and use the parsed mode for the locals defaults.@ -0,0 +81,4 @@def abi():return bool(os.environ.get("A64_PIN_ABI"))L9 (minor):
A64_PIN_ABI=0selects ABI mode and drops exact return state. Parse the documented1explicitly and test that0selects exact mode.@ -0,0 +196,4 @@p = os.path.join(gen, name)with open(p, encoding="utf-8") as f:s = f.read()t = pin_file(s, pins, stats)L8: The pass rewrites chunks before validating later ones. A setjmp wrapper in a later chunk leaves the table and early chunks pinned and later chunks plain. A direct
lift.pyrun also can leave the previous pin header behind. Validate the input before modifying it and stage a complete output set before publishing it.@ -78,0 +79,4 @@# to its C when it pins, and nothing changes without one. a64_run is how the host's void f(Ctx *) world calls a lifted# function either way.A64FN = "typedef void (*A64Fn)(Ctx *A64_NOESC);"PIN_FN = r"""#if defined(__has_include)L4: Header discovery alone activates the pinned ABI in every consumer. A pinned DLL that gets through the lift can return a pinned entry from
mkw_recomp_lookup, which the emulator calls using the old one-argumentMkwFn. ItsA64_POLL_CTXcallback also lacks register synchronization. Gate pinning explicitly and reject pinned DLL builds unless the exported ABI and poll boundary are adapted together.@ -78,0 +87,4 @@#ifdef A64_PIN/* (nx2/pin_regs.py) clang's preserve_none: the context and up to 11 guest registers in host registers. musttail needs theone signature everywhere; the pinned registers are the caller's xN_ (A64_PIN_ARGS) */#define A64_PFN __attribute__((preserve_none))L6: An older Clang can ignore
preserve_nonewhile the build and fixture suppress its warning. Equality can then pass without exercising the intended convention, or a different compiler can reject the indirect tail call. Require the attributes and probe a representative indirectmusttailwith the selected compiler and target before starting a pinned build. Run the compiled check with a capable compiler on both CI platforms.@ -78,0 +120,4 @@const int a64_site_hit_ = __builtin_expect(a64_site_e_ >> 32 == a64_site_t_ && a64_site_e_ != 0, 1)#define A64_PIN_SITE_FN ((A64Fn)((intptr_t)&a64_lookup + (int32_t)(uint32_t)a64_site_e_))#define A64_ICALL(c, t) do { A64_PIN_SITE(t); if (a64_site_hit_) A64_PCALL(A64_PIN_SITE_FN); \else { A64_PIN_STORE(c); a64_icall_site(c, a64_site_t_, a64_site_); A64_PIN_LOAD(c); } } while (0)L2: ABI mode can corrupt SP or x19 on an indirect call. A conforming callee can allocate a stack frame, issue an SVC that publishes the lowered SP, then restore its pinned SP before returning. The ABI return leaves the lowered SP in the context, and the cold or second-slot path reloads it into the caller. The first-slot hit keeps the correct caller SP. Preserve callee-saved pins across the slow guest-call path and restore them at the host entry boundary. Exercise both cache paths with an SVC inside the callee's frame.
@ -82,11 +140,16 @@ SUBST = {(RET_MISMATCH, RET_MISMATCH + POLL_DECL),("#define A64_PTR(a) (A64_MEM + (uint32_t)(a))", ADDR64),(MARK_NATIVE, MARK_NATIVE_64),(A64FN, PIN_FN),L1: With pinning unset, an update from main still discards reuse of every lifted object.
build.pyhashes the full generateda64.hinto every lifted object's key. The lifter source key also moves, so the updater repeats translation even if the chunks come out identical. Time a warm update from the merge base with pinning unset.@ -89,1 +149,4 @@("uint8_t a64_dirty[1u << 20];", "uint8_t a64_dirty[A64_DIRTY_PAGES];"),(RT_CALL, " a64_run(c, f);\n}", 3), # (a64_icall, a64_ijump, site_call)(RT_SITE2, "a64_run(c, ((A64Fn)((intptr_t)&a64_lookup + (int32_t)(uint32_t)e)));"),(RT_HOST, "#ifdef A64_PIN\n A64Fn h = NULL;\n#else\n" + RT_HOST + "\n#endif"),L5: Disabling host lookup sends ordinary NVN calls through
a64_call_miss. Two recording threads entering that path can concurrently initialize the plainstatic int statsinhost/hos_hostcall.c:92, even with profiling disabled. Keep the normal fast path through compatible thunks or leave pinned host dispatch disabled. If the slow path is used, synchronize its one-time initialization and host-slot publication.@ -48,6 +48,11 @@ def main():check("another lift setting changes the key", make_game.lift_key(str(exefs), str(work), dict(env, A64_HOT_CHUNK="")) != key)with mock.patch.dict(os.environ, {"A64_KEEP_FLAGS": "1"}):check("a lifter switch in the environment changes the key", make_game.lift_key(str(exefs), str(work), env) != key)for pin in ({"A64_PIN_REGS": "0,31"}, {"A64_PIN_REGS": "0,31", "A64_PIN_ABI": "1"}): # (nx2/pin_regs.py: lifts again)L14 (minor): Both cases compare to the unpinned key, so the ABI case still passes if the key ignores
A64_PIN_ABI. Compare exact and ABI keys with the same pinned register list.@ -0,0 +37,4 @@import kit # noqa: E402,F401 (a64-kit on the path)import pin_regs # noqa: E402RUN_ALL_ARGS = ["--cc", "clang"]L11 (minor): The suite forces
--cc clang, bypassing the script'sCCandLONGSHOT_MINGWselection. A Windows setup with bundled llvm-mingw and noclangon PATH skips or fails before that selection runs. Resolve the compiler consistently in the runner and test, honoring explicit selection and using the configured native toolchain.@ -0,0 +148,4 @@passwith env(A64_PIN_REGS="0", A64_LOCAL_REGS="4"):try:pin_regs.pin_dir(tempfile.gettempdir())L10: The conflicting-switch check points the mutating pass at the system temporary directory. If the guard regresses, the test can write
a64_pin.hthere and rewrite matching C files owned by another run. Give the negative test its own temporary directory and verify refusal leaves it untouched.@ -0,0 +322,4 @@import pollpoll.install()words, texts = made_up_program(random.Random(seed), 40, conforming)L = a64_lift.Lifter(_Image(words, (MAIN, CALLEE, JUMPER, TAIL, VIRT, VIRT + 0x100, VIRT + 0x200), {HOOK: "hos_test_hook"}))L12 (minor): The test inherits lift settings outside the four variables cleared by
env(). A staleA64_DEVIRTfile path can fail fixture construction, andA64_HOT_FUNCSorA64_KEEP_FLAGScan change the lift. Clear lift and runtime switches before constructing the lifter and pass a controlled environment to the generated executable.@ -0,0 +395,4 @@check({"bl", "blr", "br", "svc", "ret", "b", "cbz"} <= kinds, "the program has every transfer: %s" % sorted(kinds))plain = {name: open(os.path.join(gen, name), "rb").read() for name in os.listdir(gen)}with env():pin_regs.pin_dir(gen)L13 (minor): The off comparison applies
pin_dirto output that was already emitted without importingguest_localsor usinglift.py. It would pass if the change accidentally disabled normal locals in every build. Add a game-free fixture through the production option and emission path that checks the ordinary register and flag locals with pinning off and their absence with it on. Compile and run a context-based body from the real entry-hook splice as well, since it is currently checked only by string matches.Description: removed a statement about the game's hottest lifted functions (a figure taken over the game's lifted code, which the contributing rules ask to leave out) and the pointer to the doc's list; nothing else changed.
Recommendation: Close. Keep a short record of the synthetic experiment. The enabled build cannot translate the supported game, and shipping the code off still makes existing installations translate and compile lifted code again.
Does it help? No measured improvement supports merging. On the earlier
342422ddexperiment, the best synthetic timing gains were about 2–4%, within the reported spread. Exact ten-register pinning was 12.9% slower in the hot synthetic case. The current head has no gameplay or update-time comparison with6e1521a7. Matching synthetic digests on the earlier rebased head exercise the chosen call patterns. Existing reviewEven after setjmp support and the direct host calls are addressed, the gameplay HUD wrapper still breaks the pinned build. The source rewrite treats its separately named callback as part of the preceding lifted function. It inserts pinned return or transfer macros into a helper without pinned parameters, leaves that helper incompatible with
A64Fn, and makes the wrapper return noA64Retvalue. An isolated synthetic follow-up should cover the wrapper and callback as separate functions. SourceOther systems and defaults.
A64_PIN_REGSis unset andA64_PIN_ABIdefaults to exact mode. Enabling pinning disables the default guest register and flag locals. The enabled path spans Windows and Linux compiler conventions, standalone guest thread entry, host dispatch, and the emulator DLL's callback and poll boundaries. With pinning unset, the ordinary call still invokesf(c), but the production header and lifter inputs change, so existing object and translation keys move. A docs-only record should contain authored synthetic results and omit game-derived measurements from both the proposed text and its commit message. Default build cost · Documentation reviewTesting. The author reports Windows synthetic checks on
0b62ed8band seven focused failures reproduced on that head's base, with one check skipped. The description check passed on5b3b49fc. The source checks were blocked by required conditions, and Beanstalk showed no plan, targets, or reports. The enabled game is blocked at translation, so a farm run of the default build would leave the performance hypothesis unanswered. Checks · BeanstalkOverlap. The poll convention experiment shares the runtime generator, and compare fusion shares the lift and guest-local defaults. The synthetic writeup needs no source merge order. Poll convention · Compare fusion
Reviewed
5b3b49fcagainst6e1521a7. Read all nine changed files and traced the lift, runtime dispatch, Windows and Linux build paths, host and emulator entry points, and translation/object reuse with revision-matched Graphify maps and source. Source review only. No PR code was run.@ -0,0 +169,4 @@raise SystemExit("A64_PIN_REGS: a call of a setjmp owner: its host setjmp frame would come back with stale ""pinned registers (docs/dev/reference/pin-regs.md)")s = HOOK.sub(PIN_HOOK, DECL.sub(PIN_DECL, s))starts = [m.start() for m in HEAD.finditer(s)]The gameplay HUD patch (
nx2/oot_patches.py:312) inserts a plaingameplay_hud_update_game(Ctx *)definition before the nextf_...head. This slice includes both bodies.pin_functionrewrites the helper's returns and transfers to macros that need the wrapper's pinned parameters, and leaves the wrapper itself falling through without anA64Retvalue. The plain helper pointer also cannot satisfy pinnedA64Fn, even afterhost/hos_wide_ui.cmigrates its callers. Keep the experiment isolated, or handle the wrapper and named helper as separate functions with explicit signatures and returns.5b3b49fc3f01cd59d894WIP: perf(lift): A64_PIN_REGS, guest registers in host registers across calls (experiment, off: measured no-go)to WIP: test(lift): A64_PIN_REGS, guest registers in host registers across calls, kept as a game-free experiment apart from the build (measured no-go)Pushed
01cd59d8(rebased ontomain@f1f2dc5b), answering futondestroyer's review and BeanBot's: the experiment is taken out of the game's build (17218569:nx2/lift.py,nx2/rtgen.py,nx2/guest_locals.py,nx2/lifted_c.py,build.mdandtests/test_lift_cache.pyare main's again; the pinned runtime ispin_regs.write_rt's, for the fixture only), the review's cases as failing checks (dfb8e913) and their fixes (01cd59d8). The counts over the game's lifted functions are removed from the doc and from the first commit's message (978a155c, reworded in the rebase). Title, Summary, Testing, Measurements and Risks rewritten for that: a default build now hasmain's lift key and runtime (checked, in Testing), so the in-game item is gone from Still to test. Nothing is closed; that stays the maintainers' decision.Re #1981 (comment) (futondestroyer): done as you put it, without closing:
17218569takes the experiment out of the game's build.nx2/lift.py,nx2/rtgen.py,nx2/guest_locals.py,nx2/lifted_c.py,build.mdandtests/test_lift_cache.pyare main's again, so a default build has main's lift key and runtime (checked frommain@f1f2dc5band this branch: the samemake_game.lift_keyand the samertgena64.h/a64_rt.c, in Testing); what stays is the pass, its game-free fixture (the pinned runtime ispin_regs.write_rt's, for the fixture only) and the synthetic record, with the counts over the game's lifted functions removed from the doc and from the first commit's message (reworded in the rebase,978a155c: a forced change). The HUD wrapper is answered on your inline comment; keeping this record or closing it is the maintainers' call.Re #1981 (comment) (futondestroyer): right, the slice from one
f_head to the next took the helper in. The pass now stops on any definition between lifted functions (01cd59d8), and the fixture runsoot_patches.patch_gameplay_hud_screenon made-up C and checks the refusal leaves the folder as it was (it fails atdfb8e913and passes at01cd59d8). With the pass out of the game's build (17218569), handling the wrapper and the helper as separate functions with their own signatures and returns is indocs/dev/reference/pin-regs.md's integration list, for an isolated follow-up.Re #1981 (comment) (L1):
17218569takes the pass out of the lift and the runtime generator, so an update frommainno longer moves either key: frommain@f1f2dc5band this branch,make_game.lift_keyover one made-up exefs, the 49 lift sources andrtgen'sa64.h/a64_rt.ccame out identical (queue job fb2-1981-1, in Testing). With no key moving there is no warm-update cost left to time.Re #1981 (comment) (L2): fixed in
01cd59d8:a64_run, the host's way in and the runtime's miss and second-slot path, keeps the pinned registers anA64_PIN_ABIcall does not hand back and puts them back after it. The fixture's callees now lower SP, make an SVC in that frame and restore SP before RET; with four BLR targets on a two-entry site that covers the hit, second-slot and miss paths. Atdfb8e913all 12 ABI builds gave other digests than the plain ones (e.g. seed 3, O2, ABI four: plain adaef4a828ee7dfb, pinned a234a6e4ec7a62d6); at01cd59d8every build matches (queue job fb2-1981-2).Re #1981 (comment) (L3): the Builder no longer meets the option:
17218569removes the pass fromnx2/lift.py(as futondestroyer asked), soA64_PIN_REGSreaches it only throughtests/test_pin_regs.py. setjmp handling and the host's direct callers (host/oot_voice.camong them) stay in the doc's list of what a playable version needs.Re #1981 (comment) (L4): no more discovery:
pin_regs.write_rt(17218569) writes a separate pinned runtime that includesa64_pin.houtright, and only the fixture builds with it;rtgen'sa64.h, the one the game and the emulator DLL use, has none of the pinned forms, which the test checks. The DLL'sMkwFnand itsA64_POLL_CTXcallback are now in the doc's integration list.Re #1981 (comment) (L5): with the pass out of the game's build (
17218569), no build sends NVN calls througha64_call_miss: theh = NULLlookup exists only in the fixture's pinned runtime, which links no host code. The doc's integration list now names pinned thunks and the one-time initialisation ofhost/hos_hostcall.c'sstatsas prerequisites for any pinned host dispatch.Re #1981 (comment) (L6):
tests/test_pin_regs.pynow probes the selected compiler before building anything:preserve_noneunder-Werror -Wignored-attributesand an indirectmusttailwith the context and ten registers; a compiler that ignores or rejects either fails the check (17218569). It no longer declaresRUN_ALL_ARGS, so a CI leg without a capable Clang shows a failure rather than a skip.Re #1981 (comment) (L7): fixed in
01cd59d8: each range's ends are checked (ASCII digits, at most 31, ascending) before the range is made, so0-1000000000is refused at once and31-0is refused. The locals now follow main's own defaults (guest_locals.pyis main's again) and the pass refuses C lifted with them on unless both are set to 0; the test covers31-0,5-3, non-ASCII digits, partial ranges and the huge one.Re #1981 (comment) (L8): fixed in
01cd59d8:pin_dirpins every file in memory and writes only once all of them passed; the fixture puts a setjmp owner's call in a later file and checks the folder is byte for byte as before (fails atdfb8e913, passes at01cd59d8).nx2/lift.pyno longer runs the pass (17218569), so no stale header is left there.Re #1981 (comment) (L9): fixed in
01cd59d8:A64_PIN_ABIis1for AAPCS64, unset, empty or0for the exact contract, and anything else is refused; the test covers1,0, empty and three other values.Re #1981 (comment) (L10): fixed in
17218569: each refusal case runs in a temporary folder of its own, and the test checks the folder is unchanged after the refusal.Re #1981 (comment) (L11): fixed in
17218569:RUN_ALL_ARGSis gone and the test picks--cc, then$CC, thenLONGSHOT_MINGW's clang (whichrun_all.pysets to the clone's llvm-mingw), then clang on PATH. The queue runs used the Builder's llvm-mingw that way, with no--cc.Re #1981 (comment) (L12): fixed in
17218569: everyA64_,HOS_andRX_variable is cleared for the lifter, the compiler and the built programs, and main's locals are set to 0 explicitly for the pass.Re #1981 (comment) (L13):
guest_locals.pyandlift.pyare main's again (17218569), so this PR can no longer turn the normal locals off. The compiled fixture now has a function whose C starts with a realnx2/entry_hooks.pysplice (entry_hooks.installandline), built and run plain and pinned with every variant, and the test checks its pinned body is context-based (dfb8e913).Re #1981 (comment) (L14): the
tests/test_lift_cache.pychange is reverted with the rest of the build integration (17218569): the pin switches no longer reach the game's lift beyond the existingA64_prefix rule, which that test already covers.Re #1981 (comment) (L15): removed: the doc's tables over the game's lifted functions and the figures from a trace of its lifted code (
17218569), and the counts in the first commit's message (reworded in the rebase,978a155c, a forced change). The no-go keeps them in words: the per-function counts were taken locally and are not published; the synthetic workload's results stay. An instruction and spill comparison on the fixture's made-up programs was not run in this round.Re #1981 (comment) (L16): fixed in
17218569: the setup no longer says every build was exact; each variant is named with its contract (ABI marked), and the page says the two timing harnesses are not in the tree, so the timings cannot be repeated from it, whiletests/test_pin_regs.pyreproduces the plain/pinned equivalence for each contract.Re #1981 (comment) (L18): the build integration and the
build.mdrow are gone (17218569, as futondestroyer asked too); what remains is the pass, its fixture and the synthetic record. What the PR's own numbers show: a synthetic best of about 2-4 % faster, within the run spread, exact ten-register pinning 12.9 % slower in the hot run, and no game build possible with it on; it is now outside the game's build entirely. Whether to keep this record in the tree or close the PR is the maintainers' decision.Re #1981 (comment) (L17): Measurements now compares
main@f1f2dc5bwith this branch on what a default build reads (the lift key and the generated runtime: identical), the fixture results are under Testing, and Risks says no file the build reads changes, so no translation or object cache moves. The only performance figures are the branch's synthetic ones, labelled as such.Re #1981 (comment) (L19): with the experiment out of the game's build (
17218569) a default build ismain's (same lift key and runtime, in Testing), so there is no game change to run; the Linux fixture run stays in Still to test. A playable pinned variant would need the interleaved same-scene A/B you describe; that is noted for any follow-up.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.