Skip to content

cpu: add SSE2 leaf AOT translator covering 23 forms - #609

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
MarlomMedeiros:cpu-sse2-28
Nov 23, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
MarlomMedeiros:cpu-sse2-28

Conversation

@MarlomMedeiros

Copy link
Copy Markdown
Contributor

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.

Copilot AI balanced review requested due to automatic review settings November 22, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

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).

@R0Y00

R0Y00 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

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.

@R0Y00
R0Y00 merged commit 097afaf into R0Y00:main Nov 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants