cpu: treat a three-operand IMUL destination as written, not read #418
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/424"
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 grahamster2 on 2026-11-22T01:28:43Z.
Problem
Lifter.statementintools/cpu_switch_aot.pycallednote(*range(ins.op_count))forIMUL, so a three-operandimul r, r/m, immrecorded its destination (operand 0) as a read. That form computes dest = src * imm and only writes the destination. The definedness pass therefore refused functions whoseIMULdestination was not defined beforehand. The generated expression for the three-operand case already used only operands 1 and 2.Change
imul r, r/mstill notes operands 0 and 1, because it reads its destination. The emitted C++ is unchanged.tests/cpu/narrow.asmgainsimul3_fresh:imul r10, rdx, -5,imul r9w, cx, 7FFFh(followed bymovzx r9d, r9w, which reads only the word) andimul eax, ecx, 1010101h, with none of R10, R9 or RAX defined before. It is added to thecpu_narrowtranslation list and tonarrow_check.pywith a Python reference.imul2_undefined:imul eax, ecxat entry must still be rejected withundefined register rax.docs/experiments.md, "Switch dispatch through jump tables": one sentence on IMUL definedness and one on the new export and control.Evidence
Environment: Windows 11 Pro build 26200, VS Build Tools 2026 18.3 / MSVC 19.50.35725, Windows SDK 10.0.26100, Python 3.12. Commit
7cf8221on maine5e0079.ctest --preset dev --no-tests=error -E '^(conditional_import_paths|static_exe_intake|bundled_export_forwarders)$': 144 of 144 passed, with 3 capability skips (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp).docs_linkspassed, and so didtests/bidi_controls_check.py.cpu_aot_narrow_returns: 4,568 inputs matched the reference on the defined RAX bytes, the guarded trace, RBX and RSI (249 of them forimul3_fresh). All 8 rejection controls were rejected, includingimul2_undefined(undefined register rax at RVA 0x114a).cpu_narrow.dll: main's translator refusesimul3_freshwithundefined register r10 at RVA 0x112e(the firstIMUL). This branch translates it, and the translation matches native. Both refuseimul2_undefinedwithundefined register rax.cpu_switch_original,cpu_switch_swapped,cpu_switch_addr32,cpu_entry_order, the existingcpu_narrowexport list andcpu_fourth_arg. The new exports are placed after the existing ones, so the existing RVAs are unchanged.Found by: a Release /O2 corpus run while reviewing #420, where
offscreen_check.exeRVA 0x1b6a0 stopped atimul edi, ecx, 1010101h.Refs #420
AI-assisted (Claude Code).