cpu: wrap 32-bit effective addresses in the jump-table translator #243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/246"
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 Spaghetih on 2026-11-21T19:12:44Z.
## Change
Independent problem: the same 32-bit effective-address mistranslation that #205 fixed in
lower()also exists in the jump-table translator,tools/cpu_switch_aot.py(Lifter.address). That translator builds addresses itself. With a 67h prefix it summed the 32-bit base and the zero-extended 32-bit displacement in 64 bits, without wrapping:lea rax, [ecx+1]0xffffffff0x00x100000000lea rax, [ecx-8]0x100x80x100000008lea rax, [ecx-8]0xffffffff0xfffffff70x1fffffff7Lifter.addressnow wraps the sum at 32 bits and zero-extends it when the base is a 32-bit register. A 32-bit index was already rejected, because the index must be a 64-bit GPR. EIP- and ESP-based operands are now rejected alongside RIP and RSP. Previously they reachedreg(), which has no binding for them.Shared interface:
Lifter.addressincpu_switch_aot.py. #173 also edits this file (SETcc/CMOVcc), but notaddress(), and it editsswitch.asm/switch_check.py. This PR adds a separate fixture so the two do not touch the same lines. Neither depends on the other.The second commit adds
switch_addr32→cpu_aot_switch_addr32toCPU_FIXTURESintools/form_coverage.py. Without it the coverage report lists the new fixture as unclassified. #252 classifies the fixtures already onmainat another position in the table. All three branches merge cleanly in sequence, andform_coverage_checkpasses on the combination.Verification
Commit on
f85723e. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, Python 3.14.6,iced-x861.21.0,pefile2024.8.26.120 native and translated 32-bit address cases matched the reference, then the EIP/ESP rejection check. Passed.tools/cpu_switch_aot.pyfromf85723e:AssertionError: lifted lea_wrap(0xffffffff) = 0x100000000, expected 0x0. Failed as expected.translate()oncpu_switch_original.dllandcpu_switch_swapped.dll(select_rva,select_rel,run_ops,shift_narrow) produced byte-identical C++ before and after this change (189 lines each). The existing jump-table output is unaffected.ctestgave 114 passed, 0 failed and 3 capability skips:bvh_wave64_hardware,bvh_wave64_warp(lane range excludes 64) andwave_shuffle_warp. The hardware tests ran on an NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088.form_coverage_checkprintedform coverage checks passed.Evidence and follow-up
tests/cpu/switch_addr32.asm,.defandswitch_addr32_check.pyare original source written for this repository under its MIT license. They need no game files. The native image runs against the same Python reference as the translation, so the expected values come from the hardware. The inputs combine 32-bit wraparound with upper-half noise (0,0xdeadbeef00000000,0xffffffff00000000). The load and store use a page committed below 4 GiB, and each store must leave the rest of the page unchanged.docs/experiments.mddescribes the behavior after the jump-table section and gives the command.Checklist
AI-assisted (Claude Code). Every result above was run locally on the configuration listed.