cpu: lower 32-bit and 64-bit MUL, DIV, IDIV, XADD, and CMPXCHG instructions #326
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/331"
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 Vonsek on 2026-11-21T22:24:29Z.
Change
mul,div,idiv,xadd, andcmpxchgintools/ffx_version_query.pyusing portable 128-bit arithmetic for 64-bit widening multiply/divide, zero-extending 32-bit writes, and keepingLOCKprefix rejection intact.tests/cpu/mul_div.asm,tests/cpu/mul_div.def) and differential test (tests/cpu/mul_div.py) wired intoCMakeLists.txtascpu_aot_mul_div, verifying all 10 exports (467 cases including 128/64 unsigned and signed division and ZF/CF flag updates) against both the native DLL and a reference model.mul_div->cpu_aot_mul_divintools/form_coverage.py(+5 baseline x64 Integer mnemonics indocs/coverage/x64_zen2.tsv) and document the test indocs/experiments.md.Verification
Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12):
cmake --build --preset dev --target cpu_mul_div_liftedfailed with:cmake --build --preset dev --target cpu_mul_div_liftedsucceeded.ctest --preset dev --no-tests=error -R "^(cpu_aot_mul_div|cpu_aot_shift_count|cpu_aot_version_query|cpu_aot_address_size)$" -V: 4/4 passed (467 MUL, DIV, IDIV, XADD, and CMPXCHG cases matched native and translated DLLs).python -B tests/form_coverage_check.py:form coverage checks passed.Evidence and follow-up
cmpxchg,div,idiv,mul,xadd) todocs/coverage/x64_zen2.tsvcoverage; all are baseline x86-64 instructions requiring no optional CPUID feature gate.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:33:45Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
85491d3932ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:27:44Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
85491d3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T22:38:37Z.
Addressed both findings:
XADD(andCMPXCHG), and addedxadd64_mem(xadd qword ptr [rcx], rcx) totests/cpu/mul_div.asm.#DEchecks (raise_de()) to 32-bit and 64-bitDIV/IDIVbefore writing guest registers, and verified 8#DEfault cases against both the native and translated DLLs intests/cpu/mul_div.py.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:33:46Z.
Code review location:
tools/ffx_version_query.py; line 210When the memory operand uses the source register as its base or index (e.g.
xadd qword ptr [rcx], rcx), this assignment updatesrcxbeforewrite('v')reevaluatesaddress(). The store therefore goes to an address derived from the old memory contents rather than the original effective address, potentially corrupting unrelated memory or faulting. This reproduced in a native-versus-emitted Linux/x86-64 probe. Capture the effective address before updating the source register and reuse it for the load and store.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T22:33:46Z.
Code review location:
tools/ffx_version_query.py; line 188For a zero divisor or an out-of-range quotient, x86
DIV/IDIVmust raise#DE, but these paths continue with fabricated results. In a native-versus-emitted Linux/x86-64 probe,div r64withRDX:RAX=0:7and divisor 0 returnedUINT64_MAXhere, and 32-bitdivwithEDX:EAX=1:0and divisor 1 returned 0; both native instructions faulted. The signed branches likewise omit quotient-range checks. Check the divisor and quotient bounds before updating guest registers, and add the corresponding failure cases to the new fixture.AGENTS.md reference: AGENTS.md:L133-L133
Useful? React with 👍 / 👎.