cpu: lower VEX AVX packed shifts, packs, unpacks, shuffles, blends, and insert/extract #398

Merged
Vonsek merged 4 commits from upstream-pr/404 into main 2026-11-23 16:32:30 +00:00
Vonsek commented 2026-11-22 00:30:54 +00:00 (Migrated from github.com)

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


Change

  • Lower 34 VEX 128-bit and 256-bit AVX packed shift, pack, unpack, shuffle, blend, movemask, and insert/extract instructions in tools/ffx_version_query.py:
    • Packed shifts (immediate and register/memory counts): vpsllw, vpslld, vpsllq, vpsrlw, vpsrlq, vpsraw, vpsrad, vpslldq
    • Saturating packs: vpacksswb, vpackssdw, vpackuswb, vpackusdw
    • Unpack/interleave: vpunpcklbw, vpunpcklwd, vpunpckldq, vpunpcklqdq, vpunpckhbw, vpunpckhwd, vpunpckhdq, vpunpckhqdq
    • Shuffles, blends, and movemask: vpshufd, vpshuflw, vpshufhw, vpblendw, vpblendvb, vpmovmskb
    • Insert/extract: vpextrb, vpextrw, vpextrd, vpextrq, vpinsrb, vpinsrw, vpinsrd, vpinsrq
  • 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_shifts_pack.{asm,def,py}, CMake target cpu_avx_int_shifts_pack_lifted, CTest cpu_aot_avx_int_shifts_pack, 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_shifts_pack_lifted:
    ValueError: unsupported query operation at 0x1004: vpsllw xmm0,xmm1,5
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_int_shifts_pack_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_shifts_pack|cpu_aot_bmi1)$" -V: 2/2 passed (34 VEX AVX shift/pack/unpack/shuffle/blend/movemask/insert/extract cases matched native and translated DLLs + EVEX vpshufd rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 34 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:6536352432 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/404). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:30:54Z. --- ## Change - Lower 34 VEX 128-bit and 256-bit AVX packed shift, pack, unpack, shuffle, blend, movemask, and insert/extract instructions in `tools/ffx_version_query.py`: - Packed shifts (immediate and register/memory counts): `vpsllw`, `vpslld`, `vpsllq`, `vpsrlw`, `vpsrlq`, `vpsraw`, `vpsrad`, `vpslldq` - Saturating packs: `vpacksswb`, `vpackssdw`, `vpackuswb`, `vpackusdw` - Unpack/interleave: `vpunpcklbw`, `vpunpcklwd`, `vpunpckldq`, `vpunpcklqdq`, `vpunpckhbw`, `vpunpckhwd`, `vpunpckhdq`, `vpunpckhqdq` - Shuffles, blends, and movemask: `vpshufd`, `vpshuflw`, `vpshufhw`, `vpblendw`, `vpblendvb`, `vpmovmskb` - Insert/extract: `vpextrb`, `vpextrw`, `vpextrd`, `vpextrq`, `vpinsrb`, `vpinsrw`, `vpinsrd`, `vpinsrq` - 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_shifts_pack.{asm,def,py}`, CMake target `cpu_avx_int_shifts_pack_lifted`, CTest `cpu_aot_avx_int_shifts_pack`, 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_shifts_pack_lifted`: `ValueError: unsupported query operation at 0x1004: vpsllw xmm0,xmm1,5` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_int_shifts_pack_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_int_shifts_pack|cpu_aot_bmi1)$" -V`: 2/2 passed (`34 VEX AVX shift/pack/unpack/shuffle/blend/movemask/insert/extract cases matched native and translated DLLs` + EVEX `vpshufd` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 34 `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:52 +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:37:40Z.


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:42:45.976996Z c2a56e8 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:7071675393 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/404#issuecomment-7071675393). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:37:40Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c2a56e8925831f45f0d08b98e481a6de328ad384","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:42:45.976996Z">2026-11-22T00:42:45.976996Z</relative-time> | `c2a56e8` | 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:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:15:58Z.


Maintainer update at afaa07e: resolved the CMake and lowerer conflicts after #402 and kept all 34 original MASM comparisons. The existing register-form XMM paths stay in use; the new YMM memory shuffle checks both lane outputs independently. The memory count for packed shifts reads the full m128 operand before using its low 64 bits, which the cross-page fault control now verifies before any result store. The blend control uses a destination that aliases the mask, and the fixture also checks refusal of EVEX and an unsupported source register.

ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_shifts_pack|avx_int_extend_hadd|avx2_permutes|avx_packed_int|avx2_shifts)$' passed 5/5 in each preset. The original branch is fast-forwarded and CI is rerunning.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7106866438 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/404#issuecomment-7106866438). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:15:58Z. --- Maintainer update at `afaa07e`: resolved the CMake and lowerer conflicts after #402 and kept all 34 original MASM comparisons. The existing register-form XMM paths stay in use; the new YMM memory shuffle checks both lane outputs independently. The memory count for packed shifts reads the full m128 operand before using its low 64 bits, which the cross-page fault control now verifies before any result store. The blend control uses a destination that aliases the mask, and the fixture also checks refusal of EVEX and an unsupported source register. `ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(avx_int_shifts_pack|avx_int_extend_hadd|avx2_permutes|avx_packed_int|avx2_shifts)$'` passed 5/5 in each preset. The original branch is 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!398
No description provided.