cpu: lower VEX AVX packed sign/zero-extend, horizontal integer, and phminposuw #396

Merged
Vonsek merged 4 commits from upstream-pr/402 into main 2026-11-23 16:12:38 +00:00
Vonsek commented 2026-11-22 00:24:18 +00:00 (Migrated from github.com)

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


Change

  • Lower 19 VEX 128-bit and 256-bit AVX packed sign/zero-extend, horizontal integer add/sub, and horizontal minimum instructions in tools/ffx_version_query.py:
    • Sign-extend: vpmovsxbw, vpmovsxbd, vpmovsxbq, vpmovsxwd, vpmovsxwq, vpmovsxdq
    • Zero-extend: vpmovzxbw, vpmovzxbd, vpmovzxbq, vpmovzxwd, vpmovzxwq, vpmovzxdq
    • Horizontal add/sub and minpos: vphaddw, vphaddd, vphaddsw, vphsubw, vphsubd, vphsubsw, vphminposuw
  • 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_extend_hadd.{asm,def,py}, CMake target cpu_avx_int_extend_hadd_lifted, CTest cpu_aot_avx_int_extend_hadd, 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_extend_hadd_lifted:
    ValueError: unsupported query operation at 0x1004: vpmovsxbw xmm0,xmm1
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_int_extend_hadd_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_extend_hadd|cpu_aot_bmi1)$" -V: 2/2 passed (19 VEX AVX extend/horizontal/minpos cases matched native and translated DLLs + EVEX vpmovsxbw rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 19 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:6536298852 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/402). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:24:18Z. --- ## Change - Lower 19 VEX 128-bit and 256-bit AVX packed sign/zero-extend, horizontal integer add/sub, and horizontal minimum instructions in `tools/ffx_version_query.py`: - Sign-extend: `vpmovsxbw`, `vpmovsxbd`, `vpmovsxbq`, `vpmovsxwd`, `vpmovsxwq`, `vpmovsxdq` - Zero-extend: `vpmovzxbw`, `vpmovzxbd`, `vpmovzxbq`, `vpmovzxwd`, `vpmovzxwq`, `vpmovzxdq` - Horizontal add/sub and minpos: `vphaddw`, `vphaddd`, `vphaddsw`, `vphsubw`, `vphsubd`, `vphsubsw`, `vphminposuw` - 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_extend_hadd.{asm,def,py}`, CMake target `cpu_avx_int_extend_hadd_lifted`, CTest `cpu_aot_avx_int_extend_hadd`, 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_extend_hadd_lifted`: `ValueError: unsupported query operation at 0x1004: vpmovsxbw xmm0,xmm1` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_int_extend_hadd_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_extend_hadd|cpu_aot_bmi1)$" -V`: 2/2 passed (`19 VEX AVX extend/horizontal/minpos cases matched native and translated DLLs` + EVEX `vpmovsxbw` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 19 `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:14Z.


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:31:20.389565Z 5704bd3 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:7071570012 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/402#issuecomment-7071570012). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:28:14Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"5704bd310275fcc4da90bc5f9711defa3e9035a0","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:31:20.389565Z">2026-11-22T00:31:20.389565Z</relative-time> | `5704bd3` | 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:59:51Z.


Maintainer update at 5fbc4ab: resolved the shared-lowerer and CMake conflicts after #401, retaining all 19 original XMM cases. The new YMM controls are AVX2-gated and compare an 8-byte sign-extension read and a 32-byte horizontal add against native plus independent lane references. The shared width-aware memory read is used, and both EVEX and a VEX source outside the register profile produce a diagnostic.

ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_extend_hadd|avx_int_minmax_mul|avx_packed_int|avx_packed_fp)$' passed 4/4 in each preset, with the AVX2 controls exercised. The original PR branch was fast-forwarded and CI is rerunning.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7106444872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/402#issuecomment-7106444872). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T15:59:51Z. --- Maintainer update at `5fbc4ab`: resolved the shared-lowerer and CMake conflicts after #401, retaining all 19 original XMM cases. The new YMM controls are AVX2-gated and compare an 8-byte sign-extension read and a 32-byte horizontal add against native plus independent lane references. The shared width-aware memory read is used, and both EVEX and a VEX source outside the register profile produce a diagnostic. `ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_extend_hadd|avx_int_minmax_mul|avx_packed_int|avx_packed_fp)$'` passed 4/4 in each preset, with the AVX2 controls exercised. The original PR branch was fast-forwarded and 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!396
No description provided.