cpu: translate 8- and 16-bit register writes, void returns and ret 0 in the jump-table translator #276
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#276
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@bosseurdinternet on GitHub · 2026-11-21 20:07 UTC · original
Problem
tools/cpu_switch_aot.pyaccepts only 32- and 64-bit register writes and requires RAX to be fully defined at everyRET. It therefore refuses:undefined register rax);mov al, 1; ret:unsupported partial register write);ret 0encoded asC2 00 00(unsupported control flow);Measured on 1,119 functions compiled with MSVC 14.52
/O2from this repository's own C++ sources plus one plain C++ file written for the measurement:cpu_switch_aot.liftlowers 478 today. As a first refusal,ret 0accounts for 52 functions and a narrow register write for 49. Limits of that measurement: 831 of the 1,119 functions are MSVC STL instantiations, only the first refusal of each function is counted, and this is desktop code.Proposal
I am working on this now and intend to send one PR.
Lifter.writemerges 8- and 16-bit low-register destinations into the full register. AH, BH, CH and DH stay rejected. 32- and 64-bit writes are unchanged, so the C++ generated for functions that already lower stays identical.RETno longer requires RAX. Each translated function reports the number of low bytes of RAX defined at every return (0 for a void function, 1 for a bool). A return whose RAX may hold a guest address stays rejected.ret 0is accepted; any otherret Nstays rejected.Shared interfaces this changes: the read and write effects returned by
Lifter.statement,Lifter.write, and the must-defined pass at the end oflift().Overlap. #173 (SETcc and CMOVcc, by @Vonsek) changes the same
lift()loop andstatement(). The behaviours do not overlap. #173 was opened first; if it lands first I will rebase onto it. One interaction worth knowing: with byte-wide definedness, a SETcc into a byte register would not need the full register to be defined beforehand.An in-memory prototype of the design lowers 582 of the same 1,119 functions with no function lost. About 55 of the 104 gained are empty void functions and 13 are two-instruction bool functions, so roughly 36 are substantive. These are prototype numbers; the PR will report measured ones.
Alternatives
ret 0, without narrow writes: smaller, but a bool return stays refused. I can split the PR this way if preferred.Verification
A new source-built MASM fixture and CTest entry, separate from
switch.asmso it does not collide with #173:ret 8, a join of paths with different defined widths, and a returned guest address;Checklist
AI-assisted (Claude Code).