cpu: lower baseline 128-bit SSE2 packed integer ALU instructions #360

Merged
Vonsek merged 5 commits from upstream-pr/366 into main 2026-11-22 12:01:47 +00:00
Vonsek commented 2026-11-21 23:31:43 +00:00 (Migrated from github.com)

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


Change

  • Lower legacy 128-bit movdqu and 18 baseline SSE2 packed integer ALU instructions in tools/ffx_version_query.py:
    • Wrapping packed add/sub: paddb, paddw, paddd, paddq, psubb, psubw, psubd, psubq
    • Packed bitwise logic: pand, pandn, por, pxor
    • Packed equality and signed greater-than comparisons: pcmpeqb, pcmpeqw, pcmpeqd, pcmpgtb, pcmpgtw, pcmpgtd
  • 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_int.{asm,def,py}, CMake target cpu_sse2_int_lifted, CTest cpu_aot_sse2_int, 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_int_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_int_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_int|cpu_aot_bmi1)$" -V: 2/2 passed (18 baseline 128-bit SSE2 packed integer ALU cases matched native and translated DLLs + MMX 64-bit paddb 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 19 instructions (movdqu + 18 packed integer ALU ops) are baseline x86-64 SSE2 and require no CPUID capability gate.
  • Covers 17 MMX-grouped mnemonics and 2 SSE2-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535807016 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/366). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T23:31:43Z. --- ## Change - Lower legacy 128-bit `movdqu` and 18 baseline SSE2 packed integer ALU instructions in `tools/ffx_version_query.py`: - Wrapping packed add/sub: `paddb`, `paddw`, `paddd`, `paddq`, `psubb`, `psubw`, `psubd`, `psubq` - Packed bitwise logic: `pand`, `pandn`, `por`, `pxor` - Packed equality and signed greater-than comparisons: `pcmpeqb`, `pcmpeqw`, `pcmpeqd`, `pcmpgtb`, `pcmpgtw`, `pcmpgtd` - 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_int.{asm,def,py}`, CMake target `cpu_sse2_int_lifted`, CTest `cpu_aot_sse2_int`, 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_int_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_int_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_int|cpu_aot_bmi1)$" -V`: 2/2 passed (`18 baseline 128-bit SSE2 packed integer ALU cases matched native and translated DLLs` + MMX 64-bit `paddb 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 19 instructions (`movdqu` + 18 packed integer ALU ops) are baseline x86-64 SSE2 and require no CPUID capability gate. - Covers 17 `MMX`-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:42:39 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bedf35d195

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6008906747 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/366#pullrequestreview-6008906747). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T23:42:37Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `bedf35d195` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
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:03Z.


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:42:40.206190Z bedf35d 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:7071002501 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/366#issuecomment-7071002501). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T23:38:03Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"bedf35d19543612f9c20102de0b71e3da13f39ac","has_any_findings":true,"has_unresolved_findings":true,"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:42:40.206190Z">2026-11-21T23:42:40.206190Z</relative-time> | `bedf35d` | 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>
chatgpt-codex-connector[bot commented 2026-11-24 06:50:37 +00:00 (Migrated from github.com)

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

Code review location: docs/experiments.md; line 417

@@ -414,6 +414,8 @@ An immediate SHL, SHR or SAR whose masked count is zero leaves the flags unchang
 
 The shared lowering also handles 32-bit and 64-bit BMI1 bit-manipulation forms (`andn`, `bextr`, `blsi`, `blsmsk`, `blsr`, `tzcnt`), including their zero-extending 32-bit writes and ZF/CF updates. `cpu_aot_bmi1` probes CPUID leaf 7 EBX bit 3 (`BMI1`) before invoking the native fixture and exits 77 (capability skip) on hosts without BMI1; on BMI1-capable hosts it builds all twelve 32-bit and 64-bit exports from MASM source (`tests/cpu/bmi1.asm`), translates them, compares both values and observed ZF/CF flags against the native DLL and an independent reference, and checks that 16-bit `tzcnt` is rejected. Run `cmake --build --preset dev --target cpu_bmi1_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_bmi1$' -V`.
 
+Baseline 128-bit SSE2 packed integer ALU forms (`movdqu`, `paddb`/`w`/`d`/`q`, `psubb`/`w`/`d`/`q`, `pand`, `pandn`, `por`, `pxor`, `pcmpeqb`/`w`/`d`, `pcmpgtb`/`w`/`d`) are also lowered for legacy XMM encodings while preserving upper YMM bytes and rejecting 64-bit MMX forms. `cpu_aot_sse2_int` builds all eighteen exports from MASM source (`tests/cpu/sse2_int.asm`), translates them, compares all 16 output bytes against the native DLL and an independent reference, and checks that 64-bit MMX `paddb mm0, mm1` is rejected. Run `cmake --build --preset dev --target cpu_sse2_int_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_int$' -V`.

P2 Badge Align the claimed SSE2 verification with the actual fixture

A passing cpu_aot_sse2_int does not perform the independent-reference check claimed here: tests/cpu/sse2_int.py:51-57 only calls the native and lifted functions and compares their output buffers. This establishes native-versus-translated agreement, not the additional reference validation described in the experiment notes. Either add independently computed expected results or remove that claim, consistent with AGENTS.md's requirement to “State what was measured.”

AGENTS.md reference: AGENTS.md:L135-L136

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655574334 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/366#discussion_r4655574334). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T23:42:38Z. **Code review location:** `docs/experiments.md`; line 417 ~~~~diff @@ -414,6 +414,8 @@ An immediate SHL, SHR or SAR whose masked count is zero leaves the flags unchang The shared lowering also handles 32-bit and 64-bit BMI1 bit-manipulation forms (`andn`, `bextr`, `blsi`, `blsmsk`, `blsr`, `tzcnt`), including their zero-extending 32-bit writes and ZF/CF updates. `cpu_aot_bmi1` probes CPUID leaf 7 EBX bit 3 (`BMI1`) before invoking the native fixture and exits 77 (capability skip) on hosts without BMI1; on BMI1-capable hosts it builds all twelve 32-bit and 64-bit exports from MASM source (`tests/cpu/bmi1.asm`), translates them, compares both values and observed ZF/CF flags against the native DLL and an independent reference, and checks that 16-bit `tzcnt` is rejected. Run `cmake --build --preset dev --target cpu_bmi1_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_bmi1$' -V`. +Baseline 128-bit SSE2 packed integer ALU forms (`movdqu`, `paddb`/`w`/`d`/`q`, `psubb`/`w`/`d`/`q`, `pand`, `pandn`, `por`, `pxor`, `pcmpeqb`/`w`/`d`, `pcmpgtb`/`w`/`d`) are also lowered for legacy XMM encodings while preserving upper YMM bytes and rejecting 64-bit MMX forms. `cpu_aot_sse2_int` builds all eighteen exports from MASM source (`tests/cpu/sse2_int.asm`), translates them, compares all 16 output bytes against the native DLL and an independent reference, and checks that 64-bit MMX `paddb mm0, mm1` is rejected. Run `cmake --build --preset dev --target cpu_sse2_int_lifted` and `ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_int$' -V`. ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Align the claimed SSE2 verification with the actual fixture** A passing `cpu_aot_sse2_int` does not perform the independent-reference check claimed here: `tests/cpu/sse2_int.py:51-57` only calls the native and lifted functions and compares their output buffers. This establishes native-versus-translated agreement, not the additional reference validation described in the experiment notes. Either add independently computed expected results or remove that claim, consistent with `AGENTS.md`'s requirement to “State what was measured.” AGENTS.md reference: [AGENTS.md:L135-L136](https://github.com/R0Y00/Xbox2Windows/blob/bedf35d19543612f9c20102de0b71e3da13f39ac/AGENTS.md#L135-L136) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!360
No description provided.