gen.py keeps 8 V registers per function in locals by default

K = 8 cut guest time 3.9-6.2% in the town on a 7900X against K = 0. func.py tests the same default; --v-locals 0
gives the previous output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-13 20:11:39 +03:00
1 parent eb8c7ea888
commit 44bc5887f0
4 files changed
+11 -6

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ MacNativeGames cannot run on x86-64 as is: its CPU path executes ARM64 code nati
- `gen.py --v-locals K` keeps the K most used V registers of each function in a local `u128 vr[32]` that clang
holds in XMM registers (`recomp/vlocals.py`, the `RT_VLOCALS` accessors of `runtime/simd.h`): loaded at entry,
stored where they may have changed before calls and exits, reloaded after calls; `--v-trust` does not reload
V8-V15, whose low halves AAPCS64 has the callee preserve. K = 0, the default, keeps every V register in the `Cpu`.
V8-V15, whose low halves AAPCS64 has the callee preserve. K is 8 by default; K = 0 keeps every V register in the `Cpu`.
- Coverage oracle: MacNativeGames' NSO rewriter lists every site where game code touches the OS (SVCs, TLS reads, counter reads, `x18`, exclusive windows, jump tables): 68,968 sites in 1.4.3 `main`. The lifter must handle every one.
- Memory: guest address equals host address, all below 2^39 (IPC encodes 39-bit addresses). The heap, stacks and the alias region are reserved with `MEM_WRITE_WATCH`, so the graphics back end can ask which pages the CPU wrote since the last upload (`runtime/memory.c`).
- Indirect branches go through `rt_dispatch` (`runtime/dispatch.c`), which looks the target up in the address table and tail-calls it.
+4 -4
View File
@@ -212,8 +212,8 @@ def partition(est, max_fns, max_bytes, big_fn):
class Emitter:
"""C for the functions of one module. starts is the set of every function start of the module."""
def __init__(self, mod, starts, patched=None, reg_locals=regs.LOCALS, callee_saved=True, spins=None, v_locals=0,
v_trust=False):
def __init__(self, mod, starts, patched=None, reg_locals=regs.LOCALS, callee_saved=True, spins=None,
v_locals=vlocals.LOCALS, v_trust=False):
self.mod = mod
self.starts = starts
self.patched = patched or {} # {address: [(set index, [replacement words])]} (recomp/patches.py)
@@ -712,9 +712,9 @@ def main():
ap.add_argument('--no-callee-saved-trust', action='store_true',
help='reload X19-X29 and SP after every call too, instead of trusting AAPCS64 (slower; for '
'telling a broken callee from a generator bug)')
ap.add_argument('--v-locals', type=int, default=0,
ap.add_argument('--v-locals', type=int, default=vlocals.LOCALS,
help='V registers per function kept in C locals that clang holds in XMM registers, the most used '
'ones (recomp/vlocals.py; default 0: all in the Cpu, the output as before)')
f'ones (recomp/vlocals.py; default {vlocals.LOCALS}, 0: all in the Cpu)')
ap.add_argument('--v-trust', action='store_true',
help='with --v-locals: do not reload V8-V15 after a call (AAPCS64: the callee preserves their low '
'64 bits)')
+3
View File
@@ -20,6 +20,9 @@ NOTES.md has the measurements.
import re
from collections import Counter
# Default K: 8 cut guest time 3.9-6.2% in the town on a 7900X against K = 0 (build/v143-vloc NOTES.md, series s1 and g1).
LOCALS = 8
# runtime/simd.h helpers that take VCTX, with their parameters after c. Register-number parameters are d (written,
# also read by some), n, m, a (read) and t (the first of up to 4 consecutive registers; written by the sl_ld* loads).
HELPERS = {
+3 -1
View File
@@ -39,6 +39,7 @@ from unicorn import arm64_const as A
from common import BUF, BUF_SIZE, MSYS_BIN, ROOT, Emu, compiler, diff_state, rand_fpcr, rand_v, rand_x, run_harness
import gen
import patches
import vlocals
from layout import layout
from module import Module
@@ -346,7 +347,8 @@ def main():
ap.add_argument('--show', type=int, default=20)
ap.add_argument('--patches', type=Path, help='patch table whose spin waits are emitted with their gates')
ap.add_argument('--cflags', default='-march=x86-64-v3' if platform.machine().lower() in ('amd64', 'x86_64') else '')
ap.add_argument('--v-locals', type=int, default=0, help='gen.py --v-locals: V registers per function in locals')
ap.add_argument('--v-locals', type=int, default=vlocals.LOCALS,
help='gen.py --v-locals: V registers per function in locals')
ap.add_argument('--v-trust', action='store_true', help='gen.py --v-trust: V8-V15 not reloaded after a call')
ap.add_argument('--work', type=Path, default=ROOT / 'build' / 'test' / 'func',
help='work directory (chunks, harness, images); one per concurrent run')