cpu: lower SSE2 packed double arithmetic in the SSE FP leaf translator #1352

Merged
tedin7 merged 1 commit from upstream-pr/1359 into main 2026-11-24 09:45:24 +00:00
tedin7 commented 2026-11-24 09:13:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:13:14Z.


Change

tools/cpu_sse_fp_aot.py now lowers the seven legacy SSE2 packed double arithmetic forms ADDPD, SUBPD, MULPD, DIVPD, MINPD, MAXPD and SQRTPD (register source and 16-byte aligned m128 source) in bounded leaf functions. Before this change the translator refused them with unsupported instruction.

  • Each form runs the matching emmintrin.h instruction on a run-time operand: rounding mode, DAZ and FTZ are the host's, nothing is folded at translation time, and the C library square root is never used (it can differ from the hardware on denormal operands under DAZ).
  • NaN sources of ADD, SUB, MUL and DIV are resolved and quieted in software as in the packed single forms (first source operand if it is a NaN, else the second). MINPD and MAXPD use the host instruction unchanged. SQRTPD only reads its source and returns a NaN lane quiet with its payload.
  • Alignment follows the packed single forms: a displacement that is not a multiple of 16 is rejected at translation time, so no code that could fault on a misaligned address is generated. A guest ldmxcsr is still not lifted and exception flags are not observed (stated in the translator docstring and docs/experiments.md).
  • Rejected as before: VEX/EVEX, scalar forms (including the F2/F3 prefixed spellings of the same opcodes), the other packed double forms (cmppd, andpd, cvtps2pd, ...), nonvolatile or undefined registers, non-argument or indexed memory bases.
  • tests/cpu/sse_fp_check.py used addpd, sqrtpd and minpd as unsupported controls; they now use haddpd, cvtps2pd and andpd.

Follows the packed single arithmetic change in docs/experiments.md ("Legacy SSE FP compares and partial/non-temporal moves"). No open PR touches cpu_sse_fp_aot.py or the sse_fp fixture.

Verification

Linux x86-64 (QEMU virtual processor): fixture assembled with llvm-ml-19, linked with lld-link-19, original machine code run through a Windows-ABI caller, translation built with clang++-19 at -O0, -O2 and -O3 (-Wall -Wextra, only the existing unused-function notes for helpers a given fixture does not use) and compiled with MinGW g++ at -O0/-O2/-O3. python3 -m py_compile of the four Python files, tests/docs_links_check.py, tests/bidi_controls_check.py and tests/form_coverage_check.py pass. All three optimization levels passed tests/cpu/sse_fp_pd_check.py (bound through the same caller) and the unchanged check_alt_encodings_and_rejections of tests/cpu/sse_fp_check.py:

  • 11,948 native/lifted/reference cases over 29 exports bit for bit (every ordered pair of 28 edge values: signed zeros, infinities, quiet and signaling NaNs with payloads, denormals, rounding ties, overflow/underflow boundaries; plus 20 random vectors); the ALTER_IMM translation diverged from the original on all 29 exports (fewest differing cases 18).
  • 191,168 runs in the 16 MXCSR control words (4 rounding modes x neither, DAZ, FTZ, both): native, translated and the exact reference agree on 755,105 lanes; 9,567 lanes the reference leaves undecided (FTZ boundary, MIN/MAX under DAZ with a denormal result) are compared native against translated only. Each non-default word changed a result; 15 deliberately wrong reference rules were each detected; the driver restored the control word.
  • 48 unit rejection controls, 8 alternate-encoding lift checks and 9 PE-patched rejection controls.
  • Negative control: the translator from origin/main fails on the new fixture with unsupported instruction at RVA 0x1006: addpd xmm0,xmm1 (and sqrtpd xmm0,[rdx] for the memory form).
  • Eleven translator mutants built and run, each failing on a named word: add as subtract (lifted op_addpd case 1), subtract with swapped operands (op_subpd case 0), multiply as divide (op_mulpd case 0), divide as multiply (op_divpd case 0), minimum as maximum (op_minpd case 1), swapped minpd and maxpd operands (case 0), sqrtpd not quieting a NaN (op_sqrtpd case 7), NaN rule not quieting (op_addpd case 196), NaN rule choosing the second operand (op_addpd case 189), sqrtpd as a doubling (op_sqrtpd case 1).
  • Not run by me: the MSVC/MASM build and ctest run of cpu_aot_sse_fp_pd on Windows. Commands for that run: ctest --preset dev --no-tests=error -R '^cpu_aot_sse_fp_pd$' -V (and --preset release).

Evidence and follow-up

  • New fixture code is original MASM (tests/cpu/sse_fp_pd.asm, 29 exports); the reference tests/cpu/sse_fp_pd_ref.py is exact rational arithmetic with no host floating point and none of the translator. The native MXCSR driver is the existing sse_fp_harness image.
  • No new store form: results leave through the movaps stores the packed single fixture already used. Every call checks 32-byte guards around all three buffers and that output bytes the function does not write keep their fill value; misaligned displacements are rejected before any code exists.
  • Not covered: unmasked exceptions and exception flags, scalar double arithmetic, cmppd and the other packed double forms, rcpps, rsqrtps. Whether the processor returns original bits or a flushed zero for MIN/MAX under DAZ, and whether FTZ judges tininess before or after rounding, are left unconstrained in the reference rather than assumed.
  • AI-assisted.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578442855 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1359). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:13:14Z. --- ## Change `tools/cpu_sse_fp_aot.py` now lowers the seven legacy SSE2 packed double arithmetic forms `ADDPD`, `SUBPD`, `MULPD`, `DIVPD`, `MINPD`, `MAXPD` and `SQRTPD` (register source and 16-byte aligned `m128` source) in bounded leaf functions. Before this change the translator refused them with `unsupported instruction`. - Each form runs the matching `emmintrin.h` instruction on a run-time operand: rounding mode, DAZ and FTZ are the host's, nothing is folded at translation time, and the C library square root is never used (it can differ from the hardware on denormal operands under DAZ). - NaN sources of ADD, SUB, MUL and DIV are resolved and quieted in software as in the packed single forms (first source operand if it is a NaN, else the second). `MINPD` and `MAXPD` use the host instruction unchanged. `SQRTPD` only reads its source and returns a NaN lane quiet with its payload. - Alignment follows the packed single forms: a displacement that is not a multiple of 16 is rejected at translation time, so no code that could fault on a misaligned address is generated. A guest `ldmxcsr` is still not lifted and exception flags are not observed (stated in the translator docstring and `docs/experiments.md`). - Rejected as before: VEX/EVEX, scalar forms (including the `F2`/`F3` prefixed spellings of the same opcodes), the other packed double forms (`cmppd`, `andpd`, `cvtps2pd`, ...), nonvolatile or undefined registers, non-argument or indexed memory bases. - `tests/cpu/sse_fp_check.py` used `addpd`, `sqrtpd` and `minpd` as unsupported controls; they now use `haddpd`, `cvtps2pd` and `andpd`. Follows the packed single arithmetic change in `docs/experiments.md` ("Legacy SSE FP compares and partial/non-temporal moves"). No open PR touches `cpu_sse_fp_aot.py` or the `sse_fp` fixture. ## Verification Linux x86-64 (QEMU virtual processor): fixture assembled with `llvm-ml-19`, linked with `lld-link-19`, original machine code run through a Windows-ABI caller, translation built with `clang++-19` at -O0, -O2 and -O3 (`-Wall -Wextra`, only the existing unused-function notes for helpers a given fixture does not use) and compiled with MinGW `g++` at -O0/-O2/-O3. `python3 -m py_compile` of the four Python files, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `tests/form_coverage_check.py` pass. All three optimization levels passed `tests/cpu/sse_fp_pd_check.py` (bound through the same caller) and the unchanged `check_alt_encodings_and_rejections` of `tests/cpu/sse_fp_check.py`: - 11,948 native/lifted/reference cases over 29 exports bit for bit (every ordered pair of 28 edge values: signed zeros, infinities, quiet and signaling NaNs with payloads, denormals, rounding ties, overflow/underflow boundaries; plus 20 random vectors); the ALTER_IMM translation diverged from the original on all 29 exports (fewest differing cases 18). - 191,168 runs in the 16 MXCSR control words (4 rounding modes x neither, DAZ, FTZ, both): native, translated and the exact reference agree on 755,105 lanes; 9,567 lanes the reference leaves undecided (FTZ boundary, MIN/MAX under DAZ with a denormal result) are compared native against translated only. Each non-default word changed a result; 15 deliberately wrong reference rules were each detected; the driver restored the control word. - 48 unit rejection controls, 8 alternate-encoding lift checks and 9 PE-patched rejection controls. - Negative control: the translator from `origin/main` fails on the new fixture with `unsupported instruction at RVA 0x1006: addpd xmm0,xmm1` (and `sqrtpd xmm0,[rdx]` for the memory form). - Eleven translator mutants built and run, each failing on a named word: add as subtract (`lifted op_addpd case 1`), subtract with swapped operands (`op_subpd case 0`), multiply as divide (`op_mulpd case 0`), divide as multiply (`op_divpd case 0`), minimum as maximum (`op_minpd case 1`), swapped `minpd` and `maxpd` operands (`case 0`), `sqrtpd` not quieting a NaN (`op_sqrtpd case 7`), NaN rule not quieting (`op_addpd case 196`), NaN rule choosing the second operand (`op_addpd case 189`), `sqrtpd` as a doubling (`op_sqrtpd case 1`). - Not run by me: the MSVC/MASM build and `ctest` run of `cpu_aot_sse_fp_pd` on Windows. Commands for that run: `ctest --preset dev --no-tests=error -R '^cpu_aot_sse_fp_pd$' -V` (and `--preset release`). ## Evidence and follow-up - New fixture code is original MASM (`tests/cpu/sse_fp_pd.asm`, 29 exports); the reference `tests/cpu/sse_fp_pd_ref.py` is exact rational arithmetic with no host floating point and none of the translator. The native MXCSR driver is the existing `sse_fp_harness` image. - No new store form: results leave through the `movaps` stores the packed single fixture already used. Every call checks 32-byte guards around all three buffers and that output bytes the function does not write keep their fill value; misaligned displacements are rejected before any code exists. - Not covered: unmasked exceptions and exception flags, scalar double arithmetic, `cmppd` and the other packed double forms, `rcpps`, `rsqrtps`. Whether the processor returns original bits or a flushed zero for MIN/MAX under DAZ, and whether FTZ judges tininess before or after rounding, are left unconstrained in the reference rather than assumed. - AI-assisted. ## 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.
upstream-sync closed this pull request 2026-11-24 10:02:29 +00:00
tedin7 commented 2026-11-24 10:02:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:17:55Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit a53a750d2752c04137160d9106dc272dc108d7aa:

  • Debug (--preset dev):
    • Build (cpu_sse_fp_pd_*, cpu_sse_fp_*): 3.92s (configure 1.66s)
    • Test (ctest --preset dev -R '^(cpu_aot_sse_fp_pd|cpu_aot_sse_fp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_sse_fp 9.24s, cpu_aot_sse_fp_pd 20.09s)
  • Release /O2 (--preset release):
    • Build (cpu_sse_fp_pd_*, cpu_sse_fp_*): 1.30s (configure 1.79s)
    • Test (ctest --preset release -R '^(cpu_aot_sse_fp_pd|cpu_aot_sse_fp)$' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (cpu_aot_sse_fp 8.43s, cpu_aot_sse_fp_pd 18.94s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7127221190 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1359#issuecomment-7127221190). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:17:55Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `a53a750d2752c04137160d9106dc272dc108d7aa`: - **Debug (`--preset dev`)**: - Build (`cpu_sse_fp_pd_*`, `cpu_sse_fp_*`): `3.92s` (configure `1.66s`) - Test (`ctest --preset dev -R '^(cpu_aot_sse_fp_pd|cpu_aot_sse_fp)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_sse_fp` `9.24s`, `cpu_aot_sse_fp_pd` `20.09s`) - **Release `/O2` (`--preset release`)**: - Build (`cpu_sse_fp_pd_*`, `cpu_sse_fp_*`): `1.30s` (configure `1.79s`) - Test (`ctest --preset release -R '^(cpu_aot_sse_fp_pd|cpu_aot_sse_fp)$' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`cpu_aot_sse_fp` `8.43s`, `cpu_aot_sse_fp_pd` `18.94s`)
chatgpt-codex-connector[bot commented 2026-11-24 10:02:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:18:07Z.


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-24T09:24:05.769514Z a53a750 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:7127225684 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1359#issuecomment-7127225684). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:18:07Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a53a750d2752c04137160d9106dc272dc108d7aa","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-24T09:24:05.769514Z">2026-11-24T09:24:05.769514Z</relative-time> | `a53a750` | 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!1352
No description provided.