Triforce v0.8.5

A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
ruckus7382sfgsgdf
2026-11-28 10:54:41 -06:00
parent 2df08c751e
commit b527e29adb
203 changed files with 18821 additions and 2051 deletions

View File

@@ -106,9 +106,14 @@ def emit_print(cls):
def lift_print(cls):
"""(Triforce) What a worker's emit and texts are made of: emit_print, and the same for the lifter's dead_flags and for the
translator (a64emit.translate) and a64_lift.op_text, which a worker now calls itself (run_texts)"""
translator (a64emit.translate) and a64_lift.op_text, which a worker now calls itself (run_texts). (11-27) And for the kit's
vectorize_fcmp, which op_text reaches by its name in the module (nx2/local_flags.py wraps it), and the flags' form as this
process reads it (a64_lift.local_flags, nx2/local_flags.py's rule in its place): a worker that read it otherwise would write
the other form, and the lift's process the other a64_fpx.h"""
import a64emit
return [emit_print(cls), chain(getattr(cls, "dead_flags", None)), chain(a64emit.translate), chain(a64_lift.op_text)]
flags = ["%s (%s)" % ("as locals" if a64_lift.local_flags() else "in the context", " over ".join(chain(a64_lift.local_flags)))]
return [emit_print(cls), chain(getattr(cls, "dead_flags", None)), chain(a64emit.translate), chain(a64_lift.op_text),
chain(a64_lift.vectorize_fcmp), flags]
def chain(f):
@@ -190,10 +195,13 @@ def _start(blob):
f()
got = lift_print(cls)
for what, mine, theirs in zip(("the lifter's emit_function", "the lifter's dead_flags", "the translator (a64emit.translate)",
"a64_lift.op_text"), got, want):
"a64_lift.op_text", "a64_lift.vectorize_fcmp", "the flags (a64_lift.local_flags)"), got, want):
if mine != theirs:
raise RuntimeError("%s here is %s, the lift's process has %s: what set it up there must be named in `setup` "
"(nx2/chunks.py write)" % (what, " over ".join(mine), " over ".join(theirs)))
why = "what set it up there must be named in `setup` (nx2/chunks.py write)"
if what.startswith("the flags"): # (the switch as this process's environment has it, or no install() here)
why = "this process's A64_LOCAL_FLAGS is not the lift's, or " + why
raise RuntimeError("%s here is %s, the lift's process has %s: %s"
% (what, " over ".join(mine), " over ".join(theirs), why))
L = cls.__new__(cls)
vars(L).update(state)
_mine = (L, [vars(L)[k] if m == "L" else getattr(importlib.import_module(m), k) for m, k in counters])

View File

@@ -39,6 +39,7 @@ import dead_flags
import walk
import nativefp
import discover
import local_flags
import chunks
import standalone
import adr_entries # noqa: E402
@@ -60,6 +61,7 @@ vecfp.install() # ((Triforce, 11-22, LIFT-03) SSE fast paths before float form
cmpflags.install() # ((Triforce) a subtraction's V flag in a form the compiler folds, with A64_SUB_V=1 or ovf: nx2/cmpflags.py)
dead_flags.install() # ((Triforce, 11-24) the kit's dead_flags answered at once for a function that writes no flag: nx2/dead_flags.py)
walk.install() # ((Triforce, 11-24) the kit's walk, one shared entry per plain op's word: nx2/walk.py)
local_flags.install() # ((Triforce, 11-23, LX-2) NZCV as each function's locals, unless A64_LOCAL_FLAGS=0: nx2/local_flags.py; before nativefp's, which stays last)
nativefp.install() # ((Triforce, 11-26) hot float on the host's instructions / easy cases, with A64_NATIVE_FP=1 / A64_FPX_EASY=1: nx2/nativefp.py; last, so the native names go on the hot text as it leaves every other pass)
@@ -233,6 +235,7 @@ def main():
print("wrote %d code files to %s (%.0fs)" % (len(files), gen, time.time() - t0))
if nativefp.report():
print(nativefp.report())
print(local_flags.report()) # ((Triforce, 11-27) the flags' form the C has: nx2/local_flags.py)
print("done (%.0fs)" % (time.time() - t0))

94
nx2/local_flags.py Normal file
View File

@@ -0,0 +1,94 @@
"""N, Z, C and V as locals of each lifted function, on by default (A64_LOCAL_FLAGS=0: bytes of the context, as before).
(Triforce, 11-23, the fps pass's LX-2, after NX2navi 0.11.0-rc4's recomp/flags.py, which keeps the flags in a function's
locals.) The kit has the rule as a lift-time switch, A64_LOCAL_FLAGS (third_party/a64-kit/lift/a64_lift.py local_flags,
localize_regs): every c->n, c->z, c->c and c->v of a function's text becomes a local, read from the context once at the
function's start and written back only where control leaves other than by a call or a return (tail calls, indirect jumps,
SVCs and traps), and read again after an SVC. The AAPCS64 leaves the flags undefined across calls and returns, which the
kit's dead-flag pass relies on already. Without it every flag a later instruction reads is a byte stored into the context
at each compare, and the compiler must keep the store because the context outlives the function.
Measured on the owner's PC (RTX 5090, 2560x1440, the Market after the save's load, the last 40 s of each run, nine runs a
side interleaved over three batches, the shipped hot profile made without it): 139.4 -> 141.3 fps (+1.3%), the time a
frame spends outside the replay 2.10 -> 1.98 ms. In the last batch, with HOS_THREAD_TIMES: 139.3 -> 142.3 fps (+2.1%,
every run with it above every run without) and the game's workers and main thread 31.9 -> 30.4 ms of CPU a frame.
The rule (on): unset, empty or any value but 0 turns it on; 0 turns it off. The kit's own reader takes any value that is
set and not empty as on, so install() puts this rule in its place (a64_lift.local_flags) and leaves the environment as
the player set it. Every process that runs install() decides the same way: the lift's own, and each process it starts
for its emit (spawned on Windows: they run nx2/lift.py's module level again with the lift's environment).
A64_LOCAL_FLAGS is an A64_ name, so nx2/make_game.py's lift key has the player's value, and this file is in the key (it
is not in make_game.py's LIFT_KEY_NOT; tests/test_local_flags.py holds it there).
(11-27) The kit's A64_PACKED_FLAGS (an experiment, off) writes a flag-setting instruction's four flags into the context
in one store, which the flag locals do not see: every later flag read would take the flags the function started with.
install() stops the lift when both are on.
What the lifted text then has in place of c->z is fz_ (likewise fn_, fc_, fv_): an edit of the lifted C that matches or
writes a flag by its text has to know both forms (nx2/oot_patches.py patch_scene_format).
(11-27, on v0.8.4) The hot profile. The hot code is built with the shipped profile (RX_PGO, clang's -fprofile-instr-use),
which clang matches to each function by a hash of its control flow (its ifs and elses, loops, gotos, returns, !, && and
||, comparisons, ?:). With the switch the kit lifts a scalar FCMP's fast path in a code form,
"{ const uint32_t _fk = a64_fcmp32k(c,a,b); if (_fk) { the flags from _fk } else { the exact compare } }", where without
it the lift has "{ if (!a64_fcmp32(c,a,b)) { the exact compare } }": an else in place of a !, so every function that holds
an FCMP hashed differently and was compiled without its profile. That was 652 of the 1384 hot functions of v0.8.4 (17.7%
of the profile's entry counts), and clang counted 49 functions with stale entries in the first hot piece where the lift
without the switch has 21. install() therefore wraps the kit's vectorize_fcmp: the flags from _fk are written first
and the exact compare, which writes every flag the dead-flag pass keeps on each of its paths, runs after them under
"if (!_fk)", so the control flow is the one the profile was made from. The fast path computes the same three flags as
before; the exact path's first writes are dead, and the compiler drops them.
"""
import os
import re
# the kit's code form of a scalar FCMP's fast path with the flags as locals (a64_lift.vectorize_fcmp), as far as its else
KIT_FCMP = re.compile(r"\{ const uint32_t _fk = (a64_fcmp(?:32|64)k\(c,[^;]*\)); if \(_fk\) \{ c->n=\(uint8_t\)\(_fk&1\); "
r"c->z=\(uint8_t\)\(_fk>>1&1\); c->c=\(uint8_t\)!\(_fk&1\); c->v=0; \} else ")
# the same flags written first and the exact compare under "if (!_fk)": the control flow of the form without the switch
PGO_FCMP = r"{ const uint32_t _fk = \1; c->n=(uint8_t)(_fk&1); c->z=(uint8_t)(_fk>>1&1); c->c=(uint8_t)((_fk&1)^1); c->v=0; if (!_fk) "
_installed = False
def on(value):
"""Whether the flags become locals for a value of A64_LOCAL_FLAGS (None: unset)"""
return value is None or value.strip() != "0"
def profile_form(text):
"""A lifted instruction's text with the kit's code form of the FCMP fast path (if any) in the profile's control flow"""
return KIT_FCMP.sub(PGO_FCMP, text) if "_fk = a64_fcmp" in text else text
def kit_reads():
"""a64_lift.local_flags once installed: the rule (on) on the switch as the environment has it when the kit asks. By
the variable's literal name, as tests/test_lift_key_env.py wants every read of the lift's environment"""
return on(os.environ.get("A64_LOCAL_FLAGS"))
def report():
"""The lift's line on the flags' form"""
return ("flags: N, Z, C and V as each function's locals (A64_LOCAL_FLAGS=0: bytes of the context)" if kit_reads()
else "flags: bytes of the context (A64_LOCAL_FLAGS=0)")
def install():
"""The rule in place of the kit's reader (a64_lift.local_flags, which the kit calls by its name in the module), the
environment left as it is, and a stop when the kit's A64_PACKED_FLAGS is on as well (the kit's own test: set and not
empty). And, once, the wrap around the kit's vectorize_fcmp (profile_form), which a64_lift.vectorize_fpx calls by its
name in the module"""
global _installed
import a64_lift
a64_lift.local_flags = kit_reads
if kit_reads() and os.environ.get("A64_PACKED_FLAGS"):
raise SystemExit("nx2/local_flags.py: A64_PACKED_FLAGS writes the four flags into the context in one store, which "
"the flag locals (A64_LOCAL_FLAGS, on by default) do not see: every later flag read would take the "
"flags the function started with. Unset A64_PACKED_FLAGS, or set A64_LOCAL_FLAGS=0 with it")
if _installed:
return
_installed = True
base = a64_lift.vectorize_fcmp
def vectorize_fcmp(text):
return profile_form(base(text))
a64_lift.vectorize_fcmp = vectorize_fcmp

View File

@@ -53,6 +53,18 @@ import re
import sys
import whole_write # (rewrites written beside and moved over: issue 1197)
# ((Triforce, 11-26, LX-2 on v0.8.3) A lift with the flags as each function's locals (nx2/local_flags.py, on by default)
# reads and writes c->z as fz_ (likewise fn_, fc_, fv_), and its scalar FCMP calls a64_fcmp32k, in nx2/local_flags.py's
# profile form (the flags from _fk, then the exact compare under "if (!_fk)"; match it only as far as the _fk local, as
# HORSE_TEST_LOCAL does): an edit that matches a flag by its text takes both forms, or it finds nothing in such a lift and
# only warns. local_form(text): the text as such a lift writes it, by the kit's own rule
# (third_party/a64-kit/lift/a64_lift.py FLAG_REF)
FLAG_REF = re.compile(r"(?<![\w>.])c->([nzcv])\b")
def local_form(text):
return FLAG_REF.sub(r"f\1_", text)
DECL = "extern volatile int hos_fixed_resolution;\nextern volatile int hos_dynres_runs;\nextern volatile uint32_t hos_fixed_scale_bits;\n"
OLD = "if (!((c->x[8] >> 0) & 1)) { goto L_8082640c; }"
NEW = "if (hos_fixed_resolution || !((c->x[8] >> 0) & 1)) { goto L_8082640c; }\n hos_dynres_runs++;"
@@ -170,7 +182,7 @@ def patch_mouse_camera(source):
return None
if "hos_mouse_camera(c->x[0]);" in source: # (made before: a lift patched again)
return source
at = start + len(CAM_HEAD)
at = head_end(source, start + len(CAM_HEAD)) # ((Triforce, 11-27) after the flags' declaration: KIT_LOCALS)
source = source[:at] + " hos_mouse_camera(c->x[0]); /* (nx2/oot_patches.py: native mouse look) */\n" + source[at:]
return source.replace('#include "a64.h"\n', '#include "a64.h"\nextern void hos_mouse_camera(uint64_t camera);\n', 1)
@@ -622,6 +634,27 @@ HORSE_BRANCH = "if (!c->n) { goto L_82c5ae48; }\n"
HORSE_SKIP = (" if (hos_oot_horse_whole_step((uint32_t)c->vreg[10][0], " + SOUND_SLOT + " + 2192)) { goto L_82c5ae48; }"
" /* (nx2/oot_patches.py: a horse's jump blend above 60 fps) */\n")
HORSE_DECL = "extern int hos_oot_horse_whole_step(uint32_t step_bits, uint64_t slot);\n"
# ((Triforce, 11-26, LX-2) the same test and branch in a lift with the flags as locals: the FCMP's fast compare into its _fk
# local (the kit's vectorize_fcmp with A64_LOCAL_FLAGS) and the N flag read as fn_. (11-27) As far as that local: what follows
# it is the kit's "if (_fk) ..." or, as nx2/local_flags.py writes it for the hot profile, the flags and "if (!_fk) ...")
HORSE_TEST_LOCAL = HORSE_TEST.replace("{ if (!a64_fcmp32(c,c->vreg[10],c->vreg[9])) ",
"{ const uint32_t _fk = a64_fcmp32k(c,c->vreg[10],c->vreg[9]); ", 1)
HORSE_BRANCH_LOCAL = local_form(HORSE_BRANCH)
# ((Triforce, 11-27, LX-2) the line a lift with the flags as locals adds after the head of every function that uses a flag: the
# kit's localize_regs, after any registers' locals. A patch that counts a function's first lines has to leave it out)
FLAG_DECL = " uint8_t fn_ = c->n, fz_ = c->z, fc_ = c->c, fv_ = c->v;\n"
# ((Triforce, 11-27, LX-2) the guest locals' lines the kit writes right after a function's head: the registers' (A64_LOCAL_REGS)
# and the flags' (FLAG_DECL). nx2/split_giants.py takes them only as the body's first lines (locals_of): a hook at the head of
# a function it cuts (split_giants.MIN_KB or more: the player camera's update, the zstd decoder's) goes after them (head_end),
# or the giant is left whole, as the player camera's update was with the mouse look)
KIT_LOCALS = re.compile(r"(?: uint64_t x\d+_ = c->x\[\d+\](?:, x\d+_ = c->x\[\d+\])*;\n)?(?:%s)?" % re.escape(FLAG_DECL))
def head_end(source, at):
"""Where a hook at a function's head goes: at (just after the head's line), past the kit's guest locals' lines"""
return KIT_LOCALS.match(source, at).end()
# A rigid body's update before the physics step, f_804f5030, on its path for a body driven to a target (x20 the controller, x23
# the body): the game sets the target (+0x3c) to the body's position plus this frame's move and asks for (target - position) /
# dt. Above 60 fps Havok's solve delivers only part of it (0.86 at 120 fps), the next target starts from where the body ended
@@ -827,12 +860,15 @@ def patch_horse_jump(s):
return s, 0
head, end = at
body = s[head:end]
if body.count(HORSE_SKIP + HORSE_BRANCH) == 1:
forms = ((HORSE_TEST, HORSE_BRANCH), (HORSE_TEST_LOCAL, HORSE_BRANCH_LOCAL)) # (the flags in the context, or locals)
if any(body.count(HORSE_SKIP + branch) == 1 for _, branch in forms):
return s, 1
if body.count(HORSE_TEST) != 1 or HORSE_SKIP in body:
form = [f for f in forms if body.count(f[0]) == 1]
if len(form) != 1 or HORSE_SKIP in body:
return s, 0
line_end = body.find("\n", body.index(HORSE_TEST) + len(HORSE_TEST))
if line_end < 0 or not body.startswith(HORSE_BRANCH, line_end + 1):
test, branch = form[0]
line_end = body.find("\n", body.index(test) + len(test))
if line_end < 0 or not body.startswith(branch, line_end + 1):
return s, 0
body = body[:line_end + 1] + HORSE_SKIP + body[line_end + 1:]
s = s[:head] + body + s[end:]
@@ -942,7 +978,10 @@ def patch_cloth_solve(s):
if body.count(CLOTH_SOLVE_OLD) != 1:
return s, 0
first = body.index(CLOTH_SOLVE_OLD)
if body[:first].count("\n") > 2: # (the first store is the job's own first line, after the head and a hint)
# (the first store is the job's own first line, after the head and a hint; a lift with the flags as locals puts their
# declaration between the head and the hint (the kit's localize_regs, A64_LOCAL_FLAGS), which is no line of the job's own:
# (Triforce, 11-27, LX-2 on v0.8.4) counted, it left the gate out and the cloth solving at every frame above 60 fps)
if body[:first].replace(FLAG_DECL, "", 1).count("\n") > 2:
return s, 0
s = s[:head] + body[:first] + CLOTH_SOLVE_NEW + body[first:] + s[end:]
if CLOTH_SOLVE_DECL not in s:
@@ -1209,12 +1248,13 @@ def patch_host_zstd(s):
head, end = at
body = s[head:end]
hook = ZSTD_HOOK % name
if body.startswith(head_text + hook):
first = head_end(body, len(head_text)) # ((Triforce, 11-27) after the kit's locals' lines: KIT_LOCALS)
if body.startswith(hook, first):
done += 1
elif hook not in body:
plain = _unmarked(body)
if all(plain.count(_unmarked(line)) == 1 for line in shape):
s = s[:head] + head_text + hook + body[len(head_text):] + s[end:]
s = s[:head] + body[:first] + hook + body[first:] + s[end:]
done += 1
if done and ZSTD_DECL not in s:
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + ZSTD_DECL, 1)
@@ -1251,12 +1291,17 @@ RGBA16F_DECL = "int hos_scene_rgba16f(void);\n"
RGBA16F_OLD = (" c->x[9] = 0x1aULL;\n c->x[9] &= 0xFFFFFFFFULL;\n"
" { uint64_t _r = (!c->z) ? c->x[10] : c->x[9]; _r &= 0xFFFFFFFFULL; c->x[9] = _r; }\nL_80672354:;")
RGBA16F_NEW = RGBA16F_OLD.replace("c->x[9] = 0x1aULL;", "c->x[9] = hos_scene_rgba16f() ? 0x2cULL : 0x1aULL;", 1)
# ((Triforce, 11-23, LX-2) the same csel with the flags as the function's locals, nx2/local_flags.py's default: the Z flag
# is read as fz_. Without this form the patch was found 0 times in such a lift)
RGBA16F_OLD_LOCAL = RGBA16F_OLD.replace("(!c->z)", "(!fz_)", 1)
RGBA16F_NEW_LOCAL = RGBA16F_NEW.replace("(!c->z)", "(!fz_)", 1)
def patch_scene_format(s):
if RGBA16F_OLD not in s:
return None
return s.replace(RGBA16F_OLD, RGBA16F_NEW, 1).replace('#include "a64.h"\n', '#include "a64.h"\n' + RGBA16F_DECL, 1)
for old, new in ((RGBA16F_OLD, RGBA16F_NEW), (RGBA16F_OLD_LOCAL, RGBA16F_NEW_LOCAL)):
if old in s:
return s.replace(old, new, 1).replace('#include "a64.h"\n', '#include "a64.h"\n' + RGBA16F_DECL, 1)
return None
# (from TomShafford/Hookshot 55d68e8cd6 and 65c1998222) f_804566e0's two calls of f_80522050, the GPU memory a model's material
@@ -1567,6 +1612,7 @@ def patch_text_size(s):
# the parameter base that path gives it (x26) and the code goes on where the other yaw paths join, at 0x80645ad8. The stick's
# turn (state 4), the game's own recentre (state 2), the authored overrides, the pitch and the collision stay as they are.
CAM_FOLLOW_ANCHOR = "L_8064720c:;\nif (!c->z) { goto L_806492c4; }\n"
CAM_FOLLOW_ANCHOR_LOCAL = local_form(CAM_FOLLOW_ANCHOR) # ((Triforce, 11-26, LX-2) the Z flag as a local: fz_)
CAM_FOLLOW_JOIN = "L_80645ad8:;\n"
CAM_FOLLOW_HOOK = (" if (hos_disable_camera_centering()) { c->x[25] = c->x[26]; A64_POLL(c); goto L_80645ad8; }"
" /* (nx2/oot_patches.py: the Camera centering row) */\n")
@@ -1581,11 +1627,12 @@ def patch_camera_centering(s):
return s, 0
head, end = at
body = s[head:end]
if body.count(CAM_FOLLOW_ANCHOR) != 1 or body.count(CAM_FOLLOW_JOIN) != 1:
anchor = CAM_FOLLOW_ANCHOR if CAM_FOLLOW_ANCHOR in body else CAM_FOLLOW_ANCHOR_LOCAL # (the flags in the context, or locals)
if body.count(anchor) != 1 or body.count(CAM_FOLLOW_JOIN) != 1:
return s, 0
if CAM_FOLLOW_HOOK in body:
return s, int(body.count(CAM_FOLLOW_ANCHOR + CAM_FOLLOW_HOOK) == 1)
at = head + body.index(CAM_FOLLOW_ANCHOR) + len(CAM_FOLLOW_ANCHOR)
return s, int(body.count(anchor + CAM_FOLLOW_HOOK) == 1)
at = head + body.index(anchor) + len(anchor)
s = s[:at] + CAM_FOLLOW_HOOK + s[at:]
if CAM_FOLLOW_DECL not in s:
s = s.replace('#include "a64.h"\n', '#include "a64.h"\n' + CAM_FOLLOW_DECL, 1)
@@ -1717,6 +1764,10 @@ def patch_cct_speed(s):
continue
start, end = at
body = s[start:end]
if anchor != head and anchor.startswith(head) and anchor not in body:
# ((Triforce, 11-27, LX-2 on v0.8.4) an anchor that goes on past the head: a lift with the flags as locals has their
# declaration between (FLAG_DECL), and f_80964bf0's place was found 3 times, not 4: the tool did not scale it)
anchor = head + FLAG_DECL + anchor[len(head):]
if body.count(anchor + hook) == 1:
done += 1
elif body.count(anchor) == 1:
@@ -1803,6 +1854,8 @@ OC_TICK_GATES = (
"if (c->x[0] == 0) { { A64_POLL(c); hos_oc_wait = 0; goto L_828a92e4; } }"
" /* (nx2/oot_patches.py: the wait's owner refused: no wait, and the pads are the game's again) */"),
)
# ((Triforce, 11-26, LX-2) the gates in a lift with the flags as locals: the mode check's Z read as fz_, before and after)
OC_TICK_GATES_LOCAL = tuple((local_form(old), local_form(new)) for old, new in OC_TICK_GATES)
OC_DONE_OLD = "recomp_store32(c,c->x[19] + 24,c->x[9]);"
OC_DONE_NEW = (OC_DONE_OLD + "\n hos_oc_wait = 0;"
" /* (nx2/oot_patches.py: the wait action finished) */")
@@ -1823,6 +1876,9 @@ def patch_ocarina_wait(s):
return None
end = s.find("\nvoid f_", at + len(head))
body = s[at:end if end >= 0 else len(s)]
if head == OC_TICK_HEAD and not any(old in body or new in body for old, new in OC_TICK_GATES[:1]):
# (no gate in the context's form: a lift with the flags as locals, whose gates read fz_)
pairs = [OC_TICK_GATES_LOCAL[OC_TICK_GATES.index(pr)] if pr in OC_TICK_GATES else pr for pr in pairs]
out = body
for old, new in pairs:
if new in out:

View File

@@ -5,10 +5,11 @@ graph of tens of thousands of blocks): the lift's chunks of ~2 MB functions (cod
build's lifted compile time at 4-7x the seconds per MB of ordinary chunks. The lifter's own cut (a64_lift.split_large: an
extra entry where no branch crosses) cannot cut these: each is one big loop nest.
Why it is exact: a lifted function keeps all guest state in the context (c->x[], c->vreg[], NZCV, FPCR/FPSR) and in guest
memory; each guest instruction is one top-level statement whose C locals live inside its own block, and labels are written
only at the top level (third_party/a64-kit/lift/a64_lift.py emit_function). So before any top-level label nothing but *c
and memory is live, and the body can be cut there:
Why it is exact: a lifted function keeps all guest state in the context (c->x[], c->vreg[], FPCR/FPSR; NZCV too with
A64_LOCAL_FLAGS=0, in locals by default: see the guest locals below) and in guest memory; each guest instruction is one
top-level statement whose C locals live inside its own block, and labels are written only at the top level
(third_party/a64-kit/lift/a64_lift.py emit_function). So before any top-level label nothing but *c and memory is live,
and the body can be cut there:
- a piece `static uintptr_t s_<addr>_<n>(Ctx *c, uintptr_t k)` starts at the label whose id is k (or at its first
statement), runs its statements as written, and returns what comes next: 0 (the guest returned), a label id (a goto
into another piece, with its interrupt poll kept), or a tail-call id (a guest branch into another function);

View File

@@ -65,6 +65,8 @@ RUN_ALL_SKIP = {
insn.install()
lift_fixes.install()
poll.install()
import local_flags # noqa: E402
local_flags.install() # ((Triforce, 11-23, LX-2) the flags as each function's locals, as nx2/lift.py lifts them unless A64_LOCAL_FLAGS=0)
SCRATCH_SIZE = 0x100000
SENTINEL = 0x7F000000 # LR of the outermost call: a mapped page with no code, below the image
@@ -317,6 +319,8 @@ def build(tmp, P, roots, funcs, meta, img_size, addr64):
a64_rtgen.write(tmp)
with open(os.path.join(tmp, "a64_fpx.h"), "w", newline="\n") as f:
f.write(a64_lift.fpx_header(P.fpx))
if a64_lift.local_flags(): # ((Triforce, 11-23, LX-2) the FCMP helpers the flags' locals take, as the kit's write() adds them)
f.write(a64_lift.FCMPK_HEADER)
rt = os.path.join(kit.KIT, "rt")
if addr64:
rt = rtgen.write(os.path.join(tmp, "rt64")) # (its a64.h shadows the vendored one)