cpu: lower VEX AVX packed saturating, min/max, avg, multiply, and sad instructions #395

Merged
Vonsek merged 5 commits from upstream-pr/401 into main 2026-11-23 15:56:20 +00:00
Vonsek commented 2026-11-22 00:21:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-22T00:21:51Z.


Change

  • Lower 33 VEX 128-bit and 256-bit AVX packed saturating, min/max, average, multiply, multiply-add, and SAD instructions in tools/ffx_version_query.py:
    • Saturating add/sub: vpaddsb, vpaddsw, vpaddusb, vpaddusw, vpsubsb, vpsubsw, vpsubusb, vpsubusw
    • Signed/unsigned min/max: vpminsb, vpmaxsb, vpminub, vpmaxub, vpminsw, vpmaxsw, vpminuw, vpmaxuw, vpminsd, vpmaxsd, vpminud, vpmaxud
    • Average, multiply, multiply-add, and SAD: vpavgb, vpavgw, vpmulhw, vpmulhuw, vpmullw, vpmulld, vpmuldq, vpmuludq, vpmulhrsw, vpmaddwd, vpmaddubsw, vpsadbw, vmpsadbw
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX encodings) and zero upper YMM bytes for 128-bit XMM destinations.
  • Probe CPUID leaf 1 ECX bits 27 (OSXSAVE) and 28 (AVX) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with SKIP_RETURN_CODE 77 on hosts without AVX).
  • Add source-built MASM differential fixture tests/cpu/avx_int_minmax_mul.{asm,def,py}, CMake target cpu_avx_int_minmax_mul_lifted, CTest cpu_aot_avx_int_minmax_mul, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_avx_int_minmax_mul_lifted:
    ValueError: unsupported query operation at 0x1008: vpaddsb xmm0,xmm1,xmm2
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_int_minmax_mul_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_minmax_mul|cpu_aot_bmi1)$" -V: 2/2 passed (33 VEX AVX saturating/minmax/avg/mul/sad cases matched native and translated DLLs + EVEX vpmulld rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 33 AVX-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID/XCR0 check.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536278725 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/401). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:21:51Z. --- ## Change - Lower 33 VEX 128-bit and 256-bit AVX packed saturating, min/max, average, multiply, multiply-add, and SAD instructions in `tools/ffx_version_query.py`: - Saturating add/sub: `vpaddsb`, `vpaddsw`, `vpaddusb`, `vpaddusw`, `vpsubsb`, `vpsubsw`, `vpsubusb`, `vpsubusw` - Signed/unsigned min/max: `vpminsb`, `vpmaxsb`, `vpminub`, `vpmaxub`, `vpminsw`, `vpmaxsw`, `vpminuw`, `vpmaxuw`, `vpminsd`, `vpmaxsd`, `vpminud`, `vpmaxud` - Average, multiply, multiply-add, and SAD: `vpavgb`, `vpavgw`, `vpmulhw`, `vpmulhuw`, `vpmullw`, `vpmulld`, `vpmuldq`, `vpmuludq`, `vpmulhrsw`, `vpmaddwd`, `vpmaddubsw`, `vpsadbw`, `vmpsadbw` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX encodings) and zero upper YMM bytes for 128-bit XMM destinations. - Probe CPUID leaf 1 ECX bits 27 (`OSXSAVE`) and 28 (`AVX`) plus XCR0 XMM/YMM state before invoking the native fixture (exiting 77 with `SKIP_RETURN_CODE 77` on hosts without AVX). - Add source-built MASM differential fixture `tests/cpu/avx_int_minmax_mul.{asm,def,py}`, CMake target `cpu_avx_int_minmax_mul_lifted`, CTest `cpu_aot_avx_int_minmax_mul`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_avx_int_minmax_mul_lifted`: `ValueError: unsupported query operation at 0x1008: vpaddsb xmm0,xmm1,xmm2` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_int_minmax_mul_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_minmax_mul|cpu_aot_bmi1)$" -V`: 2/2 passed (`33 VEX AVX saturating/minmax/avg/mul/sad cases matched native and translated DLLs` + EVEX `vpmulld` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 33 `AVX`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID/XCR0 check.
upstream-sync closed this pull request 2026-11-24 06:42:51 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:48:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:28:17Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T00:32:28.943109Z 5700d1e Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7071570491 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/401#issuecomment-7071570491). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:28:17Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5700d1eca53cf4801acb1a3c0a066c31d3fd1141","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-22T00:32:28.943109Z">2026-11-22T00:32:28.943109Z</relative-time> | `5700d1e` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
R0Y00 commented 2026-11-24 06:49:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T15:44:41Z.


Maintainer update at e2a1f8c: resolved the conflict on main after #387, keeping both CTest registrations and the original 128-bit MASM controls. The independent comparisons also cover the modular VPMADDWD boundary and a 32-byte memory VMPSADBW whose immediate selects different offsets in the two lanes.

ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_minmax_mul|avx_packed_fp|avx_packed_int|sse2_sat_mul|ssse3_int)$' passed 5/5 in each preset. The original branch is fast-forwarded and Windows CI is rerunning.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7106041164 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/401#issuecomment-7106041164). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T15:44:41Z. --- Maintainer update at `e2a1f8c`: resolved the conflict on main after #387, keeping both CTest registrations and the original 128-bit MASM controls. The independent comparisons also cover the modular VPMADDWD boundary and a 32-byte memory VMPSADBW whose immediate selects different offsets in the two lanes. `ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_minmax_mul|avx_packed_fp|avx_packed_int|sse2_sat_mul|ssse3_int)$'` passed 5/5 in each preset. The original branch is fast-forwarded and Windows CI is rerunning.
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!395
No description provided.