WIP: perf(host): four physics glue leaves and the cloth damping's repeated powf on host code (HOS_NATIVE_GLUE) #1911

Draft
snaildev99 wants to merge 6 commits from snaildev99/Longshot:perf/native-glue into main
Contributor

Summary

Four small routines of the game's physics glue (its side of Havok) run as native host code with HOS_NATIVE_GLUE=1, and the cloth damping's repeated powf calls are replayed from the call before them, giving the game's results bit for bit: every register, every byte written, NZCV and FPSR. A call the host cannot prove exact runs the game's translated routine, with nothing written by the host. Off unless the switch is set.

The goal is less CPU work for the same frame. The cloth damping f_8003d320 calls powf twice per cloth particle with the same two arguments for every particle of a call (the damping factors to the power of the step): powf directly under it was 0.82 % of all game code in Castle Town's Market. In the game 99 % of those calls repeat the call before them, and the memo answers them from it. With nine rewrite branches on together (this one among them, merged in a test tree; named in the baseline below, the cloth and particle effect rewrites are not among them), the game used 2.7 % less CPU standing and 2.4 % less turning in the Market at a 60 fps cap, 4.1 % / 4.0 % less on the executor threads (where these routines run). This branch's own share of that has not been measured alone: the Test Farm request asks for it.

What it answers (guest addresses):

  • f_801c0d7c: a rotation matrix to a normalised quaternion (Shepperd's four cases by the signs, the sum of squares by two pairwise adds, the quaternion divided by its square root, or times 0 when the sum has no exponent bits). f_804f8990 is a byte-for-byte copy of it at another address.
  • f_80825860: a box under a transform, centre and half extents in single precision, the bounds in double and rounded outwards by a step of the bit pattern before the conversion to single; an empty box (min over max) is copied as it is.
  • f_80171890: a point under a QsTransform (translation, quaternion, scale), four lanes.
  • the two powf calls of f_8003d320's particle loop (return addresses 0x8003d8d0 and 0x8003d8e4): a memo per thread and call site, keyed on both arguments and FPCR. On a new key it runs the game's powf on the real context and on two copies whose other registers hold a pattern and its complement, so it learns exactly which bytes the call writes; the key is kept only when all three agree, nothing outside those bytes changed, SP, FPCR and PC are as before, and no FPSR flag but IXC was raised (which also keeps powf's error paths out). A replay needs FPSR.IXC already set and writes those bytes. A second argument of exactly 1 (60 fps exactly) goes straight to powf, whose entry returns at once.

How: nx2/oot_patches.py (GLUE_NATIVE, patch_glue_native, patch_glue_powf) puts if (hos_glue_<addr>(c, f_<addr>)) return; first in the four leaves and replaces the two powf calls in f_8003d320 by memo calls, in the supported build only. host/glue_kernels.c is the leaves' instruction sequences, one statement an instruction on 128-bit register values in locals, the registers copied out only once the call is known to be taken. The proof rule: every operand of every float operation zero or of a magnitude in [2^-63, 2^63), no NaN or subnormal into a comparison, and FPCR / FPSR inside the translator's RECOMP_FPX_OPEN; then IEEE gives Arm's bits, flush-to-zero changes nothing and no flag but IXC is raised. The quaternion kernel checks a shorter set with the same guarantee (the nine inputs, the four lanes, the sum of squares finite, and its root), and the box kernel gives a bound of exactly zero Arm's signed zero and IDC or UFC instead of declining it. host/oot_glue.c gates each call, stores the registers and the bytes (pages marked) or, in check mode, compares them with the translated routine's.

Read first: host/glue_kernels.c, host/oot_glue.c (hos_glue_powf_memo and its comment), the HOS_NATIVE_GLUE block of nx2/oot_patches.py, tests/test_oot_glue.py.

No code here is ported from another project.

Testing

Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game, in a test tree that merges nine rewrite branches, this one among them, on main 068fb8eb (test/rewrites @ e614ef49 on my fork; this code as at 9122e9e5): a check run with HOS_NATIVE_GLUE=check (every call the host takes is also run translated and the two compared), about five minutes in the Market and Hyrule Field: 0 mismatches. Answered by the host: the quaternion 1,701,987 of 1,702,037 calls, its copy 12,964 of 12,973, the box 200,416 of 200,528, the point 36,470 of 68,861 (32,391 declined for their values), and the powf memo replayed 2,437,027 and 2,441,712 of 2,464,825 calls at its two sites (99 %). Then the CPU measurement in Measurements, with the switch on (the quaternion answered all of its 729,365 calls there). This branch's head (the same code cherry-picked onto main a104182b, plus one commit of declarations) is not built or played.

Offline, against the game's own code: an AArch64 emulator (Unicorn) runs the game's routine on its image, a driver runs the translator's copy of the routine and the hook (HOS_NATIVE_GLUE=1, and =check on every case too) on the same case; compared, when the hook took the call, every x register, SP, all 32 q registers (128 bits), NZCV, FPSR and every byte of the case's memory against the emulator, and everything against the translated routine when it declined. Two builds: x86-64-v3 and plain x86-64.

routine calls taken by the host mismatches (v3 / x86-64 / check mode) deliberately broken copies caught (of 4,000 calls)
quaternion f_801c0d7c 1,000,000 712,961 0 / 0 / 0 a branch < as <= 200, a register not written 2,692
its copy f_804f8990 1,000,000 711,941 0 / 0 / 0 the same two: 204, 2,880
box f_80825860 1,000,000 476,792 0 / 0 / 0 a condition changed 1,427, the rounding step's constant 1,609
point f_80171890 1,000,000 719,214 0 / 0 / 0 a cleared lane dropped 2,550, an EXT's operands swapped 2,665
powf memo: f_8003d320 whole, 0 to 40 particles a call, the memo carried from call to call 200,000 calls, 2,001,438 powf calls a site 3,760,051 replays 0 / 0 / 0 NZCV not replayed 96, FPCR left out of the key 3, flags other than IXC allowed 3

The cases: realistic rotations (all four of Shepperd's cases, near a half turn), boxes, transforms and QsTransforms; small integers (exact cancellations, signed zeros); zero, tiny and huge values; edge values anywhere (NaN quiet and signalling, infinities, subnormals, FLT_MAX); junk in unused lanes; empty boxes; outputs over inputs; changed and moved constants; every FPCR mode and FPSR state; for the memo, steps and damping from small sets so keys repeat, a third of the calls reusing the last call's step, the cloth mode where the second argument changes per particle. The translated routines alone differ from the emulator only in NZCV where the translator keeps only the flags it reads; the hook writes Arm's NZCV, and check mode counts an NZCV-only difference apart ("lift's flags"), not as a mismatch. The memo is compared with the translated f_8003d320 in every register, NZCV, FPSR and byte; against the emulator it differs exactly where the translated routine does (NZCV at the routine's end, which the translator keeps only where it reads it, and x16 / x17 of the call stub, which the translator never sets). Run again at this head with this branch's host/oot_glue.c, host/glue_kernels.c and, for the memo, its nx2/oot_patches.py (so the memo calls are made by this head's patch, with its new declaration, and compiled), the same seeds and sizes, check mode on every case: the same counts, 0 mismatches in both builds and in check mode.

Game-free tests at this head: tests/test_oot_glue.py (the hooks and the memo calls placed once and only in the supported build, idempotent, a missing one reported; off, on and check over a guest window: the quaternions, boxes and points against values worked out in Python, a box in place, the declines with nothing written, a replay exact after its fill and the cases that run translated (y = 1, IXC clear, another FPCR, a register dependence, a raised flag), an NZCV-only difference counted apart, a byte or register off caught and logged; built for this CPU and for plain x86-64) passes. Of the 44 tests run (it, tests/test_switch_table.py and every test that reads nx2/oot_patches.py or nx2/entry_hooks.py, tests/test_patch_hooks_defined.py among them) 39 pass; the five others fail the same way on main a104182b on this PC: test_dev_packs, test_high_fps_fixes, test_libc_hooks, test_lift_cache ("...and the others still by their code"), test_song_note_cue. The full tests/run_all.py was not run. ruff clean.

Still to test:

  • Linux and an AMD GPU, the Market and Kokiri Forest (the repo save kokiri-start): this PR with HOS_NATIVE_GLUE unset against HOS_NATIVE_GLUE=1, the game's CPU seconds at a 60 fps cap (on a PC that holds 60 there) and the frame times uncapped, expecting the same frame rate or better with less CPU time and cloth and physics moving as without the switch (@Beanstalk linux, amd).
  • Linux, the Market for a few minutes with HOS_NATIVE_GLUE=check, expecting every oot: glue line to end MISMATCHES in all 0 (@Beanstalk linux).
  • This head built and played on Windows, the Market with HOS_NATIVE_GLUE=check and then =1, expecting no mismatch and cloth moving as on main (by hand).

Measurements

Verdict: less CPU for the same frame, measured with the nine on together: the whole game process 2.7 % less standing and 2.4 % less turning in the Market at a 60 fps cap, the executor threads 4.1 % / 4.0 % less. With the hooks built in and the switches unset, -0.3 % / -0.2 % against plain main: inside the runs' spread, so no cost measured with the switch off. This branch's own part is not separated: the Test Farm request asks for this PR alone, switch off against on. Offline, against an approximation of main's form of each routine: the cloth damping with its powf calls 2.9 times per particle (at any frame rate but exactly 60), the quaternion 1.5 to 1.9 times, the box 3.0 to 3.1 times, the point 1.75 to 2.2 times.

Baseline: three builds from scratch of two trees, the default hot list: plain main 068fb8eb (Before), and the test tree test/rewrites @ e614ef49 on my fork, which is main 068fb8eb with nine rewrite branches merged (the seven maths units, the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the six-channel reverb, and the solver; the cloth and particle effect rewrites are not among them; this branch as at 9122e9e5), lifted with A64_FPXKEEP=0 (a lift-time change of another branch left out): once with no switch set, once with the nine's switches on (HOS_NATIVE_GLUE=1 and the other eight's, among them the maths library's native powf, which this memo sits in front of). Main has since moved to a104182b; the numbers are main 068fb8eb's, and the farm request measures this PR alone on current main.
Setup: Windows 11 (build 22631), Ryzen 9 5900X, RTX 3090, 3840x2160; child Link in the Market, hands-free through scripts/longshot_ctl.py; the frame rate capped at 60, which all 15 runs held; each run 30 s standing, then 30 s turning the camera; the three variants (with two more of another change) interleaved over three rounds, the PC otherwise idle. CPU seconds a second of play (cores busy on average) from the processor's cycle counter, per thread; the median of three runs.

cores busy, median of three Before: main @ 068fb8eb After, no switch set: test/rewrites @ e614ef49 After, the nine on: test/rewrites @ e614ef49 Δ, the nine on against main
whole process, standing (the three runs) 5.156 (5.144, 5.156, 5.161) 5.140 (5.303, 5.140, 5.125) 5.017 (5.007, 5.017, 5.049) -2.7 %
whole process, turning 5.639 (5.676, 5.627, 5.639) 5.630 (5.722, 5.630, 5.628) 5.504 (5.504, 5.498, 5.577) -2.4 %
executor threads (BaseProcExecutor*), standing 2.229 2.244 2.137 -4.1 %
executor threads, turning 2.455 2.461 2.358 -4.0 %
mkw_vk capture copy, standing 0.090 0.088 0.099 +10 %
mkw_vk capture copy, turning 0.097 0.097 0.114 +18 %

The process includes the renderer's threads (about 1.4 cores), which the nine do not touch. The capture copy thread's rise is in Risks.

Offline speed (bench_leaves.py / bench_powf.c in my tools: the calling thread's own CPU time; a hooked function is written in the old form on main too, every register in the context, so the patched side runs in that form; the other side is an approximation of main's form, the six most used x registers in locals, which is at most as fast as main's real form, so a factor here may be somewhat high; ±10 % noise, other builds running on the PC; Ryzen 9 5900X):

routine its share of game code, Market / Kakariko and the trail main's form (approx.), FPCR 0 / flush-to-zero this PR, switch on factor
quaternion f_801c0d7c 0.082 % / 0.123 % 65.7 / 92.5 ns 43.9 / 49.1 ns 1.50x / 1.88x
its copy f_804f8990 0.002 % / 0.003 % 62.0 / 90.7 ns 39.0 / 48.8 ns 1.59x / 1.86x
box f_80825860 0.033 % / 0.080 % 553 / 632 ns 182 / 202 ns 3.03x / 3.12x
point f_80171890 0.014 % / 0.007 % 56.8 / 96.0 ns 32.5 / 44.3 ns 1.75x / 2.17x
f_8003d320 with its powf calls, per particle, a step other than exactly 1/60 s powf under it 0.82 % (Market) 699 ns 243 ns 2.88x
the same at exactly 1/60 s (powf returns at its entry) 118-140 ns 134 ns 1.0x

With the switch off the hooked routines measured as without the hook within these timings' noise (the hook's check is a load and a branch). The shares are self time in a Market profile and two route profiles (Kakariko and Death Mountain Trail) of earlier builds.

The switch

HOS_NATIVE_GLUE (new, run time; its row in gpu/vk/switches.def): unset or 0 off (the hooks return at once, the memo calls powf); 1 on; check runs the host's answer into a buffer, then the translated routine for real, and compares every register and byte (NZCV-only differences counted apart), logging the first mismatch. A start line oot: glue: four physics glue routines on the host (HOS_NATIVE_GLUE=1), and a line every 10 s, the last of the check run:

oot: glue (HOS_NATIVE_GLUE=check) quat f_801c0d7c: calls 1702037 (native 1701987; lifted: FPCR/FPSR 0, memory 0, values 50), compared 1701987, not compared 50, lift's flags 1622599, MISMATCHES 0; quat2 f_804f8990: calls 12973 (native 12964; lifted: FPCR/FPSR 0, memory 0, values 9), compared 12964, not compared 9, lift's flags 9485, MISMATCHES 0; aabb f_80825860: calls 200528 (native 200416; lifted: FPCR/FPSR 0, memory 0, values 112), compared 200416, not compared 112, lift's flags 24802, MISMATCHES 0; qst f_80171890: calls 68861 (native 36470; lifted: FPCR/FPSR 0, memory 0, values 32391), compared 36470, not compared 32391, lift's flags 0, MISMATCHES 0; powf at 0x8003d8cc: calls 2464825 (native 2437027; lifted: FPCR/FPSR 0, memory 0, values 0), compared 2437027, not compared 0, lift's flags 0, MISMATCHES 0; powf at 0x8003d8e0: calls 2464824 (native 2441712; lifted: FPCR/FPSR 0, memory 0, values 0), compared 2441712, not compared 0, lift's flags 0, MISMATCHES 0; MISMATCHES in all 0

It ships off in this PR. The combined measurement says on; this PR's own measurement (the farm request) decides the default before it leaves WIP.

Risks

What could break: a kernel that is not exact would give a physics or cloth value the Switch would not; a memo that missed a byte powf writes would leave a register as the game would not. Checked as in Testing; the hooks decline what they cannot prove (a float mode outside the translator's gate, a value outside the proof's range, memory outside the guest's), the memo keeps a key only when the three runs agree byte for byte, and the translated routine runs.

Beside a native powf: the maths library branch hooks powf itself. The memo calls powf through its translated function, so with both on a new key runs that native powf and a replay replaces it; offline, with a stand-in of that hook, every register, flag and byte matched f_8003d320 with that hook alone (1,895,547 replays).

A cost seen: with the nine on, the renderer's mkw_vk capture copy thread (it copies guest memory the game marked as written) used 0.009 to 0.017 more cores in the measured runs (+10 % standing / +18 % turning). The host kernels mark the pages they write, possibly more coarsely than the translated code's own marks; which of the nine adds it is not determined. It is inside the whole-process figures above.

Turning it off: leave HOS_NATIVE_GLUE unset (the default).

After updating: nothing changes for a player: saves, longshot_options.ini and the caches as before. The five patched functions are written by the translator with their registers in the context (as every patched function is), which changes their lifted code; with the switch unset the measured cost was within the runs' spread.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. (This code ran in the game in a test tree on main 068fb8eb, checked and measured; this head is not built or played.)
  • mise run test passes (any failure that also fails on main is named). (44 tests run, the branch's own and every one that reads the patch files: the five failures fail on main too; the full suite not run.)
  • Measured against main, or Measurements says why there is nothing to measure. (Measured against main with the nine on; this PR alone waits for the Test Farm.)
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. (The row is there; it ships off until this PR's own measurement.)
  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_oot_glue.py is new.)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the test tree's build; Linux not built.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Four small routines of the game's physics glue (its side of Havok) run as native host code with `HOS_NATIVE_GLUE=1`, and the cloth damping's repeated `powf` calls are replayed from the call before them, giving the game's results bit for bit: every register, every byte written, NZCV and FPSR. A call the host cannot prove exact runs the game's translated routine, with nothing written by the host. Off unless the switch is set. The goal is less CPU work for the same frame. The cloth damping `f_8003d320` calls `powf` twice per cloth particle with the same two arguments for every particle of a call (the damping factors to the power of the step): `powf` directly under it was 0.82 % of all game code in Castle Town's Market. In the game 99 % of those calls repeat the call before them, and the memo answers them from it. With nine rewrite branches on together (this one among them, merged in a test tree; named in the baseline below, the cloth and particle effect rewrites are not among them), the game used 2.7 % less CPU standing and 2.4 % less turning in the Market at a 60 fps cap, 4.1 % / 4.0 % less on the executor threads (where these routines run). This branch's own share of that has not been measured alone: the Test Farm request asks for it. What it answers (guest addresses): - `f_801c0d7c`: a rotation matrix to a normalised quaternion (Shepperd's four cases by the signs, the sum of squares by two pairwise adds, the quaternion divided by its square root, or times 0 when the sum has no exponent bits). `f_804f8990` is a byte-for-byte copy of it at another address. - `f_80825860`: a box under a transform, centre and half extents in single precision, the bounds in double and rounded outwards by a step of the bit pattern before the conversion to single; an empty box (min over max) is copied as it is. - `f_80171890`: a point under a QsTransform (translation, quaternion, scale), four lanes. - the two `powf` calls of `f_8003d320`'s particle loop (return addresses 0x8003d8d0 and 0x8003d8e4): a memo per thread and call site, keyed on both arguments and FPCR. On a new key it runs the game's `powf` on the real context and on two copies whose other registers hold a pattern and its complement, so it learns exactly which bytes the call writes; the key is kept only when all three agree, nothing outside those bytes changed, SP, FPCR and PC are as before, and no FPSR flag but IXC was raised (which also keeps `powf`'s error paths out). A replay needs FPSR.IXC already set and writes those bytes. A second argument of exactly 1 (60 fps exactly) goes straight to `powf`, whose entry returns at once. How: `nx2/oot_patches.py` (`GLUE_NATIVE`, `patch_glue_native`, `patch_glue_powf`) puts `if (hos_glue_<addr>(c, f_<addr>)) return;` first in the four leaves and replaces the two `powf` calls in `f_8003d320` by memo calls, in the supported build only. `host/glue_kernels.c` is the leaves' instruction sequences, one statement an instruction on 128-bit register values in locals, the registers copied out only once the call is known to be taken. The proof rule: every operand of every float operation zero or of a magnitude in [2^-63, 2^63), no NaN or subnormal into a comparison, and FPCR / FPSR inside the translator's `RECOMP_FPX_OPEN`; then IEEE gives Arm's bits, flush-to-zero changes nothing and no flag but IXC is raised. The quaternion kernel checks a shorter set with the same guarantee (the nine inputs, the four lanes, the sum of squares finite, and its root), and the box kernel gives a bound of exactly zero Arm's signed zero and IDC or UFC instead of declining it. `host/oot_glue.c` gates each call, stores the registers and the bytes (pages marked) or, in check mode, compares them with the translated routine's. Read first: `host/glue_kernels.c`, `host/oot_glue.c` (`hos_glue_powf_memo` and its comment), the `HOS_NATIVE_GLUE` block of `nx2/oot_patches.py`, `tests/test_oot_glue.py`. No code here is ported from another project. ## Testing **Tested:** Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. In the game, in a test tree that merges nine rewrite branches, this one among them, on main 068fb8eb (`test/rewrites` @ e614ef49 on my fork; this code as at 9122e9e5): a check run with `HOS_NATIVE_GLUE=check` (every call the host takes is also run translated and the two compared), about five minutes in the Market and Hyrule Field: **0 mismatches**. Answered by the host: the quaternion 1,701,987 of 1,702,037 calls, its copy 12,964 of 12,973, the box 200,416 of 200,528, the point 36,470 of 68,861 (32,391 declined for their values), and the `powf` memo replayed 2,437,027 and 2,441,712 of 2,464,825 calls at its two sites (99 %). Then the CPU measurement in Measurements, with the switch on (the quaternion answered all of its 729,365 calls there). This branch's head (the same code cherry-picked onto main a104182b, plus one commit of declarations) is not built or played. Offline, against the game's own code: an AArch64 emulator (Unicorn) runs the game's routine on its image, a driver runs the translator's copy of the routine and the hook (`HOS_NATIVE_GLUE=1`, and `=check` on every case too) on the same case; compared, when the hook took the call, every x register, SP, all 32 q registers (128 bits), NZCV, FPSR and every byte of the case's memory against the emulator, and everything against the translated routine when it declined. Two builds: x86-64-v3 and plain x86-64. | routine | calls | taken by the host | mismatches (v3 / x86-64 / check mode) | deliberately broken copies caught (of 4,000 calls) | |---|---|---|---|---| | quaternion `f_801c0d7c` | 1,000,000 | 712,961 | 0 / 0 / 0 | a branch `<` as `<=` 200, a register not written 2,692 | | its copy `f_804f8990` | 1,000,000 | 711,941 | 0 / 0 / 0 | the same two: 204, 2,880 | | box `f_80825860` | 1,000,000 | 476,792 | 0 / 0 / 0 | a condition changed 1,427, the rounding step's constant 1,609 | | point `f_80171890` | 1,000,000 | 719,214 | 0 / 0 / 0 | a cleared lane dropped 2,550, an EXT's operands swapped 2,665 | | `powf` memo: `f_8003d320` whole, 0 to 40 particles a call, the memo carried from call to call | 200,000 calls, 2,001,438 `powf` calls a site | 3,760,051 replays | 0 / 0 / 0 | NZCV not replayed 96, FPCR left out of the key 3, flags other than IXC allowed 3 | The cases: realistic rotations (all four of Shepperd's cases, near a half turn), boxes, transforms and QsTransforms; small integers (exact cancellations, signed zeros); zero, tiny and huge values; edge values anywhere (NaN quiet and signalling, infinities, subnormals, FLT_MAX); junk in unused lanes; empty boxes; outputs over inputs; changed and moved constants; every FPCR mode and FPSR state; for the memo, steps and damping from small sets so keys repeat, a third of the calls reusing the last call's step, the cloth mode where the second argument changes per particle. The translated routines alone differ from the emulator only in NZCV where the translator keeps only the flags it reads; the hook writes Arm's NZCV, and check mode counts an NZCV-only difference apart ("lift's flags"), not as a mismatch. The memo is compared with the translated `f_8003d320` in every register, NZCV, FPSR and byte; against the emulator it differs exactly where the translated routine does (NZCV at the routine's end, which the translator keeps only where it reads it, and x16 / x17 of the call stub, which the translator never sets). Run again at this head with this branch's `host/oot_glue.c`, `host/glue_kernels.c` and, for the memo, its `nx2/oot_patches.py` (so the memo calls are made by this head's patch, with its new declaration, and compiled), the same seeds and sizes, check mode on every case: the same counts, 0 mismatches in both builds and in check mode. Game-free tests at this head: `tests/test_oot_glue.py` (the hooks and the memo calls placed once and only in the supported build, idempotent, a missing one reported; off, on and check over a guest window: the quaternions, boxes and points against values worked out in Python, a box in place, the declines with nothing written, a replay exact after its fill and the cases that run translated (y = 1, IXC clear, another FPCR, a register dependence, a raised flag), an NZCV-only difference counted apart, a byte or register off caught and logged; built for this CPU and for plain x86-64) passes. Of the 44 tests run (it, `tests/test_switch_table.py` and every test that reads `nx2/oot_patches.py` or `nx2/entry_hooks.py`, `tests/test_patch_hooks_defined.py` among them) 39 pass; the five others fail the same way on main a104182b on this PC: `test_dev_packs`, `test_high_fps_fixes`, `test_libc_hooks`, `test_lift_cache` ("...and the others still by their code"), `test_song_note_cue`. The full `tests/run_all.py` was not run. ruff clean. **Still to test:** - Linux and an AMD GPU, the Market and Kokiri Forest (the repo save `kokiri-start`): this PR with `HOS_NATIVE_GLUE` unset against `HOS_NATIVE_GLUE=1`, the game's CPU seconds at a 60 fps cap (on a PC that holds 60 there) and the frame times uncapped, expecting the same frame rate or better with less CPU time and cloth and physics moving as without the switch (@Beanstalk linux, amd). - Linux, the Market for a few minutes with `HOS_NATIVE_GLUE=check`, expecting every `oot: glue` line to end `MISMATCHES in all 0` (@Beanstalk linux). - This head built and played on Windows, the Market with `HOS_NATIVE_GLUE=check` and then `=1`, expecting no mismatch and cloth moving as on main (by hand). ## Measurements **Verdict:** less CPU for the same frame, measured with the nine on together: the whole game process 2.7 % less standing and 2.4 % less turning in the Market at a 60 fps cap, the executor threads 4.1 % / 4.0 % less. With the hooks built in and the switches unset, -0.3 % / -0.2 % against plain main: inside the runs' spread, so no cost measured with the switch off. This branch's own part is not separated: the Test Farm request asks for this PR alone, switch off against on. Offline, against an approximation of main's form of each routine: the cloth damping with its `powf` calls 2.9 times per particle (at any frame rate but exactly 60), the quaternion 1.5 to 1.9 times, the box 3.0 to 3.1 times, the point 1.75 to 2.2 times. Baseline: three builds from scratch of two trees, the default hot list: plain main 068fb8eb (Before), and the test tree `test/rewrites` @ e614ef49 on my fork, which is main 068fb8eb with nine rewrite branches merged (the seven maths units, the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the six-channel reverb, and the solver; the cloth and particle effect rewrites are not among them; this branch as at 9122e9e5), lifted with `A64_FPXKEEP=0` (a lift-time change of another branch left out): once with no switch set, once with the nine's switches on (`HOS_NATIVE_GLUE=1` and the other eight's, among them the maths library's native `powf`, which this memo sits in front of). Main has since moved to a104182b; the numbers are main 068fb8eb's, and the farm request measures this PR alone on current main. Setup: Windows 11 (build 22631), Ryzen 9 5900X, RTX 3090, 3840x2160; child Link in the Market, hands-free through `scripts/longshot_ctl.py`; the frame rate capped at 60, which all 15 runs held; each run 30 s standing, then 30 s turning the camera; the three variants (with two more of another change) interleaved over three rounds, the PC otherwise idle. CPU seconds a second of play (cores busy on average) from the processor's cycle counter, per thread; the median of three runs. | cores busy, median of three | Before: main @ 068fb8eb | After, no switch set: test/rewrites @ e614ef49 | After, the nine on: test/rewrites @ e614ef49 | Δ, the nine on against main | |---|---|---|---|---| | whole process, standing (the three runs) | 5.156 (5.144, 5.156, 5.161) | 5.140 (5.303, 5.140, 5.125) | 5.017 (5.007, 5.017, 5.049) | -2.7 % | | whole process, turning | 5.639 (5.676, 5.627, 5.639) | 5.630 (5.722, 5.630, 5.628) | 5.504 (5.504, 5.498, 5.577) | -2.4 % | | executor threads (`BaseProcExecutor*`), standing | 2.229 | 2.244 | 2.137 | -4.1 % | | executor threads, turning | 2.455 | 2.461 | 2.358 | -4.0 % | | `mkw_vk capture copy`, standing | 0.090 | 0.088 | 0.099 | +10 % | | `mkw_vk capture copy`, turning | 0.097 | 0.097 | 0.114 | +18 % | The process includes the renderer's threads (about 1.4 cores), which the nine do not touch. The capture copy thread's rise is in Risks. Offline speed (`bench_leaves.py` / `bench_powf.c` in my tools: the calling thread's own CPU time; a hooked function is written in the old form on main too, every register in the context, so the patched side runs in that form; the other side is an approximation of main's form, the six most used x registers in locals, which is at most as fast as main's real form, so a factor here may be somewhat high; ±10 % noise, other builds running on the PC; Ryzen 9 5900X): | routine | its share of game code, Market / Kakariko and the trail | main's form (approx.), FPCR 0 / flush-to-zero | this PR, switch on | factor | |---|---|---|---|---| | quaternion `f_801c0d7c` | 0.082 % / 0.123 % | 65.7 / 92.5 ns | 43.9 / 49.1 ns | 1.50x / 1.88x | | its copy `f_804f8990` | 0.002 % / 0.003 % | 62.0 / 90.7 ns | 39.0 / 48.8 ns | 1.59x / 1.86x | | box `f_80825860` | 0.033 % / 0.080 % | 553 / 632 ns | 182 / 202 ns | 3.03x / 3.12x | | point `f_80171890` | 0.014 % / 0.007 % | 56.8 / 96.0 ns | 32.5 / 44.3 ns | 1.75x / 2.17x | | `f_8003d320` with its `powf` calls, per particle, a step other than exactly 1/60 s | `powf` under it 0.82 % (Market) | 699 ns | 243 ns | 2.88x | | the same at exactly 1/60 s (`powf` returns at its entry) | | 118-140 ns | 134 ns | 1.0x | With the switch off the hooked routines measured as without the hook within these timings' noise (the hook's check is a load and a branch). The shares are self time in a Market profile and two route profiles (Kakariko and Death Mountain Trail) of earlier builds. ### The switch `HOS_NATIVE_GLUE` (new, run time; its row in `gpu/vk/switches.def`): unset or `0` off (the hooks return at once, the memo calls `powf`); `1` on; `check` runs the host's answer into a buffer, then the translated routine for real, and compares every register and byte (NZCV-only differences counted apart), logging the first mismatch. A start line `oot: glue: four physics glue routines on the host (HOS_NATIVE_GLUE=1)`, and a line every 10 s, the last of the check run: ``` oot: glue (HOS_NATIVE_GLUE=check) quat f_801c0d7c: calls 1702037 (native 1701987; lifted: FPCR/FPSR 0, memory 0, values 50), compared 1701987, not compared 50, lift's flags 1622599, MISMATCHES 0; quat2 f_804f8990: calls 12973 (native 12964; lifted: FPCR/FPSR 0, memory 0, values 9), compared 12964, not compared 9, lift's flags 9485, MISMATCHES 0; aabb f_80825860: calls 200528 (native 200416; lifted: FPCR/FPSR 0, memory 0, values 112), compared 200416, not compared 112, lift's flags 24802, MISMATCHES 0; qst f_80171890: calls 68861 (native 36470; lifted: FPCR/FPSR 0, memory 0, values 32391), compared 36470, not compared 32391, lift's flags 0, MISMATCHES 0; powf at 0x8003d8cc: calls 2464825 (native 2437027; lifted: FPCR/FPSR 0, memory 0, values 0), compared 2437027, not compared 0, lift's flags 0, MISMATCHES 0; powf at 0x8003d8e0: calls 2464824 (native 2441712; lifted: FPCR/FPSR 0, memory 0, values 0), compared 2441712, not compared 0, lift's flags 0, MISMATCHES 0; MISMATCHES in all 0 ``` It ships off in this PR. The combined measurement says on; this PR's own measurement (the farm request) decides the default before it leaves WIP. ## Risks **What could break:** a kernel that is not exact would give a physics or cloth value the Switch would not; a memo that missed a byte `powf` writes would leave a register as the game would not. Checked as in Testing; the hooks decline what they cannot prove (a float mode outside the translator's gate, a value outside the proof's range, memory outside the guest's), the memo keeps a key only when the three runs agree byte for byte, and the translated routine runs. **Beside a native `powf`:** the maths library branch hooks `powf` itself. The memo calls `powf` through its translated function, so with both on a new key runs that native `powf` and a replay replaces it; offline, with a stand-in of that hook, every register, flag and byte matched `f_8003d320` with that hook alone (1,895,547 replays). **A cost seen:** with the nine on, the renderer's `mkw_vk capture copy` thread (it copies guest memory the game marked as written) used 0.009 to 0.017 more cores in the measured runs (+10 % standing / +18 % turning). The host kernels mark the pages they write, possibly more coarsely than the translated code's own marks; which of the nine adds it is not determined. It is inside the whole-process figures above. **Turning it off:** leave `HOS_NATIVE_GLUE` unset (the default). **After updating:** nothing changes for a player: saves, `longshot_options.ini` and the caches as before. The five patched functions are written by the translator with their registers in the context (as every patched function is), which changes their lifted code; with the switch unset the measured cost was within the runs' spread. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. (This code ran in the game in a test tree on main 068fb8eb, checked and measured; this head is not built or played.) - [ ] `mise run test` passes (any failure that also fails on `main` is named). (44 tests run, the branch's own and every one that reads the patch files: the five failures fail on main too; the full suite not run.) - [ ] Measured against `main`, or Measurements says why there is nothing to measure. (Measured against main with the nine on; this PR alone waits for the Test Farm.) - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. (The row is there; it ships off until this PR's own measurement.) - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_oot_glue.py` is new.) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the test tree's build; Linux not built.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Four leaf routines of the game's physics glue (its own side of Havok)
as host C that gives the game's bits exactly: a rotation matrix to a
normalised quaternion (f_801c0d7c and its byte-for-byte copy
f_804f8990), a box under a transform rounded outwards in double
(f_80825860) and a point under a QsTransform (f_80171890). Each kernel
is the routine's instructions in order on 128-bit register values; a
call is done only when every float operand is zero or of magnitude in
[2^-63, 2^63) (the quaternion kernel by a shorter proof written above
it), under the lift's own gate (RECOMP_FPX_OPEN); then no flag but IXC
can be raised. A box bound of exactly zero converts to the signed zero
with IDC under FZ and UFC otherwise, as Arm does. Every register the
routine writes, NZCV and FPSR are set as the routine leaves them; the
written page is marked. Anything else runs as lifted, untouched.

nx2/oot_patches.py (supported build only) puts a hook first in each of
the four lifted functions; report() names one not hooked once.
host/oot_glue.c answers them, read once from HOS_NATIVE_GLUE:
- unset / 0: every hook returns at once;
- 1: the call on the host where the kernel proves it, else lifted;
- check: the kernel into a copy, the lifted routine for real, every
  byte, x and v register, FPSR and NZCV compared (an NZCV-only
  difference is the lift's, counted apart); the lifted result is kept.
An "oot: glue" line every 10 s counts calls, native, lifted and why.
A row in gpu/vk/switches.def.

tests/test_oot_glue.py: the splices (once, first, supported build only,
idempotent, a missing routine reported), and the hooks over a guest
window of their own at -O2 and -O0: off; on against results worked out
in Python (single operations as one rounding, the boxes in double with
the nudge), declines writing nothing; check (exact lifts compared, an
NZCV difference alone the lift's, a wrong byte or register a mismatch
logged once, the 10 s line).

Exactness against the game's own routines was proven offline in
Unicorn (1,000,000 calls per routine, every register and byte); nothing
here has run in the game.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
f_8003d320, the per-particle damping the game runs after its cloth wind
callback, calls powf twice a particle, with arguments that are the same
for every particle of a call (and, at a steady frame rate, frame after
frame). nx2/oot_patches.py (patch_glue_powf, supported build only, both
calls or neither) makes the two calls hos_glue_powf_memo(c, powf, site).

The memo keeps, per thread and site, the last s0, s1 and FPCR and what
that lifted powf call did to the context. On a new key it runs powf on
the real context and on two copies whose every register but s0, s1 and
SP holds a pattern and its complement: a byte either copy changed is
one powf writes, and must be the same in both and in the real call;
the rest must be untouched; SP, FPCR and PC must not move; no FPSR flag
but IXC may be raised (which keeps powf's error paths, the ones that
set errno, out). A replay (FPSR.IXC set) writes exactly those bytes.
y = 1 (60 dt exactly 1) goes straight to powf, whose entry returns x.
Not reproduced: powf's stack frame below SP, dead once it returns.
Check mode replays into a copy, runs powf, compares every register,
NZCV and FPSR. Counted on the oot: glue line as two more entries.

tests/test_oot_glue.py: the patch (both calls, once, reported when one
is missing) and the memo against stand-in powfs: off runs them; on
fills with three runs and replays exactly whatever the other registers
hold; y = 1, IXC clear, another FPCR, a register dependence and a
raised flag run as lifted; check compares and counts a difference.

Proven offline against the stock lift and Unicorn (OoT-Modding
longshot-dev\glue-rewrite.md): 200,000 calls of f_8003d320, 3.76
million replays, every register and byte the lifted code's. Not run in
the game.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
At exactly 60 FPS (60 dt == 1) the game's powf returns x at its entry;
the splice now calls it directly there instead of through
hos_glue_powf_memo, so the hook costs nothing measurable on that path.
Proven offline again (200,000 calls of f_8003d320, every register and
byte the lifted code's).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(host): HOS_NATIVE_GLUE's hooks are declared noescape, and each function a hook passes is declared first
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
1724104b0a
The hooks' declarations in the lifted code (the four leaves' and the powf memo's) take the context as
`Ctx *A64_NOESC c`, as the lifted functions do: without it the compiler takes the context for escaped at the call,
which costs the hooked function with the switch off. nx2/split_giants.py writes a giant function's pieces before
f_<addr>, so a hook in the first piece that passes f_<addr> needs it declared above: GLUE_NATIVE_FWD, at file scope
with the hook's declaration (the memo passes f_85751000, whose call it replaces: the lift declares it already).
tests/test_oot_glue.py finds a function by its head line, no longer by its first mention (now the declaration).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: This head is not built or played; the same code, merged into a test tree on main 068fb8eb, ran on Windows 11 (RTX 3090, Ryzen 9 5900X): HOS_NATIVE_GLUE=check in the Market and Hyrule Field, 0 mismatches over about 1.95 million leaf calls and 4.9 million powf replays, then a CPU measurement at a 60 fps cap with nine rewrite branches on, this one among them (the whole process -2.7 % standing, -2.4 % turning).

Tested in game: This head is not built or played; the same code, merged into a test tree on main 068fb8eb, ran on Windows 11 (RTX 3090, Ryzen 9 5900X): HOS_NATIVE_GLUE=check in the Market and Hyrule Field, 0 mismatches over about 1.95 million leaf calls and 4.9 million powf replays, then a CPU measurement at a 60 fps cap with nine rewrite branches on, this one among them (the whole process -2.7 % standing, -2.4 % turning).
Author
Contributor

@Beanstalk linux, and amd: this PR in the child Market and in Kokiri Forest (the repo save kokiri-start), HOS_NATIVE_GLUE unset against HOS_NATIVE_GLUE=1, a few minutes each. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), per thread if you can (the executor threads are where it lands), and the frame times uncapped. Expect the same frame rate or better with less CPU time, cloth and physics moving as without the switch, and "oot: glue" lines in the log with the switch on. Then one Market run with HOS_NATIVE_GLUE=check: every "oot: glue" line should end "MISMATCHES in all 0".

@Beanstalk linux, and amd: this PR in the child Market and in Kokiri Forest (the repo save kokiri-start), HOS_NATIVE_GLUE unset against HOS_NATIVE_GLUE=1, a few minutes each. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), per thread if you can (the executor threads are where it lands), and the frame times uncapped. Expect the same frame rate or better with less CPU time, cloth and physics moving as without the switch, and "oot: glue" lines in the log with the switch on. Then one Market run with HOS_NATIVE_GLUE=check: every "oot: glue" line should end "MISMATCHES in all 0".
Member

@snaildev99 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 1724104, and the PR has changed since (a31c390), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@snaildev99 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `1724104`, and the PR has changed since (`a31c390`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Member

Possibly related, for context:

  • PR #1898 WIP: perf(host): seven of the physics' small float routines on host code, bit for bit (HOS_MATH, off by default) — Overlapping host-native physics float routines and related build/lift hooks
Possibly related, for context: - PR #1898 WIP: perf(host): seven of the physics' small float routines on host code, bit for bit (HOS_MATH, off by default) — Overlapping host-native physics float routines and related build/lift hooks
BeanBot left a comment

Recommendation: Request changes. The kernels transcribe the game’s instructions, conflicting with the repository’s prohibition on code derived from the dump. The change’s own performance gain and its cost with the switch off are also unproven.

The change adds optional host implementations for four physics routines and a per-thread memo for two cloth damping calls. It could reduce CPU work, but adds substantial instruction-level code and hooks on paths used even with the switch off; its standalone net benefit has not been measured.

Does it help: Unproven. The reported 2.7% and 2.4% process CPU reductions in the Market are medians from three Windows runs with nine rewrite branches enabled together on an older base, so they cannot establish this PR’s contribution. The standalone offline timings do not measure player frame times or the current head against its base.
Other systems: The hooks affect Windows and Linux CPU execution regardless of GPU; the switch-off path also changes lifted code. Linux, AMD and this head in the game remain untested. The combined run showed capture-copy CPU rising by 0.009–0.017 cores, but did not identify which branch caused it. No evidence was supplied for Steam Deck or other Tier 1 systems.
Switches: HOS_NATIVE_GLUE is new: unset or 0 is off, 1 enables the host paths, and check compares against lifted code. The off default limits exposure, but measurements do not yet establish the appropriate default or its overhead. Its switches.def row is present.

Reviewed: 1724104b0a against a104182b40: Read AGENTS.md, CONTRIBUTING.md, the PR template, the changed host files and header, changed portions of nx2/oot_patches.py, and the available test sections; skimmed standards, the remaining test fixture, build integration, commits and the supplied run reports. The named review checklist and adjacent Tooling AGENTS.md are absent. No earlier comments or reviews were supplied.; nothing run (a code review).
Checked and fine:

  • The hooks are restricted to the supported build, and missing patch sites are reported.
  • The host leaf paths mark their guest-memory writes; declined leaf calls leave the guest context and output untouched.
  • The switch has a documented off default and a check mode; the PR records AI assistance and names the baseline test failures.
  • No third-party files or build artifacts appear in the diff.

Blocking (to change before merge)

  1. host/glue_kernels.c:2: The file describes, and implements, the game routines one statement per Arm instruction, including instruction comments and register sequencing. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump, so this instruction-level transcription cannot merge under that rule. Replace it with independently authored implementations based on behavioral facts, with provenance consistent with the licensing policy.
  2. nx2/oot_patches.py:1461: The two call sites gain a branch even when HOS_NATIVE_GLUE is unset, and the other hooks also change the lifted functions for every player. The only in-game comparison combines nine branches on an older base, so neither this PR’s gain nor its default-path cost is established; the observed capture-copy increase is also unattributed. Measure this head alone against its merge base, switch off and on, with repeated player-scene CPU and frame-time results, and resolve any material regression.

Suggestions (the author may take or leave)

  • Exercise this head in the game on Windows and Linux, including the requested AMD run and Tier 1 hardware, and complete the full test suite and CI before merge.
  • Include uncapped frame times and 1% lows alongside capped CPU time, and investigate whether this change contributes to the capture-copy increase.

Testing: Read-only review; no builds, tests, scripts or game runs were executed. The author reports zero mismatches in offline comparisons and a combined-branch Windows check run, but this head has not been built or played in the game.
Overlaps and merge order: No overlap information was supplied; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The kernels transcribe the game’s instructions, conflicting with the repository’s prohibition on code derived from the dump. The change’s own performance gain and its cost with the switch off are also unproven. The change adds optional host implementations for four physics routines and a per-thread memo for two cloth damping calls. It could reduce CPU work, but adds substantial instruction-level code and hooks on paths used even with the switch off; its standalone net benefit has not been measured. **Does it help:** Unproven. The reported 2.7% and 2.4% process CPU reductions in the Market are medians from three Windows runs with nine rewrite branches enabled together on an older base, so they cannot establish this PR’s contribution. The standalone offline timings do not measure player frame times or the current head against its base. **Other systems:** The hooks affect Windows and Linux CPU execution regardless of GPU; the switch-off path also changes lifted code. Linux, AMD and this head in the game remain untested. The combined run showed capture-copy CPU rising by 0.009–0.017 cores, but did not identify which branch caused it. No evidence was supplied for Steam Deck or other Tier 1 systems. **Switches:** HOS_NATIVE_GLUE is new: unset or 0 is off, 1 enables the host paths, and check compares against lifted code. The off default limits exposure, but measurements do not yet establish the appropriate default or its overhead. Its switches.def row is present. **Reviewed:** 1724104b0a4d against a104182b4037: Read AGENTS.md, CONTRIBUTING.md, the PR template, the changed host files and header, changed portions of nx2/oot_patches.py, and the available test sections; skimmed standards, the remaining test fixture, build integration, commits and the supplied run reports. The named review checklist and adjacent Tooling AGENTS.md are absent. No earlier comments or reviews were supplied.; nothing run (a code review). **Checked and fine:** - The hooks are restricted to the supported build, and missing patch sites are reported. - The host leaf paths mark their guest-memory writes; declined leaf calls leave the guest context and output untouched. - The switch has a documented off default and a check mode; the PR records AI assistance and names the baseline test failures. - No third-party files or build artifacts appear in the diff. **Blocking** (to change before merge) 1. host/glue_kernels.c:2: The file describes, and implements, the game routines one statement per Arm instruction, including instruction comments and register sequencing. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump, so this instruction-level transcription cannot merge under that rule. Replace it with independently authored implementations based on behavioral facts, with provenance consistent with the licensing policy. 2. nx2/oot_patches.py:1461: The two call sites gain a branch even when HOS_NATIVE_GLUE is unset, and the other hooks also change the lifted functions for every player. The only in-game comparison combines nine branches on an older base, so neither this PR’s gain nor its default-path cost is established; the observed capture-copy increase is also unattributed. Measure this head alone against its merge base, switch off and on, with repeated player-scene CPU and frame-time results, and resolve any material regression. **Suggestions** (the author may take or leave) - Exercise this head in the game on Windows and Linux, including the requested AMD run and Tier 1 hardware, and complete the full test suite and CI before merge. - Include uncapped frame times and 1% lows alongside capped CPU time, and investigate whether this change contributes to the capture-copy increase. **Testing:** Read-only review; no builds, tests, scripts or game runs were executed. The author reports zero mismatches in offline comparisons and a combined-branch Windows check run, but this head has not been built or played in the game. **Overlaps and merge order:** No overlap information was supplied; the network is closed. --- <sub>Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -0,0 +1,429 @@
/* (longshot) The physics glue's leaf routines on host code, bit for bit: see glue_kernels.h for what each is and the
proof rule. Each kernel below is the routine's instructions in order, one statement each (the Arm instruction is in
Member

This transcribes the game routines instruction by instruction. CONTRIBUTING.md prohibits decompiled game code and code generated from the dump; please replace these kernels with independently authored implementations based on behavioral facts and document their provenance.

This transcribes the game routines instruction by instruction. CONTRIBUTING.md prohibits decompiled game code and code generated from the dump; please replace these kernels with independently authored implementations based on behavioral facts and document their provenance.
@ -1422,0 +1458,4 @@
# to the registers. The function is patched whole (both calls) or not at all.
GLUE_POWF_HEAD = "void f_8003d320(Ctx *__restrict A64_NOESC c) {\n"
GLUE_POWF_CALLS = (("c->x[30] = 0x8003d8d0ULL; f_85751000(c);", 0), ("c->x[30] = 0x8003d8e4ULL; f_85751000(c);", 1))
GLUE_POWF_NEW = ("c->x[30] = 0x%s; if ((uint32_t)c->vreg[1][0] == 0x3f800000u) f_85751000(c); else hos_glue_powf_memo(c, "
Member

This adds a branch at both call sites even with the switch off. The reported in-game numbers combine nine branches on an older base, so please measure this head alone against its base, both off and on, including frame times and the capture-copy cost.

This adds a branch at both call sites even with the switch off. The reported in-game numbers combine nine branches on an older base, so please measure this head alone against its base, both off and on, including frame times and the capture-copy cost.
Owner
@fix
BeanBot force-pushed perf/native-glue from 1724104b0a
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
beanstalk/approval waiting for a BigBean's 👍 on the request
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to a31c3908e5
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
beanstalk/approval changed since the request: ask again
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 18s
PR description / Description follows the template (pull_request_target) Successful in 24s
CI / Workflow lint (actionlint) (pull_request) Successful in 28s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 28s
Third-party parts / As their notes say (pull_request) Successful in 34s
CI / Website build and checks (pull_request) Has been cancelled
2026-11-21 00:07:58 +00:00
Compare
Member

I changed this pull request by bringing it up to date: the new head is a31c3908e5. I rebased it onto main (a764653726).

Conflicts resolved

  • gpu/vk/switches.def: Kept the new HOS_NATIVE_GLUE switch and the base branch’s updated HOS_NATIVE_ZSTD definition.
  • gpu/vk/switches.def: Kept the pull request’s powf memo description and the base branch’s updated HOS_NATIVE_ZSTD setting.

Left for the author

  • Kernel provenance and performance evidence: Provide an independently sourced behavioral specification and provenance for the full register, flag, memory and floating-point behavior before the kernels can be replaced without relying on the existing instruction transcription. The checked-in mathematical descriptions do not establish that full contract. Measure this head alone against its merge base with the switch off and on, using repeated player-scene CPU, frame-time and capture-copy results, then resolve any material regression. No files were changed and nothing was run.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request by bringing it up to date: the new head is a31c3908e5e1. I rebased it onto `main` (a764653726ba). **Conflicts resolved** - gpu/vk/switches.def: Kept the new HOS_NATIVE_GLUE switch and the base branch’s updated HOS_NATIVE_ZSTD definition. - gpu/vk/switches.def: Kept the pull request’s powf memo description and the base branch’s updated HOS_NATIVE_ZSTD setting. **Left for the author** - **Kernel provenance and performance evidence**: Provide an independently sourced behavioral specification and provenance for the full register, flag, memory and floating-point behavior before the kernels can be replaced without relying on the existing instruction transcription. The checked-in mathematical descriptions do not establish that full contract. Measure this head alone against its merge base with the switch off and on, using repeated player-scene CPU, frame-time and capture-copy results, then resolve any material regression. No files were changed and nothing was run. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot left a comment

Recommendation: Request changes. The leaf kernels transcribe game instructions in violation of the repository’s provenance rule, and the cloth memo runs speculative calls against live guest memory. The PR’s standalone performance gain is unproven.

Adds optional native paths for four physics leaves and reuses repeated cloth damping results. The combined measurements suggest a CPU saving, but this PR adds instruction-level code to maintain and changes the lifted call paths for players who leave the switch off.

Does it help: Unproven. Three interleaved Windows runs on an older base with nine rewrites enabled put Market process CPU down 2.7% standing and 2.4% turning, and executor CPU down 4.1% and 4.0%. Capture-copy CPU rose by 0.009 and 0.017 cores. The 1.5–3.1× offline timings used an approximate base and had roughly 10% noise. There are no isolated head-versus-base player measurements, uncapped frame times, or 1% lows.
Other systems: The hooks run on the CPU on Windows and Linux across GPU vendors. The reported mixed-tree run covers Windows/NVIDIA. AMD, Linux and Steam Deck remain unverified. Guest writes feed renderer capture, and the combined capture-copy cost is unattributed. Patched functions retain context registers even with the switch off. The build picks up both new C files and changes generated lift text, so build time, output size and update rebuild scope need checking. There is no direct change to saves, audio, input, menus or the renderer ABI.
Switches: HOS_NATIVE_GLUE is a new developer A/B switch. Unset and 0 disable it, 1 enables the native paths and check retains the lifted results while comparing eligible calls. The switches.def row is present. Off limits exposure, but the repo requires a measured default and the nine-branch result cannot choose it. The row overstates check coverage.

Reviewed: a31c3908e5 against a764653726: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, standards, the diff and commit messages, and the new host sources, header and test. Read the changed portions of oot_patches.py and traced the patch pipeline, register localization, split builds, guest context, guest memory marking and logging. Skimmed the wider build and test infrastructure and reported runs. No review-checklist or adjacent Tooling checkout was present. The private offline harness and raw runs were unavailable.; nothing run (a code review).
Checked and fine:

  • One host performance topic on the supplied merge base, with a Conventional Commit title and AI assistance trailers. Third-party files, generated files, build artifacts and vendor SDKs are absent from the diff.
  • Hooks are gated to the supported game build. The patch reports missing sites and the fixture checks supported-build gating and idempotence.
  • Native leaf writes are marked after the output stores. A rejected arithmetic candidate leaves guest output and guest registers untouched.
  • The fixture checks leaf outputs against Python calculations and exercises off, on, fallback and check modes. The test only creates temporary fixtures and invokes the local compiler and fixture executables.

Blocking (to change before merge)

  1. host/glue_kernels.c:2: The kernels expressly implement the game’s Arm instructions one statement at a time, including register sequencing and scratch results. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump. Replace these kernels with independently authored code from a documented behavioral contract and establish its provenance, or remove them.
  2. host/oot_glue.c:322: The two probe contexts keep the real SP and guest TLS and access live guest memory. On an error path that sets guest errno, all three calls can reach that store before the FPSR check rejects the key. Stack stores and write tracking also happen during probes, including in check mode. Remove the speculative calls. Use a verified side-effect-free path with explicit inputs and outputs, and run the original exactly once on fallback. Add a test that observes guest memory and call count.
  3. host/oot_glue.c:334: Agreement for two register patterns and one real input cannot establish the replay contract. For example, a callee that only writes a scratch byte when x5 is zero passes a fill where all three x5 values are nonzero, then replay misses the write. The same test cannot establish independence from guest memory or from a sibling powf hook. Replace inferred clobbers with a verified contract for the exact implementation, or keep those calls lifted.
  4. host/glue_kernels.c:139: The caller passes &c->n, a pointer to one scalar member. Indexing it to write z, c and v steps outside that member even when the fields are contiguous. Quaternion and nonempty box calls depend on undefined C behavior. Pass the flags as actual output storage or return packed NZCV and assign the four Ctx members directly.
  5. host/oot_glue.c:149: Check mode excuses every NZCV-only discrepancy as a lift artifact. A quaternion bug that only sets the wrong Z on a zero norm would still yield zero mismatches. Compare flags where the lift guarantees them and validate the others against an independent expected result. Add an NZCV-only mutation case and document which calls and flags check mode covers.
  6. host/oot_glue.c:84: The six-entry summary goes through hos_log, whose formatting buffer is 1024 bytes. As counters grow, the line can lose the aggregate mismatch suffix that the farm is asked to check. The fixture uses a 2048-byte logger and small counts. Put the aggregate first or log bounded per-routine lines, use 64-bit totals so long Windows runs keep reporting valid counts, and test at the real logger limit.
  7. nx2/oot_patches.py:1454: This forward declaration skips split_hot.py’s declaration filter because it does not use the canonical void f_…(Ctx *A64_NOESC); spelling. A hot leaf adds its declaration to every hot piece, changing object inputs even where the leaf is unused. Emit the canonical declaration and verify that an unrelated piece retains its prior text.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and enabled. Use repeated same-scene CPU, capture-copy and uncapped frame-time runs, cover varying time steps and cloth keys, and report clean build time and size. Resolve material regressions and use the results to choose the default.
  • This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any failures reproduced on the current base.

Testing: Read-only review. No builds, tests, scripts or game runs were executed. The author reports zero offline mismatches for pre-rebase code and zero reported mismatches in the older mixed Windows game run. The partial suite had 39 passes and five named failures reproduced on the older main.
Overlaps and merge order: #1898 overlaps native physics and lifting work. The description also identifies a sibling native powf hook that would change the callee behind this memo. No required merge order is established. Recheck both switches together on the eventual merge base.


Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The leaf kernels transcribe game instructions in violation of the repository’s provenance rule, and the cloth memo runs speculative calls against live guest memory. The PR’s standalone performance gain is unproven. Adds optional native paths for four physics leaves and reuses repeated cloth damping results. The combined measurements suggest a CPU saving, but this PR adds instruction-level code to maintain and changes the lifted call paths for players who leave the switch off. **Does it help:** Unproven. Three interleaved Windows runs on an older base with nine rewrites enabled put Market process CPU down 2.7% standing and 2.4% turning, and executor CPU down 4.1% and 4.0%. Capture-copy CPU rose by 0.009 and 0.017 cores. The 1.5–3.1× offline timings used an approximate base and had roughly 10% noise. There are no isolated head-versus-base player measurements, uncapped frame times, or 1% lows. **Other systems:** The hooks run on the CPU on Windows and Linux across GPU vendors. The reported mixed-tree run covers Windows/NVIDIA. AMD, Linux and Steam Deck remain unverified. Guest writes feed renderer capture, and the combined capture-copy cost is unattributed. Patched functions retain context registers even with the switch off. The build picks up both new C files and changes generated lift text, so build time, output size and update rebuild scope need checking. There is no direct change to saves, audio, input, menus or the renderer ABI. **Switches:** HOS_NATIVE_GLUE is a new developer A/B switch. Unset and 0 disable it, 1 enables the native paths and check retains the lifted results while comparing eligible calls. The switches.def row is present. Off limits exposure, but the repo requires a measured default and the nine-branch result cannot choose it. The row overstates check coverage. **Reviewed:** a31c3908e5e1 against a764653726ba: Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, standards, the diff and commit messages, and the new host sources, header and test. Read the changed portions of oot_patches.py and traced the patch pipeline, register localization, split builds, guest context, guest memory marking and logging. Skimmed the wider build and test infrastructure and reported runs. No review-checklist or adjacent Tooling checkout was present. The private offline harness and raw runs were unavailable.; nothing run (a code review). **Checked and fine:** - One host performance topic on the supplied merge base, with a Conventional Commit title and AI assistance trailers. Third-party files, generated files, build artifacts and vendor SDKs are absent from the diff. - Hooks are gated to the supported game build. The patch reports missing sites and the fixture checks supported-build gating and idempotence. - Native leaf writes are marked after the output stores. A rejected arithmetic candidate leaves guest output and guest registers untouched. - The fixture checks leaf outputs against Python calculations and exercises off, on, fallback and check modes. The test only creates temporary fixtures and invokes the local compiler and fixture executables. **Blocking** (to change before merge) 1. host/glue_kernels.c:2: The kernels expressly implement the game’s Arm instructions one statement at a time, including register sequencing and scratch results. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump. Replace these kernels with independently authored code from a documented behavioral contract and establish its provenance, or remove them. 2. host/oot_glue.c:322: The two probe contexts keep the real SP and guest TLS and access live guest memory. On an error path that sets guest errno, all three calls can reach that store before the FPSR check rejects the key. Stack stores and write tracking also happen during probes, including in check mode. Remove the speculative calls. Use a verified side-effect-free path with explicit inputs and outputs, and run the original exactly once on fallback. Add a test that observes guest memory and call count. 3. host/oot_glue.c:334: Agreement for two register patterns and one real input cannot establish the replay contract. For example, a callee that only writes a scratch byte when x5 is zero passes a fill where all three x5 values are nonzero, then replay misses the write. The same test cannot establish independence from guest memory or from a sibling powf hook. Replace inferred clobbers with a verified contract for the exact implementation, or keep those calls lifted. 4. host/glue_kernels.c:139: The caller passes &c->n, a pointer to one scalar member. Indexing it to write z, c and v steps outside that member even when the fields are contiguous. Quaternion and nonempty box calls depend on undefined C behavior. Pass the flags as actual output storage or return packed NZCV and assign the four Ctx members directly. 5. host/oot_glue.c:149: Check mode excuses every NZCV-only discrepancy as a lift artifact. A quaternion bug that only sets the wrong Z on a zero norm would still yield zero mismatches. Compare flags where the lift guarantees them and validate the others against an independent expected result. Add an NZCV-only mutation case and document which calls and flags check mode covers. 6. host/oot_glue.c:84: The six-entry summary goes through hos_log, whose formatting buffer is 1024 bytes. As counters grow, the line can lose the aggregate mismatch suffix that the farm is asked to check. The fixture uses a 2048-byte logger and small counts. Put the aggregate first or log bounded per-routine lines, use 64-bit totals so long Windows runs keep reporting valid counts, and test at the real logger limit. 7. nx2/oot_patches.py:1454: This forward declaration skips split_hot.py’s declaration filter because it does not use the canonical `void f_…(Ctx *A64_NOESC);` spelling. A hot leaf adds its declaration to every hot piece, changing object inputs even where the leaf is unused. Emit the canonical declaration and verify that an unrelated piece retains its prior text. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and enabled. Use repeated same-scene CPU, capture-copy and uncapped frame-time runs, cover varying time steps and cloth keys, and report clean build time and size. Resolve material regressions and use the results to choose the default. - This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any failures reproduced on the current base. **Testing:** Read-only review. No builds, tests, scripts or game runs were executed. The author reports zero offline mismatches for pre-rebase code and zero reported mismatches in the older mixed Windows game run. The partial suite had 39 passes and five named failures reproduced on the older main. **Overlaps and merge order:** #1898 overlaps native physics and lifting work. The description also identifies a sibling native powf hook that would change the callee behind this memo. No required merge order is established. Recheck both switches together on the eventual merge base. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -0,0 +1,429 @@
/* (longshot) The physics glue's leaf routines on host code, bit for bit: see glue_kernels.h for what each is and the
proof rule. Each kernel below is the routine's instructions in order, one statement each (the Arm instruction is in
Member

The instruction-by-instruction transcription conflicts with CONTRIBUTING.md. Replace it with independently authored implementations with documented provenance, or drop the kernels.

The instruction-by-instruction transcription conflicts with CONTRIBUTING.md. Replace it with independently authored implementations with documented provenance, or drop the kernels.
@ -0,0 +136,4 @@
GI void put(GlueRegs r, int i, GQ q) { r.v[i][0] = q.d[0], r.v[i][1] = q.d[1]; }
GI void put_nzcv(GlueRegs r, unsigned f) {
r.nzcv[0] = (uint8_t)(f >> 3 & 1u), r.nzcv[1] = (uint8_t)(f >> 2 & 1u), r.nzcv[2] = (uint8_t)(f >> 1 & 1u), r.nzcv[3] = (uint8_t)(f & 1u);
Member

nzcv points to the scalar c->n. Indexing past it is undefined. Return packed flags or pass real output storage.

`nzcv` points to the scalar `c->n`. Indexing past it is undefined. Return packed flags or pass real output storage.
host/oot_glue.c Outdated
@ -0,0 +81,4 @@
s[S_CHECKED], s[S_UNCHECKED], s[S_FLAGS], s[S_MISMATCH]);
}
if (check && at < sizeof line) snprintf(line + at, sizeof line - at, "; MISMATCHES in all %ld", mism);
hos_log("%s", line);
Member

The real logger truncates at 1024 bytes. Preserve the mismatch total as counters grow and cover that limit in the fixture.

The real logger truncates at 1024 bytes. Preserve the mismatch total as counters grow and cover that limit in the fixture.
host/oot_glue.c Outdated
@ -0,0 +146,4 @@
d = 2;
}
glue_count(k, S_CHECKED);
if (d == 1) {
Member

A wrong Z on a zero-norm quaternion would count as a lift artifact. Validate flags wherever there is a reliable oracle and add an NZCV-only mutation case.

A wrong Z on a zero-norm quaternion would count as a lift artifact. Validate flags wherever there is a reliable oracle and add an NZCV-only mutation case.
host/oot_glue.c Outdated
@ -0,0 +319,4 @@
glue_poison(&a, 0x5a3cc3a5f00f6996ull), glue_poison(&b, ~0x5a3cc3a5f00f6996ull);
Ctx pa = a, pb = b;
powf(c);
powf(&a);
Member

These probes run against live guest stack and TLS before rejection. An errno-setting path can run three times. Remove live probes and test that fallback executes once with its memory effects intact.

These probes run against live guest stack and TLS before rejection. An errno-setting path can run three times. Remove live probes and test that fallback executes once with its memory effects intact.
host/oot_glue.c Outdated
@ -0,0 +331,4 @@
ob = *glue_word(&b, i, &t[3]), rr = *glue_word(&pre, i, &t[4]);
uint64_t t5;
const uint64_t orr = *glue_word(c, i, &t5);
const uint64_t w = glue_bytes_differ(ra, oa) | glue_bytes_differ(rb, ob);
Member

A scratch write conditional on an input the probes miss can be silently omitted from replay. Use a verified clobber and side-effect contract for the exact callee.

A scratch write conditional on an input the probes miss can be silently omitted from replay. Use a verified clobber and side-effect contract for the exact callee.
@ -1442,0 +1451,4 @@
GLUE_NATIVE_TAG = " /* (nx2/oot_patches.py: HOS_NATIVE_GLUE, host/oot_glue.c) */\n"
GLUE_NATIVE_HOOK = " if (hos_glue_%s(c, f_%s)) return;"
GLUE_NATIVE_DECL = "extern int hos_glue_%s(Ctx *A64_NOESC c, A64Fn lifted);\n"
GLUE_NATIVE_FWD = "void f_%s(Ctx *__restrict A64_NOESC c);\n" # (the function a hook passes: split_giants.py writes a giant function's pieces before it)
Member

Use the canonical lifted prototype so split_hot.py can omit it from unrelated pieces and preserve their object cache inputs.

Use the canonical lifted prototype so split_hot.py can omit it from unrelated pieces and preserve their object cache inputs.
@ -1442,0 +1478,4 @@
# to the registers. The function is patched whole (both calls) or not at all.
GLUE_POWF_HEAD = "void f_8003d320(Ctx *__restrict A64_NOESC c) {\n"
GLUE_POWF_CALLS = (("c->x[30] = 0x8003d8d0ULL; f_85751000(c);", 0), ("c->x[30] = 0x8003d8e4ULL; f_85751000(c);", 1))
GLUE_POWF_NEW = ("c->x[30] = 0x%s; if ((uint32_t)c->vreg[1][0] == 0x3f800000u) f_85751000(c); else hos_glue_powf_memo(c, "
Member

Measure this head alone against base, unset and enabled. Include varying cloth keys, uncapped frame times, capture-copy CPU and clean build impact.

Measure this head alone against base, unset and enabled. Include varying cloth keys, uncapped frame times, capture-copy CPU and clean build impact.
@ -0,0 +350,4 @@
CHECK(c.fpsr == (!AV[i].zero ? 0x10u : fz ? 0x90u : 0x18u));
CHECK((c.n << 3 | c.z << 2 | c.c << 1 | c.v) == AV[i].nzcv);
} else { /* (the empty box: copied, NZCV and FPSR as they were) */
CHECK(c.fpsr == 0x10 && c.n == 1 && c.c == 1 && c.v == 1 && c.x[8] == ((uint64_t *)AV[i].box)[0]);
Member

Read the expected x8 with memcpy. Casting the byte array to uint64_t* assumes alignment and violates effective-type rules.

Read the expected x8 with memcpy. Casting the byte array to uint64_t* assumes alignment and violates effective-type rules.
Owner
@fix
Member

I changed this pull request as the review asked: the new head is 562e855688. I rebased it onto main (80bb1ccc18).

Changed

  • Kernel provenance: Removed host/glue_kernels.c and its header, along with their hooks in nx2/oot_patches.py.
  • Speculative calls: Removed the powf memo and its probes; both calls remain lifted. tests/test_oot_glue.py:54 checks call counts and guest-memory writes. The test was not run.
  • Inferred replay contract: Removed the replay path in host/oot_glue.c and its call-site patch in nx2/oot_patches.py; both powf calls remain lifted.
  • NZCV storage: Removed the kernels and their scalar-member indexing, leaving the quaternion and box routines lifted.
  • Check-mode flag discrepancies: Removed check mode with the native kernels, so it no longer reports or excuses NZCV discrepancies; an NZCV mutation test no longer applies.
  • Summary truncation and counters: Removed the native glue summary and counters with host/oot_glue.c; a logger-limit test no longer applies.
  • Hot-piece declarations: Removed the hook and its forward declaration. tests/test_oot_glue.py:47 checks that an unrelated hot piece retains its text; the test was not run.

Still for the author (from the review)

  • nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and enabled. Use repeated same-scene CPU, capture-copy and uncapped frame-time runs, cover varying time steps and cloth keys, and report clean build time and size. Resolve material regressions and use the results to choose the default.
  • This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any failures reproduced on the current base.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request as the review asked: the new head is 562e8556884c. I rebased it onto `main` (80bb1ccc182d). **Changed** - **Kernel provenance**: Removed host/glue_kernels.c and its header, along with their hooks in nx2/oot_patches.py. - **Speculative calls**: Removed the powf memo and its probes; both calls remain lifted. tests/test_oot_glue.py:54 checks call counts and guest-memory writes. The test was not run. - **Inferred replay contract**: Removed the replay path in host/oot_glue.c and its call-site patch in nx2/oot_patches.py; both powf calls remain lifted. - **NZCV storage**: Removed the kernels and their scalar-member indexing, leaving the quaternion and box routines lifted. - **Check-mode flag discrepancies**: Removed check mode with the native kernels, so it no longer reports or excuses NZCV discrepancies; an NZCV mutation test no longer applies. - **Summary truncation and counters**: Removed the native glue summary and counters with host/oot_glue.c; a logger-limit test no longer applies. - **Hot-piece declarations**: Removed the hook and its forward declaration. tests/test_oot_glue.py:47 checks that an unrelated hot piece retains its text; the test was not run. **Still for the author** (from the review) - nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and enabled. Use repeated same-scene CPU, capture-copy and uncapped frame-time runs, cover varying time steps and cloth keys, and report clean build time and size. Resolve material regressions and use the results to choose the default. - This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any failures reproduced on the current base. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed perf/native-glue from a31c3908e5
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
beanstalk/approval changed since the request: ask again
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 18s
PR description / Description follows the template (pull_request_target) Successful in 24s
CI / Workflow lint (actionlint) (pull_request) Successful in 28s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 28s
Third-party parts / As their notes say (pull_request) Successful in 34s
CI / Website build and checks (pull_request) Has been cancelled
to 562e855688
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
PR description / Description follows the template (pull_request_target) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 16s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Failing after 13s
beanstalk/approval can't be tested as asked: see the farm's comment
2026-11-21 00:50:22 +00:00
Compare
BeanBot left a comment

Recommendation: Request changes. The native glue optimization is gone, and the remaining fixture checks a path the merge base already provides. Update the PR to describe and justify the test-only change, then validate the current head.

Players get the same lifted physics and cloth code as on the merge base. The sole addition is a game-free fixture that could catch a future patch replacing two direct cloth damping calls, at the cost of another C++ compile and executable in the test suite. Its hot-piece comparison duplicates the source-equality assertion.

Since the last review (on a31c3908e5)
Resolved:

  • host/glue_kernels.c:2: The kernels expressly implement the game’s Arm instructions one statement at a time, including register sequencing and scratch results. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump. Replace these kernels with independently authored code f (The transcribed kernels and header are absent from HEAD. The repository squash-merges the final diff.)
  • host/oot_glue.c:322: The two probe contexts keep the real SP and guest TLS and access live guest memory. On an error path that sets guest errno, all three calls can reach that store before the FPSR check rejects the key. Stack stores and write tracking also happen during probes, including in check m (host/oot_glue.c and the powf call-site patch are gone. The new fixture checks two calls per invocation and their memory writes at tests/test_oot_glue.py:78.)
  • host/oot_glue.c:334: Agreement for two register patterns and one real input cannot establish the replay contract. For example, a callee that only writes a scratch byte when x5 is zero passes a fill where all three x5 values are nonzero, then replay misses the write. The same test cannot establish in (nx2/oot_patches.py has no memo splice. Each cloth call goes through the existing lifted path without inferred clobbers or replay.)
  • host/glue_kernels.c:139: The caller passes &c->n, a pointer to one scalar member. Indexing it to write z, c and v steps outside that member even when the fields are contiguous. Quaternion and nonempty box calls depend on undefined C behavior. Pass the flags as actual output storage or return packed (The kernels and their scalar-member flag indexing are absent from HEAD.)
  • host/oot_glue.c:149: Check mode excuses every NZCV-only discrepancy as a lift artifact. A quaternion bug that only sets the wrong Z on a zero norm would still yield zero mismatches. Compare flags where the lift guarantees them and validate the others against an independent expected result. Add an NZ (The native glue check mode is gone, including the logic that classified every NZCV-only difference as a lift artifact.)
  • host/oot_glue.c:84: The six-entry summary goes through hos_log, whose formatting buffer is 1024 bytes. As counters grow, the line can lose the aggregate mismatch suffix that the farm is asked to check. The fixture uses a 2048-byte logger and small counts. Put the aggregate first or log bounded per-r (The glue logger and counters are gone with host/oot_glue.c.)
  • nx2/oot_patches.py:1454: This forward declaration skips split_hot.py’s declaration filter because it does not use the canonical void f_…(Ctx *A64_NOESC); spelling. A hot leaf adds its declaration to every hot piece, changing object inputs even where the leaf is unused. Emit the canonical declarati (nx2/oot_patches.py no longer emits a glue forward declaration. The remaining test's hot-piece comparison is addressed separately.)
  • nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and ena (The hooks, exponent branch, and speculative calls are absent from the delivered diff. The switch A/B, capture-copy, and game build measurements no longer apply.)
    Still open:
  • This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any f (The new fixture and current full suite have no reported run. The previous mixed-tree play run and stale farm request no longer apply to the test-only diff.)
    New:
  • tests/test_oot_glue.py:53: The hot-piece check follows an assertion that patched is byte-for-byte equal to SOURCE. Both splitter calls therefore already receive identical text, and a reintroduced glue declaration fails before the split comparison runs. Remove the duplicate split and rely on the existing hot-piece tests, or give this check inputs that differ in the affected routine and verify the unrelated piece stays identical.
  • The PR still advertises HOS_NATIVE_GLUE and presents old benchmark and test results as support for the change. HEAD only adds a fixture around lift behavior already present on main. Retitle and rewrite the PR as a test-only change, explain the future regression the fixture is meant to catch, and update Testing, Measurements, Risks, and the checklist for this head.

Does it help: Not a perf change at 562e855688. The reported 2.7% standing and 2.4% turning CPU reductions came from three Windows runs with nine rewrites enabled in an older tree. The code those runs exercised is absent from the current diff.
Other systems: The diff changes the game-free test suite on Windows and Linux. It leaves the lift pipeline, game build inputs, guest write tracking, renderer capture, saves, audio, and input identical to the merge base. GPU and Steam Deck game runs are inapplicable to this diff.
Switches: None in the current diff. HOS_NATIVE_GLUE and its switch-table row are absent at HEAD.

Reviewed: 562e855688 against 80bb1ccc18: Read the current diff, commit messages, AGENTS.md, CONTRIBUTING.md, the Forgejo PR template, relevant standards, and tests/test_oot_glue.py in full. Traced patch_file, the cloth patch targets, hot-piece splitting, and test runner discovery. Compared the earlier and current changed-file sets and read the supplied comments and reviews. Skimmed the historical run reports. The review checklist and adjacent Tooling checkout were absent, and raw runs and the offline harness were unavailable.; nothing run (a code review).
Checked and fine:

  • The current diff is limited to one test and adds no game files, generated output, third-party changes, or vendor SDK files.
  • The synthetic callee checks call order and checks that both writes still happen on the second invocation.
  • The fixture uses a temporary directory, a local compiler, and its own synthetic executable. It performs no downloads and needs no game files.
  • The switch, renderer ABI, shader, and player-visible checklist items are inapplicable. The original AI assistance is recorded in the commit trailers.

Blocking (to change before merge)

  1. tests/test_oot_glue.py:53: The hot-piece check follows an assertion that patched is byte-for-byte equal to SOURCE. Both splitter calls therefore already receive identical text, and a reintroduced glue declaration fails before the split comparison runs. Remove the duplicate split and rely on the existing hot-piece tests, or give this check inputs that differ in the affected routine and verify the unrelated piece stays identical.

Waiting on the author (a run, a measurement or a decision; no edit does it)

  • The new tests/test_oot_glue.py fixture was introduced by the final fix, and BeanBot reports it was never run. Record a run of the current fixture and full suite or CI at 562e855688, and name any failures reproduced on 80bb1ccc18.
  • The PR still advertises HOS_NATIVE_GLUE and presents old benchmark and test results as support for the change. HEAD only adds a fixture around lift behavior already present on main. Retitle and rewrite the PR as a test-only change, explain the future regression the fixture is meant to catch, and update Testing, Measurements, Risks, and the checklist for this head.

Testing: Read-only review. No builds, tests, or game runs were executed. The author's prior offline comparisons and mixed-tree Windows checks exercised the withdrawn optimization. The final fixture and full suite are unverified on this head.
Overlaps and merge order: PR #1898 was related to the withdrawn native hooks. The remaining test-only diff has no demonstrated merge-order dependency.


Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The native glue optimization is gone, and the remaining fixture checks a path the merge base already provides. Update the PR to describe and justify the test-only change, then validate the current head. Players get the same lifted physics and cloth code as on the merge base. The sole addition is a game-free fixture that could catch a future patch replacing two direct cloth damping calls, at the cost of another C++ compile and executable in the test suite. Its hot-piece comparison duplicates the source-equality assertion. **Since the last review** (on a31c3908e5e1) Resolved: - host/glue_kernels.c:2: The kernels expressly implement the game’s Arm instructions one statement at a time, including register sequencing and scratch results. CONTRIBUTING.md prohibits decompiled game code and anything generated from the dump. Replace these kernels with independently authored code f (The transcribed kernels and header are absent from HEAD. The repository squash-merges the final diff.) - host/oot_glue.c:322: The two probe contexts keep the real SP and guest TLS and access live guest memory. On an error path that sets guest errno, all three calls can reach that store before the FPSR check rejects the key. Stack stores and write tracking also happen during probes, including in check m (host/oot_glue.c and the powf call-site patch are gone. The new fixture checks two calls per invocation and their memory writes at tests/test_oot_glue.py:78.) - host/oot_glue.c:334: Agreement for two register patterns and one real input cannot establish the replay contract. For example, a callee that only writes a scratch byte when x5 is zero passes a fill where all three x5 values are nonzero, then replay misses the write. The same test cannot establish in (nx2/oot_patches.py has no memo splice. Each cloth call goes through the existing lifted path without inferred clobbers or replay.) - host/glue_kernels.c:139: The caller passes &c->n, a pointer to one scalar member. Indexing it to write z, c and v steps outside that member even when the fields are contiguous. Quaternion and nonempty box calls depend on undefined C behavior. Pass the flags as actual output storage or return packed (The kernels and their scalar-member flag indexing are absent from HEAD.) - host/oot_glue.c:149: Check mode excuses every NZCV-only discrepancy as a lift artifact. A quaternion bug that only sets the wrong Z on a zero norm would still yield zero mismatches. Compare flags where the lift guarantees them and validate the others against an independent expected result. Add an NZ (The native glue check mode is gone, including the logic that classified every NZCV-only difference as a lift artifact.) - host/oot_glue.c:84: The six-entry summary goes through hos_log, whose formatting buffer is 1024 bytes. As counters grow, the line can lose the aggregate mismatch suffix that the farm is asked to check. The fixture uses a 2048-byte logger and small counts. Put the aggregate first or log bounded per-r (The glue logger and counters are gone with host/oot_glue.c.) - nx2/oot_patches.py:1454: This forward declaration skips split_hot.py’s declaration filter because it does not use the canonical `void f_…(Ctx *A64_NOESC);` spelling. A hot leaf adds its declaration to every hot piece, changing object inputs even where the leaf is unused. Emit the canonical declarati (nx2/oot_patches.py no longer emits a glue forward declaration. The remaining test's hot-piece comparison is addressed separately.) - nx2/oot_patches.py:1481: The default path pays for changed lift code and an extra exponent branch. With the switch enabled, changing non-unit keys can also turn each miss into three calls, such as in the varying cloth mode. Measure this head alone against its merge base with the switch unset and ena (The hooks, exponent branch, and speculative calls are absent from the delivered diff. The switch A/B, capture-copy, and game build measurements no longer apply.) Still open: - This rebased head has no reported in-game or full CI result. The Windows play run used a mixed tree, and the farm request is stale. Complete the head’s Windows and Linux builds and game checks, including applicable Tier 1 NVIDIA, AMD and Steam Deck coverage, then record the full suite and name any f (The new fixture and current full suite have no reported run. The previous mixed-tree play run and stale farm request no longer apply to the test-only diff.) New: - tests/test_oot_glue.py:53: The hot-piece check follows an assertion that patched is byte-for-byte equal to SOURCE. Both splitter calls therefore already receive identical text, and a reintroduced glue declaration fails before the split comparison runs. Remove the duplicate split and rely on the existing hot-piece tests, or give this check inputs that differ in the affected routine and verify the unrelated piece stays identical. - The PR still advertises HOS_NATIVE_GLUE and presents old benchmark and test results as support for the change. HEAD only adds a fixture around lift behavior already present on main. Retitle and rewrite the PR as a test-only change, explain the future regression the fixture is meant to catch, and update Testing, Measurements, Risks, and the checklist for this head. **Does it help:** Not a perf change at 562e8556884c. The reported 2.7% standing and 2.4% turning CPU reductions came from three Windows runs with nine rewrites enabled in an older tree. The code those runs exercised is absent from the current diff. **Other systems:** The diff changes the game-free test suite on Windows and Linux. It leaves the lift pipeline, game build inputs, guest write tracking, renderer capture, saves, audio, and input identical to the merge base. GPU and Steam Deck game runs are inapplicable to this diff. **Switches:** None in the current diff. HOS_NATIVE_GLUE and its switch-table row are absent at HEAD. **Reviewed:** 562e8556884c against 80bb1ccc182d: Read the current diff, commit messages, AGENTS.md, CONTRIBUTING.md, the Forgejo PR template, relevant standards, and tests/test_oot_glue.py in full. Traced patch_file, the cloth patch targets, hot-piece splitting, and test runner discovery. Compared the earlier and current changed-file sets and read the supplied comments and reviews. Skimmed the historical run reports. The review checklist and adjacent Tooling checkout were absent, and raw runs and the offline harness were unavailable.; nothing run (a code review). **Checked and fine:** - The current diff is limited to one test and adds no game files, generated output, third-party changes, or vendor SDK files. - The synthetic callee checks call order and checks that both writes still happen on the second invocation. - The fixture uses a temporary directory, a local compiler, and its own synthetic executable. It performs no downloads and needs no game files. - The switch, renderer ABI, shader, and player-visible checklist items are inapplicable. The original AI assistance is recorded in the commit trailers. **Blocking** (to change before merge) 1. tests/test_oot_glue.py:53: The hot-piece check follows an assertion that patched is byte-for-byte equal to SOURCE. Both splitter calls therefore already receive identical text, and a reintroduced glue declaration fails before the split comparison runs. Remove the duplicate split and rely on the existing hot-piece tests, or give this check inputs that differ in the affected routine and verify the unrelated piece stays identical. **Waiting on the author** (a run, a measurement or a decision; no edit does it) - The new tests/test_oot_glue.py fixture was introduced by the final fix, and BeanBot reports it was never run. Record a run of the current fixture and full suite or CI at 562e8556884c, and name any failures reproduced on 80bb1ccc182d. - The PR still advertises HOS_NATIVE_GLUE and presents old benchmark and test results as support for the change. HEAD only adds a fixture around lift behavior already present on main. Retitle and rewrite the PR as a test-only change, explain the future regression the fixture is meant to catch, and update Testing, Measurements, Risks, and the checklist for this head. **Testing:** Read-only review. No builds, tests, or game runs were executed. The author's prior offline comparisons and mixed-tree Windows checks exercised the withdrawn optimization. The final fixture and full suite are unverified on this head. **Overlaps and merge order:** PR #1898 was related to the withdrawn native hooks. The remaining test-only diff has no demonstrated merge-order dependency. --- <sub>Automated code review by BeanBot (gpt-6.2-sol), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -0,0 +50,4 @@
parser.add_argument("--cxx", default="c++")
args = parser.parse_args()
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp)
Member

The equality assertion above already guarantees identical splitter inputs. Drop the duplicate split or vary the affected routine so this checks that a real change leaves the unrelated piece intact.

The equality assertion above already guarantees identical splitter inputs. Drop the duplicate split or vary the affected routine so this checks that a real change leaves the unrelated piece intact.
Owner
@fix
Owner

@beanstalk

@beanstalk
Member

Beanstalk test farm

Commit 07150d6 · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `07150d6` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1911) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Member

I changed this pull request as the review asked: the new head is 07150d661d. I rebased it onto main (7486869e64).

Changed

  • Physics leaf fixture, tests/test_oot_glue.py:24: Added definitions for the other three leaves; the existing whole-source equality check verifies that the patcher leaves them unchanged in both builds. Tests were not run.

Not done this time (still open: the next @fix takes it)

  • Guide screenshot check: The branch’s own diff changes only tests/test_oot_glue.py. The reported source and fixture drift involves files changed on the newer base; the branch must be updated and the check rerun before deciding whether a screenshot review is needed.
  • Website build check: The branch predates changes to the graphics guide, menu and website formatter. Update the branch and rerun the check; the supplied log omits the error message needed to identify a separate fix.
  • Description and test-only change: The description still advertises the removed implementation. It needs a complete rewrite for the test-only change, including its testing and measurements; the PR title also needs updating. Restoring the implementation would reverse the earlier review’s requested removal.

Nothing was built or run: check the change. It will be reviewed again.


Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I changed this pull request as the review asked: the new head is 07150d661dd7. I rebased it onto `main` (7486869e64b1). **Changed** - **Physics leaf fixture, tests/test_oot_glue.py:24**: Added definitions for the other three leaves; the existing whole-source equality check verifies that the patcher leaves them unchanged in both builds. Tests were not run. **Not done this time (still open: the next `@fix` takes it)** - **Guide screenshot check**: The branch’s own diff changes only tests/test_oot_glue.py. The reported source and fixture drift involves files changed on the newer base; the branch must be updated and the check rerun before deciding whether a screenshot review is needed. - **Website build check**: The branch predates changes to the graphics guide, menu and website formatter. Update the branch and rerun the check; the supplied log omits the error message needed to identify a separate fix. - **Description and test-only change**: The description still advertises the removed implementation. It needs a complete rewrite for the test-only change, including its testing and measurements; the PR title also needs updating. Restoring the implementation would reverse the earlier review’s requested removal. Nothing was built or run: check the change. It will be reviewed again. --- <sub>Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed perf/native-glue from 562e855688
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
PR description / Description follows the template (pull_request_target) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 16s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Failing after 13s
beanstalk/approval can't be tested as asked: see the farm's comment
to 07150d661d
Some checks failed
beanstalk/approval changed since the request: ask again
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 12s
PR description / Description follows the template (pull_request_target) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 16s
CI / Workflow lint (actionlint) (pull_request) Successful in 16s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Successful in 6m50s
2026-11-21 07:33:27 +00:00
Compare
BeanBot left a comment

Recommendation: Request changes. The head contains only a test, but the pull request describes and measures a native physics optimization that is absent from the diff. The description and title need to reflect what would actually merge.

The change adds a game-free test that checks selected fixture functions remain unchanged by the patcher. It does not change gameplay or improve performance.

@fix will do (2)

  1. L1: The title, summary, switch, testing and measurement claims describe native hooks and a powf memo, but the diff only adds tests/test_oot_glue.py; the claimed host files and HOS_NATIVE_GLUE switch are absent. A maintainer merging this would get no optimization. Rewrite the title and description around the actual test-only change, including the applicable testing and checklist results.
  2. L2 (minor) tests/test_oot_glue.py:66: The split comparison is tautological: the preceding assertion requires patched to equal SOURCE, so both calls split identical input. (more on the line)

Checks: Still running: PR description / Description follows the template (pull_request_target), CI / Conventional Commit title (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request).

More: does it help, other systems, switches, what was read

Does it help: Not a perf change at this head. The reported 2.7% and 2.4% CPU reductions came from an earlier combined test tree and do not measure this test-only diff.

Other systems: No game, renderer, build pipeline, switch, save, audio or input code changes in the diff. The new test runs through the game-free test runner on supported development platforms.

Switches: None added, changed or removed by the diff. HOS_NATIVE_GLUE is described in the pull request but does not exist at this head.

Reviewed: 07150d661d against 7486869e64: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed test and nx2/split_hot.py in full; read the relevant standards, patcher, test runner and compiler helper in context. Reviewed the full diff and commit log. docs/review-checklist.md and the sibling Tooling AGENTS.md were absent. Earlier experimental implementations and recorded run claims were skimmed; no generated files or translations changed.; nothing run (a code review).

Checked and fine:

  • The new fixture contains synthetic values and no apparent game-derived output.
  • No generated files, third-party files, renderer API structures or switch table entries change.
  • The patcher assertion covers both supported and unsupported build modes.

Testing: Read-only review; no tests, builds or project scripts were run. The supplied CI checks are still running.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The head contains only a test, but the pull request describes and measures a native physics optimization that is absent from the diff. The description and title need to reflect what would actually merge. The change adds a game-free test that checks selected fixture functions remain unchanged by the patcher. It does not change gameplay or improve performance. **`@fix` will do (2)** 1. **L1**: The title, summary, switch, testing and measurement claims describe native hooks and a powf memo, but the diff only adds tests/test_oot_glue.py; the claimed host files and HOS_NATIVE_GLUE switch are absent. A maintainer merging this would get no optimization. Rewrite the title and description around the actual test-only change, including the applicable testing and checklist results. 2. **L2** (minor) `tests/test_oot_glue.py:66`: The split comparison is tautological: the preceding assertion requires patched to equal SOURCE, so both calls split identical input. (more on the line) **Checks:** Still running: `PR description / Description follows the template (pull_request_target)`, `CI / Conventional Commit title (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Not a perf change at this head. The reported 2.7% and 2.4% CPU reductions came from an earlier combined test tree and do not measure this test-only diff. **Other systems:** No game, renderer, build pipeline, switch, save, audio or input code changes in the diff. The new test runs through the game-free test runner on supported development platforms. **Switches:** None added, changed or removed by the diff. HOS_NATIVE_GLUE is described in the pull request but does not exist at this head. **Reviewed:** 07150d661dd7 against 7486869e64b1: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed test and nx2/split_hot.py in full; read the relevant standards, patcher, test runner and compiler helper in context. Reviewed the full diff and commit log. docs/review-checklist.md and the sibling Tooling AGENTS.md were absent. Earlier experimental implementations and recorded run claims were skimmed; no generated files or translations changed.; nothing run (a code review). **Checked and fine:** - The new fixture contains synthetic values and no apparent game-derived output. - No generated files, third-party files, renderer API structures or switch table entries change. - The patcher assertion covers both supported and unsupported build modes. **Testing:** Read-only review; no tests, builds or project scripts were run. The supplied CI checks are still running. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
@ -0,0 +63,4 @@
for supported in (False, True):
patched, _, _ = oot_patches.patch_file(SOURCE, "code_hot.c", supported)
assert patched == SOURCE
before = pieces(path / ("before%d" % supported), SOURCE)
Member

L2 (minor): The split comparison is tautological: the preceding assertion requires patched to equal SOURCE, so both calls split identical input. It cannot catch a change to the split that needlessly alters an unrelated piece when another function changes. Remove this comparison or exercise a deliberate change to a different function and check that the unrelated piece stays unchanged.

**L2** (minor): The split comparison is tautological: the preceding assertion requires patched to equal SOURCE, so both calls split identical input. It cannot catch a change to the split that needlessly alters an unrelated piece when another function changes. Remove this comparison or exercise a deliberate change to a different function and check that the unrelated piece stays unchanged.
HumanBean left a comment

Recommendation: Close. At this head the PR changes nothing in the game: its only file is a test checking that the feature in the title is not there. The feature's two parts can't come back as they were. The leaf kernels are the game's routines transcribed one instruction at a time, which the licensing rule forbids. The powf memo ran the game's powf three times on live guest state to infer what it writes.

Why the forge lists one file: the host files aren't missing because of a stack or a capped files API. They were deleted on this branch. The author's four commits (ee4128c6d, d1cd83d44, 998fcbb70, a6768d3e1) add host/glue_kernels.{c,h}, host/oot_glue.c, the nx2/oot_patches.py hooks and the HOS_NATIVE_GLUE row. BeanBot's @fix commit 699a697c3 ("keep physics routines and powf calls lifted") deletes all of them (-1,580 lines), and 07150d661 extends the leftover test. Net against the merge-base 7486869e6: tests/test_oot_glue.py +102 and nothing else. The author's code is still in the branch's history (a6768d3e1) if anyone wants it back. The title, description, measurements and checklist all describe code that is no longer in the diff.

Does it help: Not a perf change at this head (nothing the game runs changes). The numbers in the description (-2.7 % / -2.4 % process CPU in the Market, three runs each, nine branches merged together on main 068fb8eb, Windows/RTX 3090) were for the removed code. They never isolated this PR's own part, and the capture-copy thread rose +10 % / +18 % in those runs.
Other systems: none at this head. The test only runs in the game-free suite (one extra C++ compile and run).
Switches: none at this head. HOS_NATIVE_GLUE (off by default, 1 / check) was removed with the code. It was never measured alone, so no default could be chosen from these numbers.

Reviewed: 07150d661 against 7486869e6 (the merge-base with main): tests/test_oot_glue.py in full. I also read the author's original host/glue_kernels.c (its header and the quaternion kernel) and the powf memo in host/oot_glue.c (the fill, replay and hook) at a6768d3e1. I read the commit messages and every BeanBot review and comment. Nothing run (a code review). I rebased the branch onto main b62932a96 commit by commit and found no conflicts. "Not mergeable" is only the WIP state, so the rebase wasn't pushed.
Fixed in this review: nothing.
Checked and fine: the net diff adds no game files or generated output. The rebase onto current main is conflict-free.

Why not restore the original

  1. host/glue_kernels.c (at a6768d3e1): the file header says "Each kernel below is the routine's instructions in order, one statement each (the Arm instruction is in the comment …)". The quaternion kernel bears that out (/* ldr q19, [x1, #0x20] */, /* ldp q4, q18, [x1] */, register for register). CONTRIBUTING.md's Licensing section rules out "decompiled game code or anything generated from the dump". A hand transcription of the game's machine code is that, whatever the proofs around it. Bit-exactness against the game's own operation order is the whole point of these kernels, so they can't be rewritten "from behaviour" without ending up the same transcription. BeanBot's provenance point holds.
  2. host/oot_glue.c glue_powf_fill (at a6768d3e1): on every new key it calls the lifted powf three times (powf(c); powf(&a); powf(&b);), and the two pattern copies keep the real SP and guest memory. Any store powf makes (its stack frame, or errno on an error path, before the FPSR check rejects the key) happens three times. Which bytes powf writes is inferred from two register patterns, not proven. A write that depends on a register the patterns don't separate would be missed on replay. In the cloth mode where the second argument changes per particle, every call is a miss and costs three powf calls instead of one. The memo isn't game code, so the idea could come back, but only as a new PR with a stated, proven contract for the callee, measured alone, and after #1904 (native powf) settles what that callee is.

What's left isn't worth merging alone: tests/test_oot_glue.py compiles a hand-written stand-in and checks that patch_file leaves five functions untouched and that powf runs twice per call. It guards only against this PR coming back. Main has nothing it could regress. Its split check is circular (BeanBot's L2 at line 57: patched == SOURCE was just asserted).

Testing: none of this head. The author's in-game check run (0 mismatches) and offline Unicorn runs were for the removed code, in a mixed tree. The Beanstalk request was never approved.
Overlaps and merge order: #1904 (libm powf, the callee the memo sat in front of) and #2036 (cloth, the damping it memoised) are the places for a powf/cloth gain. #1898 is the same author's physics-leaf approach under HOS_MATH, and the same provenance question applies to it. Other siblings (#1899, #1900, #1902, #1903, #1905, #1909, #1910, #2001) share gpu/vk/switches.def and nx2/oot_patches.py. At this head this PR touches neither, so it has no merge-order dependency.

**Recommendation: Close.** At this head the PR changes nothing in the game: its only file is a test checking that the feature in the title is *not* there. The feature's two parts can't come back as they were. The leaf kernels are the game's routines transcribed one instruction at a time, which the licensing rule forbids. The powf memo ran the game's powf three times on live guest state to infer what it writes. **Why the forge lists one file:** the host files aren't missing because of a stack or a capped files API. They were deleted on this branch. The author's four commits (ee4128c6d, d1cd83d44, 998fcbb70, a6768d3e1) add `host/glue_kernels.{c,h}`, `host/oot_glue.c`, the `nx2/oot_patches.py` hooks and the `HOS_NATIVE_GLUE` row. BeanBot's `@fix` commit 699a697c3 ("keep physics routines and powf calls lifted") deletes all of them (-1,580 lines), and 07150d661 extends the leftover test. Net against the merge-base 7486869e6: `tests/test_oot_glue.py` +102 and nothing else. The author's code is still in the branch's history (a6768d3e1) if anyone wants it back. The title, description, measurements and checklist all describe code that is no longer in the diff. **Does it help:** Not a perf change at this head (nothing the game runs changes). The numbers in the description (-2.7 % / -2.4 % process CPU in the Market, three runs each, nine branches merged together on main 068fb8eb, Windows/RTX 3090) were for the removed code. They never isolated this PR's own part, and the capture-copy thread rose +10 % / +18 % in those runs. **Other systems:** none at this head. The test only runs in the game-free suite (one extra C++ compile and run). **Switches:** none at this head. `HOS_NATIVE_GLUE` (off by default, `1` / `check`) was removed with the code. It was never measured alone, so no default could be chosen from these numbers. **Reviewed:** 07150d661 against 7486869e6 (the merge-base with main): `tests/test_oot_glue.py` in full. I also read the author's original `host/glue_kernels.c` (its header and the quaternion kernel) and the powf memo in `host/oot_glue.c` (the fill, replay and hook) at a6768d3e1. I read the commit messages and every BeanBot review and comment. Nothing run (a code review). I rebased the branch onto main b62932a96 commit by commit and found no conflicts. "Not mergeable" is only the WIP state, so the rebase wasn't pushed. **Fixed in this review:** nothing. **Checked and fine:** the net diff adds no game files or generated output. The rebase onto current main is conflict-free. **Why not restore the original** 1. `host/glue_kernels.c` (at a6768d3e1): the file header says "Each kernel below is the routine's instructions in order, one statement each (the Arm instruction is in the comment …)". The quaternion kernel bears that out (`/* ldr q19, [x1, #0x20] */`, `/* ldp q4, q18, [x1] */`, register for register). CONTRIBUTING.md's Licensing section rules out "decompiled game code or anything generated from the dump". A hand transcription of the game's machine code is that, whatever the proofs around it. Bit-exactness against the game's own operation order is the whole point of these kernels, so they can't be rewritten "from behaviour" without ending up the same transcription. BeanBot's provenance point holds. 2. `host/oot_glue.c` `glue_powf_fill` (at a6768d3e1): on every new key it calls the lifted powf three times (`powf(c); powf(&a); powf(&b);`), and the two pattern copies keep the real SP and guest memory. Any store powf makes (its stack frame, or errno on an error path, before the FPSR check rejects the key) happens three times. Which bytes powf writes is inferred from two register patterns, not proven. A write that depends on a register the patterns don't separate would be missed on replay. In the cloth mode where the second argument changes per particle, every call is a miss and costs three powf calls instead of one. The memo isn't game code, so the idea could come back, but only as a new PR with a stated, proven contract for the callee, measured alone, and after [#1904](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1904) (native powf) settles what that callee is. **What's left isn't worth merging alone:** `tests/test_oot_glue.py` compiles a hand-written stand-in and checks that `patch_file` leaves five functions untouched and that powf runs twice per call. It guards only against this PR coming back. Main has nothing it could regress. Its split check is circular (BeanBot's L2 at line 57: `patched == SOURCE` was just asserted). **Testing:** none of this head. The author's in-game check run (0 mismatches) and offline Unicorn runs were for the removed code, in a mixed tree. The Beanstalk request was never approved. **Overlaps and merge order:** [#1904](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1904) (libm powf, the callee the memo sat in front of) and [#2036](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2036) (cloth, the damping it memoised) are the places for a powf/cloth gain. [#1898](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1898) is the same author's physics-leaf approach under `HOS_MATH`, and the same provenance question applies to it. Other siblings ([#1899](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1899), [#1900](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1900), [#1902](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1902), [#1903](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1903), [#1905](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1905), [#1909](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1909), [#1910](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1910), [#2001](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2001)) share `gpu/vk/switches.def` and `nx2/oot_patches.py`. At this head this PR touches neither, so it has no merge-order dependency.
@ -0,0 +1,102 @@
"""The physics glue and cloth powf calls remain lifted, with no speculative calls.
Owner

This file is all that is left of the PR: it checks that the glue hooks and the powf memo are absent, which guards only against this PR's own code coming back. The implementation was removed in 699a697c3 (BeanBot's @fix). See the summary for why it can't return as it was.

This file is all that is left of the PR: it checks that the glue hooks and the powf memo are absent, which guards only against this PR's own code coming back. The implementation was removed in 699a697c3 (BeanBot's @fix). See the summary for why it can't return as it was.
Some checks failed
beanstalk/approval changed since the request: ask again
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 12s
PR description / Description follows the template (pull_request_target) Successful in 13s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 16s
CI / Workflow lint (actionlint) (pull_request) Successful in 16s
Third-party parts / As their notes say (pull_request) Successful in 19s
CI / Website build and checks (pull_request) Successful in 6m50s
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/native-glue:snaildev99-perf/native-glue'
git switch 'snaildev99-perf/native-glue'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1911
No description provided.