cpu: lower CVTPI2PD MMX and memory forms in cpu_mmx_sse2_aot #2137

Merged
Ammmae0x merged 2 commits from upstream-pr/2145 into main 2026-11-25 03:58:24 +00:00
Ammmae0x commented 2026-11-25 01:34:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T01:34:45Z.


Change

Lower legacy SSE2 CVTPI2PD (Code.CVTPI2PD_XMM_MMM64) for both MM0..MM7 register sources and unaligned flat [rcx|rdx|r8 + disp] m64 memory sources in tools/cpu_mmx_sse2_aot.py, extending tests/cpu/mmx_sse2.asm, tests/cpu/mmx_sse2.def, tests/cpu/mmx_sse2_check.py, and CMakeLists.txt:

  • tools/cpu_mmx_sse2_aot.py:
    • Add Code.CVTPI2PD_XMM_MMM64 to ALLOWED_CODES and lower via op_cvtpi2pd(src), converting the low and high signed int32_t lanes of the 64-bit source into packed IEEE-754 binary64 lanes (Vec128) in volatile XMM0..XMM5.
    • Add mm_src64() helper shared with MOVQ_MM_MMM64: MM0..MM7 register sources route through read_mm() (enforcing definition tracking and setting mmx_active = True), while m64 memory sources route through load64(flat_address(ins)) (allowing unaligned byte displacements and not setting mmx_active, matching x86-64 semantics).
    • Add volatile access and std::atomic_signal_fence(std::memory_order_seq_cst) barriers in load64() / load128() so discarded guest reads retain fault ordering across surrounding stores under /O2.
  • tests/cpu/mmx_sse2.asm, tests/cpu/mmx_sse2.def, CMakeLists.txt:
    • Add 5 exports (op_cvtpi2pd_reg, op_cvtpi2pd_mem, op_cvtpi2pd_mem_disp, op_cvtpi2pd_discarded_read, op_cvtpi2pd_bridge) with ALTER_IMM controls and ; coverage: source cpu_aot_mmx_sse2 discovery for cvtpi2pd.
  • tests/cpu/mmx_sse2_check.py:
    • Replace the old unsupported_cvtpi2pd refusal with bit-for-bit native/lifted/reference differential checks across INT32_MIN, -1, 0, 1, INT32_MAX, +/-(2^24+1), and unaligned m64 offsets; ALTER_IMM divergence checks; discarded-read fault-ordering checks; signedness/lane-order mutation controls; and unit + PE-patched rejection controls (missing emms for mm register source or prior active MMX state, undefined mm, nonvolatile xmm6, VEX vcvtdq2pd, non-argument memory base).

Verification

Verified on commit 953c9417 (rebased on upstream/main 8e8b0621):

  • cmake --build --preset dev --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted -> exit 0 (0 errors, 0 warnings)
  • cmake --build --preset release --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted -> exit 0 (0 errors, 0 warnings)
  • ctest --preset dev -N -> Total Tests: 1341 (cpu_aot_mmx_sse2 present, no dropped tests)
  • ctest --preset dev -R "^cpu_aot_mmx_sse2$" --output-on-failure -V -> exit 0 (100% tests passed, 285 native/lifted/reference MMX/SSE2 cases across 17 exports matched bit-for-bit, 12 alternate-encoding lift checks, 53 unit rejection controls and 13 PE-patched rejection controls passed)
  • ctest --preset release -R "^cpu_aot_mmx_sse2$" --output-on-failure -V -> exit 0 (100% tests passed, same counts including discarded-read fault ordering under /O2)
  • ./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> exit 0 (form coverage checks passed; form_coverage.masm_mnemonics includes cvtpi2pd from tests/cpu/mmx_sse2.asm)
  • ./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> exit 0 (Self-test passed. Checked 18 Markdown files and 398 links.)
  • ./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Self-test passed. Checked 1439 tracked source, script and build/CI files: no bidirectional controls.)
  • Spot-mutation verification: temporarily disabled 3 new guards/lowering paths in tools/cpu_mmx_sse2_aot.py (CVTPI2PD_XMM_MMM64 lowering branch, mm_src64 memory-operand dispatch, and mm_src64 read_mm def/state check); all 3 mutations were killed by tests/cpu/mmx_sse2_check.py (exit 1) and cleanly restored.

Evidence and follow-up

All fixtures in tests/cpu/mmx_sse2.asm are source-built synthetic MASM leaf functions (MIT License) assembled with ml64 and translated via tools/cpu_mmx_sse2_aot.py. Negative controls cover ALTER_IMM divergence, output/signedness/lane-order mutations, faulting discarded m64 reads, and unit + PE-patched translator rejections.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595091055 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2145). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T01:34:45Z. --- ## Change Lower legacy SSE2 `CVTPI2PD` (`Code.CVTPI2PD_XMM_MMM64`) for both `MM0..MM7` register sources and unaligned flat `[rcx|rdx|r8 + disp]` `m64` memory sources in `tools/cpu_mmx_sse2_aot.py`, extending `tests/cpu/mmx_sse2.asm`, `tests/cpu/mmx_sse2.def`, `tests/cpu/mmx_sse2_check.py`, and `CMakeLists.txt`: - `tools/cpu_mmx_sse2_aot.py`: - Add `Code.CVTPI2PD_XMM_MMM64` to `ALLOWED_CODES` and lower via `op_cvtpi2pd(src)`, converting the low and high signed `int32_t` lanes of the 64-bit source into packed IEEE-754 binary64 lanes (`Vec128`) in volatile `XMM0..XMM5`. - Add `mm_src64()` helper shared with `MOVQ_MM_MMM64`: `MM0..MM7` register sources route through `read_mm()` (enforcing definition tracking and setting `mmx_active = True`), while `m64` memory sources route through `load64(flat_address(ins))` (allowing unaligned byte displacements and not setting `mmx_active`, matching x86-64 semantics). - Add `volatile` access and `std::atomic_signal_fence(std::memory_order_seq_cst)` barriers in `load64()` / `load128()` so discarded guest reads retain fault ordering across surrounding stores under `/O2`. - `tests/cpu/mmx_sse2.asm`, `tests/cpu/mmx_sse2.def`, `CMakeLists.txt`: - Add 5 exports (`op_cvtpi2pd_reg`, `op_cvtpi2pd_mem`, `op_cvtpi2pd_mem_disp`, `op_cvtpi2pd_discarded_read`, `op_cvtpi2pd_bridge`) with `ALTER_IMM` controls and `; coverage: source cpu_aot_mmx_sse2` discovery for `cvtpi2pd`. - `tests/cpu/mmx_sse2_check.py`: - Replace the old `unsupported_cvtpi2pd` refusal with bit-for-bit native/lifted/reference differential checks across `INT32_MIN`, `-1`, `0`, `1`, `INT32_MAX`, `+/-(2^24+1)`, and unaligned `m64` offsets; `ALTER_IMM` divergence checks; discarded-read fault-ordering checks; signedness/lane-order mutation controls; and unit + PE-patched rejection controls (missing `emms` for `mm` register source or prior active MMX state, undefined `mm`, nonvolatile `xmm6`, VEX `vcvtdq2pd`, non-argument memory base). ## Verification Verified on commit `953c9417` (rebased on `upstream/main` `8e8b0621`): - `cmake --build --preset dev --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted` -> exit `0` (0 errors, 0 warnings) - `cmake --build --preset release --target cpu_mmx_sse2_original cpu_mmx_sse2_original_lifted cpu_mmx_sse2_altered cpu_mmx_sse2_altered_lifted` -> exit `0` (0 errors, 0 warnings) - `ctest --preset dev -N` -> `Total Tests: 1341` (`cpu_aot_mmx_sse2` present, no dropped tests) - `ctest --preset dev -R "^cpu_aot_mmx_sse2$" --output-on-failure -V` -> exit `0` (`100% tests passed`, `285 native/lifted/reference MMX/SSE2 cases across 17 exports matched bit-for-bit`, `12 alternate-encoding lift checks, 53 unit rejection controls and 13 PE-patched rejection controls passed`) - `ctest --preset release -R "^cpu_aot_mmx_sse2$" --output-on-failure -V` -> exit `0` (`100% tests passed`, same counts including discarded-read fault ordering under `/O2`) - `./out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> exit `0` (`form coverage checks passed`; `form_coverage.masm_mnemonics` includes `cvtpi2pd` from `tests/cpu/mmx_sse2.asm`) - `./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> exit `0` (`Self-test passed. Checked 18 Markdown files and 398 links.`) - `./out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Self-test passed. Checked 1439 tracked source, script and build/CI files: no bidirectional controls.`) - Spot-mutation verification: temporarily disabled 3 new guards/lowering paths in `tools/cpu_mmx_sse2_aot.py` (`CVTPI2PD_XMM_MMM64` lowering branch, `mm_src64` memory-operand dispatch, and `mm_src64` `read_mm` def/state check); all 3 mutations were killed by `tests/cpu/mmx_sse2_check.py` (exit `1`) and cleanly restored. ## Evidence and follow-up All fixtures in `tests/cpu/mmx_sse2.asm` are source-built synthetic MASM leaf functions (MIT License) assembled with `ml64` and translated via `tools/cpu_mmx_sse2_aot.py`. Negative controls cover `ALTER_IMM` divergence, output/signedness/lane-order mutations, faulting discarded `m64` reads, and unit + PE-patched translator rejections. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-25 03:01:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:05:53Z.

Review: COMMENTED


Review of head 953c9417fdd021a8c8eb8d9347966b8d3e489293 (comment only).

Summary: No P1 or P2 findings. The CVTPI2PD lowering matches the ISA: the low and high signed int32 lanes become two binary64 lanes, in order. The memory form is an unaligned m64 read that does not set mmx_active, which is correct. The register form goes through read_mm(), so it is subject to the definition check and the emms-before-ret rule.

Commands run locally (Linux, worktree of the PR head):

  • git diff --stat origin/main...HEAD -> 5 files, +281/-19
  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py -> self-test passed, 18 Markdown files and 398 links checked
  • python3 tests/bidi_controls_check.py -> self-test passed, 1439 files, no bidirectional controls
  • gh pr checks 2145 -> Linux Python checks, Windows build/test and gfx1013 fixtures pass. Build and test on Windows at /O2 is "skipping". See the first nit.
  • Lifter probe with iced-x86 on hand-encoded bytes: cvtpi2pd xmm0,[rcx+5] lifts to xmm0 = op_cvtpi2pd(load64((rcx + 0x5ull)));. cvtpi2pd xmm5,mm7 with mm7 undefined is rejected with "undefined MMX register mm7".
  • g++ check of the op_cvtpi2pd lane math on 0x80000001FFFFFFFF: lo = -1.0 (bits 0xBFF0000000000000), hi = -2147483647.0. Signedness and lane order are correct.
  • Mutation: I changed the mm_src64 memory path to load64(1+...). The emitted C++ then differs from the string the check expects at tests/cpu/mmx_sse2_check.py:465, so that test should kill it. I reverted it with git checkout -- ..
  • tests/cpu/mmx_sse2_check.py needs the Windows-built DLLs (MSVC and the exports). I did not run it on Linux, and I did not run win2025. The PR's Windows CI job covers it, and this change is not a gfx2hlsl or shader change.

Nits (non-blocking):

  1. load64/load128 now use volatile and signal fences for every translated guest read, not just the discarded cvtpi2pd read. This is intended and the PR body says so. The /O2 Windows job is "skipping", though. Please confirm the discarded-read test (op_cvtpi2pd_discarded_read) was exercised at /O2 before marking Ready.
  2. In load128 the memcpy into a local followed by a volatile copy is a slightly roundabout way to force the read. A direct volatile 128-bit access is not portable in MSVC, so I think it is fine, but a one-line comment on why would help.
  3. The __unaligned qualifier in load64 is MSVC-specific. That fits the Windows-only toolchain, but it will not compile with a non-MSVC host compiler.

Clean-room: no external code or AI-model names seen in the diff or the title. The title is neutral. Mergeable state was reported as UNKNOWN at review time.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050557484 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2145#pullrequestreview-6050557484). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:05:53Z. **Review:** COMMENTED --- Review of head `953c9417fdd021a8c8eb8d9347966b8d3e489293` (comment only). **Summary:** No P1 or P2 findings. The CVTPI2PD lowering matches the ISA: the low and high signed int32 lanes become two binary64 lanes, in order. The memory form is an unaligned m64 read that does not set `mmx_active`, which is correct. The register form goes through `read_mm()`, so it is subject to the definition check and the `emms`-before-`ret` rule. **Commands run locally (Linux, worktree of the PR head):** - `git diff --stat origin/main...HEAD` -> 5 files, +281/-19 - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` -> self-test passed, 18 Markdown files and 398 links checked - `python3 tests/bidi_controls_check.py` -> self-test passed, 1439 files, no bidirectional controls - `gh pr checks 2145` -> Linux Python checks, Windows build/test and gfx1013 fixtures pass. `Build and test on Windows at /O2` is "skipping". See the first nit. - Lifter probe with `iced-x86` on hand-encoded bytes: `cvtpi2pd xmm0,[rcx+5]` lifts to `xmm0 = op_cvtpi2pd(load64((rcx + 0x5ull)));`. `cvtpi2pd xmm5,mm7` with `mm7` undefined is rejected with "undefined MMX register mm7". - g++ check of the `op_cvtpi2pd` lane math on `0x80000001FFFFFFFF`: lo = -1.0 (bits `0xBFF0000000000000`), hi = -2147483647.0. Signedness and lane order are correct. - Mutation: I changed the `mm_src64` memory path to `load64(1+...)`. The emitted C++ then differs from the string the check expects at `tests/cpu/mmx_sse2_check.py:465`, so that test should kill it. I reverted it with `git checkout -- .`. - `tests/cpu/mmx_sse2_check.py` needs the Windows-built DLLs (MSVC and the exports). I did not run it on Linux, and I did not run `win2025`. The PR's Windows CI job covers it, and this change is not a gfx2hlsl or shader change. **Nits (non-blocking):** 1. `load64`/`load128` now use `volatile` and signal fences for every translated guest read, not just the discarded `cvtpi2pd` read. This is intended and the PR body says so. The `/O2` Windows job is "skipping", though. Please confirm the discarded-read test (`op_cvtpi2pd_discarded_read`) was exercised at `/O2` before marking Ready. 2. In `load128` the `memcpy` into a local followed by a `volatile` copy is a slightly roundabout way to force the read. A direct `volatile` 128-bit access is not portable in MSVC, so I think it is fine, but a one-line comment on why would help. 3. The `__unaligned` qualifier in `load64` is MSVC-specific. That fits the Windows-only toolchain, but it will not compile with a non-MSVC host compiler. Clean-room: no external code or AI-model names seen in the diff or the title. The title is neutral. Mergeable state was reported as UNKNOWN at review time. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 04:03:58 +00:00
tedin7 commented 2026-11-25 04:03:58 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Re-review of head be2dbe830520a2b4de895d6045495dd3793c3945 (previous review was on 953c9417).

Delta since the last review: one commit, docs only (docs/experiments.md, +4/-2). It adds cvtpi2pd to the op list, narrows "Not covered" to "outside this profile", and adds a paragraph describing the extension. The code and tests are unchanged from the previously reviewed head.

Checks run locally (Linux):

  • git diff --stat 953c941 HEAD: 1 file, docs only.
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files and 398 links OK.
  • python3 tests/bidi_controls_check.py: self-test passed, 1439 files, no bidirectional controls.
  • git diff --check origin/main...HEAD: clean.
  • Read tools/cpu_mmx_sse2_aot.py lowering (op_cvtpi2pd, mm_src64, read_mm): lanes are signed int32 to exact binary64, low word in lane 0. A register source sets mmx_active, so emms is required before ret. A memory source goes through load64 and does not set mmx_active. This matches the doc text.
  • Mutation probe: a standalone C++ copy of the lane conversion. Reading the low word as unsigned gives 2147483648.0 where the signed form gives -2147483648.0. The signedness and lane-order controls at tests/cpu/mmx_sse2_check.py:372-379 would catch that, by reading.
  • Not run here: tests/cpu/mmx_sse2_check.py and the cpu_aot_mmx_sse2 CTest. They need pefile, iced_x86 and MASM, which this Linux host does not have. No Win2025 run was queued from this review.

CI: the Linux, Windows and gfx1013 jobs were still pending when I looked. Please wait for them to go green before Ready.

Findings: P1=0, P2=0.

  • nit: the new doc paragraph says the test "checks which surrounding output stores executed". The exact fault-ordering semantics are only proven by the Windows run, so the Win2025 result is the real gate.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051573566 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2145#pullrequestreview-6051573566). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:47:33Z. **Review:** COMMENTED --- Re-review of head `be2dbe830520a2b4de895d6045495dd3793c3945` (previous review was on `953c9417`). **Delta since the last review:** one commit, docs only (`docs/experiments.md`, +4/-2). It adds `cvtpi2pd` to the op list, narrows "Not covered" to "outside this profile", and adds a paragraph describing the extension. The code and tests are unchanged from the previously reviewed head. **Checks run locally (Linux):** - `git diff --stat 953c941 HEAD`: 1 file, docs only. - `python3 tests/docs_links_check.py`: self-test passed, 18 Markdown files and 398 links OK. - `python3 tests/bidi_controls_check.py`: self-test passed, 1439 files, no bidirectional controls. - `git diff --check origin/main...HEAD`: clean. - Read `tools/cpu_mmx_sse2_aot.py` lowering (`op_cvtpi2pd`, `mm_src64`, `read_mm`): lanes are signed int32 to exact binary64, low word in lane 0. A register source sets `mmx_active`, so `emms` is required before `ret`. A memory source goes through `load64` and does not set `mmx_active`. This matches the doc text. - Mutation probe: a standalone C++ copy of the lane conversion. Reading the low word as unsigned gives `2147483648.0` where the signed form gives `-2147483648.0`. The signedness and lane-order controls at `tests/cpu/mmx_sse2_check.py:372-379` would catch that, by reading. - Not run here: `tests/cpu/mmx_sse2_check.py` and the `cpu_aot_mmx_sse2` CTest. They need `pefile`, `iced_x86` and MASM, which this Linux host does not have. No Win2025 run was queued from this review. **CI:** the Linux, Windows and gfx1013 jobs were still pending when I looked. Please wait for them to go green before Ready. **Findings:** P1=0, P2=0. - nit: the new doc paragraph says the test "checks which surrounding output stores executed". The exact fault-ordering semantics are only proven by the Windows run, so the Win2025 result is the real gate. 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!2137
No description provided.