cpu: lower AVX broadcast, permute, shuffle, blend, dot, round, and vzeroall instructions #390

Manually merged
github merged 4 commits from gh-pr/390/head into gh-pr/390/base 2026-11-26 21:48:09 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-22 00:07 UTC · original
Vonsek:ag/cpu-lower-avx-shuffle-blend → main · +706 −4 · 7 files · 4 commits · merged 2026-11-23 17:27 UTC

Change

  • Lower 26 VEX 128-bit and 256-bit AVX broadcast, lane extract/insert, permute, shuffle, unpack, blend, dot-product, round, and vzeroall instructions in tools/ffx_version_query.py:
    • Broadcasts and 128-bit lane ops: vbroadcastss, vbroadcastsd, vbroadcastf128, vextractf128, vinsertf128, vperm2f128
    • Permutes, shuffles, unpacks, and duplicates: vpermilps, vpermilpd, vshufps, vshufpd, vunpcklps, vunpckhps, vunpcklpd, vunpckhpd, vmovddup, vmovsldup, vmovshdup
    • Blends, dot products, rounding, and state clear: vblendps, vblendpd, vblendvps, vblendvpd, vdpps, vdppd, vroundps, vroundpd, vzeroall
  • Restrict lowering to EncodingKind.VEX (rejecting EVEX and MXCSR rounding mode imm8 & 4 != 0) 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_shuffle_blend.{asm,def,py}, CMake target cpu_avx_shuffle_blend_lifted, CTest cpu_aot_avx_shuffle_blend, 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_shuffle_blend_lifted:
    ValueError: unsupported query operation at 0x1000: vbroadcastss ymm0,dword ptr [rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_shuffle_blend_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_shuffle_blend|cpu_aot_bmi1)$" -V: 2/2 passed (26 AVX broadcast/permute/shuffle/blend/dot/round/zeroall cases matched native and translated DLLs + MXCSR-mode vroundps rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • Covers 26 AVX-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures, gated by a runtime CPUID/XCR0 check.
**@⁠Vonsek** on GitHub · 2026-11-22 00:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390) `Vonsek:ag/cpu-lower-avx-shuffle-blend` → `main` · +706 −4 · 7 files · 4 commits · merged 2026-11-23 17:27 UTC ## Change - Lower 26 VEX 128-bit and 256-bit AVX broadcast, lane extract/insert, permute, shuffle, unpack, blend, dot-product, round, and `vzeroall` instructions in `tools/ffx_version_query.py`: - Broadcasts and 128-bit lane ops: `vbroadcastss`, `vbroadcastsd`, `vbroadcastf128`, `vextractf128`, `vinsertf128`, `vperm2f128` - Permutes, shuffles, unpacks, and duplicates: `vpermilps`, `vpermilpd`, `vshufps`, `vshufpd`, `vunpcklps`, `vunpckhps`, `vunpcklpd`, `vunpckhpd`, `vmovddup`, `vmovsldup`, `vmovshdup` - Blends, dot products, rounding, and state clear: `vblendps`, `vblendpd`, `vblendvps`, `vblendvpd`, `vdpps`, `vdppd`, `vroundps`, `vroundpd`, `vzeroall` - Restrict lowering to `EncodingKind.VEX` (rejecting EVEX and MXCSR rounding mode imm8 & 4 != 0) 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_shuffle_blend.{asm,def,py}`, CMake target `cpu_avx_shuffle_blend_lifted`, CTest `cpu_aot_avx_shuffle_blend`, 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_shuffle_blend_lifted`: `ValueError: unsupported query operation at 0x1000: vbroadcastss ymm0,dword ptr [rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_shuffle_blend_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_shuffle_blend|cpu_aot_bmi1)$" -V`: 2/2 passed (`26 AVX broadcast/permute/shuffle/blend/dot/round/zeroall cases matched native and translated DLLs` + MXCSR-mode `vroundps` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - Covers 26 `AVX`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures, gated by a runtime CPUID/XCR0 check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:48:07 +00:00
github manually merged commit d9320ba25a into gh-pr/390/base 2026-11-26 21:48:09 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:11 UTC · original · edited 2026-11-22 00:20 UTC

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:20:13.905996Z a0881a1 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#issuecomment-7071372757) · edited 2026-11-22 00:20 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a0881a1512acb65a6b915fc00bd6613f354a2fbe","has_any_findings":true,"has_unresolved_findings":true,"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:20:13.905996Z">2026-11-22T00:20:13.905996Z</relative-time> | `a0881a1` | 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:20 UTC · original

P2 Badge Preserve the pairwise reduction order of VDPPS

For cancellation-sensitive inputs, this sequential accumulation produces different results from the instruction. With the fixture's existing 0xd5 immediate, source lanes [1e20f, 0, -1e20f, 3] dotted with [1, 1, 1, 1] produce 0 natively but 3 in the emitted code, reproduced with a source-built AVX probe under default MXCSR. VDPPS reduces the masked products as (p0 + p1) + (p2 + p3), with intermediate rounding, rather than accumulating left to right. Emit that reduction tree and add a cancellation-sensitive differential case.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#discussion_r4655735367) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the pairwise reduction order of VDPPS** For cancellation-sensitive inputs, this sequential accumulation produces different results from the instruction. With the fixture's existing `0xd5` immediate, source lanes `[1e20f, 0, -1e20f, 3]` dotted with `[1, 1, 1, 1]` produce `0` natively but `3` in the emitted code, reproduced with a source-built AVX probe under default MXCSR. VDPPS reduces the masked products as `(p0 + p1) + (p2 + p3)`, with intermediate rounding, rather than accumulating left to right. Emit that reduction tree and add a cancellation-sensitive differential case. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:20 UTC · original

P2 Badge Limit XMM VMOVDDUP memory loads to eight bytes

For vmovddup xmm0, qword ptr [rcx], the architectural memory operand is only eight bytes, but nbytes is 16 because it describes the destination width. This initializer consequently reads eight bytes beyond the operand. When the source occupies the last eight readable bytes before a protected page, the native instruction succeeds while the emitted code faults in an unoptimized build; this was reproduced with a guarded-page probe. Derive the read size from the memory operand or special-case the 128-bit VMOVDDUP form instead of using the output width.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#discussion_r4655735374) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Limit XMM VMOVDDUP memory loads to eight bytes** For `vmovddup xmm0, qword ptr [rcx]`, the architectural memory operand is only eight bytes, but `nbytes` is 16 because it describes the destination width. This initializer consequently reads eight bytes beyond the operand. When the source occupies the last eight readable bytes before a protected page, the native instruction succeeds while the emitted code faults in an unoptimized build; this was reproduced with a guarded-page probe. Derive the read size from the memory operand or special-case the 128-bit VMOVDDUP form instead of using the output width. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -0,0 +251,4 @@
vzeroall_lift_entry PROC FRAME
.endprolog
vmovups ymm0, ymmword ptr [rcx]
vzeroall
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:20 UTC · original

P2 Badge Preserve Win64 nonvolatile XMM registers around VZEROALL

On the x64 Windows target, vzeroall clears the low 128 bits of XMM6–XMM15, which are callee-saved, but this export returns without restoring them. The native fixture is called directly through ctypes in check(), so any live caller state in those registers is lost even when the output comparison passes. A source-built register probe confirms that an XMM6 sentinel returns as zero. Save and restore the nonvolatile XMM halves, or invoke this fixture through an ABI-preserving native wrapper.

AGENTS.md reference: AGENTS.md:L37-L38

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#discussion_r4655735378) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve Win64 nonvolatile XMM registers around VZEROALL** On the x64 Windows target, `vzeroall` clears the low 128 bits of XMM6–XMM15, which are callee-saved, but this export returns without restoring them. The native fixture is called directly through ctypes in `check()`, so any live caller state in those registers is lost even when the output comparison passes. A source-built register probe confirms that an XMM6 sentinel returns as zero. Save and restore the nonvolatile XMM halves, or invoke this fixture through an ABI-preserving native wrapper. AGENTS.md reference: [AGENTS.md:L37-L38](https://github.com/R0Y00/Xbox2Windows/blob/a0881a1512acb65a6b915fc00bd6613f354a2fbe/AGENTS.md#L37-L38) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:20 UTC · original

P2 Badge Quiet signaling NaNs in the packed-rounding helper

When a source lane contains a signaling NaN and invalid exceptions are masked, VROUNDPS/VROUNDPD return a quiet NaN rather than preserving the signaling representation. This early return leaves the input bits unchanged: with the fixture's vroundps immediate 8, a source-built probe produced native bits 0x7fc00001 versus lowered bits 0x7f800001 for input 0x7f800001. Handle signaling NaNs explicitly so the helper quiets them while preserving the appropriate payload.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#discussion_r4655735382) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Quiet signaling NaNs in the packed-rounding helper** When a source lane contains a signaling NaN and invalid exceptions are masked, VROUNDPS/VROUNDPD return a quiet NaN rather than preserving the signaling representation. This early return leaves the input bits unchanged: with the fixture's `vroundps` immediate `8`, a source-built probe produced native bits `0x7fc00001` versus lowered bits `0x7f800001` for input `0x7f800001`. Handle signaling NaNs explicitly so the helper quiets them while preserving the appropriate payload. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-22 19:26 UTC · original

Verified afc5773 on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. ctest --preset dev --no-tests=error -R "^cpu_" -j 4 passes 81 of 81 on this branch's base.

Two notes:

  • tests/cpu/avx_shuffle_blend.py exercises vdpps_op/vdppd_op only with finite inputs; there are no NaN or infinity lanes. In #602 a DPPS case with several NaN products failed on this Intel host because the reference model encodes one vendor's NaN choice, and the translation runs the host's own dot-product instruction. The same case does not arise here yet, but a multi-NaN dot product would need the same vendor-tolerant check.
  • The branch no longer merges cleanly with main at ff7f68a (git merge-tree).

AI-assisted (Claude Code).

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-22 19:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#issuecomment-7084398376) Verified `afc5773` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. `ctest --preset dev --no-tests=error -R "^cpu_" -j 4` passes 81 of 81 on this branch's base. Two notes: - `tests/cpu/avx_shuffle_blend.py` exercises `vdpps_op/vdppd_op` only with finite inputs; there are no NaN or infinity lanes. In #602 a DPPS case with several NaN products failed on this Intel host because the reference model encodes one vendor's NaN choice, and the translation runs the host's own dot-product instruction. The same case does not arise here yet, but a multi-NaN dot product would need the same vendor-tolerant check. - The branch no longer merges cleanly with `main` at `ff7f68a` (`git merge-tree`). AI-assisted (Claude Code).
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 16:59 UTC · original

Updated the branch to adb3101 and preserved the existing XMM shuffle paths and #404 packed integer regression. The new YMM paths now run through the correct width dispatch. The XMM memory VMOVDDUP reads only the decoded eight bytes, verified at a no-access page boundary. VDPPS uses the host lane operation and passes the cancellation case that distinguishes a left-to-right sum. The multiple-NaN check accepts a NaN in selected lanes and still compares the other lanes bit for bit. The original AVX fixture and the existing SSE3/4, AVX packed FP and AVX integer shift/pack checks passed 4/4 in both Debug and Release. Fresh CI will run on the updated head.

**@⁠R0Y00** on GitHub · 2026-11-23 16:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#issuecomment-7107994508) Updated the branch to adb3101 and preserved the existing XMM shuffle paths and #404 packed integer regression. The new YMM paths now run through the correct width dispatch. The XMM memory VMOVDDUP reads only the decoded eight bytes, verified at a no-access page boundary. VDPPS uses the host lane operation and passes the cancellation case that distinguishes a left-to-right sum. The multiple-NaN check accepts a NaN in selected lanes and still compares the other lanes bit for bit. The original AVX fixture and the existing SSE3/4, AVX packed FP and AVX integer shift/pack checks passed 4/4 in both Debug and Release. Fresh CI will run on the updated head.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 17:08 UTC · original

d9320ba adds a Win64-native wrapper that saves and restores XMM6–XMM15 around the raw VZEROALL fixture. A separate native call now checks that an XMM6 sentinel survives. It also adds exact signaling-NaN readbacks for VROUNDPS and VROUNDPD with the invalid exception masked. This verifies the packed round intrinsics, in addition to the eight-byte VMOVDDUP guard-page and VDPPS cancellation checks from the earlier update. All four focused tests passed in Debug and Release.

**@⁠R0Y00** on GitHub · 2026-11-23 17:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#issuecomment-7108217602) d9320ba adds a Win64-native wrapper that saves and restores XMM6–XMM15 around the raw VZEROALL fixture. A separate native call now checks that an XMM6 sentinel survives. It also adds exact signaling-NaN readbacks for VROUNDPS and VROUNDPD with the invalid exception masked. This verifies the packed round intrinsics, in addition to the eight-byte VMOVDDUP guard-page and VDPPS cancellation checks from the earlier update. All four focused tests passed in Debug and Release.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:20 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0881a1512

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/390#pullrequestreview-6009144292) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `a0881a1512` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.