cpu: lift RDX:RAX multiplies, divides and sign extensions in the jump-table translator #316

Merged
bosseurdinternet merged 2 commits from upstream-pr/321 into main 2026-11-22 05:06:07 +00:00
bosseurdinternet commented 2026-11-21 22:02:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T22:02:33Z.


Change

Builds on #285 (merged) and is independent of #309. tools/cpu_switch_aot.py refused CBW, CWDE, CDQE, CDQ, CQO, one-operand MUL and IMUL, and DIV and IDIV, which MSVC emits for 64-bit multiply-high, division and modulo.

  • Explicit effects. Each form states its reads and writes of RAX and RDX. Operand 0 of a one-operand multiply or divide is a source. Every input is copied into a const temporary before RAX or RDX is written, since the source may be one of them (mul rdx) or be addressed through them.
  • Sign extensions and products of factors up to 32 bits use wrapping std::uint64_t arithmetic, with no signed conversion and no shift of a negative value. An 8-bit multiply writes AX; a 16-bit multiply merges into AX and DX.
  • 64-bit products use _umul128 and _mul128. Quotients use _udiv64, _div64, _udiv128 and _div128, which execute DIV or IDIV, so a zero divisor or a quotient that does not fit raises the same divide error as the original. No C++ / or % is emitted. The generated source now includes <intrin.h>.
  • Rejected: 8-bit divides (they write AH) and 16-bit divides, with unsupported divide width. A flag consumer after a multiply or divide stays rejected. The sign extensions, which the Intel SDM lists with "Flags Affected: None", may sit between a flag producer and its consumer.
  • A soundness fix this change requires. The constant pass for table bases and the value numbering for table indices assumed operand 0 is the only register an instruction writes. That was harmless while these instructions were refused. They now treat these instructions as writes of RAX and RDX; otherwise a MUL or CQO that overwrites a table base or index before the dispatch would be accepted. Two controls cover it.

Limitation, stated in the docs: at /O2 MSVC removes a divide whose quotient and remainder are both unused, and its divide error is then not raised. The same already happens to a load whose value is unused, for every load except a CMOVcc memory source.

Generated C++ for functions that already translate is unchanged apart from the include line.

Verification

Local runs used the same compiler build as CI (MSVC 14.52.37025: cl, link, ml64) under Wine 11.0 on Linux, at a3cc509 on main 1292d15. I reran the items below on this head unless a line says otherwise.

  • ctest --no-tests=error -R '^cpu_aot_wide_arithmetic$' -V: passed. 13 exports and 2,929 non-faulting inputs; each original and translated export is compared through the register probe with a Python reference, which rounds signed quotients toward zero itself, on RAX, the guarded trace, RBX and RSI.
  • Eight faulting inputs (zero divisors, unsigned quotients that do not fit, -2^31 / -1, -2^63 / -1): original and translation raise the same OSError and leave the same trace. Under Wine every divide error reads exception: integer divide by zero. Whether Windows reports the overflow cases as integer overflow was not observed; the test accepts either message when both sides agree.
  • Eleven rejection controls, printed one line each: div r9d patched to div r9b and to div cx; a Jcc right after a divide; cdq replaced by clc between a compare and its consumer; RAX or RDX undefined at a multiply or divide (four cases, one of them RDX holding a guest address); a flag consumer after a multiply; a multiply that overwrites a jump-table base; a sign extension that overwrites a jump-table index.
  • cpu_aot_jump_tables, cpu_aot_narrow_returns, cpu_aot_entry_order: pass unchanged. Other cpu_* tests: same results as main. Under Wine, cpu_aot_import_call, cpu_aot_ordinal_import, cpu_native_reloc_free and cpu_native_tls fail on main too because Wine's loader differs from Windows, and cpu_native_exe_start times out intermittently (#281). The Windows job is the reference for those.
  • Corpus. 1,119 functions compiled with MSVC /O2 from this repository's C++ sources plus one plain C++ file, and the /O1 and /Od builds of the same sources: /O2 642 → 650, /O1 639 → 646, /Od 15 → 15. No function is lost. All 1,296 functions translated by both have identical C++; the only shared difference is the <intrin.h> line.
  • Differential execution (each function compiled with cl and called beside the original on 64 inputs, comparing the defined RAX bytes, a seeded memory arena and whether a fault occurred): the 8 functions gained at /O2 and the 7 at /O1 match on every input, and so do all 650 translated at /O2 that could be run. This is evidence on a few inputs per function, not a proof of equivalence. With signed forms lowered as unsigned, 2 of the 8 mismatch.
  • Checked during development, not rerun on this head: cl /O2 /FAs shows each divide of the fixture as one inline div or idiv with no call or added check; all 2,566 earlier translations, library code included, compile to identical code with and without <intrin.h>; and 20 manual mutants, of which 19 fail the test. The one that survives keeps the generic operand-0 write for a one-operand form, which changes no definedness state.
  • pyflakes, tests/docs_links_check.py and tests/form_coverage_check.py passed.

Not run locally: the D3D12 tests and anything that needs Windows loader behaviour.

Evidence and follow-up

  • tests/cpu/wide_arith.asm is original MASM assembled in the build. No binaries were added. wide_arith is classified in tools/form_coverage.py.
  • Limits of the corpus numbers: desktop code built from this repository's sources, and every gained function comes from the one plain C++ file written for the measurement (gcd32, gcd64, udiv64, sdiv10, smod64, div7, a checksum and one method).
  • The signed intrinsics need unsigned-to-signed conversions, which are implementation-defined before C++20; MSVC documents wrapping, and the existing MOVSX, SAR and signed-condition code relies on the same.
  • This PR and #309 both add a line to CMakeLists.txt, docs/experiments.md and tools/form_coverage.py next to each other. I will rebase whichever lands second.
  • Follow-ups: model CDQE as a sign extension in the table-index proof; classify narrow and entry_order in tools/form_coverage.py.
  • Jump-table translator notes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6534970721 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-21T22:02:33Z. --- ## Change Builds on #285 (merged) and is independent of #309. `tools/cpu_switch_aot.py` refused `CBW`, `CWDE`, `CDQE`, `CDQ`, `CQO`, one-operand `MUL` and `IMUL`, and `DIV` and `IDIV`, which MSVC emits for 64-bit multiply-high, division and modulo. - **Explicit effects.** Each form states its reads and writes of RAX and RDX. Operand 0 of a one-operand multiply or divide is a source. Every input is copied into a `const` temporary before RAX or RDX is written, since the source may be one of them (`mul rdx`) or be addressed through them. - **Sign extensions and products of factors up to 32 bits** use wrapping `std::uint64_t` arithmetic, with no signed conversion and no shift of a negative value. An 8-bit multiply writes AX; a 16-bit multiply merges into AX and DX. - **64-bit products** use `_umul128` and `_mul128`. **Quotients** use `_udiv64`, `_div64`, `_udiv128` and `_div128`, which execute `DIV` or `IDIV`, so a zero divisor or a quotient that does not fit raises the same divide error as the original. No C++ `/` or `%` is emitted. The generated source now includes `<intrin.h>`. - **Rejected:** 8-bit divides (they write AH) and 16-bit divides, with `unsupported divide width`. A flag consumer after a multiply or divide stays rejected. The sign extensions, which the Intel SDM lists with "Flags Affected: None", may sit between a flag producer and its consumer. - **A soundness fix this change requires.** The constant pass for table bases and the value numbering for table indices assumed operand 0 is the only register an instruction writes. That was harmless while these instructions were refused. They now treat these instructions as writes of RAX and RDX; otherwise a `MUL` or `CQO` that overwrites a table base or index before the dispatch would be accepted. Two controls cover it. Limitation, stated in the docs: at `/O2` MSVC removes a divide whose quotient and remainder are both unused, and its divide error is then not raised. The same already happens to a load whose value is unused, for every load except a `CMOVcc` memory source. Generated C++ for functions that already translate is unchanged apart from the include line. ## Verification Local runs used the same compiler build as CI (MSVC 14.52.37025: `cl`, `link`, `ml64`) under Wine 11.0 on Linux, at `a3cc509` on main `1292d15`. I reran the items below on this head unless a line says otherwise. - **`ctest --no-tests=error -R '^cpu_aot_wide_arithmetic$' -V`: passed.** 13 exports and 2,929 non-faulting inputs; each original and translated export is compared through the register probe with a Python reference, which rounds signed quotients toward zero itself, on RAX, the guarded trace, RBX and RSI. - **Eight faulting inputs** (zero divisors, unsigned quotients that do not fit, -2^31 / -1, -2^63 / -1): original and translation raise the same `OSError` and leave the same trace. Under Wine every divide error reads `exception: integer divide by zero`. Whether Windows reports the overflow cases as `integer overflow` was not observed; the test accepts either message when both sides agree. - **Eleven rejection controls, printed one line each:** `div r9d` patched to `div r9b` and to `div cx`; a `Jcc` right after a divide; `cdq` replaced by `clc` between a compare and its consumer; RAX or RDX undefined at a multiply or divide (four cases, one of them RDX holding a guest address); a flag consumer after a multiply; a multiply that overwrites a jump-table base; a sign extension that overwrites a jump-table index. - **`cpu_aot_jump_tables`, `cpu_aot_narrow_returns`, `cpu_aot_entry_order`:** pass unchanged. Other `cpu_*` tests: same results as main. Under Wine, `cpu_aot_import_call`, `cpu_aot_ordinal_import`, `cpu_native_reloc_free` and `cpu_native_tls` fail on main too because Wine's loader differs from Windows, and `cpu_native_exe_start` times out intermittently (#281). The Windows job is the reference for those. - **Corpus.** 1,119 functions compiled with MSVC `/O2` from this repository's C++ sources plus one plain C++ file, and the `/O1` and `/Od` builds of the same sources: `/O2` 642 → 650, `/O1` 639 → 646, `/Od` 15 → 15. No function is lost. All 1,296 functions translated by both have identical C++; the only shared difference is the `<intrin.h>` line. - **Differential execution** (each function compiled with `cl` and called beside the original on 64 inputs, comparing the defined RAX bytes, a seeded memory arena and whether a fault occurred): the 8 functions gained at `/O2` and the 7 at `/O1` match on every input, and so do all 650 translated at `/O2` that could be run. This is evidence on a few inputs per function, not a proof of equivalence. With signed forms lowered as unsigned, 2 of the 8 mismatch. - **Checked during development, not rerun on this head:** `cl /O2 /FAs` shows each divide of the fixture as one inline `div` or `idiv` with no call or added check; all 2,566 earlier translations, library code included, compile to identical code with and without `<intrin.h>`; and 20 manual mutants, of which 19 fail the test. The one that survives keeps the generic operand-0 write for a one-operand form, which changes no definedness state. - `pyflakes`, `tests/docs_links_check.py` and `tests/form_coverage_check.py` passed. Not run locally: the D3D12 tests and anything that needs Windows loader behaviour. ## Evidence and follow-up - `tests/cpu/wide_arith.asm` is original MASM assembled in the build. No binaries were added. `wide_arith` is classified in `tools/form_coverage.py`. - Limits of the corpus numbers: desktop code built from this repository's sources, and every gained function comes from the one plain C++ file written for the measurement (`gcd32`, `gcd64`, `udiv64`, `sdiv10`, `smod64`, `div7`, a checksum and one method). - The signed intrinsics need unsigned-to-signed conversions, which are implementation-defined before C++20; MSVC documents wrapping, and the existing `MOVSX`, `SAR` and signed-condition code relies on the same. - This PR and #309 both add a line to `CMakeLists.txt`, `docs/experiments.md` and `tools/form_coverage.py` next to each other. I will rebase whichever lands second. - Follow-ups: model `CDQE` as a sign extension in the table-index proof; classify `narrow` and `entry_order` in `tools/form_coverage.py`. - [Jump-table translator notes](https://github.com/R0Y00/Xbox2Windows/blob/main/docs/experiments.md#switch-dispatch-through-jump-tables) _AI-assisted (Claude Code)._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:42:24 +00:00
bosseurdinternet commented 2026-11-24 06:48:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T22:43:33Z.


Rebased on b860dd5 after #309 landed; head is now ace1b2b. The conflicts were adjacent additions in CMakeLists.txt, docs/experiments.md and tools/form_coverage.py, and both sides are kept (cpu_aot_fourth_argument, then cpu_aot_wide_arithmetic). The translator merged without conflict.

Rerun on this head with MSVC 14.52.37025 under Wine: cpu_aot_wide_arithmetic, cpu_aot_fourth_argument, cpu_aot_narrow_returns, cpu_aot_jump_tables, cpu_aot_entry_order and cpu_aot_bmi1 pass. Corpus against main: /O2 642 → 650, /O1 639 → 646, no function lost, all 1,296 functions translated by both have identical C++, and the 8 gained at /O2 match their originals on every input in differential execution.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070381906 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7070381906). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-21T22:43:33Z. --- Rebased on `b860dd5` after #309 landed; head is now `ace1b2b`. The conflicts were adjacent additions in `CMakeLists.txt`, `docs/experiments.md` and `tools/form_coverage.py`, and both sides are kept (`cpu_aot_fourth_argument`, then `cpu_aot_wide_arithmetic`). The translator merged without conflict. Rerun on this head with MSVC 14.52.37025 under Wine: `cpu_aot_wide_arithmetic`, `cpu_aot_fourth_argument`, `cpu_aot_narrow_returns`, `cpu_aot_jump_tables`, `cpu_aot_entry_order` and `cpu_aot_bmi1` pass. Corpus against main: `/O2` 642 → 650, `/O1` 639 → 646, no function lost, all 1,296 functions translated by both have identical C++, and the 8 gained at `/O2` match their originals on every input in differential execution. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:48:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:33:35Z.


#420, #425 and #430 have landed, so please take #321 as the next branch in your jump-table translator queue. A trial merge against dec705f conflicts in tools/cpu_switch_aot.py, CMakeLists.txt, tools/form_coverage.py and docs/experiments.md. Please retain main’s frame and call handling and re-run the multiply/divide fixture and shared translator regressions after reconciliation. The other branches can wait until this one lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073617341 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7073617341). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:33:35Z. --- #420, #425 and #430 have landed, so please take #321 as the next branch in your jump-table translator queue. A trial merge against `dec705f` conflicts in `tools/cpu_switch_aot.py`, `CMakeLists.txt`, `tools/form_coverage.py` and `docs/experiments.md`. Please retain main’s frame and call handling and re-run the multiply/divide fixture and shared translator regressions after reconciliation. The other branches can wait until this one lands.
bosseurdinternet commented 2026-11-24 06:48:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-22T03:42:36Z.


Rebased onto main at 3a0f33b as one commit, 10060ec.

Reconciliation. main's frame, call, bound-callee and flag-condition handling is kept as it is. The only textual conflict in tools/cpu_switch_aot.py was the module docstring, where I kept #330's sentence on overflow and parity and added this PR's sentences. In CMakeLists.txt and tools/form_coverage.py both sides' entries are kept. In docs/experiments.md main's paragraphs are kept and this PR's two paragraphs follow the call sections; the one sentence both sides edited (instructions that leave the flags unchanged) carries both edits. This PR's code hunks applied without conflict.

Rerun on 10060ec, MSVC 14.52.37025 (cl, link, ml64) under Wine 11.0:

  • cpu_aot_wide_arithmetic: passed.
  • Shared translator regressions: cpu_aot_jump_tables, cpu_aot_flag_conditions, cpu_aot_switch_addr32, cpu_aot_entry_order, cpu_aot_narrow_returns, cpu_aot_fourth_argument, cpu_aot_stack_frames, cpu_aot_direct_calls, cpu_aot_call_entries and cpu_aot_bound_callees passed.
  • The other cpu_* tests: same results as main. Under Wine, cpu_aot_import_call, cpu_aot_ordinal_import, cpu_native_reloc_free and cpu_native_tls fail on main too, and cpu_native_exe_start timed out (#281).
  • Corpus against main: 647 → 655, 643 → 651 and 391 → 400 functions at /O2, /O1 and /Od. No function is lost, and the 1,681 translations main produces keep identical C++. The shared header gains its one #include <intrin.h> line.
  • Differential execution of the 25 newly translated functions, with callees compiled in: 8, 8 and 9 checked with no mismatch.
  • pyflakes, tests/docs_links_check.py and tests/form_coverage_check.py passed.

Not run locally: Windows itself; the Windows job is running on this head.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073724126 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7073724126). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-22T03:42:36Z. --- Rebased onto `main` at `3a0f33b` as one commit, `10060ec`. **Reconciliation.** `main`'s frame, call, bound-callee and flag-condition handling is kept as it is. The only textual conflict in `tools/cpu_switch_aot.py` was the module docstring, where I kept #330's sentence on overflow and parity and added this PR's sentences. In `CMakeLists.txt` and `tools/form_coverage.py` both sides' entries are kept. In `docs/experiments.md` main's paragraphs are kept and this PR's two paragraphs follow the call sections; the one sentence both sides edited (instructions that leave the flags unchanged) carries both edits. This PR's code hunks applied without conflict. **Rerun on `10060ec`,** MSVC 14.52.37025 (`cl`, `link`, `ml64`) under Wine 11.0: - `cpu_aot_wide_arithmetic`: passed. - Shared translator regressions: `cpu_aot_jump_tables`, `cpu_aot_flag_conditions`, `cpu_aot_switch_addr32`, `cpu_aot_entry_order`, `cpu_aot_narrow_returns`, `cpu_aot_fourth_argument`, `cpu_aot_stack_frames`, `cpu_aot_direct_calls`, `cpu_aot_call_entries` and `cpu_aot_bound_callees` passed. - The other `cpu_*` tests: same results as `main`. Under Wine, `cpu_aot_import_call`, `cpu_aot_ordinal_import`, `cpu_native_reloc_free` and `cpu_native_tls` fail on `main` too, and `cpu_native_exe_start` timed out (#281). - Corpus against `main`: 647 → 655, 643 → 651 and 391 → 400 functions at `/O2`, `/O1` and `/Od`. No function is lost, and the 1,681 translations `main` produces keep identical C++. The shared header gains its one `#include <intrin.h>` line. - Differential execution of the 25 newly translated functions, with callees compiled in: 8, 8 and 9 checked with no mismatch. - `pyflakes`, `tests/docs_links_check.py` and `tests/form_coverage_check.py` passed. Not run locally: Windows itself; the Windows job is running on this head. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:02:42Z.


Contract decision for the supported DIV/IDIV forms: reaching the instruction must preserve its observable divide error even when both result registers are overwritten before use. A conditional path that skips the divide must still complete normally. Please add a Windows MSVC /O2 differential fixture with dead quotient and remainder. Compare native and translated exception codes and the trace before/after the instruction for zero divisors and quotient overflow, plus a valid divide and a branch that skips the faulting input. Use the native Windows result as the oracle. Please keep the fix local to divide lowering. This is independent of #437.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073943778 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7073943778). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T04:02:42Z. --- Contract decision for the supported DIV/IDIV forms: reaching the instruction must preserve its observable divide error even when both result registers are overwritten before use. A conditional path that skips the divide must still complete normally. Please add a Windows MSVC /O2 differential fixture with dead quotient and remainder. Compare native and translated exception codes and the trace before/after the instruction for zero divisors and quotient overflow, plus a valid divide and a branch that skips the faulting input. Use the native Windows result as the oracle. Please keep the fix local to divide lowering. This is independent of #437.
bosseurdinternet commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-22T04:45:09Z.


Done in 75543e1, on top of the rebased 10060ec.

Contract. Reaching a supported DIV or IDIV raises its divide error even when both result registers are overwritten before use. The change is local to the divide lowering: after the intrinsic, the quotient is also stored to a volatile local, so the compiler has to perform the divide. Multiplies and everything else are untouched, and nothing depends on #437.

Fixture. tests/cpu/dead_div.asm, original MASM. Each export stores 1 to the trace before its divide and 2 after it, then overwrites RAX and RDX:

  • div32_dead (div r9d), idiv32_dead (cdq; idiv r9d), udiv128_dead (div r9 with RDX:RAX = x:x), idiv64_dead (cqo; idiv r9);
  • div_skip, where test r9, r9; jz goes around the divide for a zero divisor and both paths store 3 to a third trace word.

Test, ctest --preset dev --no-tests=error -R '^cpu_aot_dead_divides$' -V:

  • The translation is built twice: by the Debug build, and by a separate cl /O2 /W4 /LD command on the same generated source.
  • A small C++ helper (tests/cpu/guarded_call.cpp) calls the function inside __try and returns GetExceptionCode().
  • For each of 26 inputs the original runs first and is the oracle. Both translations must give its exception code, return value and trace. The test itself only requires that an input expected to fault yields 0xC0000094 or 0xC0000095 and leaves the second trace word unwritten.
  • Cases: zero divisors (including a nonzero 64-bit y whose low 32 bits are zero), quotients that do not fit (unsigned 32-bit and 128/64-bit, -2^31 / -1, -2^63 / -1), valid divides at the boundaries, and the skipped divide with two inputs. Inputs that do not fault are also compared through the register probe, for RBX and RSI.
  • A source control checks that each export has one divide and that its translation contains the volatile store.

Results.

  • This PR's Windows job: cpu_aot_dead_divides and cpu_aot_wide_arithmetic passed, and the new /O2 Windows job passed as a whole. The Debug Windows job is red only for cpu_native_exe_start ("native launch does not run the TLS callback (null reserved) before the entry point"), the intermittent failure of #281; I cannot rerun the job from the fork.
  • Locally (MSVC 14.52.37025 under Wine): the test passes, 26 inputs, 12 of them faulting. Under Wine every divide error is reported as 0xC0000094, so the distinction between the two codes is only exercised on Windows.
  • Without the store: I removed the added statement from the generated source and built it with /O2. The test then fails on the first faulting input: /O2 translation div32_dead(0x5, 0x0), zero divisor: code 0x0, with both trace words written, where the original raises 0xC0000094 after the first.
  • Corpus: the same 655, 651 and 400 functions translate at /O2, /O1 and /Od; no status or message changes; every translation is identical to 10060ec's once the added statement is removed (4, 4 and 7 functions contain a divide). The 8 /O2 functions this PR adds over main still execute with no mismatch against their originals.
  • pyflakes, tests/docs_links_check.py and tests/form_coverage_check.py passed.

Not covered: a divide whose memory operand is inaccessible is #437's subject, not this one; 8- and 16-bit divides stay rejected.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074356021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7074356021). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-22T04:45:09Z. --- Done in `75543e1`, on top of the rebased `10060ec`. **Contract.** Reaching a supported `DIV` or `IDIV` raises its divide error even when both result registers are overwritten before use. The change is local to the divide lowering: after the intrinsic, the quotient is also stored to a `volatile` local, so the compiler has to perform the divide. Multiplies and everything else are untouched, and nothing depends on #437. **Fixture.** `tests/cpu/dead_div.asm`, original MASM. Each export stores 1 to the trace before its divide and 2 after it, then overwrites RAX and RDX: - `div32_dead` (`div r9d`), `idiv32_dead` (`cdq; idiv r9d`), `udiv128_dead` (`div r9` with RDX:RAX = x:x), `idiv64_dead` (`cqo; idiv r9`); - `div_skip`, where `test r9, r9; jz` goes around the divide for a zero divisor and both paths store 3 to a third trace word. **Test,** `ctest --preset dev --no-tests=error -R '^cpu_aot_dead_divides$' -V`: - The translation is built twice: by the Debug build, and by a separate `cl /O2 /W4 /LD` command on the same generated source. - A small C++ helper (`tests/cpu/guarded_call.cpp`) calls the function inside `__try` and returns `GetExceptionCode()`. - For each of 26 inputs the original runs first and is the oracle. Both translations must give its exception code, return value and trace. The test itself only requires that an input expected to fault yields `0xC0000094` or `0xC0000095` and leaves the second trace word unwritten. - Cases: zero divisors (including a nonzero 64-bit `y` whose low 32 bits are zero), quotients that do not fit (unsigned 32-bit and 128/64-bit, `-2^31 / -1`, `-2^63 / -1`), valid divides at the boundaries, and the skipped divide with two inputs. Inputs that do not fault are also compared through the register probe, for RBX and RSI. - A source control checks that each export has one divide and that its translation contains the volatile store. **Results.** - This PR's Windows job: `cpu_aot_dead_divides` and `cpu_aot_wide_arithmetic` passed, and the new `/O2` Windows job passed as a whole. The Debug Windows job is red only for `cpu_native_exe_start` ("native launch does not run the TLS callback (null reserved) before the entry point"), the intermittent failure of #281; I cannot rerun the job from the fork. - Locally (MSVC 14.52.37025 under Wine): the test passes, 26 inputs, 12 of them faulting. Under Wine every divide error is reported as `0xC0000094`, so the distinction between the two codes is only exercised on Windows. - **Without the store:** I removed the added statement from the generated source and built it with `/O2`. The test then fails on the first faulting input: `/O2 translation div32_dead(0x5, 0x0), zero divisor: code 0x0`, with both trace words written, where the original raises `0xC0000094` after the first. - Corpus: the same 655, 651 and 400 functions translate at `/O2`, `/O1` and `/Od`; no status or message changes; every translation is identical to `10060ec`'s once the added statement is removed (4, 4 and 7 functions contain a divide). The 8 `/O2` functions this PR adds over `main` still execute with no mismatch against their originals. - `pyflakes`, `tests/docs_links_check.py` and `tests/form_coverage_check.py` passed. **Not covered:** a divide whose memory operand is inaccessible is #437's subject, not this one; 8- and 16-bit divides stay rejected. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:48:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:52:16Z.


I reran the failed Windows job on 75543e1. The first run passed cpu_aot_dead_divides and the separate /O2 job; its only failed CTest was cpu_native_exe_start (30.25 s). The required Windows check is running again. No branch update is needed for this retry.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074423942 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/321#issuecomment-7074423942). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T04:52:16Z. --- I reran the failed Windows job on 75543e1. The first run passed cpu_aot_dead_divides and the separate /O2 job; its only failed CTest was cpu_native_exe_start (30.25 s). The required Windows check is running again. No branch update is needed for this retry.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!316
No description provided.