cpu: lower 256-bit saturating add and subtract in AVX translator #1375

Merged
tedin7 merged 1 commit from upstream-pr/1382 into main 2026-11-24 10:32:19 +00:00
tedin7 commented 2026-11-24 10:02:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:02:17Z.


What

  • tools/cpu_avx_int_aot.py now lowers the eight VEX.256 register forms vpaddsb, vpaddsw, vpaddusb, vpaddusw, vpsubsb, vpsubsw, vpsubusb, vpsubusw through the existing two-half wide128 path, reusing the 128-bit helpers. Subtract computes first source minus second source.
  • op_vpaddsw is new and serves only the 256-bit form: the 128-bit vpaddsw is owned by cpu_vex_aot.py and stays rejected here (same pattern as vpaddw, vpaddd, vpsubw).
  • Memory sources (including base plus index), EVEX and every other 256-bit integer form stay rejected, exactly as for the neighbouring wide ops.
  • New fixture tests/cpu/avx_int_ymm_sat.{asm,def}, check avx_int_ymm_sat_check.py, CMake test cpu_aot_avx_int_ymm_sat (same registration and AVX2 skip as the min/max test), form_coverage.py entry.
  • The 256-bit refusal controls in avx_int_regs_check.py (translation level and PE-patched) and avx_int_ymm_addsub_check.py named vpaddsb; they now name vpackusdw (regs check) and vpmulhuw (addsub check), both still unsupported. docs/experiments.md documents the new form.

Why

The 256-bit saturating forms were the next gap in the AVX2 integer family after add, subtract, compare, min, max, abs and sign. Every 128-bit helper already existed, so the lift is the same two-half dispatch with eight new table entries.

Tested

Windows (not run locally):

ctest --preset dev --no-tests=error -R '^cpu_aot_avx_int' -V
ctest --preset release --no-tests=error -R '^cpu_aot_avx_int' -V

Ran on Linux:

  • Claim checked first: the 8 forms were refused ("unsupported VEX.256 (L=1) packed-integer encoding", and "unsupported instruction" for vpaddsw); no open PR touches these files.
  • The MASM source was assembled with llvm-ml-19 and linked with lld-link-19 (this also validates the MASM syntax). The real translate() ran on it. The C++ was built with MinGW GCC at -O0 and -O2, and native and lifted DLLs ran under Wine through a throwaway loader: 18 exports x 362 inputs matched the independent model bit for bit at both levels.
  • Four altered translations (swapped subtract operands in two exports, vpaddsb replaced by wrapping vpaddb, vpaddusw replaced by signed vpaddsw) each failed on exactly their own export.
  • The check's negative controls (upper half ignored, swapped halves, wrapping, signedness, operation, width, swapped operands, flipped bit word) were run against the lifted outputs: 64 caught.
  • check_translator() of the four ymm checks and check_rejections() of avx_int_regs_check.py (on an LLVM-built PE) pass; tests/form_coverage_check.py, docs_links_check.py, bidi_controls_check.py, py_compile and git diff --check pass.
  • Translated C++ of the existing avx_int exports (regs, addsub, minmax, abs_sign_shuf) differs before and after only by the added op_vpaddsw helper in the shared prelude.

MSVC/ML64 was NOT run locally, and the check script itself was not run end to end (it loads the DLLs with ctypes, which needs Windows); the loader above stood in for it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579284729 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1382). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:02:17Z. --- ## What - `tools/cpu_avx_int_aot.py` now lowers the eight VEX.256 register forms `vpaddsb`, `vpaddsw`, `vpaddusb`, `vpaddusw`, `vpsubsb`, `vpsubsw`, `vpsubusb`, `vpsubusw` through the existing two-half `wide128` path, reusing the 128-bit helpers. Subtract computes first source minus second source. - `op_vpaddsw` is new and serves only the 256-bit form: the 128-bit `vpaddsw` is owned by `cpu_vex_aot.py` and stays rejected here (same pattern as `vpaddw`, `vpaddd`, `vpsubw`). - Memory sources (including base plus index), EVEX and every other 256-bit integer form stay rejected, exactly as for the neighbouring wide ops. - New fixture `tests/cpu/avx_int_ymm_sat.{asm,def}`, check `avx_int_ymm_sat_check.py`, CMake test `cpu_aot_avx_int_ymm_sat` (same registration and AVX2 skip as the min/max test), `form_coverage.py` entry. - The 256-bit refusal controls in `avx_int_regs_check.py` (translation level and PE-patched) and `avx_int_ymm_addsub_check.py` named `vpaddsb`; they now name `vpackusdw` (regs check) and `vpmulhuw` (addsub check), both still unsupported. `docs/experiments.md` documents the new form. ## Why The 256-bit saturating forms were the next gap in the AVX2 integer family after add, subtract, compare, min, max, abs and sign. Every 128-bit helper already existed, so the lift is the same two-half dispatch with eight new table entries. ## Tested Windows (not run locally): ``` ctest --preset dev --no-tests=error -R '^cpu_aot_avx_int' -V ctest --preset release --no-tests=error -R '^cpu_aot_avx_int' -V ``` Ran on Linux: - Claim checked first: the 8 forms were refused ("unsupported VEX.256 (L=1) packed-integer encoding", and "unsupported instruction" for `vpaddsw`); no open PR touches these files. - The MASM source was assembled with `llvm-ml-19` and linked with `lld-link-19` (this also validates the MASM syntax). The real `translate()` ran on it. The C++ was built with MinGW GCC at -O0 and -O2, and native and lifted DLLs ran under Wine through a throwaway loader: 18 exports x 362 inputs matched the independent model bit for bit at both levels. - Four altered translations (swapped subtract operands in two exports, `vpaddsb` replaced by wrapping `vpaddb`, `vpaddusw` replaced by signed `vpaddsw`) each failed on exactly their own export. - The check's negative controls (upper half ignored, swapped halves, wrapping, signedness, operation, width, swapped operands, flipped bit word) were run against the lifted outputs: 64 caught. - `check_translator()` of the four ymm checks and `check_rejections()` of `avx_int_regs_check.py` (on an LLVM-built PE) pass; `tests/form_coverage_check.py`, `docs_links_check.py`, `bidi_controls_check.py`, `py_compile` and `git diff --check` pass. - Translated C++ of the existing avx_int exports (regs, addsub, minmax, abs_sign_shuf) differs before and after only by the added `op_vpaddsw` helper in the shared prelude. MSVC/ML64 was NOT run locally, and the check script itself was not run end to end (it loads the DLLs with ctypes, which needs Windows); the loader above stood in for it.
upstream-sync closed this pull request 2026-11-24 11:02:43 +00:00
tedin7 commented 2026-11-24 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:07:05Z.


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

  • Windows Python checks: tests/form_coverage_check.py ok (40.5s)
  • Debug (--preset dev):
    • Build (cpu_avx_int_ymm_sat*, cpu_avx_int_regs_*): 3.46s (configure 1.61s)
    • Test (ctest --preset dev -R '^(cpu_aot_avx_int_ymm_sat|cpu_aot_avx_int_regs)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_avx_int_regs 0.26s, cpu_aot_avx_int_ymm_sat 0.30s)
  • Release /O2 (--preset release):
    • Build (cpu_avx_int_ymm_sat*, cpu_avx_int_regs_*): 1.57s (configure 1.68s)
    • Test (ctest --preset release -R '^(cpu_aot_avx_int_ymm_sat|cpu_aot_avx_int_regs)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_avx_int_regs 0.25s, cpu_aot_avx_int_ymm_sat 0.30s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128338603 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1382#issuecomment-7128338603). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:07:05Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `f5c0be11d5cbde7f471f90505b5d0950e3d86475`: - **Windows Python checks**: `tests/form_coverage_check.py` ok (`40.5s`) - **Debug (`--preset dev`)**: - Build (`cpu_avx_int_ymm_sat*`, `cpu_avx_int_regs_*`): `3.46s` (configure `1.61s`) - Test (`ctest --preset dev -R '^(cpu_aot_avx_int_ymm_sat|cpu_aot_avx_int_regs)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_avx_int_regs` `0.26s`, `cpu_aot_avx_int_ymm_sat` `0.30s`) - **Release `/O2` (`--preset release`)**: - Build (`cpu_avx_int_ymm_sat*`, `cpu_avx_int_regs_*`): `1.57s` (configure `1.68s`) - Test (`ctest --preset release -R '^(cpu_aot_avx_int_ymm_sat|cpu_aot_avx_int_regs)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_avx_int_regs` `0.25s`, `cpu_aot_avx_int_ymm_sat` `0.30s`)
chatgpt-codex-connector[bot commented 2026-11-24 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:07:17Z.


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-24T10:12:10.490665Z f5c0be1 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:7128343160 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1382#issuecomment-7128343160). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T10:07:17Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f5c0be11d5cbde7f471f90505b5d0950e3d86475","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-24T10:12:10.490665Z">2026-11-24T10:12:10.490665Z</relative-time> | `f5c0be1` | 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!1375
No description provided.