cpu: lower 256-bit packed abs, sign and word shuffle forms #1335

Merged
tedin7 merged 1 commit from upstream-pr/1342 into main 2026-11-24 09:06:38 +00:00
tedin7 commented 2026-11-24 08:38:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:38:01Z.


Change

Lower the VEX.256 (AVX2) register forms of vpabsb/w/d, vpsignb/w/d, vpshufhw and vpshuflw in tools/cpu_avx_int_aot.py. Before this change these eight were rejected with unsupported VEX.256 (L=1) packed-integer encoding although their 128-bit helpers already existed. Each existing 128-bit helper now runs on the two 128-bit halves on its own, so no sign control, shuffle selector or absolute value crosses the middle of the register; vpshufhw/vpshuflw use the same imm8 for both halves, and all 256 destination bits are written. A later 128-bit VEX write to the same register still clears bits 128..255. Only YMM0..YMM5 are modeled, as before. Refs the AVX2 YMM series started by #1197.

Still rejected with the previous diagnostics: memory sources, every other VEX.256 packed-integer form, EVEX, nonvolatile or never-written vector registers. The 128-bit encodings keep their single-helper path.

Test changes: new fixture tests/cpu/avx_int_ymm_abs_sign_shuf.asm (+ .def) and check tests/cpu/avx_int_ymm_abs_sign_shuf_check.py, wired as CTest cpu_aot_avx_int_ymm_abs_sign_shuf (exits 77 without AVX2). The four refusal controls in avx_int_regs_check.py for vpabsd, vpshufhw, vpshuflw and vpsignd with YMM operands are removed because those forms are now supported, and the vpabsd control in avx_int_ymm_minmax_check.py now uses vpmulld (still unsupported). docs/experiments.md is updated.

PR #1342 fuori preset pr: ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' (and --preset release).

AI-assisted.

Verification

Not run on Windows: the test is outside the pr preset and the MASM fixture needs ML64 and MSVC. Run on Linux (x86-64 host with AVX2, Python venv from requirements-dev.txt, LLVM 19, GCC, MinGW):

  • The same 15 instruction sequences were assembled with llvm-mc-19, run natively, and the translator output built with g++ -O2: python3 -B tests/cpu/avx_int_ymm_abs_sign_shuf_check.py native.so lifted.so printed 8 256-bit forms accepted; 12 rejection controls passed and 2820 native/lifted/reference cases across 15 exports matched bit for bit; 58 negative controls were caught.
  • The MASM source assembles with llvm-ml-19 and links with lld-link-19; the translator lifted the resulting PE, and that output was built with g++ -O0 (same two result lines) and compiled with x86_64-w64-mingw32-g++ at -O0 and -O2.
  • Same check against origin/main's translator: fails at the first form (unsupported VEX.256 (L=1) packed-integer encoding ... vpabsb ymm0,ymm1).
  • Mutated translated output: vpsignd using vpsignw, vpabsb using vpabsw, vpshufhw with the immediate 0x1b changed to 0x93, vpshuflw using vpshufhw: each fails the check (op_vpsignd_ymm, op_vpabsb_ymm, op_vpshufhw_ymm_1b and op_vpshuflw_ymm_93, word 0 or 1).
  • avx_int_regs_check.py (check_rejections against a PE built with llvm-ml/lld-link): 102 unit and 11 PE-patched rejection controls passed. avx_int_ymm_minmax_check.py translator controls: passed.
  • python3 -B tests/form_coverage_check.py and python3 -B tests/docs_links_check.py: passed.

Evidence and follow-up

The reference is an independent Python model that works on one 16-byte half and one element at a time. Inputs: signed and unsigned edge values for every element width (including the most negative value), halves that differ, distinct 16-bit words for the shuffles, seeded random data, and unaligned input and output pointers. Both 16-byte guards around the output, the bytes next to the 32-byte window and the input buffers must stay unchanged. Negative controls: models that drop the upper half, reuse one half's input for the other half, apply the shuffle immediate to one half only, swap vpshufhw and vpshuflw, saturate the absolute value, invert the sign control or use another element width must each differ in the expected 64-bit words; vpabsb of 0x80 must stay 0x80; a flipped bit must be reported at its own word.

Fixtures are original MASM written for this repository; nothing comes from a title or a binary. This does not show that any program runs. A Windows run of ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' -V is still needed. Follow-up for others: YMM memory sources and the remaining 256-bit packed-integer forms.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6577865148 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1342). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:38:01Z. --- ## Change Lower the VEX.256 (AVX2) register forms of `vpabsb/w/d`, `vpsignb/w/d`, `vpshufhw` and `vpshuflw` in `tools/cpu_avx_int_aot.py`. Before this change these eight were rejected with `unsupported VEX.256 (L=1) packed-integer encoding` although their 128-bit helpers already existed. Each existing 128-bit helper now runs on the two 128-bit halves on its own, so no sign control, shuffle selector or absolute value crosses the middle of the register; `vpshufhw`/`vpshuflw` use the same `imm8` for both halves, and all 256 destination bits are written. A later 128-bit VEX write to the same register still clears bits 128..255. Only YMM0..YMM5 are modeled, as before. Refs the AVX2 YMM series started by #1197. Still rejected with the previous diagnostics: memory sources, every other VEX.256 packed-integer form, EVEX, nonvolatile or never-written vector registers. The 128-bit encodings keep their single-helper path. Test changes: new fixture `tests/cpu/avx_int_ymm_abs_sign_shuf.asm` (+ `.def`) and check `tests/cpu/avx_int_ymm_abs_sign_shuf_check.py`, wired as CTest `cpu_aot_avx_int_ymm_abs_sign_shuf` (exits 77 without AVX2). The four refusal controls in `avx_int_regs_check.py` for `vpabsd`, `vpshufhw`, `vpshuflw` and `vpsignd` with YMM operands are removed because those forms are now supported, and the `vpabsd` control in `avx_int_ymm_minmax_check.py` now uses `vpmulld` (still unsupported). `docs/experiments.md` is updated. PR #1342 fuori preset pr: `ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$'` (and `--preset release`). AI-assisted. ## Verification Not run on Windows: the test is outside the `pr` preset and the MASM fixture needs ML64 and MSVC. Run on Linux (x86-64 host with AVX2, Python venv from `requirements-dev.txt`, LLVM 19, GCC, MinGW): - The same 15 instruction sequences were assembled with `llvm-mc-19`, run natively, and the translator output built with `g++ -O2`: `python3 -B tests/cpu/avx_int_ymm_abs_sign_shuf_check.py native.so lifted.so` printed `8 256-bit forms accepted; 12 rejection controls passed` and `2820 native/lifted/reference cases across 15 exports matched bit for bit; 58 negative controls were caught`. - The MASM source assembles with `llvm-ml-19` and links with `lld-link-19`; the translator lifted the resulting PE, and that output was built with `g++ -O0` (same two result lines) and compiled with `x86_64-w64-mingw32-g++` at -O0 and -O2. - Same check against `origin/main`'s translator: fails at the first form (`unsupported VEX.256 (L=1) packed-integer encoding ... vpabsb ymm0,ymm1`). - Mutated translated output: `vpsignd` using `vpsignw`, `vpabsb` using `vpabsw`, `vpshufhw` with the immediate 0x1b changed to 0x93, `vpshuflw` using `vpshufhw`: each fails the check (`op_vpsignd_ymm`, `op_vpabsb_ymm`, `op_vpshufhw_ymm_1b` and `op_vpshuflw_ymm_93`, word 0 or 1). - `avx_int_regs_check.py` (`check_rejections` against a PE built with llvm-ml/lld-link): 102 unit and 11 PE-patched rejection controls passed. `avx_int_ymm_minmax_check.py` translator controls: passed. - `python3 -B tests/form_coverage_check.py` and `python3 -B tests/docs_links_check.py`: passed. ## Evidence and follow-up The reference is an independent Python model that works on one 16-byte half and one element at a time. Inputs: signed and unsigned edge values for every element width (including the most negative value), halves that differ, distinct 16-bit words for the shuffles, seeded random data, and unaligned input and output pointers. Both 16-byte guards around the output, the bytes next to the 32-byte window and the input buffers must stay unchanged. Negative controls: models that drop the upper half, reuse one half's input for the other half, apply the shuffle immediate to one half only, swap `vpshufhw` and `vpshuflw`, saturate the absolute value, invert the sign control or use another element width must each differ in the expected 64-bit words; `vpabsb` of `0x80` must stay `0x80`; a flipped bit must be reported at its own word. Fixtures are original MASM written for this repository; nothing comes from a title or a binary. This does not show that any program runs. A Windows run of `ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' -V` is still needed. Follow-up for others: YMM memory sources and the remaining 256-bit packed-integer forms. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
tedin7 commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:47:35Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit 9e35fe29544575c23cdae594da0f33ec9580f2a5:

  • Debug (--preset dev):
    • Build (cpu_avx_int_ymm_abs_sign_shuf, cpu_avx_int_ymm_abs_sign_shuf_lifted): 3.37s (configure 1.53s)
    • Test (ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' --no-tests=error --output-on-failure): 1/1 passed (0.31s)
  • Release /O2 (--preset release):
    • Build (cpu_avx_int_ymm_abs_sign_shuf, cpu_avx_int_ymm_abs_sign_shuf_lifted): 0.74s (configure 1.57s)
    • Test (ctest --preset release -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' --no-tests=error --output-on-failure): 1/1 passed (0.29s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126569521 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1342#issuecomment-7126569521). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:47:35Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `9e35fe29544575c23cdae594da0f33ec9580f2a5`: - **Debug (`--preset dev`)**: - Build (`cpu_avx_int_ymm_abs_sign_shuf`, `cpu_avx_int_ymm_abs_sign_shuf_lifted`): `3.37s` (configure `1.53s`) - Test (`ctest --preset dev -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' --no-tests=error --output-on-failure`): **1/1 passed** (`0.31s`) - **Release `/O2` (`--preset release`)**: - Build (`cpu_avx_int_ymm_abs_sign_shuf`, `cpu_avx_int_ymm_abs_sign_shuf_lifted`): `0.74s` (configure `1.57s`) - Test (`ctest --preset release -R '^cpu_aot_avx_int_ymm_abs_sign_shuf$' --no-tests=error --output-on-failure`): **1/1 passed** (`0.29s`)
chatgpt-codex-connector[bot commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:47:53Z.


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-24T08:52:18.451223Z 9e35fe2 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:7126575795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1342#issuecomment-7126575795). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T08:47:53Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9e35fe29544575c23cdae594da0f33ec9580f2a5","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-24T08:52:18.451223Z">2026-11-24T08:52:18.451223Z</relative-time> | `9e35fe2` | 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>
upstream-sync closed this pull request 2026-11-24 10:02:23 +00:00
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!1335
No description provided.