cpu: lower VEX AVX packed integer ALU instructions #389

Merged
Vonsek merged 5 commits from upstream-pr/395 into main 2026-11-23 15:11:34 +00:00
Vonsek commented 2026-11-22 00:15:46 +00:00 (Migrated from github.com)

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


Change

  • Lower 26 VEX 128-bit and 256-bit AVX packed integer ALU instructions in tools/ffx_version_query.py:
    • Wrapping add/sub: vpaddb, vpaddw, vpaddq, vpsubb, vpsubw, vpsubd, vpsubq
    • Bitwise: vpand, vpandn, vpor
    • Comparisons: vpcmpeqb, vpcmpeqw, vpcmpeqd, vpcmpeqq, vpcmpgtb, vpcmpgtw, vpcmpgtd, vpcmpgtq
    • Abs, sign, byte shuffle, and byte align: vpabsb, vpabsw, vpabsd, vpsignb, vpsignw, vpsignd, vpshufb, vpalignr
  • 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_packed_int.{asm,def,py}, CMake target cpu_avx_packed_int_lifted, CTest cpu_aot_avx_packed_int, 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_packed_int_lifted:
    ValueError: unsupported query operation at 0x1008: vpaddb xmm0,xmm1,xmm2
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_avx_packed_int_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_packed_int|cpu_aot_bmi1)$" -V: 2/2 passed (26 VEX AVX packed integer ALU cases matched native and translated DLLs + EVEX vpaddb 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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536223806 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/395). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T00:15:46Z. --- ## Change - Lower 26 VEX 128-bit and 256-bit AVX packed integer ALU instructions in `tools/ffx_version_query.py`: - Wrapping add/sub: `vpaddb`, `vpaddw`, `vpaddq`, `vpsubb`, `vpsubw`, `vpsubd`, `vpsubq` - Bitwise: `vpand`, `vpandn`, `vpor` - Comparisons: `vpcmpeqb`, `vpcmpeqw`, `vpcmpeqd`, `vpcmpeqq`, `vpcmpgtb`, `vpcmpgtw`, `vpcmpgtd`, `vpcmpgtq` - Abs, sign, byte shuffle, and byte align: `vpabsb`, `vpabsw`, `vpabsd`, `vpsignb`, `vpsignw`, `vpsignd`, `vpshufb`, `vpalignr` - 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_packed_int.{asm,def,py}`, CMake target `cpu_avx_packed_int_lifted`, CTest `cpu_aot_avx_packed_int`, 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_packed_int_lifted`: `ValueError: unsupported query operation at 0x1008: vpaddb xmm0,xmm1,xmm2` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_avx_packed_int_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_avx_packed_int|cpu_aot_bmi1)$" -V`: 2/2 passed (`26 VEX AVX packed integer ALU cases matched native and translated DLLs` + EVEX `vpaddb` 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.
upstream-sync closed this pull request 2026-11-24 06:42:49 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:48:14 +00:00 (Migrated from github.com)

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


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:23:46.833991Z 0fd139b 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:7071473983 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/395#issuecomment-7071473983). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:19:39Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"0fd139b9179da71fc94965e58cf6153b8701b681","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:23:46.833991Z">2026-11-22T00:23:46.833991Z</relative-time> | `0fd139b` | 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:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T14:52:17Z.


I resolved the shared vector and CMake conflicts on the current branch after #666. All 26 original VEX.128 exports still match. The added VEX.256 VPSHUFB uses a 32-byte memory source and different reference patterns for its two lanes. The translator now rejects a register outside the shared profile with a normal error and preserves the memory operand's width. Both Debug and Release passed seven focused CPU CTests. GitHub CI is rerunning.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7104663451 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/395#issuecomment-7104663451). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T14:52:17Z. --- I resolved the shared vector and CMake conflicts on the current branch after #666. All 26 original VEX.128 exports still match. The added VEX.256 VPSHUFB uses a 32-byte memory source and different reference patterns for its two lanes. The translator now rejects a register outside the shared profile with a normal error and preserves the memory operand's width. Both Debug and Release passed seven focused CPU CTests. GitHub 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!389
No description provided.