cpu: lower 64-bit GPR-to-XMM MOVQ transfers in cpu_sse_aot #2309

Merged
Ammmae0x merged 1 commit from upstream-pr/2317 into main 2026-11-25 12:15:50 +00:00
Ammmae0x commented 2026-11-25 12:02:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T12:02:51Z.


Change

Lowers 64-bit GPR-to-XMM and XMM-to-GPR MOVQ register transfers (Code.MOVQ_RM64_XMM and Code.MOVQ_XMM_RM64) in tools/cpu_sse_aot.py and extends the scalar_float differential fixture and rejection suite (tests/cpu/scalar_float.{asm,def}, tests/cpu/scalar_float_check.py, CMakeLists.txt):

  • Introduces GPR_STORE_MOVES and GPR_LOAD_MOVES dispatch tables in tools/cpu_sse_aot.py so ScalarLifter.statement() lowers MOVD (32-bit GPR via RegisterExt.is_gpr32) and MOVQ (64-bit GPR via RegisterExt.is_gpr64) between XMM and GPRs, enforcing full low-qword XMM definedness (parts(xmm, 8)), full 64-bit GPR definedness (full(gpr)), and bit-exact 64-bit transfers without NaN canonicalization or upper-32 truncation.
  • Adds movq_gpr=q:dq to tests/cpu/scalar_float.asm (using portable MASM DB encodings and a SWAP_OPERANDS control switching xor to add), tests/cpu/scalar_float.def, CMakeLists.txt, and tests/cpu/scalar_float_check.py.
  • Verifies 3599 differential (double, uint64) pairs plus 13 fixed bit-pattern answers (-0.0, SNaNs, QNaNs, subnormals, +/-inf), and adds rejection controls for MOVQ reading a 32-bit-only XMM (q:fq and patched blend_ss), undefined r11/rdx/xmm5, nonvolatile rbx/xmm6, MMX MOVQ, and width-mismatched MOVD/MOVQ encodings.

Verification

Commit: 57d1e034 (based on upstream/main da2c0a9f). Built and verified in both dev (Debug) and release (/O2) with MSVC/ML64 (& .\tools\dev.ps1):

  • cmake --build --preset dev --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harness cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_scalar_fp_lifted_o2 -> exit 0 (0 errors; 0 warnings on cpu_float_* and cpu_mxcsr_harness)
  • cmake --build --preset release --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harness cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_scalar_fp_lifted_o2 -> exit 0 (0 errors; 0 warnings on cpu_float_* and cpu_mxcsr_harness)
  • ctest --preset dev --output-on-failure -E "cpu_native_archive_" -R "^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$" -> 2/2 Passed (cpu_aot_fuzz_scalar_fp 1.36s, cpu_aot_scalar_float 5.18s; 0 skips)
  • ctest --preset release --output-on-failure -E "cpu_native_archive_" -R "^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$" -> 2/2 Passed (cpu_aot_fuzz_scalar_fp 1.37s, cpu_aot_scalar_float 5.27s; 0 skips)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 (Self-test passed. Checked 18 Markdown files and 448 links.)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed. Checked 1608 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot-mutation verification (pre-push): temporarily mutating four new guards/widths in tools/cpu_sse_aot.py (is_gpr_width(ins.op0_register), is_gpr_width(ins.op1_register), store gpr_width narrowed to 4, and omitting reads.add(full(ins.op1_register))) caused tests/cpu/scalar_float_check.py to fail with exit 1 in all 4/4 cases.

Evidence and follow-up

  • tests/cpu/scalar_float.asm is a source-built MASM fixture registered with ; coverage: source cpu_aot_scalar_float under the repository MIT license; no external binaries or game files are added.
  • Reproducible via ctest --preset dev -R "^cpu_aot_scalar_float$" and ctest --preset release -R "^cpu_aot_scalar_float$".
  • AI-assisted.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No build requirement or user-facing doc change needed.)
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6604029416 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2317). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T12:02:51Z. --- ## Change Lowers 64-bit GPR-to-XMM and XMM-to-GPR `MOVQ` register transfers (`Code.MOVQ_RM64_XMM` and `Code.MOVQ_XMM_RM64`) in `tools/cpu_sse_aot.py` and extends the `scalar_float` differential fixture and rejection suite (`tests/cpu/scalar_float.{asm,def}`, `tests/cpu/scalar_float_check.py`, `CMakeLists.txt`): - Introduces `GPR_STORE_MOVES` and `GPR_LOAD_MOVES` dispatch tables in `tools/cpu_sse_aot.py` so `ScalarLifter.statement()` lowers `MOVD` (32-bit GPR via `RegisterExt.is_gpr32`) and `MOVQ` (64-bit GPR via `RegisterExt.is_gpr64`) between XMM and GPRs, enforcing full low-qword XMM definedness (`parts(xmm, 8)`), full 64-bit GPR definedness (`full(gpr)`), and bit-exact 64-bit transfers without NaN canonicalization or upper-32 truncation. - Adds `movq_gpr=q:dq` to `tests/cpu/scalar_float.asm` (using portable MASM `DB` encodings and a `SWAP_OPERANDS` control switching `xor` to `add`), `tests/cpu/scalar_float.def`, `CMakeLists.txt`, and `tests/cpu/scalar_float_check.py`. - Verifies 3599 differential `(double, uint64)` pairs plus 13 fixed bit-pattern answers (`-0.0`, SNaNs, QNaNs, subnormals, `+/-inf`), and adds rejection controls for `MOVQ` reading a 32-bit-only XMM (`q:fq` and patched `blend_ss`), undefined `r11`/`rdx`/`xmm5`, nonvolatile `rbx`/`xmm6`, MMX `MOVQ`, and width-mismatched `MOVD`/`MOVQ` encodings. ## Verification Commit: `57d1e034` (based on `upstream/main` `da2c0a9f`). Built and verified in both `dev` (Debug) and `release` (`/O2`) with MSVC/ML64 (`& .\tools\dev.ps1`): - `cmake --build --preset dev --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harness cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_scalar_fp_lifted_o2` -> exit `0` (0 errors; 0 warnings on `cpu_float_*` and `cpu_mxcsr_harness`) - `cmake --build --preset release --target cpu_float_original cpu_float_original_lifted cpu_float_swapped cpu_float_swapped_lifted cpu_mxcsr_harness cpu_fuzz_scalar_fp cpu_fuzz_scalar_fp_lifted cpu_fuzz_scalar_fp_mutant cpu_fuzz_scalar_fp_lifted_o2` -> exit `0` (0 errors; 0 warnings on `cpu_float_*` and `cpu_mxcsr_harness`) - `ctest --preset dev --output-on-failure -E "cpu_native_archive_" -R "^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$"` -> `2/2 Passed` (`cpu_aot_fuzz_scalar_fp` 1.36s, `cpu_aot_scalar_float` 5.18s; 0 skips) - `ctest --preset release --output-on-failure -E "cpu_native_archive_" -R "^(cpu_aot_scalar_float|cpu_aot_fuzz_scalar_fp)$"` -> `2/2 Passed` (`cpu_aot_fuzz_scalar_fp` 1.37s, `cpu_aot_scalar_float` 5.27s; 0 skips) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (`form coverage checks passed`) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` (`Self-test passed. Checked 18 Markdown files and 448 links.`) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Self-test passed. Checked 1608 tracked source, script and build/CI files: no bidirectional controls.`) - Spot-mutation verification (pre-push): temporarily mutating four new guards/widths in `tools/cpu_sse_aot.py` (`is_gpr_width(ins.op0_register)`, `is_gpr_width(ins.op1_register)`, store `gpr_width` narrowed to `4`, and omitting `reads.add(full(ins.op1_register))`) caused `tests/cpu/scalar_float_check.py` to fail with exit `1` in all 4/4 cases. ## Evidence and follow-up - `tests/cpu/scalar_float.asm` is a source-built MASM fixture registered with `; coverage: source cpu_aot_scalar_float` under the repository MIT license; no external binaries or game files are added. - Reproducible via `ctest --preset dev -R "^cpu_aot_scalar_float$"` and `ctest --preset release -R "^cpu_aot_scalar_float$"`. - AI-assisted. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (No build requirement or user-facing doc change needed.) - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-25 13:00:44 +00:00
tedin7 commented 2026-11-25 13:00:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:07:33Z.

Review: COMMENTED


Review of head 57d1e03471fa2f230b79344f32b773c90b9702aa (comment only).

Verdict: no blocking findings. P1=0, P2=1, nits=1.

What I checked

  • Diff scope: tools/cpu_sse_aot.py, tests/cpu/scalar_float.{asm,def}, tests/cpu/scalar_float_check.py, CMakeLists.txt (5 files, +96/-14). Title is neutral; PR is not Draft; mergeable.
  • The new GPR_STORE_MOVES / GPR_LOAD_MOVES tables key on the exact iced Code (not just the mnemonic), and each entry checks the GPR width. This also stops MMX MOVD/MOVQ forms from slipping through the old mnemonic == M.MOVD test, since they now hit unsupported. Good tightening.
  • 64-bit store: reads the full low qword (parts(xmm, 8) via source(..., 8)), writes full(gpr) with no 32-bit zero-extension. 64-bit load: marks the full GPR as read and defines the whole low quadword of the XMM. Matches the ISA (no NaN canonicalisation, upper XMM bits zeroed by MOVQ).
  • Test coverage: 3599 differential pairs (DOUBLES x INTEGERS, with values above 2^32) plus 13 fixed bit-pattern answers (-0.0, SNaN/QNaN, subnormals, +/-inf), and rejection controls for the undefined-register, nonvolatile-register, MMX and width-mismatch cases. tests/cpu/scalar_float_check.py:788-796, :835-836.
  • CMake: movq_gpr=q:dq added to the shared signature string for both the original and swapped variants; the SWAP_OPERANDS control (add instead of xor) keeps the swapped build a real control.

Commands executed locally (Linux, worktree at the head SHA)

  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py -> Checked 18 Markdown files and 448 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • python -m py_compile tools/cpu_sse_aot.py tests/cpu/scalar_float_check.py -> OK
  • The fixture needs MSVC/ML64 PEs, so the real test ran on Win2025:
    python3 x2w_pipe.py win2025 2317 --regex cpu_aot_scalar_float --targets cpu_float_original,cpu_float_original_lifted,cpu_float_swapped,cpu_float_swapped_lifted,cpu_mxcsr_harness
    -> dev: cpu_aot_scalar_float Passed 1/1; release (/O2): Passed 1/1.

Mutations (applied via --patch, rebuilt with reconfigure, then discarded)

  1. GPR_STORE_MOVES[MOVQ_RM64_XMM] width 8 -> 4: killed (lifter build step fails, the lifted .cpp is not generated).
  2. GPR_LOAD_MOVES[MOVQ_XMM_RM64] width 8 -> 4: survived, cpu_aot_scalar_float still Passed on dev.

Findings

  • P2 tools/cpu_sse_aot.py:51 (+ :162-166): mutation 2 above is not caught. Either self.operand(ins, 1, gpr_width) ignores the width argument for a 64-bit register (then the table width is dead for loads and the is_gpr64 check is the only real guard), or the fixture does not observe a truncated load. With INTEGERS containing values above 2^32 I would expect truncation to show, so please check which one it is. If the width is ignored, say so in a comment or drop the redundant width from GPR_LOAD_MOVES; if it is observable, add the missing case.
  • nit The PR body lists CI as still pending at review time (Linux Python, Windows and gfx1013 jobs). Please confirm they are green before marking this ready.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057311832 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2317#pullrequestreview-6057311832). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:07:33Z. **Review:** COMMENTED --- Review of head `57d1e03471fa2f230b79344f32b773c90b9702aa` (comment only). **Verdict: no blocking findings. P1=0, P2=1, nits=1.** What I checked - Diff scope: `tools/cpu_sse_aot.py`, `tests/cpu/scalar_float.{asm,def}`, `tests/cpu/scalar_float_check.py`, `CMakeLists.txt` (5 files, +96/-14). Title is neutral; PR is not Draft; mergeable. - The new `GPR_STORE_MOVES` / `GPR_LOAD_MOVES` tables key on the exact iced `Code` (not just the mnemonic), and each entry checks the GPR width. This also stops MMX `MOVD`/`MOVQ` forms from slipping through the old `mnemonic == M.MOVD` test, since they now hit `unsupported`. Good tightening. - 64-bit store: reads the full low qword (`parts(xmm, 8)` via `source(..., 8)`), writes `full(gpr)` with no 32-bit zero-extension. 64-bit load: marks the full GPR as read and defines the whole low quadword of the XMM. Matches the ISA (no NaN canonicalisation, upper XMM bits zeroed by MOVQ). - Test coverage: 3599 differential pairs (DOUBLES x INTEGERS, with values above 2^32) plus 13 fixed bit-pattern answers (-0.0, SNaN/QNaN, subnormals, +/-inf), and rejection controls for the undefined-register, nonvolatile-register, MMX and width-mismatch cases. `tests/cpu/scalar_float_check.py:788-796`, `:835-836`. - CMake: `movq_gpr=q:dq` added to the shared signature string for both the original and swapped variants; the `SWAP_OPERANDS` control (`add` instead of `xor`) keeps the swapped build a real control. Commands executed locally (Linux, worktree at the head SHA) - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` -> `Checked 18 Markdown files and 448 links.` - `python3 tests/bidi_controls_check.py` -> `no bidirectional controls` - `python -m py_compile tools/cpu_sse_aot.py tests/cpu/scalar_float_check.py` -> OK - The fixture needs MSVC/ML64 PEs, so the real test ran on Win2025: `python3 x2w_pipe.py win2025 2317 --regex cpu_aot_scalar_float --targets cpu_float_original,cpu_float_original_lifted,cpu_float_swapped,cpu_float_swapped_lifted,cpu_mxcsr_harness` -> dev: `cpu_aot_scalar_float` Passed 1/1; release (/O2): Passed 1/1. Mutations (applied via `--patch`, rebuilt with reconfigure, then discarded) 1. `GPR_STORE_MOVES[MOVQ_RM64_XMM]` width 8 -> 4: killed (lifter build step fails, the lifted .cpp is not generated). 2. `GPR_LOAD_MOVES[MOVQ_XMM_RM64]` width 8 -> 4: **survived**, `cpu_aot_scalar_float` still Passed on dev. Findings - **P2** `tools/cpu_sse_aot.py:51` (+ `:162-166`): mutation 2 above is not caught. Either `self.operand(ins, 1, gpr_width)` ignores the width argument for a 64-bit register (then the table width is dead for loads and the `is_gpr64` check is the only real guard), or the fixture does not observe a truncated load. With `INTEGERS` containing values above 2^32 I would expect truncation to show, so please check which one it is. If the width is ignored, say so in a comment or drop the redundant width from `GPR_LOAD_MOVES`; if it is observable, add the missing case. - **nit** The PR body lists CI as still pending at review time (Linux Python, Windows and gfx1013 jobs). Please confirm they are green before marking this ready. AI-assisted; commands listed were executed locally.
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!2309
No description provided.