cpu: lower VEX.128 saturating, multiply and compare word forms #1301

Merged
tedin7 merged 2 commits from upstream-pr/1308 into main 2026-11-24 07:45:45 +00:00
tedin7 commented 2026-11-24 07:26:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:26:26Z.


What

  • tools/cpu_vex_aot.py lowers ten more VEX.128 16-bit forms as explicit per-lane C++: vpaddsw, vpaddusw, vpsubsw, vpsubusw, vpmullw, vpmulhuw, vpmaxuw, vpminuw, vpcmpeqw, vpcmpgtw.
  • tests/cpu/vex_words.asm adds sat_words, mul_minmax_words and cmp_words (register and memory sources, both compare operand orders). vex_words.def and the export list in CMakeLists.txt gain the three names.
  • tests/cpu/vex_words_check.py compares the three new functions, native and lifted, with an independent per-lane integer model, in addition to the existing native vs lifted comparison (same 4096 edge and random pairs, guard zones, aliasing, RCX == RDX, misaligned buffers).
  • Negative control: the existing LOGICAL_SHIFT altered build also swaps vpmulhuw for vpmulhw in mul_minmax_words. Its lifted DLL must match the altered model and differ from the original in at least one output.
  • docs/experiments.md: supported forms, semantics note, new reference and control paragraphs.

Why

These forms were rejected as unsupported. Semantics are those of the integer instructions: signed and unsigned clamps, signed vs unsigned multiply high, unsigned min/max, compare masks of all ones or zeros. They read no MXCSR bits, raise no exceptions and have no NaN or signed-zero cases. VEX.128 zeroes the upper YMM bits, which the profile never reads (unchanged). No constant folding is used.

Overlap with open PR #1188 (cpu/vex-pf-consumers): it changes CMakeLists.txt (a different region, the cpu_vex_parity block), docs/experiments.md (new section at the end), tools/ffx_version_query.py, tools/x87_lower.py, tests/cpu/vex_parity.* and x87 tests. It does not touch tools/cpu_vex_aot.py or tests/cpu/vex_words*. No textual conflict expected beyond possible adjacent-hunk context in the two shared files.

Tested

Linux (this branch, commit 5bcba0cf):

  • python3 -B tests/docs_links_check.py passed; python3 -B tests/bidi_controls_check.py passed.
  • python -m py_compile tools/cpu_vex_aot.py tests/cpu/vex_words_check.py passed.
  • vex_words_check.check_rejected_encodings() (the Linux-runnable part) passed: 9 rejected encodings.
  • The three new function bodies (plus the altered vpmulhw variant) were assembled with GNU as, run natively on an AVX2 host, lifted with cpu_vex_aot.lift, compiled with g++ and run through the check's inputs(): native, lifted and reference() agree on all 4096 pairs for each function; the altered native differs from the original model in 4071 of 4096.
  • Six translator mutations (vpmulhuw signed, vpaddusw unclamped, vpsubsw unclamped, vpmaxuw signed, vpcmpgtw unsigned, vpcmpeqw giving 1) each fail the model comparison.

Windows, not run locally:

cmake --build --preset dev --target cpu_vex_words_original_lifted cpu_vex_words_altered_lifted
ctest --preset dev --no-tests=error -R '^cpu_aot_vex_words$' -V

The Windows MSVC/ML64 test was NOT run locally. The full vex_words_check.py main path needs ML64-assembled DLLs and ctypes.windll, so it ran only in CI-style pieces above. The fixture was hand-mirrored to GNU as syntax for the Linux run, so the MASM source itself is unassembled until CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576824208 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1308). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:26:26Z. --- ## What - `tools/cpu_vex_aot.py` lowers ten more VEX.128 16-bit forms as explicit per-lane C++: `vpaddsw`, `vpaddusw`, `vpsubsw`, `vpsubusw`, `vpmullw`, `vpmulhuw`, `vpmaxuw`, `vpminuw`, `vpcmpeqw`, `vpcmpgtw`. - `tests/cpu/vex_words.asm` adds `sat_words`, `mul_minmax_words` and `cmp_words` (register and memory sources, both compare operand orders). `vex_words.def` and the export list in `CMakeLists.txt` gain the three names. - `tests/cpu/vex_words_check.py` compares the three new functions, native and lifted, with an independent per-lane integer model, in addition to the existing native vs lifted comparison (same 4096 edge and random pairs, guard zones, aliasing, RCX == RDX, misaligned buffers). - Negative control: the existing `LOGICAL_SHIFT` altered build also swaps `vpmulhuw` for `vpmulhw` in `mul_minmax_words`. Its lifted DLL must match the altered model and differ from the original in at least one output. - `docs/experiments.md`: supported forms, semantics note, new reference and control paragraphs. ## Why These forms were rejected as unsupported. Semantics are those of the integer instructions: signed and unsigned clamps, signed vs unsigned multiply high, unsigned min/max, compare masks of all ones or zeros. They read no MXCSR bits, raise no exceptions and have no NaN or signed-zero cases. VEX.128 zeroes the upper YMM bits, which the profile never reads (unchanged). No constant folding is used. Overlap with open PR #1188 (cpu/vex-pf-consumers): it changes `CMakeLists.txt` (a different region, the `cpu_vex_parity` block), `docs/experiments.md` (new section at the end), `tools/ffx_version_query.py`, `tools/x87_lower.py`, `tests/cpu/vex_parity.*` and x87 tests. It does not touch `tools/cpu_vex_aot.py` or `tests/cpu/vex_words*`. No textual conflict expected beyond possible adjacent-hunk context in the two shared files. ## Tested Linux (this branch, commit 5bcba0cf): - `python3 -B tests/docs_links_check.py` passed; `python3 -B tests/bidi_controls_check.py` passed. - `python -m py_compile tools/cpu_vex_aot.py tests/cpu/vex_words_check.py` passed. - `vex_words_check.check_rejected_encodings()` (the Linux-runnable part) passed: 9 rejected encodings. - The three new function bodies (plus the altered `vpmulhw` variant) were assembled with GNU as, run natively on an AVX2 host, lifted with `cpu_vex_aot.lift`, compiled with g++ and run through the check's `inputs()`: native, lifted and `reference()` agree on all 4096 pairs for each function; the altered native differs from the original model in 4071 of 4096. - Six translator mutations (`vpmulhuw` signed, `vpaddusw` unclamped, `vpsubsw` unclamped, `vpmaxuw` signed, `vpcmpgtw` unsigned, `vpcmpeqw` giving 1) each fail the model comparison. Windows, not run locally: ``` cmake --build --preset dev --target cpu_vex_words_original_lifted cpu_vex_words_altered_lifted ctest --preset dev --no-tests=error -R '^cpu_aot_vex_words$' -V ``` The Windows MSVC/ML64 test was NOT run locally. The full `vex_words_check.py` main path needs ML64-assembled DLLs and `ctypes.windll`, so it ran only in CI-style pieces above. The fixture was hand-mirrored to GNU as syntax for the Linux run, so the MASM source itself is unassembled until CI.
upstream-sync closed this pull request 2026-11-24 08:01:32 +00:00
tedin7 commented 2026-11-24 08:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:36:06Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at 4f3a1320:

  • Debug (--preset dev): 5/5 PASS (1.10s: cpu_aot_vex_words 1.04s, plus cpu_aot_avx_int_regs, cpu_aot_avx_int_ymm_addsub, cpu_aot_avx_int_ymm_minmax, cpu_aot_avx_move_regs)
  • Release /O2 (--preset release): 5/5 PASS (1.14s, build 1.88s: cpu_aot_vex_words 0.84s, plus the 4 AVX suites)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125167494 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1308#issuecomment-7125167494). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T07:36:06Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `4f3a1320`: - Debug (`--preset dev`): **5/5 PASS** (`1.10s`: `cpu_aot_vex_words` `1.04s`, plus `cpu_aot_avx_int_regs`, `cpu_aot_avx_int_ymm_addsub`, `cpu_aot_avx_int_ymm_minmax`, `cpu_aot_avx_move_regs`) - Release `/O2` (`--preset release`): **5/5 PASS** (`1.14s`, build `1.88s`: `cpu_aot_vex_words` `0.84s`, plus the 4 AVX suites)
chatgpt-codex-connector[bot commented 2026-11-24 08:01:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T07:36:19Z.


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-24T07:40:26.915278Z 4f3a132 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:7125171370 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1308#issuecomment-7125171370). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T07:36:19Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4f3a13209d156bb4e90e99c3224dead076c36ca2","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-24T07:40:26.915278Z">2026-11-24T07:40:26.915278Z</relative-time> | `4f3a132` | 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>
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!1301
No description provided.