cpu: lower 32-bit and 64-bit MUL, DIV, IDIV, XADD, and CMPXCHG instructions #331
No reviewers
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!331
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/331/head"
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?
@Vonsek on GitHub · 2026-11-21 22:24 UTC · original
Vonsek:ag/cpu-lower-mul-div→main· +459 −0 · 6 files · 5 commits · merged 2026-11-22 08:56 UTCChange
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
@chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:27 UTC · original · edited 2026-11-21 22:33 UTC
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.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:33 UTC · original
When 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 👍 / 👎.
@ -438,0 +466,4 @@f"if (den == 0ull || hi >= den) raise_de(den == 0); "f"for (int b = 63; b >= 0; --b) {{ const bool top = (hi >> 63) != 0; "f"hi = (hi << 1) | ((lo >> b) & 1u); if (top || hi >= den) {{ hi -= den; q |= 1ull << b; }} }} "f"rax = q; rdx = hi; }}")@chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:33 UTC · original
For 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 👍 / 👎.
@Vonsek on GitHub · 2026-11-21 22:38 UTC · original
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.@chatgpt-codex-connector[bot] on GitHub · 2026-11-21 22:33 UTC · original · reviewed
💡 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".