cpu: lower legacy SSE/MMX packed unsigned integer ops (PAVGB, PAVGW, PMULHUW, PSADBW) in cpu_sse_mmx_aot #2087

Merged
Ammmae0x merged 1 commit from upstream-pr/2094 into main 2026-11-25 12:26:48 +00:00
Ammmae0x commented 2026-11-25 00:13:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:13:14Z.


Change

Lower legacy MMX and SSE2 packed unsigned integer operations (pavgb, pavgw, pmulhuw, psadbw) in tools/cpu_sse_mmx_aot.py and add a source-built MASM fixture (tests/cpu/sse_mmx_int.asm, tests/cpu/sse_mmx_int.def), differential verification suite (tests/cpu/sse_mmx_int_check.py), and CTest registration (cpu_aot_sse_mmx_int in CMakeLists.txt):

  • Covered forms (docs/coverage/x64_zen2.tsv groups SSE / SSE2):
    • pavgb mm, mm/m64 and pavgb xmm, xmm/m128 — carry-safe unsigned byte average ((uint16_t(a) + uint16_t(b) + 1u) >> 1).
    • pavgw mm, mm/m64 and pavgw xmm, xmm/m128 — carry-safe unsigned 16-bit average ((uint32_t(a) + uint32_t(b) + 1u) >> 1).
    • pmulhuw mm, mm/m64 and pmulhuw xmm, xmm/m128 — unsigned high 16-bit product (uint32_t(a) * uint32_t(b)) >> 16.
    • psadbw mm, mm/m64 and psadbw xmm, xmm/m128 — sum of unsigned byte absolute differences zero-extended to 64 bits per independent 64-bit half (q[0], q[1]).
  • Semantics and safety guarantees:
    • MMX forms allow unaligned m64 ([rdx+1]) and enforce mmx_active / terminal emms discipline.
    • SSE2 XMM forms enforce 16-byte aligned m128 (flat_address(alignment=16)) and volatile loads so /O2 never eliminates faulting discarded reads.
    • Rejects VEX/EVEX/XOP encodings, segment/LOCK/REP prefixes, missing emms, undefined mm/xmm registers, nonvolatile XMM/GPR registers, unaligned XMM m128, RIP-relative/SIB addressing, non-r8 stores, and non-leaf branches.

Verification

Tested on commit f4b357b2 (rebased onto upstream/main 3914e891, Windows x64, MSVC 14.50, dev Debug and release /O2):

  1. cmake --build --preset dev --target cpu_sse_mmx_int_original cpu_sse_mmx_int_original_lifted cpu_sse_mmx_int_altered cpu_sse_mmx_int_altered_lifted cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered_lifted
    • Result: succeeded with 0 errors, 0 warnings.
  2. cmake --build --preset release --target ... (same targets)
    • Result: succeeded with 0 errors, 0 warnings.
  3. ctest --preset dev -R "^cpu_aot_sse_mmx" --output-on-failure -V
    • Result: 2/2 Passed (cpu_aot_sse_mmx_int, cpu_aot_sse_mmx).
    • cpu_aot_sse_mmx_int: 1258 lifted + 1258 /O2 cases across 34 exports, /O2 NULL read fault verified, 10 ALTER_IMM divergences, 4 software mutants killed, 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections passed. Capability skips: none.
  4. ctest --preset release -R "^cpu_aot_sse_mmx" --output-on-failure
    • Result: 2/2 Passed.
  5. .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
    • Result: form coverage checks passed (exit 0).
  6. .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
    • Result: Self-test passed. Checked 18 Markdown files and 394 links. (exit 0).
  7. .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
    • Result: Self-test passed. Checked 1418 tracked source, script and build/CI files: no bidirectional controls. (exit 0).

Evidence and follow-up

  • Fixture tests/cpu/sse_mmx_int.asm (; coverage: source cpu_aot_sse_mmx_int) and tests/cpu/sse_mmx_int.def are original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used.
  • Negative controls include 10 ALTER_IMM mutant exports, 4 software mutants (dropped +1 rounding, signed pmulhw, merged psadbw halves), a NULL-pointer discarded m128 read fault check under Debug and /O2, and 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections.

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:6594112066 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2094). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:13:14Z. --- ## Change Lower legacy MMX and SSE2 packed unsigned integer operations (`pavgb`, `pavgw`, `pmulhuw`, `psadbw`) in `tools/cpu_sse_mmx_aot.py` and add a source-built MASM fixture (`tests/cpu/sse_mmx_int.asm`, `tests/cpu/sse_mmx_int.def`), differential verification suite (`tests/cpu/sse_mmx_int_check.py`), and CTest registration (`cpu_aot_sse_mmx_int` in `CMakeLists.txt`): - Covered forms (`docs/coverage/x64_zen2.tsv` groups `SSE` / `SSE2`): - `pavgb mm, mm/m64` and `pavgb xmm, xmm/m128` — carry-safe unsigned byte average `((uint16_t(a) + uint16_t(b) + 1u) >> 1)`. - `pavgw mm, mm/m64` and `pavgw xmm, xmm/m128` — carry-safe unsigned 16-bit average `((uint32_t(a) + uint32_t(b) + 1u) >> 1)`. - `pmulhuw mm, mm/m64` and `pmulhuw xmm, xmm/m128` — unsigned high 16-bit product `(uint32_t(a) * uint32_t(b)) >> 16`. - `psadbw mm, mm/m64` and `psadbw xmm, xmm/m128` — sum of unsigned byte absolute differences zero-extended to 64 bits per independent 64-bit half (`q[0]`, `q[1]`). - Semantics and safety guarantees: - MMX forms allow unaligned `m64` (`[rdx+1]`) and enforce `mmx_active` / terminal `emms` discipline. - SSE2 XMM forms enforce 16-byte aligned `m128` (`flat_address(alignment=16)`) and volatile loads so `/O2` never eliminates faulting discarded reads. - Rejects VEX/EVEX/XOP encodings, segment/LOCK/REP prefixes, missing `emms`, undefined `mm`/`xmm` registers, nonvolatile XMM/GPR registers, unaligned XMM `m128`, RIP-relative/SIB addressing, non-`r8` stores, and non-leaf branches. ## Verification Tested on commit `f4b357b2` (rebased onto `upstream/main` `3914e891`, Windows x64, MSVC 14.50, `dev` Debug and `release` `/O2`): 1. `cmake --build --preset dev --target cpu_sse_mmx_int_original cpu_sse_mmx_int_original_lifted cpu_sse_mmx_int_altered cpu_sse_mmx_int_altered_lifted cpu_sse_mmx_original cpu_sse_mmx_original_lifted cpu_sse_mmx_altered_lifted` - Result: succeeded with 0 errors, 0 warnings. 2. `cmake --build --preset release --target ...` (same targets) - Result: succeeded with 0 errors, 0 warnings. 3. `ctest --preset dev -R "^cpu_aot_sse_mmx" --output-on-failure -V` - Result: `2/2` Passed (`cpu_aot_sse_mmx_int`, `cpu_aot_sse_mmx`). - `cpu_aot_sse_mmx_int`: 1258 lifted + 1258 `/O2` cases across 34 exports, `/O2` NULL read fault verified, 10 `ALTER_IMM` divergences, 4 software mutants killed, 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections passed. Capability skips: none. 4. `ctest --preset release -R "^cpu_aot_sse_mmx" --output-on-failure` - Result: `2/2` Passed. 5. `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` - Result: `form coverage checks passed` (exit 0). 6. `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` - Result: `Self-test passed. Checked 18 Markdown files and 394 links.` (exit 0). 7. `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` - Result: `Self-test passed. Checked 1418 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). ## Evidence and follow-up - Fixture `tests/cpu/sse_mmx_int.asm` (`; coverage: source cpu_aot_sse_mmx_int`) and `tests/cpu/sse_mmx_int.def` are original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used. - Negative controls include 10 `ALTER_IMM` mutant exports, 4 software mutants (dropped `+1` rounding, signed `pmulhw`, merged `psadbw` halves), a `NULL`-pointer discarded `m128` read fault check under Debug and `/O2`, and 5 VEX/EVEX + 22 IR + 3 raw + 6 PE-patched + CLI rejections. ## 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 01:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:51:23Z.

Review: COMMENTED


Review of head f4b357b25440a63be13b59a76bf98dfefad8318a (PAVGB/PAVGW/PMULHUW/PSADBW lowering in cpu_sse_mmx_aot).

Verdict: no P1, no P2. Looks correct.

Commands executed locally:

  • git diff --check origin/main...HEAD: clean
  • git merge-tree --write-tree --name-only origin/main HEAD: no conflicts
  • python3 tests/bidi_controls_check.py: pass
  • python3 tests/docs_links_check.py: pass
  • python3 -I -m py_compile tests/cpu/sse_mmx_int_check.py tools/cpu_sse_mmx_aot.py: ok
  • gh pr checks 2094: Linux Python checks, Windows build/test and gfx1013 fixtures pass
  • Windows Server 2025 (MSVC 14.44, Debug dev and Release /O2, ctest -R '^(cpu_aot_sse_mmx|cpu_aot_sse_mmx_int)$'): 2/2 passed on each preset

Mutation: in tools/cpu_sse_mmx_aot.py, op_pavgb64 changed (ab + bb + 1u) >> 1u to (ab + bb) >> 1u and run on Win2025 through --patch. cpu_aot_sse_mmx_int FAILED (lifted op_pavgb_mm_reg case 1 mismatch against the expected value). So the tests cover the change. Mutation reverted with git checkout -- ..

Code read (helper math, ALLOWED_CODES wiring, 16-byte alignment for xmm memory sources, unaligned m64 for mm):

  • P1: none
  • P2: none
  • P3: tools/cpu_sse_mmx_aot.py op_pmulhuw64: aw * bw is uint32_t, which is safe (max 0xFFFE0001). A short comment saying so would help the next reader. Optional.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049862406 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2094#pullrequestreview-6049862406). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:51:23Z. **Review:** COMMENTED --- Review of head `f4b357b25440a63be13b59a76bf98dfefad8318a` (PAVGB/PAVGW/PMULHUW/PSADBW lowering in `cpu_sse_mmx_aot`). **Verdict: no P1, no P2. Looks correct.** Commands executed locally: - `git diff --check origin/main...HEAD`: clean - `git merge-tree --write-tree --name-only origin/main HEAD`: no conflicts - `python3 tests/bidi_controls_check.py`: pass - `python3 tests/docs_links_check.py`: pass - `python3 -I -m py_compile tests/cpu/sse_mmx_int_check.py tools/cpu_sse_mmx_aot.py`: ok - `gh pr checks 2094`: Linux Python checks, Windows build/test and gfx1013 fixtures pass - Windows Server 2025 (MSVC 14.44, Debug `dev` and Release `/O2`, `ctest -R '^(cpu_aot_sse_mmx|cpu_aot_sse_mmx_int)$'`): 2/2 passed on each preset Mutation: in `tools/cpu_sse_mmx_aot.py`, `op_pavgb64` changed `(ab + bb + 1u) >> 1u` to `(ab + bb) >> 1u` and run on Win2025 through `--patch`. `cpu_aot_sse_mmx_int` FAILED (`lifted op_pavgb_mm_reg case 1` mismatch against the expected value). So the tests cover the change. Mutation reverted with `git checkout -- .`. Code read (helper math, ALLOWED_CODES wiring, 16-byte alignment for xmm memory sources, unaligned m64 for mm): - P1: none - P2: none - P3: `tools/cpu_sse_mmx_aot.py` `op_pmulhuw64`: `aw * bw` is `uint32_t`, which is safe (max 0xFFFE0001). A short comment saying so would help the next reader. Optional. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 13:00:36 +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!2087
No description provided.