cpu: lower legacy SSE2 cmpsd (scalar double compare, predicates 0..7) #1197

Merged
tedin7 merged 2 commits from upstream-pr/1204 into main 2026-11-24 05:19:09 +00:00
tedin7 commented 2026-11-24 03:33:05 +00:00 (Migrated from github.com)

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


What

  • tools/cpu_sse2_aot.py: accept the legacy SSE2 form CMPSD_XMM_XMMM64_IMM8 (xmm or flat m64 source, imm8 0..7). The low qword is computed with the host SSE2 scalar compare on the raw operand bits, so NaN inputs, signed zeros, subnormals and a live MXCSR (DAZ) behave as for the instruction. Bits 127:64 of the destination are preserved. imm8 above 7 and VEX/EVEX encodings reject. The string compare shares the mnemonic but is a different iced Code and is untouched.
  • tests/cpu/sse2_regs.asm: ten new exports (op_cmpsd_0..7, op_cmpsd_mem, op_cmpsd_mem_plus1); op_cmpsd_1/3/6 flip predicate under ALTER_IMM.
  • tests/cpu/sse2_regs_check.py: native vs lifted vs Python reference on every ordered pair of 26 edge doubles (signed zeros, subnormals, infinities, sNaN/qNaN payloads, boundaries) with dirty distinct upper qwords; ALTER_IMM divergence control for the cmpsd exports; alternate-encoding, imm8 above 7, VEX, nonvolatile xmm6 and undefined-destination rejection controls, plus a PE-patched imm8 control.
  • CMakeLists.txt: the ten export names added to cpu_sse2_exports (needed so the translator lifts them).
  • docs/experiments.md: SSE2 section updated (form list, semantics, counts, measured results).

Why

cmpsd is the scalar counterpart of the already lowered cmppd. The scalar compare writes only the low qword, so upper-bit preservation and exact NaN and signed-zero handling need explicit coverage. Delegating to the host compare keeps MXCSR behaviour exact without constant folding. The coverage table lists the cmpsd mnemonic only for the string compare, so this adds no SSE2 group form.

Tested

Linux (x86-64, venv with iced-x86, pefile):

  • python -m py_compile tools/cpu_sse2_aot.py tests/cpu/sse2_regs_check.py
  • python3 -B tests/docs_links_check.py (passed)
  • python3 -B tests/bidi_controls_check.py (passed)
  • python3 -B tests/form_coverage_check.py (passed)
  • check_alt_encodings_and_rejections run up to its PE-patching step (all lift and rejection controls passed; the step needs the built native DLL).
  • Independent semantics check (not part of the suite): lifted C++ compiled with g++ and compared with the instruction's own machine code run natively, 3 source forms x 8 predicates x 26x26 edge doubles x 7 MXCSR words (default, DAZ, FTZ+DAZ, four rounding controls): 113,568 cases matched, upper qword preserved. A DAZ control confirmed MXCSR is live. The check's reference model matched native on 13,680 cases; a wrong-predicate reference mismatched on 23 (negative control). ALTER_IMM predicates diverge on all 684 cases of each altered export.

Windows CI command: ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$' -V

The Windows MSVC/ML64 build and the cpu_aot_sse2_regs test were NOT run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6574001248 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:33:05Z. --- ## What - tools/cpu_sse2_aot.py: accept the legacy SSE2 form CMPSD_XMM_XMMM64_IMM8 (xmm or flat m64 source, imm8 0..7). The low qword is computed with the host SSE2 scalar compare on the raw operand bits, so NaN inputs, signed zeros, subnormals and a live MXCSR (DAZ) behave as for the instruction. Bits 127:64 of the destination are preserved. imm8 above 7 and VEX/EVEX encodings reject. The string compare shares the mnemonic but is a different iced Code and is untouched. - tests/cpu/sse2_regs.asm: ten new exports (op_cmpsd_0..7, op_cmpsd_mem, op_cmpsd_mem_plus1); op_cmpsd_1/3/6 flip predicate under ALTER_IMM. - tests/cpu/sse2_regs_check.py: native vs lifted vs Python reference on every ordered pair of 26 edge doubles (signed zeros, subnormals, infinities, sNaN/qNaN payloads, boundaries) with dirty distinct upper qwords; ALTER_IMM divergence control for the cmpsd exports; alternate-encoding, imm8 above 7, VEX, nonvolatile xmm6 and undefined-destination rejection controls, plus a PE-patched imm8 control. - CMakeLists.txt: the ten export names added to cpu_sse2_exports (needed so the translator lifts them). - docs/experiments.md: SSE2 section updated (form list, semantics, counts, measured results). ## Why cmpsd is the scalar counterpart of the already lowered cmppd. The scalar compare writes only the low qword, so upper-bit preservation and exact NaN and signed-zero handling need explicit coverage. Delegating to the host compare keeps MXCSR behaviour exact without constant folding. The coverage table lists the cmpsd mnemonic only for the string compare, so this adds no SSE2 group form. ## Tested Linux (x86-64, venv with iced-x86, pefile): - python -m py_compile tools/cpu_sse2_aot.py tests/cpu/sse2_regs_check.py - python3 -B tests/docs_links_check.py (passed) - python3 -B tests/bidi_controls_check.py (passed) - python3 -B tests/form_coverage_check.py (passed) - check_alt_encodings_and_rejections run up to its PE-patching step (all lift and rejection controls passed; the step needs the built native DLL). - Independent semantics check (not part of the suite): lifted C++ compiled with g++ and compared with the instruction's own machine code run natively, 3 source forms x 8 predicates x 26x26 edge doubles x 7 MXCSR words (default, DAZ, FTZ+DAZ, four rounding controls): 113,568 cases matched, upper qword preserved. A DAZ control confirmed MXCSR is live. The check's reference model matched native on 13,680 cases; a wrong-predicate reference mismatched on 23 (negative control). ALTER_IMM predicates diverge on all 684 cases of each altered export. Windows CI command: ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$' -V The Windows MSVC/ML64 build and the cpu_aot_sse2_regs test were NOT run locally.
upstream-sync closed this pull request 2026-11-24 06:46:53 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:46:53 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a34ceea699

ℹ️ 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:6033395231 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#pullrequestreview-6033395231). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:52:30Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `a34ceea699` <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>
tedin7 commented 2026-11-24 06:46:53 +00:00 (Migrated from github.com)

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

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033400070 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#pullrequestreview-6033400070). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:53:15Z. **Review:** COMMENTED --- _No description provided._
chatgpt-codex-connector[bot commented 2026-11-24 06:50:16 +00:00 (Migrated from github.com)

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


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:52:32.528725Z a34ceea 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:7121431706 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#issuecomment-7121431706). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:47:55Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a34ceea6993e4ed4746e7917bc073340d3493a47","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-24T03:52:32.528725Z">2026-11-24T03:52:32.528725Z</relative-time> | `a34ceea` | 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>
tedin7 commented 2026-11-24 06:50:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:50:28Z.


Windows Server 2025 verification (56387003) — PASS (Debug + Release /O2)

  • Environment: Windows Server 2025 Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U, D3D12 WARP
  • Debug (--preset dev) (2.34s build+test):
    • cmake --build --preset dev -j 6 --target cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse2_regs_altered_lifted
    • ctest --test-dir out\build\dev -R "^cpu_aot_sse2_regs$" --output-on-failure -> 1/1 passed (0 skipped, 1.04s)
  • Release /O2 (--preset release) (4.12s configure+build+test):
    • cmake --preset release && cmake --build --preset release -j 6 --target cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse2_regs_altered_lifted
    • ctest --test-dir out\build\release -R "^cpu_aot_sse2_regs$" --output-on-failure -> 1/1 passed (0 skipped, 1.03s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7122386353 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#issuecomment-7122386353). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T04:50:28Z. --- Windows Server 2025 verification (`56387003`) — **PASS (Debug + Release `/O2`)** - **Environment**: Windows Server 2025 Build 26100, MSVC 14.44.35207, AMD Ryzen 5 PRO 5650U, D3D12 WARP - **Debug (`--preset dev`)** (2.34s build+test): - `cmake --build --preset dev -j 6 --target cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse2_regs_altered_lifted` - `ctest --test-dir out\build\dev -R "^cpu_aot_sse2_regs$" --output-on-failure` -> **1/1 passed** (0 skipped, 1.04s) - **Release `/O2` (`--preset release`)** (4.12s configure+build+test): - `cmake --preset release && cmake --build --preset release -j 6 --target cpu_sse2_regs_original cpu_sse2_regs_original_lifted cpu_sse2_regs_altered_lifted` - `ctest --test-dir out\build\release -R "^cpu_aot_sse2_regs$" --output-on-failure` -> **1/1 passed** (0 skipped, 1.03s)
chatgpt-codex-connector[bot commented 2026-11-24 06:50:40 +00:00 (Migrated from github.com)

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

Code review location: CMakeLists.txt; line 1563

@@ -1559,6 +1559,8 @@ if(EXISTS "${INTAKE_PYTHON}")
     set(cpu_sse2_exports
         "op_cmppd_0,op_cmppd_1,op_cmppd_2,op_cmppd_3,op_cmppd_4,op_cmppd_5,op_cmppd_6,op_cmppd_7,"
         "op_cmppd_mem,"
+        "op_cmpsd_0,op_cmpsd_1,op_cmpsd_2,op_cmpsd_3,op_cmpsd_4,op_cmpsd_5,op_cmpsd_6,op_cmpsd_7,"
+        "op_cmpsd_mem,op_cmpsd_mem_plus1,"

P1 Badge Export the new CMPSD procedures from the native fixture

On the Windows build, cpu_asm_fixture() links the native fixture through tests/cpu/sse2_regs.def (CMakeLists.txt:976), but that file still contains only the original 57 exports. A repository-wide search finds no other export directives for the new op_cmpsd_* procedures, so the custom translation step now fails in export_rva() with expected one local export for op_cmpsd_0, preventing either lifted DLL from being generated and the differential test from running. Add all ten new names to the native .def file as well.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675297152 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#discussion_r4675297152). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T03:52:30Z. **Code review location:** `CMakeLists.txt`; line 1563 ~~~~diff @@ -1559,6 +1559,8 @@ if(EXISTS "${INTAKE_PYTHON}") set(cpu_sse2_exports "op_cmppd_0,op_cmppd_1,op_cmppd_2,op_cmppd_3,op_cmppd_4,op_cmppd_5,op_cmppd_6,op_cmppd_7," "op_cmppd_mem," + "op_cmpsd_0,op_cmpsd_1,op_cmpsd_2,op_cmpsd_3,op_cmpsd_4,op_cmpsd_5,op_cmpsd_6,op_cmpsd_7," + "op_cmpsd_mem,op_cmpsd_mem_plus1," ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Export the new CMPSD procedures from the native fixture** On the Windows build, `cpu_asm_fixture()` links the native fixture through `tests/cpu/sse2_regs.def` (`CMakeLists.txt:976`), but that file still contains only the original 57 exports. A repository-wide search finds no other export directives for the new `op_cmpsd_*` procedures, so the custom translation step now fails in `export_rva()` with `expected one local export for op_cmpsd_0`, preventing either lifted DLL from being generated and the differential test from running. Add all ten new names to the native `.def` file as well. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 06:50:40 +00:00 (Migrated from github.com)

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

Code review location: CMakeLists.txt; line 1563

@@ -1559,6 +1559,8 @@ if(EXISTS "${INTAKE_PYTHON}")
     set(cpu_sse2_exports
         "op_cmppd_0,op_cmppd_1,op_cmppd_2,op_cmppd_3,op_cmppd_4,op_cmppd_5,op_cmppd_6,op_cmppd_7,"
         "op_cmppd_mem,"
+        "op_cmpsd_0,op_cmpsd_1,op_cmpsd_2,op_cmpsd_3,op_cmpsd_4,op_cmpsd_5,op_cmpsd_6,op_cmpsd_7,"
+        "op_cmpsd_mem,op_cmpsd_mem_plus1,"

Fixed in 56387003: the ten op_cmpsd_* names are now listed in tests/cpu/sse2_regs.def, next to the existing exports. I checked it by reading export_rva() usage and the .def list only. The Windows build of this definition file was not run locally; CI will build it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4675301508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1204#discussion_r4675301508). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:53:15Z. **Code review location:** `CMakeLists.txt`; line 1563 ~~~~diff @@ -1559,6 +1559,8 @@ if(EXISTS "${INTAKE_PYTHON}") set(cpu_sse2_exports "op_cmppd_0,op_cmppd_1,op_cmppd_2,op_cmppd_3,op_cmppd_4,op_cmppd_5,op_cmppd_6,op_cmppd_7," "op_cmppd_mem," + "op_cmpsd_0,op_cmpsd_1,op_cmpsd_2,op_cmpsd_3,op_cmpsd_4,op_cmpsd_5,op_cmpsd_6,op_cmpsd_7," + "op_cmpsd_mem,op_cmpsd_mem_plus1," ~~~~ --- Fixed in 56387003: the ten `op_cmpsd_*` names are now listed in `tests/cpu/sse2_regs.def`, next to the existing exports. I checked it by reading `export_rva()` usage and the `.def` list only. The Windows build of this definition file was not run locally; CI will build it.
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!1197
No description provided.