WIP: perf(host): seven of the physics' small float routines on host code, bit for bit (HOS_MATH, on by default) #1898
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1898
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:perf/native-math"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Seven small float routines of the game's physics and actor loops run on host code with the game's exact results, behind a new switch,
HOS_MATH, on by default (=0gives the lifted code). They are ported from Hookshot's native engine, which came from the HeyListen fork; see Credit below. The routines:Together their functions hold 3.7 % of the game's code time in a Market profile and 2.1 % on a Kakariko and Death Mountain Trail route. Of that, relxf has 0.11 % / 0.04 % and support 0.19 % / 0.41 %.
The goal is less CPU work for the same frames. A call the host cannot prove exact runs the lifted routine and nothing is written. A call is answered natively only in the following state:
Every byte the host writes is marked for the GPU mirror (
HOS_WRITTEN).How:
nx2/oot_patches.py(MATH_GATES,patch_math_gates; the supported build only) puts a gate first in each lifted function:hos_math_on_<addr>is 1 until the first call has read the switches (afterlongshot_env.txt), then 0 unless the unit is on. So with the switch off the gate is one load and an untaken branch.host/hos_math.creads each routine's arguments from the guest registers and memory. It computes into a scratch copy and writes the outputs back marked. Registers and FPSR are left as the caller may see them: the routines are void, and what the game's code leaves in caller-saved registers is not read after the call. The arithmetic is inhost/hos_math_kernels.c, plain C operation for operation. The hook declarations takeA64_NOESC, as the lifted code's own calls do.Read first:
host/hos_math.c:run,run_n,run_body,run_support, the checkcompare/compare_n,FP_OPEN.host/hos_math_kernels.c:HmGuardand thehm_*operations.nx2/oot_patches.py:patch_math_gates.tests/test_native_math.py.HOS_MATH*rows ingpu/vk/switches.def.host/PROVENANCE.md.Credit. This is ported code.
host/PROVENANCE.mdname the sources file by file.Testing
Tested: Windows 11, RTX 3090 (NVIDIA 610.88), Ryzen 9 5900X. This code (before the rebase onto current main and the
A64_NOESCdeclarations) ran in the game in two test trees on main068fb8eb:test/native-math-ports@ 596563cc:HOS_MATH_CHECK=1with all seven units. Every call was answered natively into a copy and compared with the lifted routine's result. 0 mismatches.test/rewrites(nine rewrite branches merged, named under Measurements): check mode again, the Market and Hyrule Field, about five minutes. The seven units compared 0.3 to 8.6 million calls each, with 0 mismatches. FPCR.FZ was set in every call on the worker threads.HOS_MATH=1was played with nothing visibly different.test/rewrites@ e614ef49,HOS_MATH=1with every other rewrite on, all 15 runs held 60 fps.This head is not built or played.
Exactness offline. A harness runs the game's own routine in Unicorn, on the game's executable. It runs the real
host/hos_math.candhost/hos_math_kernels.cthrough their gates, compiled with the build's host flags, on the same memory and registers. Every byte either side changed must be equal, under FPCR 0 and under FPCR.FZ. A declining call must have written nothing. The input modes:Every rounding mode, DN, FZ16 and AHP was tried, and FPSR with IXC clear or other flags set. When the units were ported:
Deliberately broken versions are caught (1 to 8,746 mismatching cases each):
What the game's code does that the host's does not: it raises sticky FPSR flags (IOC, OFC, UFC, IDC, QC) from lanes it computes and does not use. FPSR is read in the whole game only by the sdk's four float-environment functions.
Run again on this branch, the host files built from this head with seed 41, FPCR 0 and FZ for every answered case, 0 differing bytes everywhere:
The host files are byte for byte the ones checked in the game. The
A64_NOESCchange is in the lifted caller's declaration only, which this harness does not compile.Game-free checks at this head:
tests/test_native_math.pypasses. It covers:tests/test_switch_table.py,tests/test_patch_hooks_defined.py,test_log_levels,test_utf8_paths,test_doc_anchors,test_check_third_partyandtest_env_onpass.nx2/oot_patches.pyornx2/entry_hooks.pypass. The other five fail here and on maina104182balike:test_dev_packs,test_high_fps_fixes,test_libc_hooks,test_lift_cache,test_song_note_cue.tests/run_all.pywas not run.Still to test:
HOS_MATH=0against 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 and physics as without it (@Beanstalk linux, amd).HOS_MATH_CHECK=1 HOS_MATH_LOG=1in the Market and Hyrule Field. Expect everymath: <unit>: ... mismatches 0line and noMISMATCHline. ThenHOS_MATH=1: bodies resting on and bumping into each other look as before (by hand).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:
How much of that is these seven units is not separated. The Test Farm request asks for this branch's own number.
Baseline: main
068fb8eb(#1802) against the test treetest/rewrites@ e614ef49. That tree is main068fb8ebwith nine rewrite branches merged (not every rewrite there is: the cloth and particle effect branches were not in it): these seven units (596563cc, before theA64_NOESCdeclarations), the maths library, animation, bounds, crowd, visibility, glue, the effect triggers with the reverb, and the solver. It was lifted withA64_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 since068fb8eb; 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).
068fb8ebThe 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. Over the game's own threads, with the float fallback change too: -5.7 % standing and -5.0 % turning. On the executors, where these units mostly run: -4.1 % / -4.0 % with the rewrites on.
Offline: CPU time a call, not the game. On realistic inputs answered natively, against the same functions in the old lift's form (every register in the context;
build-hookshot's stock lift, Hookshot's translator), compiled with the hot pieces' flags; one pinned thread, best of nine interleaved rounds:relxf and support were not timed offline. These factors are against the old form, not against main's lift, which keeps registers in C locals where it can: against main's form they are smaller by an amount not measured. A gated function is written in the old form. Its cost with the switch off was measured in the old form only: within the noise for four units, 12 % for sphere's gated copy, and that was before the declarations took
A64_NOESC. At the process's scale the game measurement above found no off cost.The switches
HOS_MATH(new, run time,kill, on by default):0off (the lifted routines, main's results);1answers the units natively where exact.HOS_MATH_UNITSnames the units: a comma list ofbox,affine,verts,sphere,body,relxf,support, orall(the default).HOS_MATH_CHECK=1runs both on every call. The game keeps the lifted result. A difference logsmath: <unit> MISMATCH at out ..., fpcr ...: lifted ... / native ...with the inputs.HOS_MATH_LOG=1logs every 10 s and at the end:The start line names each unit's state, for example
math: box native; ...; support native; (HOS_MATH, on by default; =0 runs them lifted). 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_MATH=0gives 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 box, sphere, placement or support point would show in the physics or in what is culled: bodies passing through or catching on each other, models popping near the screen's edges. Every answered call in the two in-game check runs matched the lifted routine.
Open: in the CPU measurement, the renderer's
mkw_vk capture copythread 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 units mark what they write (HOS_WRITTEN, possibly more coarsely than the lifted stores' own marks). Which rewrite causes it is not determined; this branch is one of several candidates.Turning it off:
HOS_MATH=0;HOS_MATH_UNITSleaves out single units.After updating: the game is translated again once (
nx2/oot_patches.pyis in the lift's key). The routines run on the host by default, with the game's exact results; saves,longshot_options.iniand the caches do not change.Checklist
Ready for review
main; the title is a Conventional Commit.068fb8eb, in check mode and on; this head is not built or played.)mise run testpasses (any failure that also fails onmainis named). (The tests that read the changed files pass, apart from five that fail on maina104182btoo; the whole suite not run.)main, or Measurements says why there is nothing to measure. (Measured with the other rewrite branches merged; this branch alone not yet.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. (The four rows are there; on by default,HOS_MATH=0gives main's lifted code; this PR's own measurement can still turn it off.)tests/that reads changed source is updated, not weakened. (tests/test_native_math.py, new;tests/test_switch_table.pyreads the four rows.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Five small float routines of the physics and actor loops answered by native code: a body's box from its oriented box (0x81a040bc), a centre / half-extents box under a 3x4 matrix (0x80ba6d80), a convex vertex set's box (0x81746440), a model's bounding sphere (0x800a8400) and the per-body box update of Havok's last solver substep (0x817d9d80). A call goes native only in the translation's own native float state (FPCR at its default but FZ, FPSR.IXC set) and when every value is one x86 and the translated Arm code agree on; otherwise the lifted function runs. HOS_MATH=1 turns them on, HOS_MATH_UNITS picks units, HOS_MATH_CHECK=1 runs both and compares (the game keeps the lifted result), HOS_MATH_LOG=1 logs the counters. Ported from Hookshot's native engine: Hookshot commit 60a53da7 ("A fork's native engine", merged in 7229f15b), committed by NotRexed; the engine comes from HeyListen, a GPL-3.0-or-later fork of Hookshot. Its host/hl_math.c, native/include/hl/math/Exact.h, Bounds.h, BodyBox.h, native/src/math/Bounds.cpp, BodyBox.cpp, native/src/c/hl_math.cpp and native/include/hl/bridge/MathBridge.h, from C++20 to C operation for operation (host/PROVENANCE.md). Changed from there: every byte the native path writes is marked for the GPU mirror (Hookshot's 32-byte answers were not); the native path needs FPSR.IXC set and leaves FPSR alone (Hookshot's set IXC); the counters are kept only when they are logged (six worker threads otherwise add to one cache line on every call); the switches are read at the first call, after longshot_env.txt; the unit Hookshot answers through a pointer (0x81a040bc, whose lookup hook nothing in Hookshot's runtime calls) is gated like the others; the subIntegrateLastStep check (nothing native there yet) is left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>Tested in game: Ran in the game in two test trees on main
068fb8eb(Windows, RTX 3090): HOS_MATH_CHECK with all seven units twice, 0 mismatches (0.3 to 8.6 million calls a unit in the second run, the Market and Hyrule Field), then HOS_MATH=1 with nothing visibly different, and on in a 15-run CPU measurement at a 60 fps cap with the other rewrite branches (every run held 60); this head itself is not built or played.@Beanstalk linux, and amd: this branch with HOS_MATH unset against HOS_MATH=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 and physics as without the switch, a "math: box native; ... support native;" start line with the switch set, and no "MISMATCH" in the log.
@snaildev99 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was for2b48740, and the PR has changed since (92962a4), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Possibly related, for context:
Recommendation: Request changes. The gates and diagnostic counters have cross-thread data races, and native calls can leave guest floating-point flags different from the lifted routines. The PR also has not shown that its own gain outweighs its default-off and GPU-mirror costs.
The change can replace seven physics and actor maths routines with guarded host implementations, with differential checking and fallback to lifted code. It adds substantial arithmetic and integration code; the reported earlier-tree checks are encouraging, but the current head’s performance and behavior remain unverified.
Does it help: Unproven. The PR reports 2.7% less whole-process CPU standing and 2.4% less turning with all rewrite branches enabled on an older base, not this PR alone. Its isolated offline timings use an older lift, and the current head has no game measurement against its base. Average FPS, 1% lows, frame times, build time, and the suspected mirror-copy cost are also missing.
Other systems: The gates execute even with the switch off and affect lifted-code compilation on Windows and Linux. Native writes can affect GPU mirror traffic on every GPU; the combined run saw the copy thread use 0.010–0.014 more cores, with the responsible rewrite unknown. Linux, AMD, Steam Deck and this head on Windows remain untested. Guest floating-point environment readers can observe flags omitted by the native path.
Switches: HOS_MATH defaults off; HOS_MATH_UNITS defaults to all; HOS_MATH_CHECK and HOS_MATH_LOG default off. All four have table rows. The off default is conservative but was chosen because the change is unmeasured, contrary to the project’s measurement-based switch rule; there is not yet evidence to choose a performance default.
Reviewed:
2b4874087eagainsta104182b40: Read the repository rules, PR template, standards, commits, gate diff, provenance, host integration and arithmetic excerpts. Skimmed portions of the kernels, header and test fixture; the tool output for those files was truncated, so a full code review remains outstanding. docs/review-checklist.md and the adjacent Tooling checkout were absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Blocking (to change before merge)
Suggestions (the author may take or leave)
Testing: No commands from the project, builds or tests were run, as requested. The PR reports game-free checks and earlier-tree in-game comparisons; this head has not been built or played.
Overlaps and merge order: Not established; 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.
@ -0,0 +54,4 @@/* (the translation's own float gate, RECOMP_FPX_OPEN: FPCR at its default but FZ, the host's inhibit bit 32 included, andFPSR.IXC already set. With IXC set the native path leaves FPSR as it is and is right to: every value it answers for isone whose only Arm flag would be IXC. Hookshot's answered without IXC and set it, a flag the game had not raised) */#define FP_OPEN(c) (((c)->fpsr & FPSR_IXC) && !((c)->fpcr & ~FPCR_FZ))IXC being set does not cover the other sticky flags the lifted routine can raise. A later floating-point environment read can therefore see a different FPSR; please preserve those flags or decline when they could differ, and test guest state.
@ -0,0 +342,4 @@return;for (int i = 0; i < UNITS; i++) {const Unit *u = &units[i];if (!u->calls) continue;Periodic reports read counters while workers update them atomically. These plain reads race with those writes in log and check modes; please take an atomic or otherwise synchronized snapshot.
@ -386,0 +390,4 @@# Each gets a gate first in its lifted function: hos_math_on_<addr> is 1 until the first call has read the switches, then 0# unless the unit is on (one load and an untaken branch when off); hos_math_<addr>(c) returns 1 when it answered.MATH_GATES = ("81a040bc", "80ba6d80", "81746440", "800a8400", "817d9d80")MATH_GATE = (" if (__builtin_expect(hos_math_on_%s, 0) && hos_math_%s(c)) return; "This volatile load races with start() writing the gate when workers first enter concurrently, including with the switch unset. Please use atomic gate loads and stores and publish initialization safely.
This gate also changes the default-off lifted code. The isolated old-lift measurement found a 12% sphere cost, while the combined game run cannot attribute costs to this PR. Please measure this head against its base, including off, frame pacing, build time and mirror-copy traffic.
WIP: perf(host): seven of the physics' small float routines on host code, bit for bit (HOS_MATH, off by default)to WIP: perf(host): seven of the physics' small float routines on host code, bit for bit (HOS_MATH, on by default)HOS_MATHis now on by default (e690fad0), as docs/dev/standards.md asks: a switch ships at its value from the first push, not off because it is new.HOS_MATH=0gives main's lifted code. The row's kind iskill, unset reads as on (env_on_or), and the test runs it unset and=1(on),=0and=off(off) andcheck; it fails when the old read is put back. Title and description updated to match.Recommendation: Request changes. By their own description, the kernels are the game's routines transcribed one guest operation per line, in the guest's order. CONTRIBUTING.md's Licensing section rules that out ("no decompiled game code or anything generated from the dump"), and the sibling PR whose kernels were written the same way is blocked for the same reason. Apart from that, the code is careful and its exactness evidence is strong, but this branch's gain hasn't been measured on its own.
For a player, seven of the physics' and actor loops' small float routines run as plain host C with the game's exact results, which means less CPU per frame. The code is clean: the gates fall back to the lifted function, the kernels write nothing when they decline, there is a check mode and the marks match the lifted stores. Against that, it adds about 1,900 lines of host C and about 1,400 lines of test, and its gain isn't separated from eight other branches.
Does it help: Unproven. The only game measurement is the
test/rewritestree, which has nine rewrite branches on together, on main068fb8eb: −2.7 % process CPU standing and −2.4 % turning (median of 3, Windows, RTX 3090, 60 fps cap). How much of that comes from these seven units isn't known. The offline per-call factors (1.2x to 4.9x) are measured against the old lift's form, not main's. relxf and support weren't timed at all.Other systems:
A64_MARKwith the lifted store's watched-page filter (nx2/build.pygives every host fileMARK_BITMAP;hos_math.cis the only host file that usesA64_MARKtoday, so nothing else changes). The open "capture copy +10–18 %" observation from the combined run isn't attributed to any branch.nx2/fastfp.py). Only the SDK's fenv functions read FPSR.Switches:
HOS_MATH(kill, on by default;=0gives main's lifted code). The on default is consistent with standards.md and with the exactness evidence (0 mismatches over 0.3–8.6 M calls per unit in game, plus the Unicorn differential runs). But it rests on a combined measurement, so it is Unproven alone. I left the default as it is. The farm run should confirm it.HOS_MATH_UNITS(attempt, "all"),HOS_MATH_CHECKandHOS_MATH_LOG(diag, off): the defaults are right, and these are developer switches.gpu/vk/switches.def, and the code reads them the way the rows say (env_on_or("HOS_MATH", 1)).Reviewed:
e690fad06against its fork pointa104182b4. I also rebased it onto mainb62932a96: the only conflict was a textual one innx2/oot_patches.py'sreport(), where I kept both main's "sprint press" warning and the PR's "math gates" warning, and the interdiff to the PR head is empty.host/hos_math.c,host/hos_math_kernels.c,host/hos_math_kernels.h, thenx2/oot_patches.pyandnx2/build.pyhunks,gpu/vk/switches.def,host/PROVENANCE.mdandtests/test_mark_bitmap_host.py.tests/test_native_math.py(its docstring, and what it runs: it compiles and runs the host files in a temp directory and downloads nothing).Fixed in this review: nothing pushed. The permission system refused the push to snaildev99's fork, so here are the two changes as suggestions:
report()conflict above: keep bothifblocks).host/PROVENANCE.md:57: the support unit's answer is marked withA64_MARK(with the lifted store's watched-page filter), notHOS_WRITTEN(stale since845dd761). The description's "Every byte the host writes is marked for the GPU mirror (HOS_WRITTEN)" is stale in the same way.Checked and fine:
report().start()publishes the unit state with a release store ofstarted.run*()re-reads it with an acquire load, so a thread that saw a stale gate of 1 still sees the unit off.FP_OPENis stricter than the lift'sRECOMP_FPX_OPEN(every FPCR bit but FZ), so it only declines more.bypassset, so nested gates don't recurse, and the game keeps the lifted bytes.A64_MARKcovers the first and last byte's pages, and every native range is 192 bytes or less, so at most two pages._Static_asserts.Blocking (to change before merge)
host/hos_math_kernels.c:3-4andhost/hos_math_kernels.h:7-8: licensing. The header says "Each line is one guest operation, in the guest's order; the comments name the guest function a sequence is read from". That is a statement-for-instruction transcription of the game's code, and porting it through Hookshot/HeyListen (GPL) doesn't change what it was made from. The clearest cases are:hos_math_body_box_update(:434-738), the game's per-body solver step, transcribed op by op, with the game's own literal constants (HM_BYTE,HM_SPEED,HM_ROUND,HM_CASTat:404-407), its stream-record tags (0x0000000403000010,0x0000000d04000010at:701,:714), its block limit (4048,:696) and its lane shuffles (:488-489, "the guest's lane order" at:588);:757: "The guest (111 instructions ...)") and its lane-shuffled columns (:803-808);:852-890) and the three-vertex select table.The affine box (
:317) and the vertex-set box (:207) are standard maths (centre ± |M|·e, a min/max over transformed points). Their operation order is arguably a fact needed for bit-exactness, but even those are presented as read from the guest. CONTRIBUTING.md allows host code written from facts about behaviour, described in your own words. It doesn't allow the game's functions re-expressed in C. Fixing it means either rewriting the units from a behavioural spec (what each computes, the order of roundings as a documented fact, and a public source where there is one), or a maintainer ruling that this form is acceptable. Either way, it also applies to the siblings that port the same engine.Suggestions (the author may take or leave)
nx2/oot_patches.py:443/host/hos_math.c:70: the gate is a plainvolatile intthatstart()writes while other threads read it. That's benign on x86-64 and arm64, but formally a data race.__atomic_load_n(&hos_math_on_X, __ATOMIC_RELAXED)in the generated gate costs the same and settles it (BeanBot's point 1: still there, not blocking).host/hos_math.c:338-366:report()reads counters with plain loads while workers add to them atomically. It's diagnostic only. Relaxed atomic loads would make it clean (BeanBot's point 2: still there, not blocking).host/bounds_kernels.c) next tohos_math_affine_box. Two kernels of the same routine should become one.Questions
fpsr-differscount per unit? Does the game ever call the SDK's fenv functions (fetestexceptand the like) while these units run? If it doesn't, please say so in Risks, and the point is settled. If it does, a unit whose lifted run raised a flag has to decline.Testing: the in-game evidence (check mode with 0 mismatches, then on) is from older test trees on main
068fb8eb, Windows/NVIDIA only. This head and mainb62932a96are neither built nor played. Still missing:=0, and against main);The Beanstalk request was made for
2b48740and has lapsed (it needs a BigBean's 👍 on a new request). CI is pending one690fad0(blocked by required conditions). The rule from the Wait still applies once the licensing point is settled: on its own measurement and out of WIP.Overlaps and merge order: 1899 adds the identical
nx2/build.pyMARK_BITMAP hunk andtests/test_mark_bitmap_host.py(the same blob), so whichever merges second will merge cleanly or need a trivial rebase. 1900, 1902, 1903, 1904, 1909, 1910, 1911, 2001 and 2036 add rows toswitches.defand hooks innx2/oot_patches.pynext to these. They're independent hooks, and each needs only a textual rebase after the other. Settle the licensing question for the whole family once.@ -36,0 +54,4 @@`engine/host/hl_math.c`; written by Sacrappy in commit `7412a10f`, fixed in `1bc4239a` and `4bb9c91d`, read at`62b2cb69`), as merged into Hookshot by NotRexed (commit `732c2bd1`, the same code at Hookshot's `upstream/main``29619a1c`), ported from C++20 to C operation for operation. Changed: Longshot's gate, the 16-byte answer marked(`HOS_WRITTEN`), the float gate `FP_OPEN`, an answer only while the lanes' pointer holds the block the function'sNit: the answer is marked with
A64_MARK(with the lifted store's watched-page filter) since845dd761, notHOS_WRITTEN. My push of this fix was refused, so it's a suggestion.@ -0,0 +1,923 @@/* (longshot) Bit-exact native kernels (hos_math_kernels.h has the rules and where they come from). Ported from Hookshot'snative engine, Hookshot commit 60a53da7 (NotRexed; the engine from the HeyListen fork of Hookshot, GPL-3.0-or-later):native/include/hl/math/Exact.h, native/src/math/Bounds.cpp and BodyBox.cpp, C++20 to C, operation for operation. Eachline is one guest operation, in the guest's order; the comments name the guest function a sequence is read from. */Licensing (blocking): "each line is one guest operation, in the guest's order" describes a transcription of the game's code. CONTRIBUTING.md forbids that, even when it comes through Hookshot/HeyListen. The units need to be written from a behavioural spec, or a maintainer has to rule on it. Details are in the review summary.
@ -0,0 +431,4 @@r[2][2] = hm_sub32(g, hm_sub32(g, 1.0f, xx), yy);}int hos_math_body_box_update(const HosMathBodyIn *in, HosMathBodyOut *out, int *why) {The clearest case: the game's per-body solver step, op by op, with its literal constants (:404-407), record tags (:701, :714), block limit (:696) and lane shuffles (:488-489, :588).
@ -0,0 +754,4 @@/* ---- the relative placement of two precise transforms, 0x817036a0 (relxf) ----Ported from HeyListen's engine/native/src/math/Support.cpp, relative_transform (commit 7412a10f, by Sacrappy; the samecode in Hookshot since 732c2bd1, merged by NotRexed), and Exact.h's binary64 multiply, C++20 to C operation foroperation. GPL-3.0-or-later. The guest (111 instructions; x1 = a, x2 = b, x0 = the result) stores the zero word first,"The guest (111 instructions ...)": relxf too is presented as read from the instructions.
@ -386,0 +415,4 @@if gate in out: # (made before: a lift patched again)continueat = start + len(head)out = (out[:at] + gate + out[at:]).replace(Suggestion:
extern volatile intread whilestart()writes it. It's benign on x86-64/arm64, but__atomic_load_n(&hos_math_on_%s, __ATOMIC_RELAXED)in MATH_GATE costs the same and removes the formal data race.e690fad06aee6aafc2faPushed to this branch from the review (head
ee6aafc2f): rebased onto mainb62932a96commit by commit, with one conflict innx2/oot_patches.py'sreport()resolved by keeping both warnings; andee6aafc2docs(host): PROVENANCE names A64_MARK, not HOS_WRITTEN. The review's blocking points still stand.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.