cpu: lower baseline 128-bit SSE2 saturating, multiply, min/max, avg, and sad instructions #361

Merged
Vonsek merged 4 commits from upstream-pr/367 into main 2026-11-22 10:48:52 +00:00
Vonsek commented 2026-11-21 23:35:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T23:35:17Z.


Change

  • Lower legacy 128-bit movdqu and 20 baseline SSE2 packed integer instructions in tools/ffx_version_query.py:
    • Saturating add/sub: paddsb, paddsw, paddusb, paddusw, psubsb, psubsw, psubusb, psubusw
    • Packed multiply and multiply-add: pmulhw, pmulhuw, pmullw, pmaddwd, pmuludq
    • Packed min/max, average, and sum of absolute differences: pminub, pmaxub, pminsw, pmaxsw, pavgb, pavgw, psadbw
  • Restrict lowering to EncodingKind.LEGACY XMM forms, preserving upper YMM bytes (16..31) and rejecting 64-bit MMX encodings.
  • Add source-built MASM differential fixture tests/cpu/sse2_sat_mul.{asm,def,py}, CMake target cpu_sse2_sat_mul_lifted, CTest cpu_aot_sse2_sat_mul, coverage mapping in tools/form_coverage.py, and documentation in docs/experiments.md.

Verification

  • Confirmed pre-fix failure on cmake --build --preset dev --target cpu_sse2_sat_mul_lifted:
    ValueError: unsupported query operation at 0x1000: movdqu xmm0,[rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_sse2_sat_mul_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_sat_mul|cpu_aot_bmi1)$" -V: 2/2 passed (20 baseline 128-bit SSE2 saturating/mul/minmax/avg/sad cases matched native and translated DLLs, including saturation extremes, INT16_MIN * INT16_MIN wrapping in pmaddwd, and 64-bit MMX paddsb mm0, mm1 rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • All 21 instructions (movdqu + 20 packed integer ops) are baseline x86-64 SSE2 and require no CPUID capability gate.
  • Covers 11 MMX-grouped mnemonics, 8 SSE-grouped mnemonics, and 2 SSE2-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535837550 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/367). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T23:35:17Z. --- ## Change - Lower legacy 128-bit `movdqu` and 20 baseline SSE2 packed integer instructions in `tools/ffx_version_query.py`: - Saturating add/sub: `paddsb`, `paddsw`, `paddusb`, `paddusw`, `psubsb`, `psubsw`, `psubusb`, `psubusw` - Packed multiply and multiply-add: `pmulhw`, `pmulhuw`, `pmullw`, `pmaddwd`, `pmuludq` - Packed min/max, average, and sum of absolute differences: `pminub`, `pmaxub`, `pminsw`, `pmaxsw`, `pavgb`, `pavgw`, `psadbw` - Restrict lowering to `EncodingKind.LEGACY` XMM forms, preserving upper YMM bytes (16..31) and rejecting 64-bit MMX encodings. - Add source-built MASM differential fixture `tests/cpu/sse2_sat_mul.{asm,def,py}`, CMake target `cpu_sse2_sat_mul_lifted`, CTest `cpu_aot_sse2_sat_mul`, coverage mapping in `tools/form_coverage.py`, and documentation in `docs/experiments.md`. ## Verification - Confirmed pre-fix failure on `cmake --build --preset dev --target cpu_sse2_sat_mul_lifted`: `ValueError: unsupported query operation at 0x1000: movdqu xmm0,[rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_sse2_sat_mul_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_sat_mul|cpu_aot_bmi1)$" -V`: 2/2 passed (`20 baseline 128-bit SSE2 saturating/mul/minmax/avg/sad cases matched native and translated DLLs`, including saturation extremes, `INT16_MIN * INT16_MIN` wrapping in `pmaddwd`, and 64-bit MMX `paddsb mm0, mm1` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - All 21 instructions (`movdqu` + 20 packed integer ops) are baseline x86-64 SSE2 and require no CPUID capability gate. - Covers 11 `MMX`-grouped mnemonics, 8 `SSE`-grouped mnemonics, and 2 `SSE2`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures.
upstream-sync closed this pull request 2026-11-24 06:42:39 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:48:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T23:38:54Z.


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-21T23:41:45.894361Z 8c712ac 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:7071011938 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/367#issuecomment-7071011938). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T23:38:54Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"8c712acce3aa41ac83c7bb14bb0810ab62c6d1c9","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-21T23:41:45.894361Z">2026-11-21T23:41:45.894361Z</relative-time> | `8c712ac` | 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!361
No description provided.