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

Merged
Vonsek merged 5 commits from upstream-pr/382 into main 2026-11-23 21:29:33 +00:00
Vonsek commented 2026-11-21 23:58:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T23:58:32Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536052851 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T23:58:32Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:42:44 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:08:30Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6009081070 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#pullrequestreview-6009081070). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:08:30Z. **Review:** COMMENTED --- <!-- 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>
chatgpt-codex-connector[bot commented 2026-11-24 06:48:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:02:27Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7071270865 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7071270865). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:02:27Z. --- <!-- 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>
R0Y00 commented 2026-11-24 06:49:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:08:08Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112613733 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7112613733). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:08:08Z. --- 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 commented 2026-11-24 06:49:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:43:18Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7113464082 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7113464082). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:43:18Z. --- 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 commented 2026-11-24 06:49:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:56:37Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7113778653 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7113778653). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:56:37Z. --- 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 commented 2026-11-24 06:49:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:13:37Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7114175278 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#issuecomment-7114175278). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:13:37Z. --- 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.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:08:31Z.

Code review location: tools/ffx_version_query.py; line 41

@@ -30,6 +31,18 @@
 template<class T> void store(word address, T v) {
     memcpy(reinterpret_cast<void*>(address), &v, sizeof v);
 }
+static inline int32_t cvt_to_i32(double x, bool trunc) {
+    if (!std::isfinite(x)) return static_cast<int32_t>(0x80000000u);
+    double r;
+    if (trunc) {
+        r = std::trunc(x);
+    } else {
+        const double f = std::floor(x), d = x - f;
+        r = (d < 0.5) ? f : ((d > 0.5) ? (f + 1.0) : (std::fmod(f, 2.0) == 0.0 ? f : (f + 1.0)));

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655673778 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#discussion_r4655673778). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:08:31Z. **Code review location:** `tools/ffx_version_query.py`; line 41 ~~~~diff @@ -30,6 +31,18 @@ template<class T> void store(word address, T v) { memcpy(reinterpret_cast<void*>(address), &v, sizeof v); } +static inline int32_t cvt_to_i32(double x, bool trunc) { + if (!std::isfinite(x)) return static_cast<int32_t>(0x80000000u); + double r; + if (trunc) { + r = std::trunc(x); + } else { + const double f = std::floor(x), d = x - f; + r = (d < 0.5) ? f : ((d > 0.5) ? (f + 1.0) : (std::fmod(f, 2.0) == 0.0 ? f : (f + 1.0))); ~~~~ --- **<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 -->
chatgpt-codex-connector[bot commented 2026-11-24 06:50:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T00:08:31Z.

Code review location: tools/ffx_version_query.py; line 306

@@ -210,6 +229,81 @@ def write(expr):
             stmt = (f"{{ auto input = {src}; {dst} = {{}}; for (size_t n=0; n<16; n+=4) {{ "
                     f"auto v = load<uint32_t>(reinterpret_cast<word>(input.data()+n)) {operation}; "
                     f"memcpy({dst}.data()+n, &v, 4); }} }}")
+        elif op in (M.MOVAPS, M.MOVAPD, M.MOVDQA) and i.encoding == EncodingKind.LEGACY and has_wide:
+            if i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY:
+                stmt = f"memcpy({wide_xmm[i.op0_register]}.data(), reinterpret_cast<const void*>({address()}), 16);"
+            elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm:
+                stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data(), 16);"
+            elif (i.op0_kind == K.REGISTER and i.op0_register in wide_xmm
+                  and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm):
+                stmt = f"memcpy({wide_xmm[i.op0_register]}.data(), {wide_xmm[i.op1_register]}.data(), 16);"
+            else:
+                raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}")
+        elif op in (M.MOVLPS, M.MOVLPD, M.MOVHPS, M.MOVHPD) and i.encoding == EncodingKind.LEGACY and has_wide:
+            off = 0 if op in (M.MOVLPS, M.MOVLPD) else 8
+            if i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY:
+                stmt = f"memcpy({wide_xmm[i.op0_register]}.data()+{off}, reinterpret_cast<const void*>({address()}), 8);"
+            elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm:
+                stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data()+{off}, 8);"
+            else:
+                raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}")
+        elif op in (M.MOVHLPS, M.MOVLHPS) and i.encoding == EncodingKind.LEGACY and has_wide and i.op0_register in wide_xmm and i.op1_register in wide_xmm:
+            dst, src = wide_xmm[i.op0_register], wide_xmm[i.op1_register]
+            d_off, s_off = (0, 8) if op == M.MOVHLPS else (8, 0)
+            stmt = f"{{ uint8_t t[8]; memcpy(t, {src}.data()+{s_off}, 8); memcpy({dst}.data()+{d_off}, t, 8); }}"
+        elif (op in (M.CVTDQ2PS, M.CVTDQ2PD, M.CVTPS2DQ, M.CVTPD2DQ, M.CVTTPS2DQ, M.CVTTPD2DQ,
+                     M.CVTPS2PD, M.CVTPD2PS, M.CMPPS, M.CMPPD,
+                     M.SQRTSS, M.MINSS, M.MAXSS, M.SQRTSD, M.MINSD, M.MAXSD)
+              and i.encoding == EncodingKind.LEGACY and i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and has_wide):
+            dst = wide_xmm[i.op0_register]
+            mem_bytes = (4 if op in (M.SQRTSS, M.MINSS, M.MAXSS)
+                         else (8 if op in (M.CVTDQ2PD, M.CVTPS2PD, M.SQRTSD, M.MINSD, M.MAXSD) else 16))
+            if i.op1_kind == K.REGISTER and i.op1_register in wide_xmm:
+                src_init = f"std::array<uint8_t,16> rhs; memcpy(rhs.data(), {wide_xmm[i.op1_register]}.data(), 16);"
+            elif i.op1_kind == K.MEMORY:
+                src_init = f"std::array<uint8_t,16> rhs{{}}; memcpy(rhs.data(), reinterpret_cast<const void*>({address()}), {mem_bytes});"
+            else:
+                raise ValueError(f"unsupported SSE2 source at {i.ip:#x}: {i}")
+            if op == M.CVTDQ2PS:
+                stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+=4) {{ "
+                        f"int32_t x; memcpy(&x, rhs.data()+n, 4); const float v = static_cast<float>(x); memcpy({dst}.data()+n, &v, 4); }} }}")
+            elif op == M.CVTDQ2PD:
+                stmt = (f"{{ {src_init} for (size_t k=0; k<2; ++k) {{ "
+                        f"int32_t x; memcpy(&x, rhs.data()+4*k, 4); const double v = static_cast<double>(x); memcpy({dst}.data()+8*k, &v, 8); }} }}")
+            elif op in (M.CVTPS2DQ, M.CVTTPS2DQ):
+                tr = "true" if op == M.CVTTPS2DQ else "false"
+                stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+=4) {{ "
+                        f"float x; memcpy(&x, rhs.data()+n, 4); const int32_t v = cvt_to_i32(double(x), {tr}); memcpy({dst}.data()+n, &v, 4); }} }}")
+            elif op in (M.CVTPD2DQ, M.CVTTPD2DQ):
+                tr = "true" if op == M.CVTTPD2DQ else "false"
+                stmt = (f"{{ {src_init} memset({dst}.data()+8, 0, 8); for (size_t k=0; k<2; ++k) {{ "
+                        f"double x; memcpy(&x, rhs.data()+8*k, 8); const int32_t v = cvt_to_i32(x, {tr}); memcpy({dst}.data()+4*k, &v, 4); }} }}")
+            elif op == M.CVTPS2PD:
+                stmt = (f"{{ {src_init} for (size_t k=0; k<2; ++k) {{ "
+                        f"float x; memcpy(&x, rhs.data()+4*k, 4); const double v = static_cast<double>(x); memcpy({dst}.data()+8*k, &v, 8); }} }}")
+            elif op == M.CVTPD2PS:
+                stmt = (f"{{ {src_init} memset({dst}.data()+8, 0, 8); for (size_t k=0; k<2; ++k) {{ "
+                        f"double x; memcpy(&x, rhs.data()+8*k, 8); const float v = static_cast<float>(x); memcpy({dst}.data()+4*k, &v, 4); }} }}")
+            elif op in (M.CMPPS, M.CMPPD):
+                pred = i.immediate(2) & 7
+                ftype, utype, lane_size = ("float", "uint32_t", 4) if op == M.CMPPS else ("double", "uint64_t", 8)
+                cond = {
+                    0: "a == b", 1: "a < b", 2: "a <= b", 3: "(std::isnan(a) || std::isnan(b))",
+                    4: "!(a == b)", 5: "!(a < b)", 6: "!(a <= b)", 7: "(!std::isnan(a) && !std::isnan(b))",
+                }[pred]
+                stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+={lane_size}) {{ "
+                        f"{ftype} a, b; memcpy(&a, {dst}.data()+n, {lane_size}); memcpy(&b, rhs.data()+n, {lane_size}); "
+                        f"const {utype} v = ({cond}) ? static_cast<{utype}>(~{utype}(0)) : {utype}(0); "
+                        f"memcpy({dst}.data()+n, &v, {lane_size}); }} }}")
+            elif op in (M.SQRTSS, M.SQRTSD):
+                ftype, lane_size = ("float", 4) if op == M.SQRTSS else ("double", 8)
+                stmt = (f"{{ {src_init} {ftype} b; memcpy(&b, rhs.data(), {lane_size}); "
+                        f"const {ftype} v = std::sqrt(b); memcpy({dst}.data(), &v, {lane_size}); }}")
+            else:  # MINSS, MAXSS, MINSD, MAXSD
+                ftype, lane_size = ("float", 4) if op in (M.MINSS, M.MAXSS) else ("double", 8)
+                cmp_op = "<" if op in (M.MINSS, M.MINSD) else ">"
+                stmt = (f"{{ {src_init} {ftype} a, b; memcpy(&a, {dst}.data(), {lane_size}); memcpy(&b, rhs.data(), {lane_size}); "
+                        f"const {ftype} v = (a {cmp_op} b) ? a : b; memcpy({dst}.data(), &v, {lane_size}); }}")

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4655673783 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/382#discussion_r4655673783). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T00:08:31Z. **Code review location:** `tools/ffx_version_query.py`; line 306 ~~~~diff @@ -210,6 +229,81 @@ def write(expr): stmt = (f"{{ auto input = {src}; {dst} = {{}}; for (size_t n=0; n<16; n+=4) {{ " f"auto v = load<uint32_t>(reinterpret_cast<word>(input.data()+n)) {operation}; " f"memcpy({dst}.data()+n, &v, 4); }} }}") + elif op in (M.MOVAPS, M.MOVAPD, M.MOVDQA) and i.encoding == EncodingKind.LEGACY and has_wide: + if i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY: + stmt = f"memcpy({wide_xmm[i.op0_register]}.data(), reinterpret_cast<const void*>({address()}), 16);" + elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm: + stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data(), 16);" + elif (i.op0_kind == K.REGISTER and i.op0_register in wide_xmm + and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm): + stmt = f"memcpy({wide_xmm[i.op0_register]}.data(), {wide_xmm[i.op1_register]}.data(), 16);" + else: + raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}") + elif op in (M.MOVLPS, M.MOVLPD, M.MOVHPS, M.MOVHPD) and i.encoding == EncodingKind.LEGACY and has_wide: + off = 0 if op in (M.MOVLPS, M.MOVLPD) else 8 + if i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and i.op1_kind == K.MEMORY: + stmt = f"memcpy({wide_xmm[i.op0_register]}.data()+{off}, reinterpret_cast<const void*>({address()}), 8);" + elif i.op0_kind == K.MEMORY and i.op1_kind == K.REGISTER and i.op1_register in wide_xmm: + stmt = f"memcpy(reinterpret_cast<void*>({address()}), {wide_xmm[i.op1_register]}.data()+{off}, 8);" + else: + raise ValueError(f"unsupported {op} form at {i.ip:#x}: {i}") + elif op in (M.MOVHLPS, M.MOVLHPS) and i.encoding == EncodingKind.LEGACY and has_wide and i.op0_register in wide_xmm and i.op1_register in wide_xmm: + dst, src = wide_xmm[i.op0_register], wide_xmm[i.op1_register] + d_off, s_off = (0, 8) if op == M.MOVHLPS else (8, 0) + stmt = f"{{ uint8_t t[8]; memcpy(t, {src}.data()+{s_off}, 8); memcpy({dst}.data()+{d_off}, t, 8); }}" + elif (op in (M.CVTDQ2PS, M.CVTDQ2PD, M.CVTPS2DQ, M.CVTPD2DQ, M.CVTTPS2DQ, M.CVTTPD2DQ, + M.CVTPS2PD, M.CVTPD2PS, M.CMPPS, M.CMPPD, + M.SQRTSS, M.MINSS, M.MAXSS, M.SQRTSD, M.MINSD, M.MAXSD) + and i.encoding == EncodingKind.LEGACY and i.op0_kind == K.REGISTER and i.op0_register in wide_xmm and has_wide): + dst = wide_xmm[i.op0_register] + mem_bytes = (4 if op in (M.SQRTSS, M.MINSS, M.MAXSS) + else (8 if op in (M.CVTDQ2PD, M.CVTPS2PD, M.SQRTSD, M.MINSD, M.MAXSD) else 16)) + if i.op1_kind == K.REGISTER and i.op1_register in wide_xmm: + src_init = f"std::array<uint8_t,16> rhs; memcpy(rhs.data(), {wide_xmm[i.op1_register]}.data(), 16);" + elif i.op1_kind == K.MEMORY: + src_init = f"std::array<uint8_t,16> rhs{{}}; memcpy(rhs.data(), reinterpret_cast<const void*>({address()}), {mem_bytes});" + else: + raise ValueError(f"unsupported SSE2 source at {i.ip:#x}: {i}") + if op == M.CVTDQ2PS: + stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+=4) {{ " + f"int32_t x; memcpy(&x, rhs.data()+n, 4); const float v = static_cast<float>(x); memcpy({dst}.data()+n, &v, 4); }} }}") + elif op == M.CVTDQ2PD: + stmt = (f"{{ {src_init} for (size_t k=0; k<2; ++k) {{ " + f"int32_t x; memcpy(&x, rhs.data()+4*k, 4); const double v = static_cast<double>(x); memcpy({dst}.data()+8*k, &v, 8); }} }}") + elif op in (M.CVTPS2DQ, M.CVTTPS2DQ): + tr = "true" if op == M.CVTTPS2DQ else "false" + stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+=4) {{ " + f"float x; memcpy(&x, rhs.data()+n, 4); const int32_t v = cvt_to_i32(double(x), {tr}); memcpy({dst}.data()+n, &v, 4); }} }}") + elif op in (M.CVTPD2DQ, M.CVTTPD2DQ): + tr = "true" if op == M.CVTTPD2DQ else "false" + stmt = (f"{{ {src_init} memset({dst}.data()+8, 0, 8); for (size_t k=0; k<2; ++k) {{ " + f"double x; memcpy(&x, rhs.data()+8*k, 8); const int32_t v = cvt_to_i32(x, {tr}); memcpy({dst}.data()+4*k, &v, 4); }} }}") + elif op == M.CVTPS2PD: + stmt = (f"{{ {src_init} for (size_t k=0; k<2; ++k) {{ " + f"float x; memcpy(&x, rhs.data()+4*k, 4); const double v = static_cast<double>(x); memcpy({dst}.data()+8*k, &v, 8); }} }}") + elif op == M.CVTPD2PS: + stmt = (f"{{ {src_init} memset({dst}.data()+8, 0, 8); for (size_t k=0; k<2; ++k) {{ " + f"double x; memcpy(&x, rhs.data()+8*k, 8); const float v = static_cast<float>(x); memcpy({dst}.data()+4*k, &v, 4); }} }}") + elif op in (M.CMPPS, M.CMPPD): + pred = i.immediate(2) & 7 + ftype, utype, lane_size = ("float", "uint32_t", 4) if op == M.CMPPS else ("double", "uint64_t", 8) + cond = { + 0: "a == b", 1: "a < b", 2: "a <= b", 3: "(std::isnan(a) || std::isnan(b))", + 4: "!(a == b)", 5: "!(a < b)", 6: "!(a <= b)", 7: "(!std::isnan(a) && !std::isnan(b))", + }[pred] + stmt = (f"{{ {src_init} for (size_t n=0; n<16; n+={lane_size}) {{ " + f"{ftype} a, b; memcpy(&a, {dst}.data()+n, {lane_size}); memcpy(&b, rhs.data()+n, {lane_size}); " + f"const {utype} v = ({cond}) ? static_cast<{utype}>(~{utype}(0)) : {utype}(0); " + f"memcpy({dst}.data()+n, &v, {lane_size}); }} }}") + elif op in (M.SQRTSS, M.SQRTSD): + ftype, lane_size = ("float", 4) if op == M.SQRTSS else ("double", 8) + stmt = (f"{{ {src_init} {ftype} b; memcpy(&b, rhs.data(), {lane_size}); " + f"const {ftype} v = std::sqrt(b); memcpy({dst}.data(), &v, {lane_size}); }}") + else: # MINSS, MAXSS, MINSD, MAXSD + ftype, lane_size = ("float", 4) if op in (M.MINSS, M.MAXSS) else ("double", 8) + cmp_op = "<" if op in (M.MINSS, M.MINSD) else ">" + stmt = (f"{{ {src_init} {ftype} a, b; memcpy(&a, {dst}.data(), {lane_size}); memcpy(&b, rhs.data(), {lane_size}); " + f"const {ftype} v = (a {cmp_op} b) ? a : b; memcpy({dst}.data(), &v, {lane_size}); }}") ~~~~ --- **<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 -->
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!376
No description provided.