cpu: lower baseline 128-bit SSE/SSE2 packed conversions, compares, half moves, and scalar sqrt/min/max #382

Manually merged
github merged 5 commits from gh-pr/382/head into gh-pr/382/base 2026-11-26 21:47:30 +00:00
Owner

@⁠Vonsek on GitHub · 2026-11-21 23:58 UTC · original
Vonsek:ag/cpu-lower-sse2-packed-cvt → main · +446 −7 · 8 files · 5 commits · merged 2026-11-23 21:29 UTC

Change

  • Lower 25 baseline 128-bit SSE/SSE2 instructions in tools/ffx_version_query.py:
    • Packed conversions with exact ties-to-even/truncation and integer-indefinite (0x80000000) clamping: cvtdq2ps, cvtdq2pd, cvtps2dq, cvtpd2dq, cvttps2dq, cvttpd2dq, cvtps2pd, cvtpd2ps
    • Packed FP compares (all 8 predicates): cmpps, cmppd
    • Aligned and half-register moves: movaps, movapd, movdqa, movhlps, movlhps, movlps, movhps, movlpd, movhpd
    • Scalar sqrt/min/max preserving upper XMM lanes: sqrtss, minss, maxss, sqrtsd, minsd, maxsd
  • Restrict lowering to EncodingKind.LEGACY XMM forms, rejecting VEX encodings.
  • Add source-built MASM differential fixture tests/cpu/sse2_packed_cvt.{asm,def,py}, CMake target cpu_sse2_packed_cvt_lifted, CTest cpu_aot_sse2_packed_cvt, 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_packed_cvt_lifted:
    ValueError: unsupported query operation at 0x1000: movdqa xmm1,[rcx]
  • Built and tested on Windows 11 x64 (VS 2022 Build Tools):
    • cmake --build --preset dev --target cpu_sse2_packed_cvt_lifted succeeded with 0 warnings
    • ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_packed_cvt|cpu_aot_bmi1)$" -V: 2/2 passed (22 baseline 128-bit SSE/SSE2 conversion/compare/move/scalar cases matched native and translated DLLs + VEX vcvtdq2ps rejection control)
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: form coverage checks passed

Evidence and follow-up

  • All 25 instructions are baseline x86-64 SSE/SSE2 and require no CPUID capability gate.
  • Covers 9 SSE-grouped mnemonics and 16 SSE2-grouped mnemonics in docs/coverage/x64_zen2.tsv using source-built fixtures.
**@⁠Vonsek** on GitHub · 2026-11-21 23:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382) `Vonsek:ag/cpu-lower-sse2-packed-cvt` → `main` · +446 −7 · 8 files · 5 commits · merged 2026-11-23 21:29 UTC ## Change - Lower 25 baseline 128-bit SSE/SSE2 instructions in `tools/ffx_version_query.py`: - Packed conversions with exact ties-to-even/truncation and integer-indefinite (`0x80000000`) clamping: `cvtdq2ps`, `cvtdq2pd`, `cvtps2dq`, `cvtpd2dq`, `cvttps2dq`, `cvttpd2dq`, `cvtps2pd`, `cvtpd2ps` - Packed FP compares (all 8 predicates): `cmpps`, `cmppd` - Aligned and half-register moves: `movaps`, `movapd`, `movdqa`, `movhlps`, `movlhps`, `movlps`, `movhps`, `movlpd`, `movhpd` - Scalar `sqrt`/`min`/`max` preserving upper XMM lanes: `sqrtss`, `minss`, `maxss`, `sqrtsd`, `minsd`, `maxsd` - Restrict lowering to `EncodingKind.LEGACY` XMM forms, rejecting VEX encodings. - Add source-built MASM differential fixture `tests/cpu/sse2_packed_cvt.{asm,def,py}`, CMake target `cpu_sse2_packed_cvt_lifted`, CTest `cpu_aot_sse2_packed_cvt`, 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_packed_cvt_lifted`: `ValueError: unsupported query operation at 0x1000: movdqa xmm1,[rcx]` - Built and tested on Windows 11 x64 (VS 2022 Build Tools): - `cmake --build --preset dev --target cpu_sse2_packed_cvt_lifted` succeeded with 0 warnings - `ctest --preset dev --no-tests=error -R "^(cpu_aot_sse2_packed_cvt|cpu_aot_bmi1)$" -V`: 2/2 passed (`22 baseline 128-bit SSE/SSE2 conversion/compare/move/scalar cases matched native and translated DLLs` + VEX `vcvtdq2ps` rejection control) - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: `form coverage checks passed` ## Evidence and follow-up - All 25 instructions are baseline x86-64 SSE/SSE2 and require no CPUID capability gate. - Covers 9 `SSE`-grouped mnemonics and 16 `SSE2`-grouped mnemonics in `docs/coverage/x64_zen2.tsv` using source-built fixtures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:47:29 +00:00
github manually merged commit bda89d7b80 into gh-pr/382/base 2026-11-26 21:47:30 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:02 UTC · original · edited 2026-11-22 00:08 UTC

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-22T00:08:33.340900Z 970a0d0 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7071270865) · edited 2026-11-22 00:08 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"970a0d0df3a05602a5ce1f15db4e5e5690a681d2","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-22T00:08:33.340900Z">2026-11-22T00:08:33.340900Z</relative-time> | `970a0d0` | 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:08 UTC · original

P2 Badge Honor MXCSR rounding in packed float-to-int conversions

When the caller selects round-down or round-toward-zero in MXCSR, CVTPS2DQ and CVTPD2DQ must use that mode, but this helper always rounds to nearest-even. Comparing the emitted helper with native SSE2 on Linux x86-64, 1.75 converts to 2 here versus 1 natively under round-down. This can silently change the lifted exports' integer results under non-default rounding modes. Use an MXCSR-aware conversion or explicitly reject unsupported modes, and include rounding-mode controls in the differential fixture.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#discussion_r4655673778) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Honor MXCSR rounding in packed float-to-int conversions** When the caller selects round-down or round-toward-zero in MXCSR, `CVTPS2DQ` and `CVTPD2DQ` must use that mode, but this helper always rounds to nearest-even. Comparing the emitted helper with native SSE2 on Linux x86-64, `1.75` converts to `2` here versus `1` natively under round-down. This can silently change the lifted exports' integer results under non-default rounding modes. Use an MXCSR-aware conversion or explicitly reject unsupported modes, and include rounding-mode controls in the differential fixture. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:08 UTC · original

P2 Badge Normalize scalar min/max operands when DAZ is enabled

With MXCSR.DAZ enabled, native scalar min/max instructions treat subnormal inputs as signed zero, but this conditional can copy the selected operand's original subnormal bits. Compiling the emitted block unoptimized on Linux x86-64, MINSS with float input bit patterns 0x00000001 and 0x3f800000 produces 0x00000001, whereas native SSE2 produces 0x00000000; the double variant has the same mismatch. This affects unoptimized generated code, including the Debug build selected by the dev preset. Use scalar SSE intrinsics or apply DAZ normalization before selecting the result, and cover this mode in the fixture.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#discussion_r4655673783) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Normalize scalar min/max operands when DAZ is enabled** With MXCSR.DAZ enabled, native scalar min/max instructions treat subnormal inputs as signed zero, but this conditional can copy the selected operand's original subnormal bits. Compiling the emitted block unoptimized on Linux x86-64, `MINSS` with float input bit patterns `0x00000001` and `0x3f800000` produces `0x00000001`, whereas native SSE2 produces `0x00000000`; the double variant has the same mismatch. This affects unoptimized generated code, including the Debug build selected by the `dev` preset. Use scalar SSE intrinsics or apply DAZ normalization before selecting the result, and cover this mode in the fixture. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 20:08 UTC · original

I checked the conflict against current main. Packed conversions and scalar min/max already have MXCSR-aware paths there. Please keep those paths when updating this older branch. #985 is reviewing the overlapping CMPPS/MOVLPS/MOVHPS forms and has a pending /O2 memory-read control. The independent remainder here is the packed-double compare and the double half-memory moves (CMPPD/MOVLPD/MOVHPD), plus any new tests for main's current behavior. Please replace the old VCVTDQ2PS rejection control with a form the current profile still refuses.

**@⁠R0Y00** on GitHub · 2026-11-23 20:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7112613733) I checked the conflict against current main. Packed conversions and scalar min/max already have MXCSR-aware paths there. Please keep those paths when updating this older branch. #985 is reviewing the overlapping CMPPS/MOVLPS/MOVHPS forms and has a pending /O2 memory-read control. The independent remainder here is the packed-double compare and the double half-memory moves (CMPPD/MOVLPD/MOVHPD), plus any new tests for main's current behavior. Please replace the old VCVTDQ2PS rejection control with a form the current profile still refuses.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 20:43 UTC · original

I resolved the conflicts against the merged #985 in 1f9c6af. This keeps the shared lowerer's existing intrinsic conversion and scalar arithmetic paths. CMPPD now tests both a register source and a native aligned memory operand. The lowerer uses the existing aligned-memory and ordered-load helpers, and the refusal control now checks a CMPPD write to XMM6. ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(sse2_packed_cvt|sse_fp)$' passed 2/2 in each Windows preset. Both GitHub Windows jobs will run for the updated head.

**@⁠R0Y00** on GitHub · 2026-11-23 20:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7113464082) I resolved the conflicts against the merged #985 in `1f9c6af`. This keeps the shared lowerer's existing intrinsic conversion and scalar arithmetic paths. CMPPD now tests both a register source and a native aligned memory operand. The lowerer uses the existing aligned-memory and ordered-load helpers, and the refusal control now checks a CMPPD write to XMM6. `ctest --preset <dev|release> --no-tests=error -R '^cpu_aot_(sse2_packed_cvt|sse_fp)$'` passed 2/2 in each Windows preset. Both GitHub Windows jobs will run for the updated head.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 20:56 UTC · original

Follow-up at 40ea243: the older always-nearest and scalar conditional implementations are absent. The current conversion and MINSS/MINSD paths use the existing hardware intrinsics. I added independent exact outputs for CVTPS2DQ in round-down, CVTPD2DQ in round-toward-zero, and MINSS/MINSD with DAZ. Both Windows Debug and /O2 passed. The helper saves and restores MXCSR, and lives outside the translated coverage file. I also corrected the duplicated documentation text from my previous integration commit.

**@⁠R0Y00** on GitHub · 2026-11-23 20:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7113778653) Follow-up at `40ea243`: the older always-nearest and scalar conditional implementations are absent. The current conversion and MINSS/MINSD paths use the existing hardware intrinsics. I added independent exact outputs for CVTPS2DQ in round-down, CVTPD2DQ in round-toward-zero, and MINSS/MINSD with DAZ. Both Windows Debug and /O2 passed. The helper saves and restores MXCSR, and lives outside the translated coverage file. I also corrected the duplicated documentation text from my previous integration commit.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 21:13 UTC · original

The prior /O2 CI failed because cpu_aot_float_shuffles still expected legacy MOVAPD memory loads to be unsupported. I pushed bda89d7 to require the new alignment-checked lowering there. The native/lifted SSE2 fixture now also checks that misaligned MOVAPD and misaligned CMPPD memory sources each raise an access violation. The shuffle, SSE2 conversion and SSE FP selections passed 3/3 in both Windows Debug and Release. The new head has fresh CI.

**@⁠R0Y00** on GitHub · 2026-11-23 21:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7114175278) The prior /O2 CI failed because `cpu_aot_float_shuffles` still expected legacy MOVAPD memory loads to be unsupported. I pushed `bda89d7` to require the new alignment-checked lowering there. The native/lifted SSE2 fixture now also checks that misaligned MOVAPD and misaligned CMPPD memory sources each raise an access violation. The shuffle, SSE2 conversion and SSE FP selections passed 3/3 in both Windows Debug and Release. The new head has fresh CI.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-22 00:08 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 970a0d0df3

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

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-22 00:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/382#pullrequestreview-6009081070) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `970a0d0df3` <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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.