cpu: lower 256-bit packed integer min and max in the AVX translator #1276

Merged
tedin7 merged 1 commit from upstream-pr/1283 into main 2026-11-24 07:06:05 +00:00
tedin7 commented 2026-11-24 06:44:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:44:04Z.


What

  • tools/cpu_avx_int_aot.py accepts the VEX.256 (AVX2) register forms of vpmaxsb/sw/sd/ub/uw/ud and vpminsb/sw/sd/ub/uw/ud. Each 128-bit half is computed on its own through the existing wide128 path and all 256 destination bits are written. Two new helpers, op_vpmaxsw and op_vpminsw, are added because the 128-bit word forms belong to cpu_vex_aot.py and stay rejected here.
  • Memory sources, other L=1 integer forms, EVEX and nonvolatile or never-written registers keep their existing refusals.
  • New fixture tests/cpu/avx_int_ymm_minmax.asm/.def (15 exports: the 12 forms, two aliasing cases, a 256-bit write followed by a 128-bit write) and tests/cpu/avx_int_ymm_minmax_check.py, with CMake exports and a form_coverage.py entry. Same structure as the add/subtract/compare PR.
  • Removed the 256-bit vpmaxsd refusal control from avx_int_regs_check.py (it now describes a supported form) and replaced the same use in avx_int_ymm_addsub_check.py with vpmulld.
  • docs/experiments.md: one paragraph for the new forms.

Why

The translator lowered the XMM min/max forms but refused every YMM one. The new check compares native and translated output against an independent model over the lane-width edges (0, 1, 0x7f, 0x80, 0xff, 0x7fff, 0x8000, 0xffff, INT32 min/max, UINT32 max) with different lower and upper halves. Negative controls: upper-half-ignored model, flipped signedness, opposite pick and other widths must all differ; a memory-operand form is refused.

Tested

Windows (not run here):

cmake --build --preset dev --target cpu_avx_int_ymm_minmax_lifted
ctest --preset dev --no-tests=error -R '^cpu_aot_avx_int_ymm_minmax$' -V

Linux (run here, AVX2 host): the same instruction sequences assembled with GNU as, the translator run on them, the lifted C++ built with g++ and run against the native code: 12 forms accepted, 9 translator rejection controls passed, 3450 native/lifted/model cases matched, 64 negative controls caught. Changing the translated vpmaxsd to the unsigned helper, and vpminuw to the signed helper, in the lifted C++ made the check fail. Also run: tests/docs_links_check.py, tests/bidi_controls_check.py, tests/form_coverage_check.py, py_compile, and the translator part of the add/subtract check.

MSVC/ML64 was NOT run locally. The PE build, avx_int_regs_check.py end to end and the Windows ctest run have not been exercised.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576245787 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1283). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:44:04Z. --- ## What - `tools/cpu_avx_int_aot.py` accepts the VEX.256 (AVX2) register forms of `vpmaxsb/sw/sd/ub/uw/ud` and `vpminsb/sw/sd/ub/uw/ud`. Each 128-bit half is computed on its own through the existing `wide128` path and all 256 destination bits are written. Two new helpers, `op_vpmaxsw` and `op_vpminsw`, are added because the 128-bit word forms belong to `cpu_vex_aot.py` and stay rejected here. - Memory sources, other `L=1` integer forms, EVEX and nonvolatile or never-written registers keep their existing refusals. - New fixture `tests/cpu/avx_int_ymm_minmax.asm`/`.def` (15 exports: the 12 forms, two aliasing cases, a 256-bit write followed by a 128-bit write) and `tests/cpu/avx_int_ymm_minmax_check.py`, with CMake exports and a `form_coverage.py` entry. Same structure as the add/subtract/compare PR. - Removed the 256-bit `vpmaxsd` refusal control from `avx_int_regs_check.py` (it now describes a supported form) and replaced the same use in `avx_int_ymm_addsub_check.py` with `vpmulld`. - `docs/experiments.md`: one paragraph for the new forms. ## Why The translator lowered the XMM min/max forms but refused every YMM one. The new check compares native and translated output against an independent model over the lane-width edges (0, 1, 0x7f, 0x80, 0xff, 0x7fff, 0x8000, 0xffff, INT32 min/max, UINT32 max) with different lower and upper halves. Negative controls: upper-half-ignored model, flipped signedness, opposite pick and other widths must all differ; a memory-operand form is refused. ## Tested Windows (not run here): ``` cmake --build --preset dev --target cpu_avx_int_ymm_minmax_lifted ctest --preset dev --no-tests=error -R '^cpu_aot_avx_int_ymm_minmax$' -V ``` Linux (run here, AVX2 host): the same instruction sequences assembled with GNU as, the translator run on them, the lifted C++ built with g++ and run against the native code: 12 forms accepted, 9 translator rejection controls passed, 3450 native/lifted/model cases matched, 64 negative controls caught. Changing the translated `vpmaxsd` to the unsigned helper, and `vpminuw` to the signed helper, in the lifted C++ made the check fail. Also run: `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/form_coverage_check.py`, py_compile, and the translator part of the add/subtract check. MSVC/ML64 was NOT run locally. The PE build, `avx_int_regs_check.py` end to end and the Windows ctest run have not been exercised.
tedin7 commented 2026-11-24 07:00:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T06:50:44Z.


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

  • tests/form_coverage_check.py — PASS (39.25s)
  • Debug (--preset dev): 63/63 PASS (cpu_aot_avx_int_ymm_minmax, cpu_aot_avx_int_ymm_addsub, cpu_aot_avx_int_regs, plus 60 downstream WARP tests)
  • Release /O2 (--preset release): 63/63 PASS (cpu_aot_avx_int_ymm_minmax 0.24s, cpu_aot_avx_int_ymm_addsub 0.27s, cpu_aot_avx_int_regs 0.33s, plus 60 downstream WARP tests)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124349569 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1283#issuecomment-7124349569). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:50:44Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `ccd18f16`: - `tests/form_coverage_check.py` — **PASS** (`39.25s`) - Debug (`--preset dev`): **63/63 PASS** (`cpu_aot_avx_int_ymm_minmax`, `cpu_aot_avx_int_ymm_addsub`, `cpu_aot_avx_int_regs`, plus 60 downstream WARP tests) - Release `/O2` (`--preset release`): **63/63 PASS** (`cpu_aot_avx_int_ymm_minmax` `0.24s`, `cpu_aot_avx_int_ymm_addsub` `0.27s`, `cpu_aot_avx_int_regs` `0.33s`, plus 60 downstream WARP tests)
chatgpt-codex-connector[bot commented 2026-11-24 07:00:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T06:50:56Z.


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-24T06:54:40.113564Z ccd18f1 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:7124353078 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1283#issuecomment-7124353078). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T06:50:56Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ccd18f16ce665632f66a917c675999c59b9c6408","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-24T06:54:40.113564Z">2026-11-24T06:54:40.113564Z</relative-time> | `ccd18f1` | 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 07:07:39 +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!1276
No description provided.