cpu: lower VEX.256 YMM VPMULDQ, VPMULUDQ, VPMULHRSW, and VPSADBW in cpu_avx_int_aot #2109

Merged
Ammmae0x merged 1 commit from upstream-pr/2117 into main 2026-11-25 09:38:15 +00:00
Ammmae0x commented 2026-11-25 00:47:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:47:27Z.


Change

Enable VEX.256 (L=1, AVX2, register-only YMM0..YMM5) lowering for vpmuldq, vpmuludq, vpmulhrsw, and vpsadbw in tools/cpu_avx_int_aot.py, and add a source-built differential fixture and CTest (cpu_aot_avx_int_ymm_mul_sad):

  • Register vpmuldq, vpmuludq, vpmulhrsw, and vpsadbw in WIDE_BINARY_HELPERS and WIDE_BINARY_CODES so each 128-bit lane ([127:0] and [255:128]) runs independently through the existing portable 128-bit helpers via wide128.
  • Export host_has_avx2() under _MSC_VER (checking CPUID.01H:ECX[27:28], _xgetbv(0) & 6 == 6, CPUID.00H:EAX >= 7, and CPUID.07H.0:EBX[5]) so native differential tests skip cleanly (exit 77) on non-AVX2 hosts while still running AOT lowering and rejection checks.
  • Add MASM fixture tests/cpu/avx_int_ymm_mul_sad.asm (registered ; coverage: source cpu_aot_avx_int_ymm_mul_sad), tests/cpu/avx_int_ymm_mul_sad.def, differential harness tests/cpu/avx_int_ymm_mul_sad_check.py, and CMake targets/test cpu_aot_avx_int_ymm_mul_sad with SKIP_RETURN_CODE 77 and FORM_COVERAGE_RECORD.

Verification

Commit: 53f15645 (based on upstream/main 3ebc3523).

  • cmake --preset dev && cmake --build --preset dev --target cpu_avx_int_ymm_addsub cpu_avx_int_ymm_addsub_lifted cpu_avx_int_ymm_minmax cpu_avx_int_ymm_minmax_lifted cpu_avx_int_ymm_sat cpu_avx_int_ymm_sat_lifted cpu_avx_int_ymm_abs_sign_shuf cpu_avx_int_ymm_abs_sign_shuf_lifted cpu_avx_int_ymm_mul_sad_original cpu_avx_int_ymm_mul_sad_original_lifted cpu_avx_int_ymm_mul_sad_altered cpu_avx_int_ymm_mul_sad_altered_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_int_ymm" -E "cpu_native_archive_" -V -> 5/5 Passed (0 capability skips).
  • ctest --preset release --no-tests=error -R "^cpu_aot_avx_int_ymm" -E "cpu_native_archive_" -V -> 5/5 Passed (cpu_aot_avx_int_ymm_mul_sad 0.28s; 0 capability skips).
  • FORM_COVERAGE_RECORD (dev and release) -> ret, vmovdqu, vpmuldq, vpmulhrsw, vpmuludq, vpsadbw, 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.
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> exit 0.
  • Spot-mutation verification: independently removing VPMULDQ from WIDE_BINARY_CODES, disabling the m256 memory-operand rejection guard in lift_code(), and dropping + 0x4000 rounding in op_vpmulhrsw each caused ctest --preset dev -R "^cpu_aot_avx_int_ymm_mul_sad$" to fail (exit 8).

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

Evidence and follow-up

tests/cpu/avx_int_ymm_mul_sad.asm and tests/cpu/avx_int_ymm_mul_sad.def are source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 10 exports (including destination aliasing, YMM -> XMM upper-lane zero-extension, and chained ops) over 1840 native/lifted/reference cases with unaligned-buffer guard checks, 14 rejection controls (m256 memory operands, EVEX, nonvolatile YMM6..15, undefined sources, missing ret, carved-out 128-bit forms), 5 faulty reference mutants, and 4 ALTER_YMM build controls.

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:6594520472 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2117). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:47:27Z. --- ## Change Enable VEX.256 (`L=1`, AVX2, register-only `YMM0..YMM5`) lowering for `vpmuldq`, `vpmuludq`, `vpmulhrsw`, and `vpsadbw` in `tools/cpu_avx_int_aot.py`, and add a source-built differential fixture and CTest (`cpu_aot_avx_int_ymm_mul_sad`): - Register `vpmuldq`, `vpmuludq`, `vpmulhrsw`, and `vpsadbw` in `WIDE_BINARY_HELPERS` and `WIDE_BINARY_CODES` so each 128-bit lane (`[127:0]` and `[255:128]`) runs independently through the existing portable 128-bit helpers via `wide128`. - Export `host_has_avx2()` under `_MSC_VER` (checking `CPUID.01H:ECX[27:28]`, `_xgetbv(0) & 6 == 6`, `CPUID.00H:EAX >= 7`, and `CPUID.07H.0:EBX[5]`) so native differential tests skip cleanly (exit 77) on non-AVX2 hosts while still running AOT lowering and rejection checks. - Add MASM fixture `tests/cpu/avx_int_ymm_mul_sad.asm` (registered `; coverage: source cpu_aot_avx_int_ymm_mul_sad`), `tests/cpu/avx_int_ymm_mul_sad.def`, differential harness `tests/cpu/avx_int_ymm_mul_sad_check.py`, and CMake targets/test `cpu_aot_avx_int_ymm_mul_sad` with `SKIP_RETURN_CODE 77` and `FORM_COVERAGE_RECORD`. ## Verification Commit: `53f15645` (based on `upstream/main` `3ebc3523`). - `cmake --preset dev && cmake --build --preset dev --target cpu_avx_int_ymm_addsub cpu_avx_int_ymm_addsub_lifted cpu_avx_int_ymm_minmax cpu_avx_int_ymm_minmax_lifted cpu_avx_int_ymm_sat cpu_avx_int_ymm_sat_lifted cpu_avx_int_ymm_abs_sign_shuf cpu_avx_int_ymm_abs_sign_shuf_lifted cpu_avx_int_ymm_mul_sad_original cpu_avx_int_ymm_mul_sad_original_lifted cpu_avx_int_ymm_mul_sad_altered cpu_avx_int_ymm_mul_sad_altered_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_int_ymm" -E "cpu_native_archive_" -V` -> `5/5 Passed` (0 capability skips). - `ctest --preset release --no-tests=error -R "^cpu_aot_avx_int_ymm" -E "cpu_native_archive_" -V` -> `5/5 Passed` (`cpu_aot_avx_int_ymm_mul_sad` 0.28s; 0 capability skips). - `FORM_COVERAGE_RECORD` (`dev` and `release`) -> `ret`, `vmovdqu`, `vpmuldq`, `vpmulhrsw`, `vpmuludq`, `vpsadbw`, `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`. - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> exit `0`. - Spot-mutation verification: independently removing `VPMULDQ` from `WIDE_BINARY_CODES`, disabling the `m256` memory-operand rejection guard in `lift_code()`, and dropping `+ 0x4000` rounding in `op_vpmulhrsw` each caused `ctest --preset dev -R "^cpu_aot_avx_int_ymm_mul_sad$"` to fail (exit `8`). No capability skips (exit 77) observed on this AVX2-capable host. ## Evidence and follow-up `tests/cpu/avx_int_ymm_mul_sad.asm` and `tests/cpu/avx_int_ymm_mul_sad.def` are source-built MASM fixtures authored directly in this repository under the MIT license. The harness validates 10 exports (including destination aliasing, `YMM -> XMM` upper-lane zero-extension, and chained ops) over 1840 native/lifted/reference cases with unaligned-buffer guard checks, 14 rejection controls (`m256` memory operands, EVEX, nonvolatile `YMM6..15`, undefined sources, missing `ret`, carved-out 128-bit forms), 5 faulty reference mutants, and 4 `ALTER_YMM` build controls. ## 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:58 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 53f15645e45b5311ed669fdf446ef8a4d9f9e438 (PR #2117).

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

Checked:

  • git diff --stat origin/main...HEAD: 5 files, +491. Touches tools/cpu_avx_int_aot.py, CMakeLists.txt, and the new fixture, .def and check script.
  • The 128-bit helpers match the ISA semantics, so running them per 128-bit lane via wide128 is correct for all four ops.
    • op_vpmuldq and op_vpmuludq multiply dwords 0 and 2 into two qwords.
    • op_vpmulhrsw computes (a*b + 0x4000) >> 15, keeping the low 16 bits.
    • op_vpsadbw produces two 16-bit sums in the low bits of each qword.
    • None of them reads across the 128-bit lane boundary, so the per-lane split is right.
  • The Python reference in avx_int_ymm_mul_sad_check.py is written independently of the C++ helpers (struct-based).
    • It has mutant controls: drop_round for vpmulhrsw, and altered-build controls.
    • It also has rejection checks.
  • CMake: variant naming, exports and SKIP_RETURN_CODE 77 follow the sibling cpu_avx_int_ymm_* tests. FORM_COVERAGE_RECORD is set.
  • CI: Build and test on Windows pass, Run platform-independent Python checks on Linux pass, and Assemble and translate gfx1013 fixtures pass. The O2 job and the chart job were skipped. Mergeable state was UNKNOWN at review time.
  • The title is neutral. I saw nothing that looks clean-room-problematic.

Commands run locally, in the PR worktree:

  • python3 tests/docs_links_check.py -> self-test passed; 18 Markdown files and 395 links checked.
  • python3 tests/bidi_controls_check.py -> 1427 files checked, no bidirectional controls.
  • git diff --check origin/main...HEAD -> clean.

Not run locally:

  • The native differential test needs MASM-built PE fixtures and iced_x86/pefile. Neither is available on this Linux host (iced_x86 is missing), so the test can't run here.
  • Because of that, I did not run a real mutation of the new logic. I relied on the in-test mutant controls plus the green Windows CI job. No Win2025 run was started. The change is a CPU-AOT lowering, not gfx2hlsl or shaders.

Nits (non-blocking):

  • host_has_avx2() is now exported from the shared PRELUDE under _MSC_VER, so it ends up in every AOT output. Sibling tests define their own copy in Python (avx_int_ymm_minmax_check.py:152, avx_int_ymm_sat_check.py:177). Consider reusing the exported symbol across those tests in a follow-up. This is a cleanup only.
  • Mergeable was UNKNOWN at review time. Please re-check it after a rebase.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050554470 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2117#pullrequestreview-6050554470). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:05:38Z. **Review:** COMMENTED --- Review of head `53f15645e45b5311ed669fdf446ef8a4d9f9e438` (PR #2117). **Verdict: no blocking findings. P1=0, P2=0.** Checked: - `git diff --stat origin/main...HEAD`: 5 files, +491. Touches `tools/cpu_avx_int_aot.py`, `CMakeLists.txt`, and the new fixture, `.def` and check script. - The 128-bit helpers match the ISA semantics, so running them per 128-bit lane via `wide128` is correct for all four ops. - `op_vpmuldq` and `op_vpmuludq` multiply dwords 0 and 2 into two qwords. - `op_vpmulhrsw` computes `(a*b + 0x4000) >> 15`, keeping the low 16 bits. - `op_vpsadbw` produces two 16-bit sums in the low bits of each qword. - None of them reads across the 128-bit lane boundary, so the per-lane split is right. - The Python reference in `avx_int_ymm_mul_sad_check.py` is written independently of the C++ helpers (struct-based). - It has mutant controls: `drop_round` for vpmulhrsw, and altered-build controls. - It also has rejection checks. - CMake: variant naming, exports and `SKIP_RETURN_CODE 77` follow the sibling `cpu_avx_int_ymm_*` tests. `FORM_COVERAGE_RECORD` is set. - CI: `Build and test on Windows` pass, `Run platform-independent Python checks on Linux` pass, and `Assemble and translate gfx1013 fixtures` pass. The O2 job and the chart job were skipped. Mergeable state was UNKNOWN at review time. - The title is neutral. I saw nothing that looks clean-room-problematic. Commands run locally, in the PR worktree: - `python3 tests/docs_links_check.py` -> self-test passed; 18 Markdown files and 395 links checked. - `python3 tests/bidi_controls_check.py` -> 1427 files checked, no bidirectional controls. - `git diff --check origin/main...HEAD` -> clean. Not run locally: - The native differential test needs MASM-built PE fixtures and `iced_x86`/`pefile`. Neither is available on this Linux host (`iced_x86` is missing), so the test can't run here. - Because of that, I did not run a real mutation of the new logic. I relied on the in-test mutant controls plus the green Windows CI job. No Win2025 run was started. The change is a CPU-AOT lowering, not gfx2hlsl or shaders. Nits (non-blocking): - `host_has_avx2()` is now exported from the shared `PRELUDE` under `_MSC_VER`, so it ends up in every AOT output. Sibling tests define their own copy in Python (`avx_int_ymm_minmax_check.py:152`, `avx_int_ymm_sat_check.py:177`). Consider reusing the exported symbol across those tests in a follow-up. This is a cleanup only. - Mergeable was UNKNOWN at review time. Please re-check it after a rebase. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 10:05:15 +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!2109
No description provided.