cpu: lower MASKMOVQ and MASKMOVDQU instructions #1079

Merged
Ammmae0x merged 1 commit from upstream-pr/1086 into main 2026-11-24 01:02:08 +00:00
Ammmae0x commented 2026-11-24 00:42:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T00:42:42Z.


Change

Extends the legacy SSE/MMX AOT translator and the MASM fixture to lift and verify maskmovq (SSE) and maskmovdqu (SSE2), completing SSE2 form coverage alongside the existing SSE/MMX leaf slice:

  • Lowers MASKMOVQ_RDI_MM_MM and MASKMOVDQU_RDI_XMM_XMM via op_maskmovq and op_maskmovdqu helpers writing only bytes with (mask[i] & 0x80) != 0 under std::atomic_signal_fence(std::memory_order_seq_cst).
  • Adds MOV_R64_RM64 / MOV_RM64_R64 register-only tracking for nonvolatile rdi save to a volatile scratch GPR (rax/r9/r10/r11), mov rdi, r8, and restoration before ret, rejecting unrestored rdi, unsaved writes, non-r8 targets, 67h edi targets, segment overrides, and movq reads of registers holding saved rdi.
  • Adds exports op_maskmovq, op_maskmovdqu, and op_maskmov_pipeline in tests/cpu/sse_mmx.asm, tests/cpu/sse_mmx.def, and CMakeLists.txt, plus ALTER_IMM source/mask swaps on op_maskmovq and op_maskmovdqu, VirtualAlloc/VirtualProtect k=8/k=16 page-abutting checks and native partial-edge observations, VEX vmaskmovdqu rejection, and ABI/state/PE-patched rejection controls in tests/cpu/sse_mmx_check.py.
  • Documents the expanded contract, verification commands, and measured results in docs/experiments.md.

Verification

All checks ran after rebasing onto upstream/main (f7c9f57, branch commit c738c7e):

  • ctest --preset dev -N: Total Tests: 612 (0 dropped tests).
  • cmake --build --preset dev --target cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered cpu_sse_mmx_altered_lifted: passed (0 errors, 0 warnings).
  • cmake --build --preset release --target cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered cpu_sse_mmx_altered_lifted: passed (0 errors, 0 warnings).
  • ctest --preset dev --no-tests=error -R "^cpu_aot_sse_mmx$" -V: 1 passed, 0 failed, 0 skipped (1/1 passed in 0.73s; 339 native/lifted/reference cases across 21 exports matched bit-for-bit, 24 k=8/k=16 page-abutting checks, 54 native partial-edge observations, ALTER_IMM divergence on 6 exports [3, 3, 7, 7, 22, 30], output mutation control, 9 alternate-encoding checks, 81 unit rejections, 16 PE-patched rejections).
  • ctest --preset release --no-tests=error -R "^cpu_aot_sse_mmx$" -V: 1 passed, 0 failed, 0 skipped (1/1 passed in 0.71s; identical case/control counts under /O2).
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: passed (form coverage checks passed).
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: passed (Self-test passed. Checked 15 Markdown files and 242 links.).
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: passed (Self-test passed. Checked 917 tracked source, script and build/CI files: no bidirectional controls.).

Evidence and follow-up

All fixtures are original MASM source in tests/cpu/sse_mmx.asm and synthetic unit/PE-patched controls in tests/cpu/sse_mmx_check.py. For this portable first slice, [rdi..rdi+7] (maskmovq) or [rdi..rdi+15] (maskmovdqu) must be writable ordinary memory; non-temporal cache hints, implementation-dependent partial-page or all-zero-mask fault behavior, and non-r8 destinations remain outside this leaf profile.

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:6571956520 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1086). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-24T00:42:42Z. --- ## Change Extends [the legacy SSE/MMX AOT translator](tools/cpu_sse_mmx_aot.py) and [the MASM fixture](tests/cpu/sse_mmx.asm) to lift and verify `maskmovq` (`SSE`) and `maskmovdqu` (`SSE2`), completing `SSE2` form coverage alongside the existing `SSE`/`MMX` leaf slice: - Lowers `MASKMOVQ_RDI_MM_MM` and `MASKMOVDQU_RDI_XMM_XMM` via `op_maskmovq` and `op_maskmovdqu` helpers writing only bytes with `(mask[i] & 0x80) != 0` under `std::atomic_signal_fence(std::memory_order_seq_cst)`. - Adds `MOV_R64_RM64` / `MOV_RM64_R64` register-only tracking for nonvolatile `rdi` save to a volatile scratch GPR (`rax`/`r9`/`r10`/`r11`), `mov rdi, r8`, and restoration before `ret`, rejecting unrestored `rdi`, unsaved writes, non-`r8` targets, `67h` `edi` targets, segment overrides, and `movq` reads of registers holding saved `rdi`. - Adds exports `op_maskmovq`, `op_maskmovdqu`, and `op_maskmov_pipeline` in `tests/cpu/sse_mmx.asm`, `tests/cpu/sse_mmx.def`, and `CMakeLists.txt`, plus `ALTER_IMM` source/mask swaps on `op_maskmovq` and `op_maskmovdqu`, `VirtualAlloc`/`VirtualProtect` `k=8`/`k=16` page-abutting checks and native partial-edge observations, VEX `vmaskmovdqu` rejection, and ABI/state/PE-patched rejection controls in `tests/cpu/sse_mmx_check.py`. - Documents the expanded contract, verification commands, and measured results in `docs/experiments.md`. ## Verification All checks ran after rebasing onto `upstream/main` (`f7c9f57`, branch commit `c738c7e`): - `ctest --preset dev -N`: `Total Tests: 612` (0 dropped tests). - `cmake --build --preset dev --target cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered cpu_sse_mmx_altered_lifted`: passed (0 errors, 0 warnings). - `cmake --build --preset release --target cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered cpu_sse_mmx_altered_lifted`: passed (0 errors, 0 warnings). - `ctest --preset dev --no-tests=error -R "^cpu_aot_sse_mmx$" -V`: `1 passed, 0 failed, 0 skipped` (1/1 passed in 0.73s; 339 native/lifted/reference cases across 21 exports matched bit-for-bit, 24 `k=8`/`k=16` page-abutting checks, 54 native partial-edge observations, `ALTER_IMM` divergence on 6 exports `[3, 3, 7, 7, 22, 30]`, output mutation control, 9 alternate-encoding checks, 81 unit rejections, 16 PE-patched rejections). - `ctest --preset release --no-tests=error -R "^cpu_aot_sse_mmx$" -V`: `1 passed, 0 failed, 0 skipped` (1/1 passed in 0.71s; identical case/control counts under `/O2`). - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: passed (`form coverage checks passed`). - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: passed (`Self-test passed. Checked 15 Markdown files and 242 links.`). - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: passed (`Self-test passed. Checked 917 tracked source, script and build/CI files: no bidirectional controls.`). ## Evidence and follow-up All fixtures are original MASM source in `tests/cpu/sse_mmx.asm` and synthetic unit/PE-patched controls in `tests/cpu/sse_mmx_check.py`. For this portable first slice, `[rdi..rdi+7]` (`maskmovq`) or `[rdi..rdi+15]` (`maskmovdqu`) must be writable ordinary memory; non-temporal cache hints, implementation-dependent partial-page or all-zero-mask fault behavior, and non-`r8` destinations remain outside this leaf profile. ## 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.
upstream-sync closed this pull request 2026-11-24 06:46:14 +00:00
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!1079
No description provided.