WIP: perf(host): a model's box and the transform history's rotation step on host code, bit for bit (HOS_NATIVE_BOUNDS, on by default) #1899

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

Summary

Two routines of the game's model bounds run on host code with the game's exact results, behind a new switch, on by default (HOS_NATIVE_BOUNDS=0 gives the lifted code):

  • The model box (f_80ba37a0, 3,444 instructions). It builds a model's box from its meshes' boxes under their bones. For each mesh it puts the local box under each of its bones' matrices (the arithmetic of f_80ba6d80), takes the min / max, adds an optional offset, and unions the result into the model's box. With the box calls it makes, it holds 0.94 % of the game's code time in a Market profile.
  • The transform history's rotation step, a stretch inside f_80021ca0 (0x800232c0 to 0x80023870 / 0x80023890). It takes two 3x3 rotations to quaternions in binary64, the relative rotation by fused multiply-adds, its normalisation and its axis. The acos after it stays lifted. It holds 0.41 % of game code in the Market: 22.6 % of f_80021ca0's own time, part of which is the lift's software binary64 FMA.

Most of both runs on the executors and the module workers. A third piece, the sphere merge f_800a8000, is exact offline and in this branch's host code, but it is not spliced in: against main's form it did not beat its cost with the switch off (BOUNDS_SPHERE_SPLICE = False).

The goal is less CPU work for the same frames. A call the host cannot prove exact runs the lifted routine, with nothing written.

The model box answers a call whole or not at all. It declines when:

  • the float state is not the lift's own open one (FPCR 0 or FZ, FPSR.IXC set);
  • a float operation in any of the four lanes falls outside the lift's own keep rule (FPX1);
  • another function sits in either virtual slot it asks;
  • a mesh takes the per-vertex path;
  • a read overlaps the output box or the frame;
  • an address is outside the guest window.

A done call writes the six words once, marks the page (HOS_WRITTEN), sets NZCV as the game does and leaves x0 as the game does.

The rotation step answers when every binary64 operation passes FPX1, or when an exact-zero fused multiply-add is proven by magnitudes (each operand zero or at least 2^-480). It needs a hardware FMA. It writes every register the stretch writes (d0-d17 and d24-d27 with their upper halves cleared, s11 / s15, x8-x10), the last FCMP's NZCV and the three stack stores.

How: nx2/oot_patches.py (the supported build only) splices the hooks in:

  • the model box: if (hos_bounds_80ba37a0(c, f_80ba37a0)) return; first in f_80ba37a0;
  • the rotation step: a hook after L_800232c0 that jumps to either end, plus exit hooks at both ends for check mode.

f_80ba37a0 and f_800a8000 are declared at file scope, because nx2/split_giants.py may put a hook in a piece written before f_<addr>. The hooks' declarations take A64_NOESC, as the lifted code's own calls do. Guest addresses are checked against the whole 39-bit guest window (hos_guest_range, HOS_SPACE_END). The first version required addresses below 4 GB, and in the game it declined every call; see Testing.

Read first:

  • host/oot_bounds.c: the switch, the counters, check mode.
  • host/bounds_kernels.c: the model box. Its header describes the game's routine.
  • host/bounds_rot.c: the rotation step.
  • nx2/oot_patches.py: patch_bounds_native, patch_bounds_rot, BOUNDS_SPHERE_SPLICE.
  • tests/test_bounds_kernels.py, tests/test_oot_bounds.py.
  • The row in gpu/vk/switches.def.

Testing

Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. This code ran in the game in test trees on main 068fb8eb that merge nine rewrite branches, as follows.

  • The first check run, before the fix (HOS_NATIVE_BOUNDS=check, the Market and Hyrule Field, about five minutes): the hooks answered nothing.
    • The model box declined 153,522 of 153,525 calls for their address.
    • The rotation step declined all 449,808 the same way.
    • The cause: the code took the vendored a64.h's 32-bit guest pointer for the game's. The game's build widens it to a 39-bit window, with the heap at 64 GB and the thread stacks near 2^39.
    • Fixed in 142cc160 here (69c7351d on the session's branch). tests/test_oot_bounds.py now runs its fixture with the guest window at 0, at 64 GB and just below 2^39, and fails on any address decline there. The old code fails it.
  • After the fix, with the switch on (test/rewrites @ e614ef49, in the CPU measurement below, every other rewrite on; all 15 runs held 60 fps):
    • the model box answered 191,487 of 191,488 calls;
    • the rotation step answered 667,648 of 667,648.
  • Check mode has not been run since the fix, so in the game nothing has been compared yet.
  • This head is not built or played.

Exactness offline. Unicorn runs the game's own routine on the executable, and a driver runs the real host files.

  • The model box:
    • 800,000 calls, 752,934 compared and 442,797 done natively by the FMA build. 0 mismatches in six builds (x86-64-v3, v2 and x86-64, each with the SSE and the plain C kernels).
    • Compared on every native call: every memory region of the case, FPSR, NZCV, x19-x30, SP and q8-q15 (128 bits). Every declined call wrote nothing.
    • The cases: realistic models (1 to 24 meshes, 0 to 40 bones), empty models and meshes, offsets, NaNs, infinities, zeros, subnormals and the extreme normals anywhere, half-integer models with signed zeros and ties, the output over the model, a box, a record or a matrix, the other virtual slots, the per-vertex path. Every FPCR and FPSR setting was tried.
    • After the inlining change: 240,000 more calls, 0 mismatches.
    • After the x0 change: 200,000 more, 0 mismatches.
  • The rotation step:
    • 240,000 states, 184,566 answered, 0 mismatches in every x register, SP, all q registers (128 bits), NZCV, FPSR and the stack and object blocks.
    • The states: nearby, still, identity, quarter and half turns, tiny angles and edge values.
    • Exit 2 (w > 1 after rounding) was reached 5 times.
  • Above 4 GB, after the fix:
    • data at 64 GB with FZ in every call, and just below 2^39 with mixed FPCR;
    • the model box: 188,265 compared, 116,130 native;
    • the rotation step: 120,000, 97,521 native;
    • 0 mismatches.
  • Deliberately broken versions are caught (121 to 3,109 mismatching cases of 4,000):
    • an unfused multiply-add;
    • a dropped max;
    • a wrong NZCV bit;
    • a wrong offset lane;
    • a dropped negation;
    • an upper half not cleared.
  • Not run again at this head. The host files are byte for byte the ones proven above (session head 6171f3d6). The upkeep commit changes only the hooks' declarations in the lifted file, which the harness does not compile: its driver calls the hooks directly.

Game-free checks at this head:

  • tests/test_bounds_kernels.py and tests/test_oot_bounds.py pass. They cover:
    • both kernels against references;
    • the hooks off, on and in check mode;
    • the guest window at three places;
    • each splice once, on the supported build only;
    • the declarations before the code;
    • no other function hooked.
  • tests/test_switch_table.py, tests/test_patch_hooks_defined.py, test_log_levels, test_utf8_paths, test_doc_anchors, test_check_third_party and test_env_on pass.
  • 36 of the other 41 tests that read nx2/oot_patches.py or nx2/entry_hooks.py pass. The other five fail here and on main a104182b alike: test_dev_packs, test_high_fps_fixes, test_libc_hooks, test_lift_cache, test_song_note_cue.
  • tests/run_all.py was not run.

Still to test:

  • This head on Windows: HOS_NATIVE_BOUNDS=check in the Market and Hyrule Field. Expect oot: bounds (HOS_NATIVE_BOUNDS=check) lines with calls taken natively and MISMATCHES 0, and no oot: bounds: MISMATCH line. Then =1: no model missing, popping or wrongly lit at the screen's edges (by hand).
  • Linux and an AMD GPU: the child Market and Hyrule Field by day, a few minutes each. Compare this branch with HOS_NATIVE_BOUNDS=0 against unset (on), and main against this branch with the switch unset. Measure the game's CPU seconds with the frame rate capped at 60, standing and turning, and the frame times uncapped. Expect less CPU time with the switch on, the same frame rate or better, no cost with it =0, and the picture as without it (@Beanstalk linux, amd).

Measurements

Verdict: less CPU work, measured together with the other rewrite branches, not yet alone. In a test tree that merges nine rewrite branches (named in the baseline below; the cloth and particle effect rewrites and some later pieces are not among them), at a 60 fps cap in the Market:

  • Those nine on used 2.7 % less CPU standing and 2.4 % less turning (the whole process) than main.
  • With the float fallback change of another branch on top: -3.7 % / -3.0 %.
  • The hooks in with every switch off cost nothing measurable: -0.3 % / -0.2 %.

How much of that is this branch is not separated. The Test Farm request asks for this branch's own number.

Baseline: main 068fb8eb (#1802) against the test tree test/rewrites @ e614ef49. That tree is main 068fb8eb with nine rewrite branches merged (not every rewrite there is: the cloth and particle effect branches were not in it): the seven maths units, the maths library, animation, this branch at 6171f3d6 (before the A64_NOESC declarations), crowd, visibility, glue, the effect triggers with the reverb, and the solver. It was lifted with A64_FPXKEEP=0, so that the lift is main's apart from the hooks. It is not this PR alone: the run-time switches were all on together. Main has moved since 068fb8eb; this branch was not measured on current main.
Setup: Windows 11, Ryzen 9 5900X, RTX 3090, 3840x2160; the child Market, hands-free; frame rate capped at 60 (all 15 runs held 60). Each run: 30 s standing, then 30 s turning the camera. Five variants, interleaved over three rounds, the PC otherwise idle. The figure: CPU seconds per second of play (cores busy on average) of the whole process, from the processor's cycle counter; the median of three runs (the three in brackets).

Before: main @ 068fb8eb After, every switch off: test/rewrites @ e614ef49 After, the nine branches on: test/rewrites @ e614ef49 Δ off Δ on
Market standing, cores 5.156 [5.144 5.156 5.161] 5.140 [5.303 5.140 5.125] 5.017 [5.007 5.017 5.049] -0.3 % -2.7 %
Market turning, cores 5.639 [5.676 5.627 5.639] 5.630 [5.722 5.630 5.628] 5.504 [5.504 5.498 5.577] -0.2 % -2.4 %

The off figures are inside the runs' spread. The process includes the renderer's threads (about 1.4 cores standing), which the rewrites do not touch. With the nine on: the executors -4.1 % / -4.0 %; the module workers, where the rotation step runs, 0.847 to 0.844 cores standing and 0.884 to 0.875 turning (they also run other rewrites' routines).

Offline: CPU time a call, not the game. Ryzen 9 5900X, best of 7. Main's form is the lift with registers as C locals that main writes, approximated from the stock lift by the translator kit's localize pass (not main's lifter). A spliced function is written in the older context form, and "switch off" is that form plus the hook. The switch-off column was measured before the declarations took A64_NOESC.

piece main's form (approximated) switch off this PR, switch on factor against main's form
model box, 4 meshes x 16 bones 7,866 ns 7,739 ns 791 ns 9.9x
model box, 8 x 8 / 3 x 40 / 2 x 4 7,714 / 13,676 / 1,146 ns 7,755 / 15,134 / 1,162 ns 880 / 2,023 / 164 ns 8.8x / 6.8x / 7.0x
model box, a one-bone mesh 157 ns 146 ns 54 ns 2.9x
rotation step, moving / still / mixed objects 660 / 976 / 1,075 ns 630 / 951 / 1,066 ns 262 / 200 / 292 ns 2.5x / 4.9x / 3.7x

The sphere merge was 0.88x (copy path) and 1.3x (merge path) against main's form, so it stays unspliced.

The rotation splice puts the whole of f_80021ca0 into the old form. Its other 77 % (pointer chasing and logic) is where main's locals help most, and that is not measurable offline. If main's locals save more than about 21 % of that remainder, the splice loses. The game measurement above found no off cost at the process's scale, but only this branch's own farm number settles it.

The switch

HOS_NATIVE_BOUNDS (new, run time, kill, on by default): 0 off (the lifted routines, main's results); unset or 1 on (host code where it is exact, the rest lifted).

check runs both on every call. The game keeps the lifted result. The first difference logs oot: bounds: MISMATCH (the first) in ....

Every 10 s a line counts the calls:

oot: bounds (HOS_NATIVE_BOUNDS=1) model box f_80ba37a0: calls N (native N, lifted N: FPCR/FPSR, range, alias, virtual, per-vertex, float, path), meshes and boxes native; rotation step f_80021ca0: calls N (native N, lifted N: ...); sphere merge f_800a8000: calls 0 ...

In check mode the line adds compared N, MISMATCHES 0. The row in gpu/vk/switches.def still names the sphere merge, whose host code is here unspliced. It ships on: docs/dev/standards.md has a switch ship at its value from the first push, never off because it is new, and the measurement with the rewrite branches together says on. HOS_NATIVE_BOUNDS=0 gives main's lifted code. This PR's own measurement (the farm request) can still turn it off before it leaves WIP.

Risks

What could break: a wrong model box would show as a model culled while on screen, or drawn and lit with the wrong bounds. A wrong rotation step would feed the transform history a wrong angle. In the game nothing has been compared since the fix. The check run in Still to test is the next step.

Open: in the CPU measurement, the renderer's mkw_vk capture copy thread used 10 to 18 % more CPU (0.009 to 0.017 cores), in both variants with the rewrites on and in neither without. That thread copies guest memory the game marked as written, and the native kernels mark what they write (HOS_WRITTEN; here the model box's output page). Which rewrite causes it is not determined; this branch is one of several candidates.

Turning it off: HOS_NATIVE_BOUNDS=0.

After updating: the game is translated again once (nx2/oot_patches.py is in the lift's key). The routines run on the host by default, with the game's exact results; saves, longshot_options.ini and the caches do not change.

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. (Run on in a merged test tree on main 068fb8eb after the fix; check mode not since the fix; this head is not built or played.)
  • mise run test passes (any failure that also fails on main is named). (The tests that read the changed files pass, apart from five that fail on main a104182b too; the whole suite not run.)
  • Measured against main, or Measurements says why there is nothing to measure. (Measured with the other rewrite branches merged; this branch alone not yet.)
  • 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; on by default, =0 gives main's lifted code; this PR's own measurement can still turn it off.)
  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_bounds_kernels.py and tests/test_oot_bounds.py, new; they find functions by their head lines.)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the merged test tree. 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 Two routines of the game's model bounds run on host code with the game's exact results, behind a new switch, on by default (`HOS_NATIVE_BOUNDS=0` gives the lifted code): - **The model box (f_80ba37a0, 3,444 instructions).** It builds a model's box from its meshes' boxes under their bones. For each mesh it puts the local box under each of its bones' matrices (the arithmetic of f_80ba6d80), takes the min / max, adds an optional offset, and unions the result into the model's box. With the box calls it makes, it holds 0.94 % of the game's code time in a Market profile. - **The transform history's rotation step**, a stretch inside f_80021ca0 (0x800232c0 to 0x80023870 / 0x80023890). It takes two 3x3 rotations to quaternions in binary64, the relative rotation by fused multiply-adds, its normalisation and its axis. The acos after it stays lifted. It holds 0.41 % of game code in the Market: 22.6 % of f_80021ca0's own time, part of which is the lift's software binary64 FMA. Most of both runs on the executors and the module workers. A third piece, the sphere merge f_800a8000, is exact offline and in this branch's host code, but it is not spliced in: against main's form it did not beat its cost with the switch off (`BOUNDS_SPHERE_SPLICE = False`). The goal is less CPU work for the same frames. A call the host cannot prove exact runs the lifted routine, with nothing written. The model box answers a call whole or not at all. It declines when: - the float state is not the lift's own open one (FPCR 0 or FZ, FPSR.IXC set); - a float operation in any of the four lanes falls outside the lift's own keep rule (FPX1); - another function sits in either virtual slot it asks; - a mesh takes the per-vertex path; - a read overlaps the output box or the frame; - an address is outside the guest window. A done call writes the six words once, marks the page (`HOS_WRITTEN`), sets NZCV as the game does and leaves x0 as the game does. The rotation step answers when every binary64 operation passes FPX1, or when an exact-zero fused multiply-add is proven by magnitudes (each operand zero or at least 2^-480). It needs a hardware FMA. It writes every register the stretch writes (d0-d17 and d24-d27 with their upper halves cleared, s11 / s15, x8-x10), the last FCMP's NZCV and the three stack stores. How: `nx2/oot_patches.py` (the supported build only) splices the hooks in: - the model box: `if (hos_bounds_80ba37a0(c, f_80ba37a0)) return;` first in f_80ba37a0; - the rotation step: a hook after `L_800232c0` that jumps to either end, plus exit hooks at both ends for check mode. f_80ba37a0 and f_800a8000 are declared at file scope, because `nx2/split_giants.py` may put a hook in a piece written before `f_<addr>`. The hooks' declarations take `A64_NOESC`, as the lifted code's own calls do. Guest addresses are checked against the whole 39-bit guest window (`hos_guest_range`, `HOS_SPACE_END`). The first version required addresses below 4 GB, and in the game it declined every call; see Testing. Read first: - `host/oot_bounds.c`: the switch, the counters, check mode. - `host/bounds_kernels.c`: the model box. Its header describes the game's routine. - `host/bounds_rot.c`: the rotation step. - `nx2/oot_patches.py`: `patch_bounds_native`, `patch_bounds_rot`, `BOUNDS_SPHERE_SPLICE`. - `tests/test_bounds_kernels.py`, `tests/test_oot_bounds.py`. - The row in `gpu/vk/switches.def`. ## Testing **Tested:** Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. This code ran in the game in test trees on main 068fb8eb that merge nine rewrite branches, as follows. - **The first check run, before the fix** (`HOS_NATIVE_BOUNDS=check`, the Market and Hyrule Field, about five minutes): the hooks answered nothing. - The model box declined 153,522 of 153,525 calls for their address. - The rotation step declined all 449,808 the same way. - The cause: the code took the vendored `a64.h`'s 32-bit guest pointer for the game's. The game's build widens it to a 39-bit window, with the heap at 64 GB and the thread stacks near 2^39. - Fixed in 142cc160 here (69c7351d on the session's branch). `tests/test_oot_bounds.py` now runs its fixture with the guest window at 0, at 64 GB and just below 2^39, and fails on any address decline there. The old code fails it. - **After the fix**, with the switch on (`test/rewrites` @ e614ef49, in the CPU measurement below, every other rewrite on; all 15 runs held 60 fps): - the model box answered 191,487 of 191,488 calls; - the rotation step answered 667,648 of 667,648. - Check mode has not been run since the fix, so in the game nothing has been compared yet. - This head is not built or played. Exactness offline. Unicorn runs the game's own routine on the executable, and a driver runs the real host files. - **The model box:** - 800,000 calls, 752,934 compared and 442,797 done natively by the FMA build. 0 mismatches in six builds (x86-64-v3, v2 and x86-64, each with the SSE and the plain C kernels). - Compared on every native call: every memory region of the case, FPSR, NZCV, x19-x30, SP and q8-q15 (128 bits). Every declined call wrote nothing. - The cases: realistic models (1 to 24 meshes, 0 to 40 bones), empty models and meshes, offsets, NaNs, infinities, zeros, subnormals and the extreme normals anywhere, half-integer models with signed zeros and ties, the output over the model, a box, a record or a matrix, the other virtual slots, the per-vertex path. Every FPCR and FPSR setting was tried. - After the inlining change: 240,000 more calls, 0 mismatches. - After the x0 change: 200,000 more, 0 mismatches. - **The rotation step:** - 240,000 states, 184,566 answered, 0 mismatches in every x register, SP, all q registers (128 bits), NZCV, FPSR and the stack and object blocks. - The states: nearby, still, identity, quarter and half turns, tiny angles and edge values. - Exit 2 (w > 1 after rounding) was reached 5 times. - **Above 4 GB, after the fix:** - data at 64 GB with FZ in every call, and just below 2^39 with mixed FPCR; - the model box: 188,265 compared, 116,130 native; - the rotation step: 120,000, 97,521 native; - 0 mismatches. - **Deliberately broken versions are caught** (121 to 3,109 mismatching cases of 4,000): - an unfused multiply-add; - a dropped max; - a wrong NZCV bit; - a wrong offset lane; - a dropped negation; - an upper half not cleared. - **Not run again at this head.** The host files are byte for byte the ones proven above (session head 6171f3d6). The upkeep commit changes only the hooks' declarations in the lifted file, which the harness does not compile: its driver calls the hooks directly. Game-free checks at this head: - `tests/test_bounds_kernels.py` and `tests/test_oot_bounds.py` pass. They cover: - both kernels against references; - the hooks off, on and in check mode; - the guest window at three places; - each splice once, on the supported build only; - the declarations before the code; - no other function hooked. - `tests/test_switch_table.py`, `tests/test_patch_hooks_defined.py`, `test_log_levels`, `test_utf8_paths`, `test_doc_anchors`, `test_check_third_party` and `test_env_on` pass. - 36 of the other 41 tests that read `nx2/oot_patches.py` or `nx2/entry_hooks.py` pass. The other five fail here and on main a104182b alike: `test_dev_packs`, `test_high_fps_fixes`, `test_libc_hooks`, `test_lift_cache`, `test_song_note_cue`. - `tests/run_all.py` was not run. **Still to test:** - This head on Windows: `HOS_NATIVE_BOUNDS=check` in the Market and Hyrule Field. Expect `oot: bounds (HOS_NATIVE_BOUNDS=check)` lines with calls taken natively and `MISMATCHES 0`, and no `oot: bounds: MISMATCH` line. Then `=1`: no model missing, popping or wrongly lit at the screen's edges (by hand). - Linux and an AMD GPU: the child Market and Hyrule Field by day, a few minutes each. Compare this branch with `HOS_NATIVE_BOUNDS=0` against unset (on), and main against this branch with the switch unset. Measure the game's CPU seconds with the frame rate capped at 60, standing and turning, and the frame times uncapped. Expect less CPU time with the switch on, the same frame rate or better, no cost with it `=0`, and the picture as without it (@Beanstalk linux, amd). ## Measurements **Verdict:** less CPU work, measured together with the other rewrite branches, not yet alone. In a test tree that merges nine rewrite branches (named in the baseline below; the cloth and particle effect rewrites and some later pieces are not among them), at a 60 fps cap in the Market: - Those nine on used 2.7 % less CPU standing and 2.4 % less turning (the whole process) than main. - With the float fallback change of another branch on top: -3.7 % / -3.0 %. - The hooks in with every switch off cost nothing measurable: -0.3 % / -0.2 %. How much of that is this branch is not separated. The Test Farm request asks for this branch's own number. Baseline: main 068fb8eb (#1802) against the test tree `test/rewrites` @ e614ef49. That tree is main 068fb8eb with nine rewrite branches merged (not every rewrite there is: the cloth and particle effect branches were not in it): the seven maths units, the maths library, animation, this branch at 6171f3d6 (before the `A64_NOESC` declarations), crowd, visibility, glue, the effect triggers with the reverb, and the solver. It was lifted with `A64_FPXKEEP=0`, so that the lift is main's apart from the hooks. It is not this PR alone: the run-time switches were all on together. Main has moved since 068fb8eb; this branch was not measured on current main. Setup: Windows 11, Ryzen 9 5900X, RTX 3090, 3840x2160; the child Market, hands-free; frame rate capped at 60 (all 15 runs held 60). Each run: 30 s standing, then 30 s turning the camera. Five variants, interleaved over three rounds, the PC otherwise idle. The figure: CPU seconds per second of play (cores busy on average) of the whole process, from the processor's cycle counter; the median of three runs (the three in brackets). | | Before: main @ 068fb8eb | After, every switch off: test/rewrites @ e614ef49 | After, the nine branches on: test/rewrites @ e614ef49 | Δ off | Δ on | |---|---|---|---|---|---| | Market standing, cores | 5.156 [5.144 5.156 5.161] | 5.140 [5.303 5.140 5.125] | 5.017 [5.007 5.017 5.049] | -0.3 % | -2.7 % | | Market turning, cores | 5.639 [5.676 5.627 5.639] | 5.630 [5.722 5.630 5.628] | 5.504 [5.504 5.498 5.577] | -0.2 % | -2.4 % | The off figures are inside the runs' spread. The process includes the renderer's threads (about 1.4 cores standing), which the rewrites do not touch. With the nine on: the executors -4.1 % / -4.0 %; the module workers, where the rotation step runs, 0.847 to 0.844 cores standing and 0.884 to 0.875 turning (they also run other rewrites' routines). Offline: CPU time a call, not the game. Ryzen 9 5900X, best of 7. Main's form is the lift with registers as C locals that main writes, approximated from the stock lift by the translator kit's `localize` pass (not main's lifter). A spliced function is written in the older context form, and "switch off" is that form plus the hook. The switch-off column was measured before the declarations took `A64_NOESC`. | piece | main's form (approximated) | switch off | this PR, switch on | factor against main's form | |---|---|---|---|---| | model box, 4 meshes x 16 bones | 7,866 ns | 7,739 ns | 791 ns | 9.9x | | model box, 8 x 8 / 3 x 40 / 2 x 4 | 7,714 / 13,676 / 1,146 ns | 7,755 / 15,134 / 1,162 ns | 880 / 2,023 / 164 ns | 8.8x / 6.8x / 7.0x | | model box, a one-bone mesh | 157 ns | 146 ns | 54 ns | 2.9x | | rotation step, moving / still / mixed objects | 660 / 976 / 1,075 ns | 630 / 951 / 1,066 ns | 262 / 200 / 292 ns | 2.5x / 4.9x / 3.7x | The sphere merge was 0.88x (copy path) and 1.3x (merge path) against main's form, so it stays unspliced. The rotation splice puts the whole of f_80021ca0 into the old form. Its other 77 % (pointer chasing and logic) is where main's locals help most, and that is not measurable offline. If main's locals save more than about 21 % of that remainder, the splice loses. The game measurement above found no off cost at the process's scale, but only this branch's own farm number settles it. ### The switch `HOS_NATIVE_BOUNDS` (new, run time, `kill`, on by default): `0` off (the lifted routines, main's results); unset or `1` on (host code where it is exact, the rest lifted). `check` runs both on every call. The game keeps the lifted result. The first difference logs `oot: bounds: MISMATCH (the first) in ...`. Every 10 s a line counts the calls: ``` oot: bounds (HOS_NATIVE_BOUNDS=1) model box f_80ba37a0: calls N (native N, lifted N: FPCR/FPSR, range, alias, virtual, per-vertex, float, path), meshes and boxes native; rotation step f_80021ca0: calls N (native N, lifted N: ...); sphere merge f_800a8000: calls 0 ... ``` In check mode the line adds `compared N, MISMATCHES 0`. The row in `gpu/vk/switches.def` still names the sphere merge, whose host code is here unspliced. It ships on: docs/dev/standards.md has a switch ship at its value from the first push, never off because it is new, and the measurement with the rewrite branches together says on. `HOS_NATIVE_BOUNDS=0` gives main's lifted code. This PR's own measurement (the farm request) can still turn it off before it leaves WIP. ## Risks **What could break:** a wrong model box would show as a model culled while on screen, or drawn and lit with the wrong bounds. A wrong rotation step would feed the transform history a wrong angle. In the game nothing has been compared since the fix. The check run in Still to test is the next step. Open: in the CPU measurement, the renderer's `mkw_vk capture copy` thread used 10 to 18 % more CPU (0.009 to 0.017 cores), in both variants with the rewrites on and in neither without. That thread copies guest memory the game marked as written, and the native kernels mark what they write (`HOS_WRITTEN`; here the model box's output page). Which rewrite causes it is not determined; this branch is one of several candidates. **Turning it off:** `HOS_NATIVE_BOUNDS=0`. **After updating:** the game is translated again once (`nx2/oot_patches.py` is in the lift's key). The routines run on the host by default, with the game's exact results; saves, `longshot_options.ini` and the caches do not change. ## 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. (Run on in a merged test tree on main 068fb8eb after the fix; check mode not since the fix; this head is not built or played.) - [ ] `mise run test` passes (any failure that also fails on `main` is named). (The tests that read the changed files pass, apart from five that fail on main a104182b too; the whole suite not run.) - [ ] Measured against `main`, or Measurements says why there is nothing to measure. (Measured with the other rewrite branches merged; this branch alone not yet.) - [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; on by default, `=0` gives main's lifted code; this PR's own measurement can still turn it off.) - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_bounds_kernels.py` and `tests/test_oot_bounds.py`, new; they find functions by their head lines.) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: in the merged test tree. 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)
f_80ba37a0 (virtual slot 0x2f0 of three model classes, called per model
by the bounds pass f_831e65d0) builds a model's axis-aligned box: per
mesh, its local box under each of its bones' matrices (the box
transform f_80ba6d80, inlined here), min / max into one box, an
optional offset, then the union into the output. host/bounds_kernels.c
does the same in plain C and on SSE2 (+ FMA3 where the build targets
it; the fused multiply-add otherwise in binary64, declining at a
binary32 midpoint as the lift's own FPX1 does), and answers a call
only when every float operation of it, all four lanes, passes the
lift's FPX1 keep rule (then IEEE gives the Arm bits and Arm raises no
flag but IXC). A call is declined whole, having written nothing, for
another function in either virtual slot the routine asks, a per-vertex
mesh, a read overlapping the output box or the routine's frame, or an
address past 4 GB. The kernel only reads: the caller stores the six
words.

tests/test_bounds_kernels.py: the box transform, SSE and plain C,
against a model of the game's instructions (each FMLA one rounding of
the exact product-sum, by round-to-odd in binary64); the whole routine
against a model of it over a guest window; the declines; built for
this CPU, x86-64-v2, x86-64 and with -ffp-contract=on. Nothing is
wired here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nx2/oot_patches.py (supported build only) puts
"if (hos_bounds_80ba37a0(c, f_80ba37a0)) return;" first in the lifted
f_80ba37a0, once; report() warns when it was not hooked once.

host/oot_bounds.c answers it, read once from HOS_NATIVE_BOUNDS:
- unset / 0: the hook returns at once, the lifted code runs;
- 1: the call on the host when the kernel can prove the game's bits,
  under the lift's own gate for native float (RECOMP_FPX_OPEN); the six
  words at x1 written once and their page marked (HOS_WRITTEN), NZCV
  as the routine's last CMP leaves it; otherwise the lifted routine;
- check: the kernel (which only reads), then the lifted routine for
  real, then the six words, FPSR, x19-x30, SP and v8-v15 compared (the
  lifted result is kept); the first mismatch is logged with its detail.
An "oot: bounds" line every 10 s counts the calls (native, lifted and
why, meshes and boxes, compared, MISMATCHES). A row in
gpu/vk/switches.def.

tests/test_oot_bounds.py: the splice (once, first, supported build
only, idempotent, the warning) and the hook over a guest window of its
own: off, on (answers, marks, NZCV, declines that write nothing) and
check (an exact lift passes, a word off is a mismatch).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clang kept the per-lane class checks (v_bad_mul, v_bad_fma, ...) out of
line on Windows x64, a call with spilled vector registers for every
operation of every box: the kernel took ~44 ns a box. Inlined, ~19 ns
(offline bench, Ryzen 9 5900X); the same instructions, the same bits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The transform history f_80021ca0 (the area's largest routine) does all
of its binary64 maths in one stretch, from the label L_800232c0 to the
call of acos at L_80023870 (or L_80023890): two 3x3 rotations (the
previous and the latest transform) to quaternions by the trace method
(four cases each), their relative rotation by fused multiply-adds, its
normalisation, w >= 0 and the axis. host/bounds_rot.c does the same on
the host: every register the stretch writes (binary64, upper halves
cleared), x8-x10, NZCV of its last FCMP and its three stack stores.
It answers only under the lift's float gate and when every operation
keeps the lift's FPX1 rule, or is a fused multiply-add whose zero
result is proven exact by its operands' magnitudes (each zero or at
least 2^-480): the lift sends those to its software body, and still
objects (identity relative rotations) make them often. The game's
error report, a NaN root and an infinite norm stay lifted. Needs a
hardware FMA (FMA3, AArch64); without one every call is declined.

nx2/oot_patches.py: the hook after L_800232c0 (it jumps to either end)
and an exit hook after L_80023870 / L_80023890 for check mode, the
supported build only, a function missing a label left as lifted with a
warning. host/oot_bounds.c: the answer, check mode at the exits, its
counts on the oot: bounds line.

The model box hook now leaves x0 as the game does (the last mesh's
shape, or SP - 0x180 after a box); of the 46 call sites of a slot
0x2f0, the 13 that read a scratch register after the call use it as a
return value and pass no output box (other classes' slot).

tests: the rotation step's known cases and declines; the splices and
the hook off / on / check; x0 in both model box tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
f_800a8000 merges two bounding spheres (a four-lane centre and a
radius): when one lies inside the other the larger is copied, 32 bytes
in the game's own load / store order, else the merged sphere (centre
along the centres' line, radius (d + rA + rB) / 2). The bounds pass
f_831e65d0 calls it per mesh (into its first sphere), and so do the
per-model calc f_8009bb80 and two others. host/bounds_sphere.c does it
in plain C under the lift's float gate and FPX1 rule (all four lanes;
lane 3 of the centres counts in the distance), leaving v0-v5, x8 (x9,
x10 on the copy path) and NZCV as the routine does; a NaN root (the
library sqrtf) and anything out of the class stay lifted. Callers read
no other register it could have touched (f_8009bb80 reads x3, x13, v7
after the call: its own).

host/oot_bounds.c: the hook first in the lifted function (nx2/
oot_patches.py), check mode on a copy of the spheres (the lifted result
kept, every byte and register compared), counts on the oot: bounds
line. f_800a8400 (the perf session's sphere) and f_80ba6d80 are not
touched: the bounds pass still calls them, native or not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first check run (the merged test build, the Market and Hyrule
Field) answered no call: the model box and the rotation step declined
every one for "range", the sphere merge all but three with no reason
counted. The kernels and hooks took the vendored a64.h's 32-bit
A64_PTR for the game's: they required every address below 4 GB. The
game's build has nx2/rtgen.py's A64_ADDR64 (A64_MEM + the 64-bit
address over the 39-bit window): its heap starts at 64 GB
(HOS_HEAP_BASE) and the threads' stacks sit near the top.

- The model box kernel checks its accesses against the window's end
  (BoundsBox.end, HOS_SPACE_END in Longshot), not 4 GB.
- The rotation step and the sphere merge hooks check their memory with
  hos_guest_range alone (their extra "below 4 GB" tests are gone).
- The sphere merge counts every way out (FPCR/FPSR, float, range,
  spheres too far apart to copy in check mode), and the line shows them.
- The entry hooks declare the function they pass (f_80ba37a0,
  f_800a8000): main's split_giants.py writes a giant function's pieces
  before f_<addr> (the merged branch carried this already).

tests/test_oot_bounds.py runs its hook fixture with the guest window at
0, at the heap base (64 GB) and just below the top of the window, and
fails if any call there is declined for range (the old code fails it).
tests/test_bounds_kernels.py: the range declines past the window's end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measured offline against main's locals form (an approximation made by
localize.py from the stock text), with the 64-byte copy-in on every
side: the copy path 45.6 ns native against 40.2 in main's form, the
merge path 63.4 against 82.1 (1.3x), for 0.04 % of game code. The
brief's rule: a piece that does not beat main's form by more than its
off cost stays unwired. BOUNDS_SPHERE_SPLICE (off) keeps the splice
code; the host side and its tests stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(lift): HOS_NATIVE_BOUNDS' hooks declare their context A64_NOESC
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Description follows the template (pull_request_target) Successful in 17s
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
2e7be224ec
The lifted functions' own context parameter is A64_NOESC; the bounds hooks were declared `extern int
hos_bounds_<x>(Ctx *c, ...)`, so the compiler had to take the context for escaped at the hook's call, in the hooked
function's code whether the switch is on or not. hos_bounds_80ba37a0, hos_bounds_800a8000 (declared, not spliced),
hos_bounds_80021ca0_rot and hos_bounds_80021ca0_rot_exit now take `Ctx *A64_NOESC c`, as the lifted code's own calls do.
The functions the hooks pass (f_80ba37a0, f_800a8000) were already declared at file scope.

tests/test_oot_bounds.py finds the other functions by their head line `void f_<addr>(Ctx *__restrict A64_NOESC c) {`,
not their first mention.

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

Tested in game: Ran in the game in merged test trees of the rewrite branches on main 068fb8eb (Windows, RTX 3090): the first check run found its hooks declining every call for their address (fixed for the 39-bit guest window), and after the fix, switched on in a 15-run CPU measurement at a 60 fps cap (every run held 60), the model box answered 191,487 of 191,488 calls and the rotation step 667,648 of 667,648; check mode has not been run since the fix, and this head itself is not built or played.

Tested in game: Ran in the game in merged test trees of the rewrite branches on main 068fb8eb (Windows, RTX 3090): the first check run found its hooks declining every call for their address (fixed for the 39-bit guest window), and after the fix, switched on in a 15-run CPU measurement at a 60 fps cap (every run held 60), the model box answered 191,487 of 191,488 calls and the rotation step 667,648 of 667,648; check mode has not been run since the fix, and this head itself is not built or played.
Author
Contributor

@Beanstalk linux, and amd: this branch with HOS_NATIVE_BOUNDS unset against HOS_NATIVE_BOUNDS=1 (the same build), and main against this branch with the switch unset, each in the child Market for a few minutes and in Hyrule Field by day for a few minutes. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), standing and turning the camera, and the frame times uncapped. Expect less CPU time with the switch at 1, the same frame rate or better, no extra CPU time with the switch unset against main, the picture as without the switch (no model missing or popping at the screen's edges), an "oot: bounds (HOS_NATIVE_BOUNDS=1)" line in the log with calls taken natively, and no "MISMATCH" in the log.

@Beanstalk linux, and amd: this branch with HOS_NATIVE_BOUNDS unset against HOS_NATIVE_BOUNDS=1 (the same build), and main against this branch with the switch unset, each in the child Market for a few minutes and in Hyrule Field by day for a few minutes. Measure the game's CPU seconds with the frame rate capped at 60 (on a PC that holds 60 there), standing and turning the camera, and the frame times uncapped. Expect less CPU time with the switch at 1, the same frame rate or better, no extra CPU time with the switch unset against main, the picture as without the switch (no model missing or popping at the screen's edges), an "oot: bounds (HOS_NATIVE_BOUNDS=1)" line in the log with calls taken natively, and no "MISMATCH" in the log.
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 2e7be22, and the PR has changed since (ba1907e), 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 `2e7be22`, and the PR has changed since (`ba1907e`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
BeanBot left a comment

Recommendation: Request changes. The non-FMA fallback can read uninitialized values, and the rotation splice may impose a cost even at the default setting that has not been isolated. The branch also carries an unspliced sphere implementation and a test that fails on machines without hardware FMA.

The change attempts to reduce CPU work in model bounds and transform history while preserving lifted results. Offline comparisons are encouraging, but the in-game gain for this branch is unproven, and the default-off hooks still change the lifted code. Fix the fallback and test portability, remove the unused sphere path, and measure the branch independently before choosing its default.

Does it help: Unproven. The reported three-run Market medians show 2.7% less whole-process CPU standing and 2.4% less turning with all rewrite branches enabled together, against an older main; they do not isolate this PR. The switch-off differences of -0.3% and -0.2% are within the reported spread. No branch-only average FPS, 1% lows or frame times are supplied.
Other systems: The hooks affect the lifted functions even with the switch unset, including the rest of f_80021ca0 where register localization is lost. Windows NVIDIA was exercised in a merged test tree, but this head has not been played or checked in-game after the address fix. Linux, AMD and Steam Deck behavior, frame pacing, build time and the reported increase in renderer capture-copy CPU remain unverified. The rotation kernel declines without hardware FMA.
Switches: HOS_NATIVE_BOUNDS is new and defaults to off; 1 attempts the native paths and check compares them with the lifted paths. The default has not been chosen from isolated platform measurements, contrary to the switch standard. Its table row also claims the sphere merge runs natively, although that splice is disabled.

Reviewed: 2e7be224ec against a104182b40: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, commit log, the splice diff and substantial portions of the changed host code and tests. The combined file output was truncated, so portions of the rotation kernel, sphere kernel and tests were only skimmed; the unchanged portions of nx2/oot_patches.py and dependent code were searched selectively. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. Network access was unavailable, so overlapping PRs could not be checked.; nothing run (a code review).
Checked and fine:

  • The model-box hook leaves the lifted path available when its checks decline and marks its native output after writing.
  • The reported offline comparisons cover the corrected 39-bit guest addresses and include deliberate mismatch checks.
  • The diff does not change third_party or generated shader files.

Blocking (to change before merge)

  1. host/bounds_kernels.c:105: On a build without hardware FMA, a midpoint makes fma1 return without writing its output, but both the scalar and SSE callers subsequently read that uninitialized float before declining. This is undefined behavior on a supported non-FMA build; write a defined value before returning or stop processing immediately, and cover the midpoint fallback.
  2. tests/test_oot_bounds.py:345: The fixture requires the rotation hook to answer, although bounds_rot_80021ca0 deliberately declines every call without hardware FMA. On an older x86 CPU, or a compiler invocation without FMA, this makes the test fail for the intended fallback. Test the decline on those builds and retain the native assertions when FMA is available.
  3. nx2/oot_patches.py:842: The rotation hook prevents localization of the whole function even when HOS_NATIVE_BOUNDS is unset. The PR notes that the unmeasured remainder can outweigh the saving, and the combined switch-off runs cannot isolate that cost. Measure this head against its base with the switch off and on, including frame times and the affected threads; preserve the localized path or remove the splice if it regresses.
  4. nx2/oot_patches.py:832: The sphere splice is permanently false, yet the PR adds its kernel, hook, counters and tests, and the switch table tells users it runs. This leaves an implementation with no player benefit to maintain. Remove the unspliced path and its table claim; bring it back with a measured benefit if warranted.

Suggestions (the author may take or leave)

  • Run check mode on this head after the address fix, then exercise the native mode visually on the stated scenes.
  • Complete the requested Linux and AMD runs, Tier 1 coverage, full checks and head CI; measure build time and investigate the capture-copy CPU increase.
  • Choose and document the switch default from the branch-only measurements.

Testing: No commands from the project were run, and no files were changed. The PR reports game-free checks and offline comparisons, but the full suite and this head's in-game check remain outstanding.
Overlaps and merge order: Unknown; 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 non-FMA fallback can read uninitialized values, and the rotation splice may impose a cost even at the default setting that has not been isolated. The branch also carries an unspliced sphere implementation and a test that fails on machines without hardware FMA. The change attempts to reduce CPU work in model bounds and transform history while preserving lifted results. Offline comparisons are encouraging, but the in-game gain for this branch is unproven, and the default-off hooks still change the lifted code. Fix the fallback and test portability, remove the unused sphere path, and measure the branch independently before choosing its default. **Does it help:** Unproven. The reported three-run Market medians show 2.7% less whole-process CPU standing and 2.4% less turning with all rewrite branches enabled together, against an older main; they do not isolate this PR. The switch-off differences of -0.3% and -0.2% are within the reported spread. No branch-only average FPS, 1% lows or frame times are supplied. **Other systems:** The hooks affect the lifted functions even with the switch unset, including the rest of f_80021ca0 where register localization is lost. Windows NVIDIA was exercised in a merged test tree, but this head has not been played or checked in-game after the address fix. Linux, AMD and Steam Deck behavior, frame pacing, build time and the reported increase in renderer capture-copy CPU remain unverified. The rotation kernel declines without hardware FMA. **Switches:** HOS_NATIVE_BOUNDS is new and defaults to off; 1 attempts the native paths and check compares them with the lifted paths. The default has not been chosen from isolated platform measurements, contrary to the switch standard. Its table row also claims the sphere merge runs natively, although that splice is disabled. **Reviewed:** 2e7be224ec5a against a104182b4037: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, commit log, the splice diff and substantial portions of the changed host code and tests. The combined file output was truncated, so portions of the rotation kernel, sphere kernel and tests were only skimmed; the unchanged portions of nx2/oot_patches.py and dependent code were searched selectively. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. Network access was unavailable, so overlapping PRs could not be checked.; nothing run (a code review). **Checked and fine:** - The model-box hook leaves the lifted path available when its checks decline and marks its native output after writing. - The reported offline comparisons cover the corrected 39-bit guest addresses and include deliberate mismatch checks. - The diff does not change third_party or generated shader files. **Blocking** (to change before merge) 1. host/bounds_kernels.c:105: On a build without hardware FMA, a midpoint makes fma1 return without writing its output, but both the scalar and SSE callers subsequently read that uninitialized float before declining. This is undefined behavior on a supported non-FMA build; write a defined value before returning or stop processing immediately, and cover the midpoint fallback. 2. tests/test_oot_bounds.py:345: The fixture requires the rotation hook to answer, although bounds_rot_80021ca0 deliberately declines every call without hardware FMA. On an older x86 CPU, or a compiler invocation without FMA, this makes the test fail for the intended fallback. Test the decline on those builds and retain the native assertions when FMA is available. 3. nx2/oot_patches.py:842: The rotation hook prevents localization of the whole function even when HOS_NATIVE_BOUNDS is unset. The PR notes that the unmeasured remainder can outweigh the saving, and the combined switch-off runs cannot isolate that cost. Measure this head against its base with the switch off and on, including frame times and the affected threads; preserve the localized path or remove the splice if it regresses. 4. nx2/oot_patches.py:832: The sphere splice is permanently false, yet the PR adds its kernel, hook, counters and tests, and the switch table tells users it runs. This leaves an implementation with no player benefit to maintain. Remove the unspliced path and its table claim; bring it back with a measured benefit if warranted. **Suggestions** (the author may take or leave) - Run check mode on this head after the address fix, then exercise the native mode visually on the stated scenes. - Complete the requested Linux and AMD runs, Tier 1 coverage, full checks and head CI; measure build time and investigate the capture-copy CPU increase. - Choose and document the switch default from the branch-only measurements. **Testing:** No commands from the project were run, and no files were changed. The PR reports game-free checks and offline comparisons, but the full suite and this head's in-game check remain outstanding. **Overlaps and merge order:** Unknown; 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 +102,4 @@
const double s = (double)a * (double)b + (double)z;
uint64_t d;
memcpy(&d, &s, 8);
if ((d & UINT64_C(0x1fffffff)) == UINT64_C(0x10000000)) return 0; /* (a64_suyu.h RECOMP_FPX_MIDPOINT) */
Member

On a non-FMA build this returns without writing *r, but both callers read that value before declining the box. Please initialize the output or return immediately from the callers, and test a midpoint on the non-FMA path.

On a non-FMA build this returns without writing `*r`, but both callers read that value before declining the box. Please initialize the output or return immediately from the callers, and test a midpoint on the non-FMA path.
@ -799,0 +839,4 @@
# HOS_NATIVE_BOUNDS: the transform history's rotation step, a hook at the label L_800232c0 of f_80021ca0 (it answers
# by jumping to L_80023870 or L_80023890) and one after each of those two labels (check mode compares there)
BOUNDS_ROT_HEAD = "void f_80021ca0(Ctx *__restrict A64_NOESC c) {\n"
BOUNDS_ROT = (("L_800232c0", " { const int _h = hos_bounds_80021ca0_rot(c); if (_h == 1) goto L_80023870; if (_h == 2) goto L_80023890; }"),
Member

This splice also changes the rest of the function when the switch is off by preventing register localization. The combined runs do not isolate that possible cost; please measure this branch alone against its base and preserve the localized path or remove the splice if it regresses.

This splice also changes the rest of the function when the switch is off by preventing register localization. The combined runs do not isolate that possible cost; please measure this branch alone against its base and preserve the localized path or remove the splice if it regresses.
@ -799,0 +829,4 @@
# HOS_NATIVE_BOUNDS: the sphere merge f_800a8000, a hook first in the lifted function. NOT spliced (BOUNDS_SPHERE_SPLICE):
# measured offline against main's locals form it lost on its copy path (45.6 against 40.2 ns a call) and won 1.3x on
# its merge path, for 0.04 % of game code; a piece that does not beat main's form stays unwired (the rewrite brief).
BOUNDS_SPHERE_SPLICE = False
Member

With this permanently false, the sphere kernel, hook, counters and tests have no runtime benefit, while the switch row says the sphere runs natively. Please remove the unused path and correct the row until it has a measured benefit.

With this permanently false, the sphere kernel, hook, counters and tests have no runtime benefit, while the switch row says the sphere runs natively. Please remove the unused path and correct the row until it has a measured benefit.
@ -0,0 +342,4 @@
static void test_rot_on(void) {
rot_consts(), rot_expect();
Ctx c = rot_ctx();
CHECK(hos_bounds_80021ca0_rot(&c) == 1);
Member

Without hardware FMA the rotation kernel intentionally declines every call, so this assertion fails on that supported configuration. Please assert the fallback there and keep the native assertions for FMA builds.

Without hardware FMA the rotation kernel intentionally declines every call, so this assertion fails on that supported configuration. Please assert the fallback there and keep the native assertions for FMA builds.
Co-Authored-By: Codex Sol <[email protected]>
(cherry picked from commit bce938b6dbf4ac5858af8a0eb7fe490fc13bd328)
fix(build): the host's native hooks test the watch bitmap too (A64_MARK_BITMAP)
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 8s
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
ba1907e76e
Every host file is now compiled with MARK_BITMAP, the lifted code's own setting, instead of none (or, on the crowd
branch, only host/oot_crowd.c). A native hook's A64_MARK then tests the first page's watch bit exactly as the lifted
store it stands for does, and the hooks' #ifdef A64_GPU_PAGE guards (the uniform-bitmap preflights in reverb and
visibility) are compiled in. hos_mark_written / HOS_WRITTEN, the host's own marks, still mark every page.
RX_MARK_BITMAP=0 turns the bitmap off for the lifted code and the hooks alike.

tests/test_mark_bitmap_host.py reads nx2/build.py (no build) and fails if the lifted flags or a host compile job
lack an unconditional MARK_BITMAP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
perf(host): HOS_NATIVE_BOUNDS is on by default; =0 runs the bounds routines lifted
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 19s
75e496103b
docs/dev/standards.md: a switch ships at its value from the branch's first push, never off because it is new.
The row's kind is kill, unset reads as 1 (env_on_or), and the test runs unset as on and 0 / off as off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
snaildev99 changed title from WIP: perf(host): a model's box and the transform history's rotation step on host code, bit for bit (HOS_NATIVE_BOUNDS, off by default) to WIP: perf(host): a model's box and the transform history's rotation step on host code, bit for bit (HOS_NATIVE_BOUNDS, on by default) 2026-11-21 07:46:02 +00:00
Author
Contributor

HOS_NATIVE_BOUNDS is now on by default (75e49610), as docs/dev/standards.md asks: a switch ships at its value from the first push, not off because it is new. HOS_NATIVE_BOUNDS=0 gives main's lifted code. The row's kind is kill, unset reads as on (env_on_or), and the test runs it unset and =1 (on), =0 and =off (off) and check; it fails when the old read is put back. Title and description updated to match.

`HOS_NATIVE_BOUNDS` is now on by default (75e49610), as docs/dev/standards.md asks: a switch ships at its value from the first push, not off because it is new. `HOS_NATIVE_BOUNDS=0` gives main's lifted code. The row's kind is `kill`, unset reads as on (`env_on_or`), and the test runs it unset and `=1` (on), `=0` and `=off` (off) and `check`; it fails when the old read is put back. Title and description updated to match.
HumanBean left a comment

Recommendation: Request changes. The host code is the game's routines transcribed from its disassembly (most plainly host/bounds_rot.c, which follows the game's instructions one at a time, keeps the game's register numbers and labels each branch block with its address). CONTRIBUTING.md's Licensing section forbids that whatever the speed gain. Separately, this branch's own gain isn't measured yet, and the hook costs f_80021ca0 its register locals even with the switch at 0.

The PR moves two hot routines of the game's model bounds onto host code (the model box f_80ba37a0, and the rotation step inside f_80021ca0), aiming for less CPU time per frame with the same picture. The offline speedups are large (7-10x for the box, 2.5-5x for the rotation step), and the exactness work is careful: a gate, the FPX1 rule in every lane, aliasing and range declines, and a check mode. It can't merge in this form because of how the code was written.

Does it help: Unproven. The only in-game numbers come from a merged tree of nine rewrite branches on an old main (068fb8eb): -2.7 % / -2.4 % whole-process CPU in the Market at a 60 fps cap, as medians of 3 runs. They don't isolate this PR. The "every switch off" column (-0.3 % / -0.2 %) is inside the spread. No branch-only frame times or 1 % lows are given. Check mode hasn't run in the game since the 39-bit address fix, and this head hasn't been built or played.
Other systems: Patched functions keep the context instead of locals (nx2/guest_locals.py, touches() / keep_mentioned()). So f_80ba37a0 and the whole of f_80021ca0 lose the locals for every player, with the switch on or off. The PR says the other 77 % of f_80021ca0 is where locals help most and that the splice loses if they save more than ~21 % there. That cost is not measured. A CPU below x86-64-v3 gets an x86-64-v2 / x86-64 build (nx2/build.py MARCH). There the rotation step declines every call (no FMA) but still pays the de-localised function. The model box takes the binary64 path and declines at midpoints. nx2/build.py now compiles every host file with -DA64_MARK_BITMAP. Today that changes only A64_MARK in host code (rtgen.py:64), which only these hooks use, so nothing else moves. Linux, AMD and the Steam Deck weren't run. The renderer's capture-copy thread rose 10-18 % in the merged runs, and the cause is still open.
Switches: HOS_NATIVE_BOUNDS is new, kind kill, default on (unset or 1; =0 lifted; check). On is the right default only once the gain is this PR's own and exactness has been checked in the game. Neither holds yet: the gain is Unproven and check mode hasn't run since the fix. The row (switches.def:107) still says the sphere merge f_800a8000 runs on host code, but it is not spliced. The row also has a stray " ," after "bones)".

Reviewed: 75e496103 against a104182b (its fork point), and the same 11 commits rebased onto main@origin b62932a96 (local 40670c2c; see below). Read in full: host/oot_bounds.c, host/bounds_kernels.c/.h, host/bounds_rot.c, host/bounds_sphere.c, the nx2/oot_patches.py and nx2/build.py diffs, and nx2/guest_locals.py's touches / keep_mentioned / check_patched. Skimmed: the C fixtures of tests/test_oot_bounds.py and tests/test_bounds_kernels.py, and tests/test_mark_bitmap_host.py. Nothing was run (this is a code review).
Fixed in this review: I rebased the 11 commits onto main b62932a96 one by one. The conflicts were only the HOS_NATIVE_ZSTD row main changed beside the new row, and main's " The supported build only." on the line before the new docstring bullet. I also added one commit, fix(host): the model box's no-FMA multiply-add writes its result on a decline too (see Blocking 4). The push to the head branch was refused, so neither landed. The PR still conflicts with main. The fix is given below as a suggestion.
Checked and fine:

  • The splices go through touches(), so the patched functions keep the context the hooks read. check_patched would stop a lift that gave one locals.
  • The rotation hook fires only when all three labels are found exactly once.
  • The model box writes nothing on a decline. It writes the six words once and marks them (A64_MARK, the bitmap tested).
  • The rotation step's three stack stores are range-checked (sp+0xe8, 0x24 bytes).
  • The bounds_inside / sphere_inside guards stop a check-mode call from recursing.
  • The lifted function head form these patches match is still main's (guest_locals.HEAD).
  • BeanBot's earlier switch-default point is answered: it is now on and read by env_on_or.

Blocking (to change before merge)

  1. Licensing: the kernels are the game's code transcribed. CONTRIBUTING.md forbids "decompiled game code or anything generated from the dump". It allows writing from facts about behaviour, in your own words.
    • host/bounds_rot.c is an instruction-by-instruction transcription of 0x800232c0..0x80023890 and its branch blocks:
      • the variables are the game's registers, in the game's allocation and order (d0..d27; e.g. :153 d3 = r_fma(&r, d1, d6, d2), then d1 = ...(d0, d6, d2), d0 = ...(d5, d6, d2));
      • the branch blocks carry their addresses (:158 /* 80024bdc */, :171 (8002337c), :213 qB (80023380), :308 80023720);
      • the comments quote instructions (:128 tbnz w9, :424 ldr s11, [sp, #0xe8]);
      • it reproduces the game's leftover register values (:430 x8 = 0x3ba3d70a, x9 = 0x3cf5c28f, x10).
    • host/bounds_sphere.c and host/bounds_kernels.c are written more as behaviour, but are also "read from the game's code" (their headers say so). They carry its instructions in comments (bounds_kernels.c:292 ldr x0, [x9, x1, lsl #3], :326 add x0, sp, #0x180 before the BL, :392 b.le; bounds_sphere.c fcsel mi, fcmp s0, s0). They also rebuild the game's leftover register file (x0, v0-v5, x8-x10, NZCV) from it.
    • The "every register the stretch writes" contract can only be met by mirroring the game's instructions. That is what makes it a transcription.
    • A version that could merge would answer at a function boundary with only the routine's documented results (the box, the angle), written from what the routine computes, with no instruction comments or addresses beyond the hook sites. Or leave these routines lifted.
  2. nx2/oot_patches.py:833-835: BOUNDS_SPHERE_HEAD / BOUNDS_SPHERE_DECL contain void f_800a8000, which mentioned_addresses() matches. So keep_mentioned takes f_800a8000's locals away on every build, although BOUNDS_SPHERE_SPLICE = False and the PR found the sphere loses against main's form. Unspliced code costs a hot function its locals and gains nothing. As BeanBot asked, remove the sphere path (the kernel, the hook, its counters, the row text and the tests), or at least keep its address out of this file until it is spliced.
  3. nx2/oot_patches.py:841 (the rotation splice): it takes f_80021ca0's locals for everyone, including at HOS_NATIVE_BOUNDS=0 and on CPUs without FMA, where it can never answer. The PR's own estimate says this can cost more than it saves. Measure this branch alone on current main: switch unset, =0, and main, each as CPU time plus frame times. Drop the rotation splice if the =0 column or main-vs-on shows a cost. (BeanBot's point, still open.)
  4. host/bounds_kernels.c:105: on a no-FMA build, fma1 returns 0 at a midpoint without writing *r, and both callers read r before they check ok. Suggested fix (the commit I couldn't push):
        memcpy(&d, &s, 8);
        *r = (float)s;   /* (written on a decline too: the callers read it before they look at the answer) */
        return (d & UINT64_C(0x1fffffff)) != UINT64_C(0x10000000);   /* (a64_suyu.h RECOMP_FPX_MIDPOINT: 0, declined) */
    
    (BeanBot's point, still open at this head.)
  5. tests/test_oot_bounds.py:346: the fixture is built with -march=native when it can be, and requires the rotation hook to answer. On a CPU without FMA, which gets an x86-64-v2 game build, the kernel declines by design, so the test fails. test_bounds_kernels.py already has the #if !(defined(__FMA__) ...) branch; do the same here. (BeanBot's point, still open.)
  6. gpu/vk/switches.def:107: the row says the sphere merge runs on host code; it doesn't. Also remove the stray " ," after "bones)".

Suggestions

  • Check mode: rot_pending.on is cleared only at an exit hook. If the lifted stretch ever left by another path, the next arrival at an exit would compare against stale state and log a false MISMATCH. Clearing it at the entry hook would close that.

Testing: The PR reports offline Unicorn comparisons, but those run the game's routine from the executable on this author's PC. In-game, it ran only in a merged tree on Windows / RTX 3090 / 5900X. Check mode hasn't run since the fix, and this head hasn't been built or played. Linux, AMD, the Steam Deck and a branch-only measurement are still missing. The Beanstalk request was for 2e7be22 and has lapsed. CI on the head was not looked at.
Overlaps and merge order:

  • #1898 (HOS_MATH) hooks f_80ba6d80, the box transform this PR's model box inlines, and the sphere at 0x800a8400. The hooks are on different functions, so there is no double splice. But with this PR on, the box transform's calls from f_80ba37a0 never reach 1898's hook, so the two gains overlap and must be measured together.
  • #1904 (libm acos) is complementary: the rotation step leaves acos lifted.
  • #1898, #1900, #1902, #1903, #1905, #1909, #1910, #1911, #2001 and #2036 all add rows to switches.def and splices to nx2/oot_patches.py. Several carry the same nx2/build.py MARK_BITMAP change and a new tests/test_mark_bitmap_host.py. Whichever merges second conflicts; the build.py change belongs in one PR only.
**Recommendation: Request changes.** The host code is the game's routines transcribed from its disassembly (most plainly `host/bounds_rot.c`, which follows the game's instructions one at a time, keeps the game's register numbers and labels each branch block with its address). CONTRIBUTING.md's Licensing section forbids that whatever the speed gain. Separately, this branch's own gain isn't measured yet, and the hook costs f_80021ca0 its register locals even with the switch at 0. The PR moves two hot routines of the game's model bounds onto host code (the model box f_80ba37a0, and the rotation step inside f_80021ca0), aiming for less CPU time per frame with the same picture. The offline speedups are large (7-10x for the box, 2.5-5x for the rotation step), and the exactness work is careful: a gate, the FPX1 rule in every lane, aliasing and range declines, and a check mode. It can't merge in this form because of how the code was written. **Does it help:** Unproven. The only in-game numbers come from a merged tree of nine rewrite branches on an old main (068fb8eb): -2.7 % / -2.4 % whole-process CPU in the Market at a 60 fps cap, as medians of 3 runs. They don't isolate this PR. The "every switch off" column (-0.3 % / -0.2 %) is inside the spread. No branch-only frame times or 1 % lows are given. Check mode hasn't run in the game since the 39-bit address fix, and this head hasn't been built or played. **Other systems:** Patched functions keep the context instead of locals (`nx2/guest_locals.py`, `touches()` / `keep_mentioned()`). So f_80ba37a0 and the whole of f_80021ca0 lose the locals for every player, with the switch on or off. The PR says the other 77 % of f_80021ca0 is where locals help most and that the splice loses if they save more than ~21 % there. That cost is not measured. A CPU below x86-64-v3 gets an x86-64-v2 / x86-64 build (`nx2/build.py` MARCH). There the rotation step declines every call (no FMA) but still pays the de-localised function. The model box takes the binary64 path and declines at midpoints. `nx2/build.py` now compiles every host file with `-DA64_MARK_BITMAP`. Today that changes only `A64_MARK` in host code (rtgen.py:64), which only these hooks use, so nothing else moves. Linux, AMD and the Steam Deck weren't run. The renderer's capture-copy thread rose 10-18 % in the merged runs, and the cause is still open. **Switches:** `HOS_NATIVE_BOUNDS` is new, kind `kill`, default **on** (unset or 1; `=0` lifted; `check`). On is the right default only once the gain is this PR's own and exactness has been checked in the game. Neither holds yet: the gain is Unproven and check mode hasn't run since the fix. The row (switches.def:107) still says the sphere merge f_800a8000 runs on host code, but it is not spliced. The row also has a stray " ," after "bones)". **Reviewed:** 75e496103 against a104182b (its fork point), and the same 11 commits rebased onto main@origin b62932a96 (local 40670c2c; see below). Read in full: `host/oot_bounds.c`, `host/bounds_kernels.c`/`.h`, `host/bounds_rot.c`, `host/bounds_sphere.c`, the `nx2/oot_patches.py` and `nx2/build.py` diffs, and `nx2/guest_locals.py`'s touches / keep_mentioned / check_patched. Skimmed: the C fixtures of `tests/test_oot_bounds.py` and `tests/test_bounds_kernels.py`, and `tests/test_mark_bitmap_host.py`. Nothing was run (this is a code review). **Fixed in this review:** I rebased the 11 commits onto main b62932a96 one by one. The conflicts were only the `HOS_NATIVE_ZSTD` row main changed beside the new row, and main's " The supported build only." on the line before the new docstring bullet. I also added one commit, `fix(host): the model box's no-FMA multiply-add writes its result on a decline too` (see Blocking 4). **The push to the head branch was refused, so neither landed.** The PR still conflicts with main. The fix is given below as a suggestion. **Checked and fine:** - The splices go through `touches()`, so the patched functions keep the context the hooks read. `check_patched` would stop a lift that gave one locals. - The rotation hook fires only when all three labels are found exactly once. - The model box writes nothing on a decline. It writes the six words once and marks them (A64_MARK, the bitmap tested). - The rotation step's three stack stores are range-checked (`sp+0xe8`, 0x24 bytes). - The `bounds_inside` / `sphere_inside` guards stop a check-mode call from recursing. - The lifted function head form these patches match is still main's (`guest_locals.HEAD`). - BeanBot's earlier switch-default point is answered: it is now on and read by `env_on_or`. **Blocking** (to change before merge) 1. **Licensing: the kernels are the game's code transcribed.** CONTRIBUTING.md forbids "decompiled game code or anything generated from the dump". It allows writing from facts about behaviour, in your own words. - `host/bounds_rot.c` is an instruction-by-instruction transcription of 0x800232c0..0x80023890 and its branch blocks: - the variables are the game's registers, in the game's allocation and order (d0..d27; e.g. :153 `d3 = r_fma(&r, d1, d6, d2)`, then `d1 = ...(d0, d6, d2)`, `d0 = ...(d5, d6, d2)`); - the branch blocks carry their addresses (:158 `/* 80024bdc */`, :171 `(8002337c)`, :213 `qB (80023380)`, :308 `80023720`); - the comments quote instructions (:128 `tbnz w9`, :424 `ldr s11, [sp, #0xe8]`); - it reproduces the game's leftover register values (:430 `x8 = 0x3ba3d70a, x9 = 0x3cf5c28f`, x10). - `host/bounds_sphere.c` and `host/bounds_kernels.c` are written more as behaviour, but are also "read from the game's code" (their headers say so). They carry its instructions in comments (bounds_kernels.c:292 `ldr x0, [x9, x1, lsl #3]`, :326 `add x0, sp, #0x180 before the BL`, :392 `b.le`; bounds_sphere.c `fcsel mi`, `fcmp s0, s0`). They also rebuild the game's leftover register file (x0, v0-v5, x8-x10, NZCV) from it. - The "every register the stretch writes" contract can only be met by mirroring the game's instructions. That is what makes it a transcription. - A version that could merge would answer at a function boundary with only the routine's documented results (the box, the angle), written from what the routine computes, with no instruction comments or addresses beyond the hook sites. Or leave these routines lifted. 2. `nx2/oot_patches.py:833-835`: `BOUNDS_SPHERE_HEAD` / `BOUNDS_SPHERE_DECL` contain `void f_800a8000`, which `mentioned_addresses()` matches. So `keep_mentioned` takes f_800a8000's locals away on every build, although `BOUNDS_SPHERE_SPLICE = False` and the PR found the sphere loses against main's form. Unspliced code costs a hot function its locals and gains nothing. As BeanBot asked, remove the sphere path (the kernel, the hook, its counters, the row text and the tests), or at least keep its address out of this file until it is spliced. 3. `nx2/oot_patches.py:841` (the rotation splice): it takes f_80021ca0's locals for everyone, including at `HOS_NATIVE_BOUNDS=0` and on CPUs without FMA, where it can never answer. The PR's own estimate says this can cost more than it saves. Measure this branch alone on current main: switch unset, `=0`, and main, each as CPU time plus frame times. Drop the rotation splice if the `=0` column or main-vs-on shows a cost. (BeanBot's point, still open.) 4. `host/bounds_kernels.c:105`: on a no-FMA build, `fma1` returns 0 at a midpoint without writing `*r`, and both callers read `r` before they check `ok`. Suggested fix (the commit I couldn't push): ```c memcpy(&d, &s, 8); *r = (float)s; /* (written on a decline too: the callers read it before they look at the answer) */ return (d & UINT64_C(0x1fffffff)) != UINT64_C(0x10000000); /* (a64_suyu.h RECOMP_FPX_MIDPOINT: 0, declined) */ ``` (BeanBot's point, still open at this head.) 5. `tests/test_oot_bounds.py:346`: the fixture is built with `-march=native` when it can be, and requires the rotation hook to answer. On a CPU without FMA, which gets an x86-64-v2 game build, the kernel declines by design, so the test fails. `test_bounds_kernels.py` already has the `#if !(defined(__FMA__) ...)` branch; do the same here. (BeanBot's point, still open.) 6. `gpu/vk/switches.def:107`: the row says the sphere merge runs on host code; it doesn't. Also remove the stray " ," after "bones)". **Suggestions** - Check mode: `rot_pending.on` is cleared only at an exit hook. If the lifted stretch ever left by another path, the next arrival at an exit would compare against stale state and log a false MISMATCH. Clearing it at the entry hook would close that. **Testing:** The PR reports offline Unicorn comparisons, but those run the game's routine from the executable on this author's PC. In-game, it ran only in a merged tree on Windows / RTX 3090 / 5900X. Check mode hasn't run since the fix, and this head hasn't been built or played. Linux, AMD, the Steam Deck and a branch-only measurement are still missing. The Beanstalk request was for 2e7be22 and has lapsed. CI on the head was not looked at. **Overlaps and merge order:** - [#1898](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1898) (HOS_MATH) hooks f_80ba6d80, the box transform this PR's model box inlines, and the sphere at 0x800a8400. The hooks are on different functions, so there is no double splice. But with this PR on, the box transform's calls from f_80ba37a0 never reach 1898's hook, so the two gains overlap and must be measured together. - [#1904](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1904) (libm acos) is complementary: the rotation step leaves acos lifted. - [#1898](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1898), [#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), [#1911](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1911), [#2001](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2001) and [#2036](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2036) all add rows to `switches.def` and splices to `nx2/oot_patches.py`. Several carry the same `nx2/build.py` MARK_BITMAP change and a new `tests/test_mark_bitmap_host.py`. Whichever merges second conflicts; the build.py change belongs in one PR only.
@ -104,6 +104,7 @@ SW(HOS_MOVIE_PACE, kill, bool, "on: a 60 FPS cap is raised for a movie's picture
SW(HOS_MUTEX_TRACE, diag, int, "0: off", "Logs mutex waits longer than <ms>, with the thread that held the mutex.")
SW(HOS_MUTEX_WATCH, diag, string, "off", "Logs every operation on the mutex at that guest address (hex) and its condition variables' signals.")
SW(HOS_MW_WAKE, kill, enum, "only changes to objects linked into a multi-wait wake WaitAny", "=all: every event, semaphore or queue change wakes every WaitAny, as before.")
SW(HOS_NATIVE_BOUNDS, kill, enum, "on: the model bounds routines on host code where it gives the game's bits exactly, the rest lifted", "=0 (or false, off, no): every call runs as lifted, as on main; 1 (or unset) runs the model box (f_80ba37a0: a model's box from its meshes' boxes under their bones) , the transform history's rotation step (in f_80021ca0) and the sphere merge (f_800a8000) on host code where it gives the game's bits exactly, the rest lifted; check runs both on every call and logs any difference (slow). An oot: bounds line every 10 s counts the calls (host/oot_bounds.c).")
Owner

The sphere merge is not spliced, so the row shouldn't say it runs on host code. Also remove the stray " ," after "bones)".

The sphere merge is not spliced, so the row shouldn't say it runs on host code. Also remove the stray " ," after "bones)".
@ -0,0 +102,4 @@
const double s = (double)a * (double)b + (double)z;
uint64_t d;
memcpy(&d, &s, 8);
if ((d & UINT64_C(0x1fffffff)) == UINT64_C(0x10000000)) return 0; /* (a64_suyu.h RECOMP_FPX_MIDPOINT) */
Owner

Without a hardware FMA this returns 0 before it writes *r, but both callers read r before they check ok. Write *r = (float)s; first and return the midpoint test (the suggestion is in the review).

Without a hardware FMA this returns 0 before it writes `*r`, but both callers read `r` before they check `ok`. Write `*r = (float)s;` first and return the midpoint test (the suggestion is in the review).
@ -0,0 +289,4 @@
const float o0 = f_of(ld32(mh + 0x2d0)), o1 = f_of(ld32(mh + 0x2d4)), o2 = f_of(ld32(mh + 0x2d8));
for (uint32_t i = 0; i < n; i++) {
RD(tp, tbl + 8 * (uint64_t)ld16(idx + 2 * i), 8);
x0 = ld64(tp); /* (ldr x0, [x9, x1, lsl #3]) */
Owner

Instruction text from the game's disassembly (also :326 add x0, sp, #0x180 before the BL, :392 b.le). Rebuilding the game's leftover x0 from its code is part of the licensing problem in the review.

Instruction text from the game's disassembly (also :326 `add x0, sp, #0x180 before the BL`, :392 `b.le`). Rebuilding the game's leftover x0 from its code is part of the licensing problem in the review.
@ -0,0 +155,4 @@
d0 = r_fma(&r, d5, d6, d2);
if (!r.ok) goto declined;
f = r_cmp(d2, d3);
if (LE(f)) { /* 80024bdc */
Owner

Licensing: this follows the game's instructions one at a time, with the game's register allocation (d0..d27) and each branch block labelled by its address (80024bdc, 8002337c, 80023380, 80023720). That is a transcription of the game's code, which CONTRIBUTING.md's Licensing section forbids.

Licensing: this follows the game's instructions one at a time, with the game's register allocation (d0..d27) and each branch block labelled by its address (`80024bdc`, `8002337c`, `80023380`, `80023720`). That is a transcription of the game's code, which CONTRIBUTING.md's Licensing section forbids.
@ -799,0 +830,4 @@
# measured offline against main's locals form it lost on its copy path (45.6 against 40.2 ns a call) and won 1.3x on
# its merge path, for 0.04 % of game code; a piece that does not beat main's form stays unwired (the rewrite brief).
BOUNDS_SPHERE_SPLICE = False
BOUNDS_SPHERE_HEAD = "void f_800a8000(Ctx *__restrict A64_NOESC c) {\n"
Owner

void f_800a8000 here is matched by mentioned_addresses(), so keep_mentioned takes f_800a8000's locals away although the sphere is not spliced. Remove the sphere path, or keep its address out of this file until it is spliced.

`void f_800a8000` here is matched by `mentioned_addresses()`, so `keep_mentioned` takes f_800a8000's locals away although the sphere is not spliced. Remove the sphere path, or keep its address out of this file until it is spliced.
Owner

Splicing this costs the whole of f_80021ca0 its locals, including at HOS_NATIVE_BOUNDS=0 and on CPUs without FMA, where it never answers. Please give a branch-only measurement on current main (unset / =0 / main), CPU time and frame times.

Splicing this costs the whole of f_80021ca0 its locals, including at `HOS_NATIVE_BOUNDS=0` and on CPUs without FMA, where it never answers. Please give a branch-only measurement on current main (unset / =0 / main), CPU time and frame times.
@ -0,0 +343,4 @@
static void test_rot_on(void) {
rot_consts(), rot_expect();
Ctx c = rot_ctx();
CHECK(hos_bounds_80021ca0_rot(&c) == 1);
Owner

On a CPU without FMA (-march=native gives none) the kernel declines by design and this fails. Expect a decline under #if !(defined(__FMA__) || defined(__aarch64__)), as test_bounds_kernels.py does.

On a CPU without FMA (`-march=native` gives none) the kernel declines by design and this fails. Expect a decline under `#if !(defined(__FMA__) || defined(__aarch64__))`, as test_bounds_kernels.py does.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
beanstalk/approval changed since the request: ask again
PR description / Description follows the template (pull_request_target) Successful in 19s
This pull request has changes conflicting with the target branch.
  • gpu/vk/switches.def
  • nx2/oot_patches.py
Some workflows are waiting to be reviewed.
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/native-bounds:snaildev99-perf/native-bounds'
git switch 'snaildev99-perf/native-bounds'
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!1899
No description provided.