cpu: accept a fourth integer argument in R9 as an explicit per-entry choice #304
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/309"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T21:42:04Z.
Change
Builds on #285 (merged). Reworked after review: the fourth argument is an explicit per-entry choice, and the default is unchanged.
word f(word rcx, word rdx, word r8). R9 is undefined at entry and is a scratch register: a read before a write is rejected withundefined register r9, and a write followed by a read is accepted, withr9as a local. The generated C++ of every function translated this way is identical to main's.name:4, in the export list of the CLI, oftranslate()and ofcpu_translation(). R9 is then defined at entry and the generated function has a fourthword r9parameter.name:3is the explicit default. Any other count is rejected withunsupported argument count.lift(pe, name, arguments=3)takes the count directly, andFunction.argumentsrecords the entry's argument registers; the entry state, the local declarations and the signature follow it.name:4. The CLI and CMake already pass one comma-separated list, so the suffix needs no CMake change.@Nwould collide with stdcall decoration. An export whose own name contains:cannot be named this way.Shared interfaces: the export-list syntax,
lift's new keyword,Function.arguments(the module constantARGUMENTSis replaced byARGUMENT_REGISTERSandDEFAULT_ARGUMENTS), andtests/cpu/register_probe.asm, which gainsprobe4;probeandclobber_controlare unchanged.Verification
Local runs used the same compiler build as CI (MSVC 14.52.37025:
cl,link,ml64) under Wine 11.0 on Linux, ate144565on main6ee2406. I reran the items below on this head unless a line says otherwise.ctest --no-tests=error -R '^cpu_aot_fourth_argument$' -V: passed. The build translatesr9_mix:4,r9_loop:4,no_r9:4,r9_scratch. Four-argument entries are called throughprobe4and the three-argument entry throughprobe; 7,719 calls per side match a Python reference on return value, guarded trace, RBX and RSI. The test requires the count recorded on eachFunctionto equal the count its list item names, and the built source to equal the translation of that list.narrow.asm'sbyte_merge, which writes R9 before reading it, keeps(word rcx, word rdx, word r8)withr9a local, and 249 pairs throughprobematch the native export and thecpu_aot_narrow_returnsreference;r9_mixrejected in three-argument mode withundefined register r9, and the same export accepted asr9_mix:4with a four-parameter signature;r9_scratch, which writes R9 and then reads it, accepted in three-argument mode, andr9_scratch:3gives the same translation;no_r9:4gives identical results for every fourth argument;5andxrejected; R9 patched to R10 rejected withundefined register r10.switch_check.py,switch_addr32_check.py,entry_order_check.pyandnarrow_check.pyare unchanged, andcpu_aot_jump_tables,cpu_aot_switch_addr32,cpu_aot_entry_orderandcpu_aot_narrow_returnspass.cpu_*tests: same results as main. Under Wine,cpu_aot_import_call,cpu_aot_ordinal_import,cpu_native_reloc_freeandcpu_native_tlsfail on main too because Wine's loader differs from Windows. The Windows job is the reference for those./O2from this repository's C++ sources plus one plain C++ file, and the/O1and/Odbuilds: the same 642, 639 and 15 functions translate, all 1,296 have identical C++, and the shared header is identical.r9_mixis accepted without a suffix andr9_scratchrecords four arguments, which the controls above reject./O2and at/O1. Their mangled names show four integer-class parameters each. This is an upper bound that assumes the right count was chosen for each entry;probe4stack offsets) each fail the test or the build. Not caught by any test: R11 also defined at entry;/W4 /WXagain, asdocs/experiments.mdstates.pyflakes,tests/docs_links_check.pyandtests/form_coverage_check.pypassed.Not run locally: the D3D12 tests and anything that needs Windows loader behaviour.
Evidence and follow-up
tests/cpu/fourth_arg.asmandprobe4are original MASM assembled in the build. No binaries were added.fourth_argis classified intools/form_coverage.py.CMakeLists.txt,docs/experiments.mdandtools/form_coverage.py. I will rebase whichever lands second.AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:56:49Z.
Please keep the existing three-argument signature and its entry definedness as the default. Make the four-argument ABI an explicit per-entry choice, matched by the host declaration and probe. On a three-argument entry R9 is a scratch register: reject a read before definition and allow a write followed by a read. Verify an existing three-argument caller, and show the same R9-first-read fixture rejected in three-argument mode and accepted with the explicit fourth argument.
Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T21:59:19Z.
Understood. I am reworking it that way: the three-argument signature and entry definedness stay the default, so R9 is a scratch register there (a read before definition rejected, a write followed by a read accepted), and the four-argument ABI becomes an explicit per-entry choice matched by the host declaration and the probe. The update will come as a new commit on this branch with the controls you list: an existing three-argument caller verified, and the same R9-first-read export rejected in three-argument mode and accepted with the explicit fourth argument. With the default restored, the generated C++ of every function main already translates should be identical again; I will report that check.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T22:22:13Z.
Reworked as requested, in a new commit
e144565on top of the first one, rebased on6ee2406.Default unchanged. An entry listed by name keeps
word f(word rcx, word rdx, word r8)and R9 undefined at entry. Compared with main and with no allowed difference, the same 642, 639 and 15 corpus functions translate at/O2,/O1and/Od, all 1,296 have identical C++, and the shared header is identical.Explicit per-entry choice.
name:4in the export list (CLI,translate(),cpu_translation()) gives that entry a fourth integer argument in R9;name:3is the explicit default; other counts are rejected.Function.argumentsrecords it, and the entry state, locals and signature follow it. The fixture buildsr9_mix:4,r9_loop:4,no_r9:4,r9_scratch, so both modes are in one image.Matched by the host declaration and probe. Four-argument entries are called through
probe4, the three-argument entry throughprobe, and the test requires the recorded count to equal the one the list item names.The controls you listed, from
cpu_aot_fourth_argument -V:The existing three-argument tests (
switch_check.py,switch_addr32_check.py,entry_order_check.py,narrow_check.py) are unchanged and pass. The title and description are updated; the description says which checks I reran on this head and which were run during development.AI-assisted (Claude Code).