cpu: lower VEX.128 VPADDB, VPSUBB, VPCMPEQB, and VPCMPGTB in cpu_vex_aot #2351

Merged
Ammmae0x merged 1 commit from upstream-pr/2359 into main 2026-11-25 14:25:15 +00:00
Ammmae0x commented 2026-11-25 13:35:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T13:35:01Z.


Change

Lower VEX.128 byte-domain arithmetic and compare instructions (VPADDB, VPSUBB, VPCMPEQB, VPCMPGTB) in tools/cpu_vex_aot.py and add a source-built differential, aliasing, mutation, and rejection test suite (tests/cpu/vex_bytes_arith.{asm,def}, tests/cpu/vex_bytes_arith_check.py, registered as cpu_aot_vex_bytes_arith in CMakeLists.txt):

  • Add M.VPADDB, M.VPSUBB, M.VPCMPEQB, and M.VPCMPGTB to BINARY in tools/cpu_vex_aot.py with portable 16-byte per-lane C++ helpers (BYTEWISE: uint8_t wraparound for paddb/psubb, 0xFF/0x00 masks for pcmpeqb and signed int8_t pcmpgtb).
  • Preserve existing profile boundaries: VEX.128 only (XMM0..XMM5 register operands and flat [rcx|rdx|r8] 16-byte memory sources; stores only to [r8]), rejecting VEX.256 (L=1), EVEX, legacy SSE2, nonvolatile XMM6..15, undefined sources, displaced/indexed/non-arg memory operands, and non-[r8] stores.

Verification

Verified on commit 424137b9 (rebased onto upstream/main 43608f2e; host supports AVX, 0 capability skips):

  • cmake --build --preset dev --target cpu_vex_bytes_arith_original cpu_vex_bytes_arith_original_lifted cpu_vex_bytes_arith_altered cpu_vex_bytes_arith_altered_lifted cpu_vex_bytes_original cpu_vex_bytes_original_lifted cpu_vex_bytes_altered cpu_vex_bytes_altered_lifted -> succeeded (exit 0)
  • ctest --preset dev -R "^cpu_aot_vex_" -E "cpu_native_archive_" --output-on-failure -> 100% tests passed, 0 tests failed out of 5 (5.10 sec; cpu_aot_vex_words, cpu_aot_vex_words_ext, cpu_aot_vex_bytes, cpu_aot_vex_bytes_arith, cpu_aot_vex_parity)
  • cmake --build --preset release --target ... -> succeeded (exit 0)
  • ctest --preset release -R "^cpu_aot_vex_" -E "cpu_native_archive_" --output-on-failure -> 100% tests passed, 0 tests failed out of 5 (5.18 sec)
  • ctest --preset release -R "^cpu_aot_vex_bytes_arith$" --output-on-failure -V -> AOT lowering validated (25 rejected encodings + 3 patched PE rejections), 1024 pairs across all 11 exports match native and reference bit for bit, aliased outputs / RCX == RDX / 8-byte unaligned buffers match native, 6 mutant controls + 4 ALTER_BYTE_ARITH controls caught (exit 0; FORM_COVERAGE_RECORD recorded ret, vmovdqa, vmovdqu, vpaddb, vpcmpeqb, vpcmpgtb, vpsubb, vzeroupper)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 459 links. (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1648 tracked source, script and build/CI files: no bidirectional controls. (exit 0)

Evidence and follow-up

  • tests/cpu/vex_bytes_arith.asm (; coverage: record cpu_aot_vex_bytes_arith) is a clean-room synthetic MASM fixture exercising register and [rcx|rdx|r8] memory forms of vpaddb, vpsubb, vpcmpeqb, and vpcmpgtb, dst==src1==src2 self-subtraction zeroing, a multi-register store-reload chain, and a 16-byte-aligned vmovdqa path.
  • Negative controls cover 25 rejected encodings (VEX.256, EVEX, legacy SSE2, XMM6..15, undefined sources, displaced/indexed/non-arg memory, non-[r8] stores), 3 patched-PE rejections, 6 faulty Python reference mutants (saturate_add, swap_sub, saturate_sub, eq_one, unsigned_gt, swap_gt), and 4 ALTER_BYTE_ARITH build controls. Hosts lacking AVX skip cleanly with exit code 77.

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.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6605693755 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2359). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T13:35:01Z. --- ## Change Lower VEX.128 byte-domain arithmetic and compare instructions (`VPADDB`, `VPSUBB`, `VPCMPEQB`, `VPCMPGTB`) in `tools/cpu_vex_aot.py` and add a source-built differential, aliasing, mutation, and rejection test suite (`tests/cpu/vex_bytes_arith.{asm,def}`, `tests/cpu/vex_bytes_arith_check.py`, registered as `cpu_aot_vex_bytes_arith` in `CMakeLists.txt`): - Add `M.VPADDB`, `M.VPSUBB`, `M.VPCMPEQB`, and `M.VPCMPGTB` to `BINARY` in `tools/cpu_vex_aot.py` with portable 16-byte per-lane C++ helpers (`BYTEWISE`: `uint8_t` wraparound for `paddb`/`psubb`, `0xFF`/`0x00` masks for `pcmpeqb` and signed `int8_t` `pcmpgtb`). - Preserve existing profile boundaries: VEX.128 only (`XMM0..XMM5` register operands and flat `[rcx|rdx|r8]` 16-byte memory sources; stores only to `[r8]`), rejecting VEX.256 (`L=1`), EVEX, legacy SSE2, nonvolatile `XMM6..15`, undefined sources, displaced/indexed/non-arg memory operands, and non-`[r8]` stores. ## Verification Verified on commit `424137b9` (rebased onto `upstream/main` `43608f2e`; host supports AVX, 0 capability skips): - `cmake --build --preset dev --target cpu_vex_bytes_arith_original cpu_vex_bytes_arith_original_lifted cpu_vex_bytes_arith_altered cpu_vex_bytes_arith_altered_lifted cpu_vex_bytes_original cpu_vex_bytes_original_lifted cpu_vex_bytes_altered cpu_vex_bytes_altered_lifted` -> succeeded (exit 0) - `ctest --preset dev -R "^cpu_aot_vex_" -E "cpu_native_archive_" --output-on-failure` -> `100% tests passed, 0 tests failed out of 5` (`5.10 sec`; `cpu_aot_vex_words`, `cpu_aot_vex_words_ext`, `cpu_aot_vex_bytes`, `cpu_aot_vex_bytes_arith`, `cpu_aot_vex_parity`) - `cmake --build --preset release --target ...` -> succeeded (exit 0) - `ctest --preset release -R "^cpu_aot_vex_" -E "cpu_native_archive_" --output-on-failure` -> `100% tests passed, 0 tests failed out of 5` (`5.18 sec`) - `ctest --preset release -R "^cpu_aot_vex_bytes_arith$" --output-on-failure -V` -> `AOT lowering validated (25 rejected encodings + 3 patched PE rejections)`, `1024 pairs` across all 11 exports match native and reference bit for bit, aliased outputs / `RCX == RDX` / 8-byte unaligned buffers match native, 6 mutant controls + 4 `ALTER_BYTE_ARITH` controls caught (exit 0; `FORM_COVERAGE_RECORD` recorded `ret`, `vmovdqa`, `vmovdqu`, `vpaddb`, `vpcmpeqb`, `vpcmpgtb`, `vpsubb`, `vzeroupper`) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 459 links.` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1648 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) ## Evidence and follow-up - `tests/cpu/vex_bytes_arith.asm` (`; coverage: record cpu_aot_vex_bytes_arith`) is a clean-room synthetic MASM fixture exercising register and `[rcx|rdx|r8]` memory forms of `vpaddb`, `vpsubb`, `vpcmpeqb`, and `vpcmpgtb`, `dst==src1==src2` self-subtraction zeroing, a multi-register store-reload chain, and a 16-byte-aligned `vmovdqa` path. - Negative controls cover 25 rejected encodings (VEX.256, EVEX, legacy SSE2, `XMM6..15`, undefined sources, displaced/indexed/non-arg memory, non-`[r8]` stores), 3 patched-PE rejections, 6 faulty Python reference mutants (`saturate_add`, `swap_sub`, `saturate_sub`, `eq_one`, `unsigned_gt`, `swap_gt`), and 4 `ALTER_BYTE_ARITH` build controls. Hosts lacking AVX skip cleanly with exit code 77. ## 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. AI-assisted.
tedin7 commented 2026-11-25 14:05:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:40:07Z.

Review: COMMENTED


Review of head 424137b9b2

Scope: adds VEX.128 VPADDB / VPSUBB / VPCMPEQB / VPCMPGTB to the BINARY table in tools/cpu_vex_aot.py, plus a BYTEWISE helper, a new MASM fixture (tests/cpu/vex_bytes_arith.asm/.def), a checker, and CMake wiring.

Checked

  • Semantics: wraparound add/sub per byte, equality mask 0xFF/0x00, and signed (int8) greater-than for VPCMPGTB are correct. Operand order is a = src1 (vvvv), b = src2 (rm), which is right for the non-commutative VPSUBB and VPCMPGTB.
  • Sibling consistency: the entries sit next to the existing word-width ones (paddw, pcmpgtw) and use the same dispatch path (cpu_vex_aot.py:263).
  • Fixture covers reg and mem forms, dst == src1 == src2 (psubb_self), a chain, and an aligned variant. The altered build (ALTER_BYTE_ARITH) swaps operands or opcodes for differential controls.
  • Checker vectors include the signed and wrap boundaries (0x7E/0x7F/0x80/0x81/0xFE/0xFF), 1024 pairs. It also carries its own negative controls (unsigned_gt, swap_gt, eq_one).
  • CMake: new test follows the cpu_aot_vex_bytes pattern, with a SKIP_RETURN_CODE 77 and a coverage record.
  • CI on this head: Linux Python checks pass, Windows build and test pass, gfx1013 fixtures pass.

Commands run locally

  • git diff --stat origin/main...HEAD: 5 files, +566.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: self-test passed, 19 files, 459 links.
  • python3 tests/bidi_controls_check.py: self-test passed, 1648 files, no bidi controls.
  • python3 -I -c "import ast..." on the checker: syntax OK.
  • python3 -B tests/cpu/vex_bytes_arith_check.py: cannot run on Linux here (iced_x86 missing, and it needs the Windows-built DLLs). Not run.

Not done

  • No local mutation run: the new test needs the MSVC-built fixtures, so it was not possible on Linux. The Windows CI job is the evidence for that. I did not queue a Windows VM run because the change is Python lowering plus a CPU fixture, not shader or C++ code.

Findings

  • P1: none.
  • P2: none.
  • Nit: the comment // cpu_aot_vex_bytes_arith in CMakeLists.txt is a bare label. A one-line description would match the sibling blocks.
  • Nit: the lowering is a macro (BYTEWISE). It is fine here, but the sibling helpers are plain functions. Consistency only.

Title is neutral and the PR is mergeable. No clean-room concerns seen.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058653738 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2359#pullrequestreview-6058653738). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:40:07Z. **Review:** COMMENTED --- Review of head 424137b9b2dc9b63f337aeeb405a77898b04002b Scope: adds VEX.128 VPADDB / VPSUBB / VPCMPEQB / VPCMPGTB to the `BINARY` table in `tools/cpu_vex_aot.py`, plus a `BYTEWISE` helper, a new MASM fixture (`tests/cpu/vex_bytes_arith.asm/.def`), a checker, and CMake wiring. Checked - Semantics: wraparound add/sub per byte, equality mask 0xFF/0x00, and signed (int8) greater-than for VPCMPGTB are correct. Operand order is `a = src1 (vvvv)`, `b = src2 (rm)`, which is right for the non-commutative VPSUBB and VPCMPGTB. - Sibling consistency: the entries sit next to the existing word-width ones (`paddw`, `pcmpgtw`) and use the same dispatch path (`cpu_vex_aot.py:263`). - Fixture covers reg and mem forms, `dst == src1 == src2` (`psubb_self`), a chain, and an aligned variant. The altered build (`ALTER_BYTE_ARITH`) swaps operands or opcodes for differential controls. - Checker vectors include the signed and wrap boundaries (0x7E/0x7F/0x80/0x81/0xFE/0xFF), 1024 pairs. It also carries its own negative controls (`unsigned_gt`, `swap_gt`, `eq_one`). - CMake: new test follows the `cpu_aot_vex_bytes` pattern, with a `SKIP_RETURN_CODE 77` and a coverage record. - CI on this head: Linux Python checks pass, Windows build and test pass, gfx1013 fixtures pass. Commands run locally - `git diff --stat origin/main...HEAD`: 5 files, +566. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: self-test passed, 19 files, 459 links. - `python3 tests/bidi_controls_check.py`: self-test passed, 1648 files, no bidi controls. - `python3 -I -c "import ast..."` on the checker: syntax OK. - `python3 -B tests/cpu/vex_bytes_arith_check.py`: cannot run on Linux here (`iced_x86` missing, and it needs the Windows-built DLLs). Not run. Not done - No local mutation run: the new test needs the MSVC-built fixtures, so it was not possible on Linux. The Windows CI job is the evidence for that. I did not queue a Windows VM run because the change is Python lowering plus a CPU fixture, not shader or C++ code. Findings - P1: none. - P2: none. - Nit: the comment `// cpu_aot_vex_bytes_arith` in `CMakeLists.txt` is a bare label. A one-line description would match the sibling blocks. - Nit: the lowering is a macro (`BYTEWISE`). It is fine here, but the sibling helpers are plain functions. Consistency only. Title is neutral and the PR is mergeable. No clean-room concerns seen. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 15:01:42 +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!2351
No description provided.