cpu: lower 256-bit packed integer add, subtract and compare in the AVX translator #1190

Merged
tedin7 merged 1 commit from upstream-pr/1197 into main 2026-11-24 04:14:26 +00:00
tedin7 commented 2026-11-24 03:29:29 +00:00 (Migrated from github.com)

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


Change

Lower the VEX.256 (AVX2) register forms of vpaddb/w/d/q, vpsubb/w/d/q, vpcmpeqb/w/d/q and vpcmpgtb/w/d/q in tools/cpu_avx_int_aot.py. Before this change every VEX.256 packed-integer form was rejected there. Each 128-bit half is computed on its own, so no carry, borrow or compare crosses the middle of the register, 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.

Still rejected with the previous diagnostics: memory sources, every other VEX.256 packed-integer form, EVEX, nonvolatile or never-written vector registers, and the 128-bit encodings of vpaddw, vpaddd and vpsubw (owned by cpu_vex_aot.py).

Test changes: new fixture tests/cpu/avx_int_ymm_addsub.asm and check tests/cpu/avx_int_ymm_addsub_check.py (CTest cpu_aot_avx_int_ymm_addsub, exits 77 without AVX2). The four refusal controls in avx_int_regs_check.py for vpaddq, vpsubb, vpsubd and vpcmpeqd with YMM operands are removed because those forms are now supported; the two PE-patch controls that used them now use vpaddsb and vpslld (still unsupported).

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): the same 25 instruction sequences were assembled with llvm-mc-19, run natively, and the translator output was built with g++ -O1; the real check script then ran on those two shared objects.

  • python3 -B tests/cpu/avx_int_ymm_addsub_check.py native.so lifted.so: 16 forms accepted, 13 rejection controls passed, 5575 native/lifted/reference cases across 25 exports matched bit for bit, 86 negative controls caught.
  • Same command against origin/main's translator: fails at the first form (unsupported VEX.256 (L=1) packed-integer encoding ... vpaddb ymm0,ymm1,ymm2).
  • Mutated translated output (upper half reads the lower half; signed compare made unsigned in vpcmpgtw; vpsubw operands swapped): each fails the check, at op_vpaddb_ymm word 2, op_vpcmpgtw_ymm word 0 and op_vpsubw_ymm word 0.
  • python3 -B tests/form_coverage_check.py: passed. python3 -B tests/docs_links_check.py: passed.
  • avx_int_regs_check.py unit rejection controls: passed (its PE-patch part needs the Windows DLL and was not run).

Evidence and follow-up

The reference is an independent Python model that works on one element at a time. Inputs: signed and unsigned edge values for every element width, lower and upper halves that differ, a carry and a borrow at the top of the lower half, equal-lane patterns for the compares, 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: a model that ignores the upper half must differ only in words 2 or 3; a model that carries or borrows across the halves must differ at word 2; the opposite operation and every other element width must be caught; a flipped bit must be reported at its own 64-bit 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_addsub$' -V is still needed. Follow-up for others: YMM memory sources, vpaddsb and the other saturating or min/max forms at 256 bits.

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:6573962920 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1197). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:29:29Z. --- ## Change Lower the VEX.256 (AVX2) register forms of `vpaddb/w/d/q`, `vpsubb/w/d/q`, `vpcmpeqb/w/d/q` and `vpcmpgtb/w/d/q` in `tools/cpu_avx_int_aot.py`. Before this change every VEX.256 packed-integer form was rejected there. Each 128-bit half is computed on its own, so no carry, borrow or compare crosses the middle of the register, 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. Still rejected with the previous diagnostics: memory sources, every other VEX.256 packed-integer form, EVEX, nonvolatile or never-written vector registers, and the 128-bit encodings of `vpaddw`, `vpaddd` and `vpsubw` (owned by `cpu_vex_aot.py`). Test changes: new fixture `tests/cpu/avx_int_ymm_addsub.asm` and check `tests/cpu/avx_int_ymm_addsub_check.py` (CTest `cpu_aot_avx_int_ymm_addsub`, exits 77 without AVX2). The four refusal controls in `avx_int_regs_check.py` for `vpaddq`, `vpsubb`, `vpsubd` and `vpcmpeqd` with YMM operands are removed because those forms are now supported; the two PE-patch controls that used them now use `vpaddsb` and `vpslld` (still unsupported). 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): the same 25 instruction sequences were assembled with `llvm-mc-19`, run natively, and the translator output was built with `g++ -O1`; the real check script then ran on those two shared objects. - `python3 -B tests/cpu/avx_int_ymm_addsub_check.py native.so lifted.so`: 16 forms accepted, 13 rejection controls passed, 5575 native/lifted/reference cases across 25 exports matched bit for bit, 86 negative controls caught. - Same command against `origin/main`'s translator: fails at the first form (`unsupported VEX.256 (L=1) packed-integer encoding ... vpaddb ymm0,ymm1,ymm2`). - Mutated translated output (upper half reads the lower half; signed compare made unsigned in `vpcmpgtw`; `vpsubw` operands swapped): each fails the check, at `op_vpaddb_ymm` word 2, `op_vpcmpgtw_ymm` word 0 and `op_vpsubw_ymm` word 0. - `python3 -B tests/form_coverage_check.py`: passed. `python3 -B tests/docs_links_check.py`: passed. - `avx_int_regs_check.py` unit rejection controls: passed (its PE-patch part needs the Windows DLL and was not run). ## Evidence and follow-up The reference is an independent Python model that works on one element at a time. Inputs: signed and unsigned edge values for every element width, lower and upper halves that differ, a carry and a borrow at the top of the lower half, equal-lane patterns for the compares, 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: a model that ignores the upper half must differ only in words 2 or 3; a model that carries or borrows across the halves must differ at word 2; the opposite operation and every other element width must be caught; a flipped bit must be reported at its own 64-bit 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_addsub$' -V` is still needed. Follow-up for others: YMM memory sources, `vpaddsb` and the other saturating or min/max forms at 256 bits. ## 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.
upstream-sync closed this pull request 2026-11-24 06:46:51 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:50:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:33:29Z.


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-24T03:38:10.569257Z d61477b 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:7121209035 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1197#issuecomment-7121209035). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:33:29Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"d61477b3a2eca9041603284606c23b362933aacd","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-24T03:38:10.569257Z">2026-11-24T03:38:10.569257Z</relative-time> | `d61477b` | 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!1190
No description provided.