cpu: add SSE2 leaf AOT translator covering 23 forms #603

Merged
MarlomMedeiros merged 3 commits from upstream-pr/609 into main 2026-11-23 13:27:47 +00:00
MarlomMedeiros commented 2026-11-22 15:41:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-22T15:41:29Z.


Change

  • Add tools/cpu_sse2_aot.py, a leaf AOT translator covering 23 of the 64 forms in docs/coverage/x64_zen2.tsv group SSE2, legacy encodings only: cmppd (all 8 imm8 predicates), packed converts cvtdq2pd/cvtdq2ps/cvtpd2dq/cvtpd2ps/cvtps2dq/cvtps2pd/cvttpd2dq/cvttps2dq, cvtpi2pd (m64 source), cvtsd2si (r32/r64), maxsd/minsd/sqrtsd, movapd/movdqa, movhpd/movlpd, movntdq/movntpd/movnti, lfence/mfence. Generated C++ uses a portable Vec128 lane model, no intrinsics.
  • Carve out 36 SSE2 forms for sibling translators (the scalar_float and ffx_version_query families, including the open SSE2 lowering stack): each rejects as unsupported so every form has exactly one owner. movdqa serves as the fixture's only transport form.
  • Reject 5 task forms that cannot fit the leaf ABI, with documented reasons and rejection controls: cvtpd2pi, cvttpd2pi, movdq2q, movq2dq use MMX register operands and maskmovdqu stores through implicit DS:rdi.
  • Add source-built MASM differential fixture tests/cpu/sse2_regs.{asm,def} + sse2_regs_check.py, CTest cpu_aot_sse2_regs, coverage mapping in tools/form_coverage.py/tests/form_coverage_check.py, and documentation in docs/experiments.md.

Verification

  • Built and tested on Windows 11 x64 (Ryzen 7 5800X3D, MSVC 19.52):
    • ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$' : passed (1,168 native/lifted/reference cases matched bit-for-bit across 57 exports; ALTER_IMM diverged on all 3 mutated exports, 28 cases each; output-mutation control caught)
    • ctest --preset dev --no-tests=error -R '^cpu_' : 112/112 passed
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py : passed (SSE2 group 14 -> 37/64, total x64 Zen 2 549 -> 572/948)
    • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py : passed
  • Negative controls: 66 unit rejection cases (36 reserved SSE2 forms, 7 MMX/implicit-address encodings, 1 cmppd immediate, 4 VEX/EVEX, 18 ABI/state/addressing/prefix violations), 12 PE-patched DLL rejections, 10 alternate-encoding accepts each asserting the expected lowered statement.

Evidence and follow-up

  • The six upper-zeroing converts run on dirty-seeded destinations so a merge-style lowering leaks input bits instead of zeros; scalar sd ops are tested for destination upper-64 preservation the same way.
  • Not covered: the 36 reserved SSE2 forms, MMX-domain operands and maskmovdqu, unaligned movapd/movdqa/movnt* faults (aligned moves lower to memcpy and accept any address), control flow or calls mixed with SSE2 state, nonvolatile XMM6..XMM15 prologues, title CPU execution.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544314411 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/609). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-22T15:41:29Z. --- ## Change - Add `tools/cpu_sse2_aot.py`, a leaf AOT translator covering 23 of the 64 forms in `docs/coverage/x64_zen2.tsv` group `SSE2`, legacy encodings only: `cmppd` (all 8 imm8 predicates), packed converts `cvtdq2pd`/`cvtdq2ps`/`cvtpd2dq`/`cvtpd2ps`/`cvtps2dq`/`cvtps2pd`/`cvttpd2dq`/`cvttps2dq`, `cvtpi2pd` (m64 source), `cvtsd2si` (r32/r64), `maxsd`/`minsd`/`sqrtsd`, `movapd`/`movdqa`, `movhpd`/`movlpd`, `movntdq`/`movntpd`/`movnti`, `lfence`/`mfence`. Generated C++ uses a portable `Vec128` lane model, no intrinsics. - Carve out 36 SSE2 forms for sibling translators (the scalar_float and ffx_version_query families, including the open SSE2 lowering stack): each rejects as unsupported so every form has exactly one owner. `movdqa` serves as the fixture's only transport form. - Reject 5 task forms that cannot fit the leaf ABI, with documented reasons and rejection controls: `cvtpd2pi`, `cvttpd2pi`, `movdq2q`, `movq2dq` use MMX register operands and `maskmovdqu` stores through implicit `DS:rdi`. - Add source-built MASM differential fixture `tests/cpu/sse2_regs.{asm,def}` + `sse2_regs_check.py`, CTest `cpu_aot_sse2_regs`, coverage mapping in `tools/form_coverage.py`/`tests/form_coverage_check.py`, and documentation in `docs/experiments.md`. ## Verification - Built and tested on Windows 11 x64 (Ryzen 7 5800X3D, MSVC 19.52): - `ctest --preset dev --no-tests=error -R '^cpu_aot_sse2_regs$'` : passed (1,168 native/lifted/reference cases matched bit-for-bit across 57 exports; ALTER_IMM diverged on all 3 mutated exports, 28 cases each; output-mutation control caught) - `ctest --preset dev --no-tests=error -R '^cpu_'` : 112/112 passed - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` : passed (SSE2 group 14 -> 37/64, total x64 Zen 2 549 -> 572/948) - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` : passed - Negative controls: 66 unit rejection cases (36 reserved SSE2 forms, 7 MMX/implicit-address encodings, 1 cmppd immediate, 4 VEX/EVEX, 18 ABI/state/addressing/prefix violations), 12 PE-patched DLL rejections, 10 alternate-encoding accepts each asserting the expected lowered statement. ## Evidence and follow-up - The six upper-zeroing converts run on dirty-seeded destinations so a merge-style lowering leaks input bits instead of zeros; scalar `sd` ops are tested for destination upper-64 preservation the same way. - Not covered: the 36 reserved SSE2 forms, MMX-domain operands and `maskmovdqu`, unaligned `movapd`/`movdqa`/`movnt*` faults (aligned moves lower to memcpy and accept any address), control flow or calls mixed with SSE2 state, nonvolatile `XMM6`..`XMM15` prologues, title CPU execution.
upstream-sync closed this pull request 2026-11-24 06:43:55 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 06:43:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-22T15:41:43Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6013069399 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/609#pullrequestreview-6013069399). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-22T15:41:43Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
legacy-code-archaeologist commented 2026-11-24 06:48:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T18:41:26Z.


Verification of 75e4701 on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. It merges cleanly with main, and all 112 cpu_ tests pass (the only skip is the usual cpu_aot_crypto_sha capability skip). The new check reports:

ctest --preset dev --no-tests=error -R sse2_regs -V
1168 native/lifted/reference SSE2 cases across 57 exports matched bit-for-bit; altered controls diverged on {'op_cmppd_1': 28, 'op_cmppd_3': 28, 'op_cmppd_6': 28}; output mutation control caught
10 alternate-encoding lift checks, 66 unit rejection controls (...) and 12 PE-patched rejection controls passed

Unlike #602, where a vendor-dependent DPPS NaN case fails on Intel, the native/lifted/reference comparison here holds on Skylake.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7083795176 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/609#issuecomment-7083795176). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T18:41:26Z. --- Verification of `75e4701` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. It merges cleanly with `main`, and all 112 `cpu_` tests pass (the only skip is the usual `cpu_aot_crypto_sha` capability skip). The new check reports: ```text ctest --preset dev --no-tests=error -R sse2_regs -V 1168 native/lifted/reference SSE2 cases across 57 exports matched bit-for-bit; altered controls diverged on {'op_cmppd_1': 28, 'op_cmppd_3': 28, 'op_cmppd_6': 28}; output mutation control caught 10 alternate-encoding lift checks, 66 unit rejection controls (...) and 12 PE-patched rejection controls passed ``` Unlike #602, where a vendor-dependent DPPS NaN case fails on Intel, the native/lifted/reference comparison here holds on Skylake. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:49:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T13:01:38Z.


I resolved the coverage-test conflict in 85c504d on your original branch and switched the fixture to its source-local coverage registration. The generated code now emits host LFENCE/MFENCE, and the aligned-buffer profile rejects misaligned displacements for full 128-bit memory operands. The existing unaligned qword controls are preserved. The docs spell out the aligned bases, private buffers and default MXCSR controls used by the fixture.

Windows dev and /O2 each passed 1,168 native/lifted/reference comparisons across 57 exports, all three mutation witnesses, 69 unit rejection controls and 12 PE-patched controls. Form coverage and docs links passed. GitHub CI is running on this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7101955846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/609#issuecomment-7101955846). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T13:01:38Z. --- I resolved the coverage-test conflict in 85c504d on your original branch and switched the fixture to its source-local coverage registration. The generated code now emits host LFENCE/MFENCE, and the aligned-buffer profile rejects misaligned displacements for full 128-bit memory operands. The existing unaligned qword controls are preserved. The docs spell out the aligned bases, private buffers and default MXCSR controls used by the fixture. Windows dev and /O2 each passed 1,168 native/lifted/reference comparisons across 57 exports, all three mutation witnesses, 69 unit rejection controls and 12 PE-patched controls. Form coverage and docs links passed. GitHub CI is running on this head.
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!603
No description provided.