cpu: lower opt-in memory-operand AVX move, shuffle, and blend forms (--mem-ops) in cpu_avx_move_aot #2122

Merged
Ammmae0x merged 1 commit from upstream-pr/2130 into main 2026-11-25 11:32:45 +00:00
Ammmae0x commented 2026-11-25 01:11:36 +00:00 (Migrated from github.com)

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


Change

Add opt-in memory-operand lowering (allow_memory=False default / --mem-ops CLI flag) for all 20 register-domain AVX move, shuffle, permute, unpack, blend, and lane forms in tools/cpu_avx_move_aot.py, and add a source-built differential fixture and CTest (cpu_aot_avx_move_ext_mem):

  • Keep default allow_memory=False register-only rejections unchanged so cpu_aot_avx_move_regs and cpu_aot_avx_move_mem retain their exact existing contracts.
  • Under --mem-ops, lower memory operands for vblendpd/vblendps/vblendvpd/vblendvps, vperm2f128, vpermilpd/vpermilps (imm8 and variable forms), vshufpd/vshufps, vunpcklpd/vunpcklps/vunpckhpd/vunpckhps, vmovshdup/vmovsldup (m128/m256), vmovddup (exact m64 for XMM via load_vec64 vs m256 for YMM), vinsertf128 (m128), vinsertps (exact m32 via load_vec32 with imm8 & 0x3f ignoring COUNT_S for memory operands), and memory stores vextractf128 (m128) / vextractps (m32) enforcing R8 destination via flat_address(..., store=True).
  • Preserve unaligned memory reads, raw bit transfer (no NaN canonicalization), XMM upper-128 zero-extension, and discarded-read fault ordering across /O2 via volatile + __unaligned + std::atomic_signal_fence(std::memory_order_seq_cst) helpers.
  • Export host_has_avx() (CPUID.01H:ECX[27:28] + _xgetbv(0) & 6 == 6) for clean exit-77 skipping on non-AVX hosts.
  • Add MASM fixture tests/cpu/avx_move_ext_mem.asm (registered ; coverage: source cpu_aot_avx_move_ext_mem), tests/cpu/avx_move_ext_mem.def, differential harness tests/cpu/avx_move_ext_mem_check.py, and CMake targets/test cpu_aot_avx_move_ext_mem with SKIP_RETURN_CODE 77 and FORM_COVERAGE_RECORD.

Verification

Commit: 30303f42 (based on upstream/main 6921dcfd).

  • cmake --preset dev && cmake --build --preset dev --target cpu_avx_move_ext_mem_altered cpu_avx_move_ext_mem_altered_lifted cpu_avx_move_ext_mem_original cpu_avx_move_ext_mem_original_lifted cpu_avx_move_mem_altered cpu_avx_move_mem_altered_lifted cpu_avx_move_mem_original cpu_avx_move_mem_original_lifted cpu_avx_move_regs_altered cpu_avx_move_regs_altered_lifted cpu_avx_move_regs_original cpu_avx_move_regs_original_lifted -> exit 0, 0 errors, 0 warnings.
  • cmake --preset release && cmake --build --preset release --target ... (same 12 targets) -> exit 0, 0 errors, 0 warnings.
  • ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V -> 3/3 Passed (0 capability skips).
  • ctest --preset release --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V -> 3/3 Passed (cpu_aot_avx_move_regs 0.77s, cpu_aot_avx_move_mem 0.78s, cpu_aot_avx_move_ext_mem 0.67s; 0 capability skips).
  • FORM_COVERAGE_RECORD (dev and release) -> all 20 AVX mnemonics (vblendpd/ps/vpd/vps, vextractf128, vextractps, vinsertf128, vinsertps, vmovddup, vmovshdup, vmovsldup, vperm2f128, vpermilpd/ps, vshufpd/ps, vunpckhpd/hps/lpd/lps) plus ret, vmovdqu, vzeroupper.
  • 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 (Checked 18 Markdown files and 398 links.).
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0 (Checked 1433 tracked source, script and build/CI files: no bidirectional controls.).
  • Spot-mutation verification (5/5 killed, exit 8): disabling allow_memory=False default rejection, relaxing vextractps store=True R8 check, dropping vinsertps m32 imm8 & 0x3f mask, widening XMM vmovddup from load_vec64 to load128, and replacing load_vec32 volatile load with non-volatile memcpy on release /O2 (caught by discarded-read fault test).

No capability skips (exit 77) observed on this AVX-capable host.

Evidence and follow-up

tests/cpu/avx_move_ext_mem.asm and tests/cpu/avx_move_ext_mem.def are source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 41 exports across 1312 native/lifted/reference cases (including IEEE-754 NaN/inf/-0 raw bit preservation, unaligned displacements, XMM upper-128 zeroing, VirtualAlloc/PAGE_NOACCESS page-edge m32/m64 no-overread tests, discarded-read fault ordering, and ALTER_IMM differential controls), 20 default allow_memory=False rejections, and 14 unit + 4 patched-PE --mem-ops 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:6594809358 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2130). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T01:11:36Z. --- ## Change Add opt-in memory-operand lowering (`allow_memory=False` default / `--mem-ops` CLI flag) for all 20 register-domain AVX move, shuffle, permute, unpack, blend, and lane forms in `tools/cpu_avx_move_aot.py`, and add a source-built differential fixture and CTest (`cpu_aot_avx_move_ext_mem`): - Keep default `allow_memory=False` register-only rejections unchanged so `cpu_aot_avx_move_regs` and `cpu_aot_avx_move_mem` retain their exact existing contracts. - Under `--mem-ops`, lower memory operands for `vblendpd`/`vblendps`/`vblendvpd`/`vblendvps`, `vperm2f128`, `vpermilpd`/`vpermilps` (imm8 and variable forms), `vshufpd`/`vshufps`, `vunpcklpd`/`vunpcklps`/`vunpckhpd`/`vunpckhps`, `vmovshdup`/`vmovsldup` (`m128`/`m256`), `vmovddup` (exact `m64` for XMM via `load_vec64` vs `m256` for YMM), `vinsertf128` (`m128`), `vinsertps` (exact `m32` via `load_vec32` with `imm8 & 0x3f` ignoring `COUNT_S` for memory operands), and memory stores `vextractf128` (`m128`) / `vextractps` (`m32`) enforcing `R8` destination via `flat_address(..., store=True)`. - Preserve unaligned memory reads, raw bit transfer (no NaN canonicalization), XMM upper-128 zero-extension, and discarded-read fault ordering across `/O2` via `volatile` + `__unaligned` + `std::atomic_signal_fence(std::memory_order_seq_cst)` helpers. - Export `host_has_avx()` (`CPUID.01H:ECX[27:28]` + `_xgetbv(0) & 6 == 6`) for clean exit-77 skipping on non-AVX hosts. - Add MASM fixture `tests/cpu/avx_move_ext_mem.asm` (registered `; coverage: source cpu_aot_avx_move_ext_mem`), `tests/cpu/avx_move_ext_mem.def`, differential harness `tests/cpu/avx_move_ext_mem_check.py`, and CMake targets/test `cpu_aot_avx_move_ext_mem` with `SKIP_RETURN_CODE 77` and `FORM_COVERAGE_RECORD`. ## Verification Commit: `30303f42` (based on `upstream/main` `6921dcfd`). - `cmake --preset dev && cmake --build --preset dev --target cpu_avx_move_ext_mem_altered cpu_avx_move_ext_mem_altered_lifted cpu_avx_move_ext_mem_original cpu_avx_move_ext_mem_original_lifted cpu_avx_move_mem_altered cpu_avx_move_mem_altered_lifted cpu_avx_move_mem_original cpu_avx_move_mem_original_lifted cpu_avx_move_regs_altered cpu_avx_move_regs_altered_lifted cpu_avx_move_regs_original cpu_avx_move_regs_original_lifted` -> exit `0`, 0 errors, 0 warnings. - `cmake --preset release && cmake --build --preset release --target ...` (same 12 targets) -> exit `0`, 0 errors, 0 warnings. - `ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V` -> `3/3 Passed` (0 capability skips). - `ctest --preset release --no-tests=error -R "^cpu_aot_avx_move" -E "cpu_native_archive_" -V` -> `3/3 Passed` (`cpu_aot_avx_move_regs` 0.77s, `cpu_aot_avx_move_mem` 0.78s, `cpu_aot_avx_move_ext_mem` 0.67s; 0 capability skips). - `FORM_COVERAGE_RECORD` (`dev` and `release`) -> all 20 AVX mnemonics (`vblendpd/ps/vpd/vps`, `vextractf128`, `vextractps`, `vinsertf128`, `vinsertps`, `vmovddup`, `vmovshdup`, `vmovsldup`, `vperm2f128`, `vpermilpd/ps`, `vshufpd/ps`, `vunpckhpd/hps/lpd/lps`) plus `ret`, `vmovdqu`, `vzeroupper`. - `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` (`Checked 18 Markdown files and 398 links.`). - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0` (`Checked 1433 tracked source, script and build/CI files: no bidirectional controls.`). - Spot-mutation verification (5/5 killed, exit `8`): disabling `allow_memory=False` default rejection, relaxing `vextractps` `store=True` `R8` check, dropping `vinsertps` `m32` `imm8 & 0x3f` mask, widening XMM `vmovddup` from `load_vec64` to `load128`, and replacing `load_vec32` volatile load with non-volatile `memcpy` on `release` `/O2` (caught by discarded-read fault test). No capability skips (exit 77) observed on this AVX-capable host. ## Evidence and follow-up `tests/cpu/avx_move_ext_mem.asm` and `tests/cpu/avx_move_ext_mem.def` are source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 41 exports across 1312 native/lifted/reference cases (including IEEE-754 NaN/inf/-0 raw bit preservation, unaligned displacements, XMM upper-128 zeroing, `VirtualAlloc`/`PAGE_NOACCESS` page-edge `m32`/`m64` no-overread tests, discarded-read fault ordering, and `ALTER_IMM` differential controls), 20 default `allow_memory=False` rejections, and 14 unit + 4 patched-PE `--mem-ops` 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:00:59 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 30303f423cf8635695bcd7308fc5c886cfa09437

Scope: tools/cpu_avx_move_aot.py (--mem-ops / allow_memory), new fixture tests/cpu/avx_move_ext_mem.{asm,def} + avx_move_ext_mem_check.py, CMake test cpu_aot_avx_move_ext_mem.

Result: no P1, no P2. Two nits.

What I checked (Linux, locally)

  • git diff --stat origin/main...HEAD: 5 files, +1152/-43. Title is neutral, PR is MERGEABLE.
  • gh pr checks 2130: Windows build/test, gfx1013 fixtures, and Linux Python checks all pass. The /O2 job and the coverage chart job were skipped.
  • python3 tests/docs_links_check.py: pass (18 files, 398 links).
  • python3 tests/bidi_controls_check.py: pass.
  • git diff --check origin/main...HEAD: clean.
  • The new check script imports ctypes.wintypes, loads the MASM-built PE, and needs ml64. I could not run it on Linux, so I did not run win2025. The native differential result rests on the CI Windows job. I did not see the test name in the logs I fetched, so please confirm that cpu_aot_avx_move_ext_mem actually ran and did not exit 77.
  • I called lift_code directly with iced-x86 encodings (venv, local):
    • vinsertps xmm,xmm,[rcx+8],0FFh with allow_memory=True lifts to load_vec32(...) with imm 0x3fu. The default (allow_memory=False) still rejects it.
    • vextractps [r8+8],xmm,2 lifts to store32. [rcx+8] is rejected, so only R8 is allowed for stores.
    • vextractf128 [r8+8],ymm,1 lifts to store128.
    • vmovddup memory form: XMM uses load_vec64 (exact m64), YMM uses load256.
  • Mutation: I changed immediate8 & 0x3f to & 0xff for the memory vinsertps. The lifted code changed to 0xffu. The fixture uses imm 0D2h/0D4h (bits 7:6 set), so the native differential should kill this mutation. I only confirmed that the generated source changes. I could not run the native kill. I reverted with git checkout -- ..

Findings

  • nit: read_vec_or_mem always calls flat_address(ins), so memory sources must be rooted in an argument GPR. That matches the existing contract. A one-line note in the docstring or --mem-ops help would make this clear.
  • nit: store32/store64/store128/store256 gained signal fences but are not volatile. This is fine for ordering against the loads. Say so in a comment if the intent is "fault ordering of discarded reads only".

Correctness notes (no action)

  • Evaluating write_vec before the memory read keeps the "defined register" bookkeeping consistent. Operand order in the emitted statements is unchanged.
  • Default register-only rejections are unchanged, so cpu_aot_avx_move_regs and cpu_aot_avx_move_mem keep their contracts.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050743165 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2130#pullrequestreview-6050743165). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:20:50Z. **Review:** COMMENTED --- ## Review of head `30303f423cf8635695bcd7308fc5c886cfa09437` Scope: `tools/cpu_avx_move_aot.py` (`--mem-ops` / `allow_memory`), new fixture `tests/cpu/avx_move_ext_mem.{asm,def}` + `avx_move_ext_mem_check.py`, CMake test `cpu_aot_avx_move_ext_mem`. ### Result: no P1, no P2. Two nits. **What I checked (Linux, locally)** - `git diff --stat origin/main...HEAD`: 5 files, +1152/-43. Title is neutral, PR is MERGEABLE. - `gh pr checks 2130`: Windows build/test, gfx1013 fixtures, and Linux Python checks all pass. The /O2 job and the coverage chart job were skipped. - `python3 tests/docs_links_check.py`: pass (18 files, 398 links). - `python3 tests/bidi_controls_check.py`: pass. - `git diff --check origin/main...HEAD`: clean. - The new check script imports `ctypes.wintypes`, loads the MASM-built PE, and needs `ml64`. I could not run it on Linux, so I did not run `win2025`. The native differential result rests on the CI Windows job. I did not see the test name in the logs I fetched, so please confirm that `cpu_aot_avx_move_ext_mem` actually ran and did not exit 77. - I called `lift_code` directly with iced-x86 encodings (venv, local): - `vinsertps xmm,xmm,[rcx+8],0FFh` with `allow_memory=True` lifts to `load_vec32(...)` with imm `0x3fu`. The default (`allow_memory=False`) still rejects it. - `vextractps [r8+8],xmm,2` lifts to `store32`. `[rcx+8]` is rejected, so only R8 is allowed for stores. - `vextractf128 [r8+8],ymm,1` lifts to `store128`. - `vmovddup` memory form: XMM uses `load_vec64` (exact m64), YMM uses `load256`. - Mutation: I changed `immediate8 & 0x3f` to `& 0xff` for the memory `vinsertps`. The lifted code changed to `0xffu`. The fixture uses imm `0D2h`/`0D4h` (bits 7:6 set), so the native differential should kill this mutation. I only confirmed that the generated source changes. I could not run the native kill. I reverted with `git checkout -- .`. **Findings** - nit: `read_vec_or_mem` always calls `flat_address(ins)`, so memory sources must be rooted in an argument GPR. That matches the existing contract. A one-line note in the docstring or `--mem-ops` help would make this clear. - nit: `store32`/`store64`/`store128`/`store256` gained signal fences but are not `volatile`. This is fine for ordering against the loads. Say so in a comment if the intent is "fault ordering of discarded reads only". **Correctness notes (no action)** - Evaluating `write_vec` before the memory read keeps the "defined register" bookkeeping consistent. Operand order in the emitted statements is unchanged. - Default register-only rejections are unchanged, so `cpu_aot_avx_move_regs` and `cpu_aot_avx_move_mem` keep their contracts. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 12:01:35 +00:00
Ammmae0x commented 2026-11-25 12:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T11:37:30Z.


Confirmed at head 30303f42 on Windows x64 (AVX-capable host; CI pr preset only runs the 30-test smoke subset):

  • ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V -> 1/1 Passed (exit 0, not skipped with exit 77).
  • ctest --preset release --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V (/O2) -> 1/1 Passed (exit 0, not skipped with exit 77).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161288228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2130#issuecomment-7161288228). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T11:37:30Z. --- Confirmed at head `30303f42` on Windows x64 (AVX-capable host; CI `pr` preset only runs the 30-test smoke subset): - `ctest --preset dev --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V` -> **1/1 Passed** (exit 0, not skipped with exit 77). - `ctest --preset release --no-tests=error -R "^cpu_aot_avx_move_ext_mem$" -V` (`/O2`) -> **1/1 Passed** (exit 0, not skipped with exit 77). AI-assisted.
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!2122
No description provided.