cpu: lift legacy SSE2 cmppd in the SSE FP translator #1390

Merged
tedin7 merged 2 commits from upstream-pr/1397 into main 2026-11-24 10:47:08 +00:00
tedin7 commented 2026-11-24 10:30:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:30:04Z.


Change

Lifts the legacy SSE2 packed double compare cmppd xmm, xmm/m128, imm8 (predicates 0..7: EQ, LT, LE, UNORD, NEQ, NLT, NLE, ORD) in the SSE FP leaf translator, tools/cpu_sse_fp_aot.py. Each 64-bit lane becomes an all-ones or all-zero mask. The lowering uses the hardware _mm_cmp*_pd intrinsics on run-time operands, so NaN handling and DAZ are decided by the processor and not by C operators or the C library. imm8 >= 8 (AVX-only predicates) and m128 displacements that are not multiples of 16 reject at translation time. VEX/EVEX vcmppd and scalar cmpsd stay rejected. The packed single check that used cmppd as its unsupported instruction now uses cvtpd2ps, which still rejects.

This is a CPU AOT change, outside the shader/SPIR-V path. No other open PR touches tools/cpu_sse_fp_aot.py or tests/cpu/sse_fp*.

AI-assisted.

Verification

Linux x86-64 (QEMU virtual CPU, not the Windows CI machine). Fixture assembled with llvm-ml-19, linked with lld-link-19, native code run through a Windows-ABI caller, translation built with clang++-19 at -O0, -O2 and -O3 (MinGW g++ -Wall -Wextra clean at the same levels). Each ran the full sse_fp_pd_check.py entry points:

  • 4,532 compare cases over 11 exports: native, lifted and an independent reference match bit for bit.
  • 72,512 compare runs in 16 MXCSR states (4 rounding modes x DAZ x FTZ): native, lifted and reference agree; rounding mode and FTZ change nothing, DAZ changes every export except UNORD, ORD and the self compare.
  • 61 unit and 11 PE-patched rejection controls pass; the existing arithmetic checks are unchanged (11,948 and 191,168 runs).
  • py_compile, docs_links_check.py, bidi_controls_check.py, form_coverage_check.py pass; x2w_pipe.py preflight verdict OK.
  • Fails on origin/main: the translator stops on the new fixture with unsupported instruction at RVA 0x1187: cmpeqpd xmm0,xmm1.
  • Seven translator mutants (NEQ as EQ, LE as LT, UNORD as ORD, 32-bit mask, numeric result, NaN as ordered, a software compare that ignores DAZ) each fail on a named word, e.g. lifted op_cmppd_4 case 0.

Not run here: the MSVC build and ctest. PR outside preset pr: ctest --preset dev -R '^cpu_aot_sse_fp(_pd)?$' (and --preset release).

Evidence and follow-up

  • The fixture is source-built MASM written for this change; no game files or dumps. The reference (tests/cpu/sse_fp_pd_ref.py) uses integer bit patterns and exact values, written from the predicate rules, not from a host comparison.
  • Signaling-NaN exception flags are not observed (MXCSR exceptions stay masked), as in the other forms of this translator.
  • Docs: docs/experiments.md has a new "Packed double compare" subsection.

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:6579767878 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:30:04Z. --- ## Change Lifts the legacy SSE2 packed double compare `cmppd xmm, xmm/m128, imm8` (predicates 0..7: EQ, LT, LE, UNORD, NEQ, NLT, NLE, ORD) in the SSE FP leaf translator, `tools/cpu_sse_fp_aot.py`. Each 64-bit lane becomes an all-ones or all-zero mask. The lowering uses the hardware `_mm_cmp*_pd` intrinsics on run-time operands, so NaN handling and DAZ are decided by the processor and not by C operators or the C library. `imm8 >= 8` (AVX-only predicates) and `m128` displacements that are not multiples of 16 reject at translation time. VEX/EVEX `vcmppd` and scalar `cmpsd` stay rejected. The packed single check that used `cmppd` as its unsupported instruction now uses `cvtpd2ps`, which still rejects. This is a CPU AOT change, outside the shader/SPIR-V path. No other open PR touches `tools/cpu_sse_fp_aot.py` or `tests/cpu/sse_fp*`. AI-assisted. ## Verification Linux x86-64 (QEMU virtual CPU, not the Windows CI machine). Fixture assembled with `llvm-ml-19`, linked with `lld-link-19`, native code run through a Windows-ABI caller, translation built with `clang++-19` at -O0, -O2 and -O3 (MinGW `g++` -Wall -Wextra clean at the same levels). Each ran the full `sse_fp_pd_check.py` entry points: - 4,532 compare cases over 11 exports: native, lifted and an independent reference match bit for bit. - 72,512 compare runs in 16 MXCSR states (4 rounding modes x DAZ x FTZ): native, lifted and reference agree; rounding mode and FTZ change nothing, DAZ changes every export except UNORD, ORD and the self compare. - 61 unit and 11 PE-patched rejection controls pass; the existing arithmetic checks are unchanged (11,948 and 191,168 runs). - `py_compile`, `docs_links_check.py`, `bidi_controls_check.py`, `form_coverage_check.py` pass; `x2w_pipe.py preflight` verdict OK. - Fails on `origin/main`: the translator stops on the new fixture with `unsupported instruction at RVA 0x1187: cmpeqpd xmm0,xmm1`. - Seven translator mutants (NEQ as EQ, LE as LT, UNORD as ORD, 32-bit mask, numeric result, NaN as ordered, a software compare that ignores DAZ) each fail on a named word, e.g. `lifted op_cmppd_4 case 0`. Not run here: the MSVC build and `ctest`. PR outside preset pr: `ctest --preset dev -R '^cpu_aot_sse_fp(_pd)?$'` (and `--preset release`). ## Evidence and follow-up - The fixture is source-built MASM written for this change; no game files or dumps. The reference (`tests/cpu/sse_fp_pd_ref.py`) uses integer bit patterns and exact values, written from the predicate rules, not from a host comparison. - Signaling-NaN exception flags are not observed (MXCSR exceptions stay masked), as in the other forms of this translator. - Docs: `docs/experiments.md` has a new "Packed double compare" subsection. ## 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 11:02:49 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 11:02:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:40:25Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a14701685

ℹ️ 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:6037716915 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#pullrequestreview-6037716915). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T10:40:25Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `7a14701685` <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>
tedin7 commented 2026-11-24 11:02:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:45:56Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037804746 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#pullrequestreview-6037804746). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:45:56Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 11:03:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:34:09Z.


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

  • Debug (--preset dev): ctest --preset dev -R '^cpu_aot_sse_fp(_pd)?$' --no-tests=error --output-on-failure — 2/2 passed (cpu_aot_sse_fp 7.97s, cpu_aot_sse_fp_pd 22.36s)
  • Release /O2 (--preset release): ctest --preset release -R '^cpu_aot_sse_fp(_pd)?$' --no-tests=error --output-on-failure — 2/2 passed (cpu_aot_sse_fp 7.80s, cpu_aot_sse_fp_pd 21.92s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128954285 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#issuecomment-7128954285). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:34:09Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `7a147016`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^cpu_aot_sse_fp(_pd)?$' --no-tests=error --output-on-failure` — **2/2 passed** (`cpu_aot_sse_fp` 7.97s, `cpu_aot_sse_fp_pd` 22.36s) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^cpu_aot_sse_fp(_pd)?$' --no-tests=error --output-on-failure` — **2/2 passed** (`cpu_aot_sse_fp` 7.80s, `cpu_aot_sse_fp_pd` 21.92s)
chatgpt-codex-connector[bot commented 2026-11-24 11:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:34:21Z.


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-24T10:40:27.910537Z 7a14701 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:7128958697 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#issuecomment-7128958697). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T10:34:21Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7a1470168570bfe51e7ce98f5ee0b7d8f0a80845","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-24T10:40:27.910537Z">2026-11-24T10:40:27.910537Z</relative-time> | `7a14701` | 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>
chatgpt-codex-connector[bot commented 2026-11-24 11:03:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:40:25Z.

Code review location: tests/cpu/sse_fp_pd_check.py; line 167

@@ -84,6 +88,91 @@ def arith_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None
     return bytes(out), bytes(wild)
 
 
+def cmp_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None):
+    """Expected 32-byte output of a compare export: two 64-bit masks, the upper half keeps its fill.
+    The ALTER_IMM build assembles predicate (n xor 4)."""
+    pred = CMP_PREDICATE[name] ^ (4 if altered else 0)
+    source = {"op_cmppd_mem": b[0:16], "op_cmppd_mem_disp": b[16:32], "op_cmppd_self": a[0:16]}.get(name, b[0:16])
+    return pk_q(*ref.compare(a[0:16], source, pred, mode, quirk)) + FILL[16:]
+
+
+def check_cmp_differential(native_path, lifted_path, altered_path):
+    native = base.bind_exports(native_path, "", CMP_EXPORTS)
+    lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS)
+    altered = base.bind_exports(altered_path, "lifted_", CMP_EXPORTS)
+    pairs = arith_pairs()
+    for name in CMP_EXPORTS:
+        diverged = 0
+        for idx, (a, b) in enumerate(pairs):
+            want = cmp_reference(name, a, b)
+            base.assert_equal_output("native", name, idx, base.invoke(native[name], a, b), want)
+            base.assert_equal_output("lifted", name, idx, base.invoke(lifted[name], a, b), want)
+            got_alt = base.invoke(altered[name], a, b)
+            base.assert_equal_output("altered", name, idx, got_alt, cmp_reference(name, a, b, altered=True))
+            diverged += got_alt != want
+        if not diverged:
+            raise AssertionError(f"altered control {name} did not diverge from original")
+    want = cmp_reference("op_cmppd_0", *pairs[0])
+    mutated = bytearray(want)
+    mutated[9] ^= 0x80
+    try:
+        base.assert_equal_output("mutation", "op_cmppd_0", 0, bytes(mutated), want)
+    except AssertionError:
+        pass
+    else:
+        raise AssertionError("mutated compare mask was not caught by comparator")
+    print(f"{len(CMP_EXPORTS) * len(pairs)} native/lifted/reference packed double compare cases across "
+          f"{len(CMP_EXPORTS)} exports matched bit for bit; altered predicates diverged on every export")
+
+
+# Each wrong rule must disagree with the processor on some call in the given mode.
+CMP_QUIRKS = (
+    ("nan_ordered", "op_cmppd_3"), ("nan_ordered", "op_cmppd_7"), ("nan_ordered", "op_cmppd_0"),
+    ("zero_signed", "op_cmppd_0"), ("zero_signed", "op_cmppd_1"), ("eq_for_neq", "op_cmppd_4"),
+    ("lt_for_le", "op_cmppd_2"), ("swap_ord", "op_cmppd_3"), ("swap_ord", "op_cmppd_7"),
+    ("mask32", "op_cmppd_0"), ("numeric", "op_cmppd_5"), ("ignore_daz", "op_cmppd_0"),
+    ("ignore_daz", "op_cmppd_1"), ("ignore_daz", "op_cmppd_6"),
+)
+# UNORD and ORD only look at NaN, and a register compared with itself is equal to itself under any DAZ:
+# DAZ cannot change those exports. FTZ and rounding never matter to a compare.
+DAZ_BLIND = ("op_cmppd_3", "op_cmppd_7", "op_cmppd_self")
+
+
+def check_cmp_modes(native_path, lifted_path, harness_path):
+    driver = base.bind_mxcsr_driver(harness_path)
+    native = base.bind_exports(native_path, "", CMP_EXPORTS)
+    lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS)
+    pairs = arith_pairs()
+    seen = {}
+    modes = tuple(ref.Mode(rc, daz, ftz) for rc in range(4) for daz in (False, True) for ftz in (False, True))
+    for mode in modes:
+        for name in CMP_EXPORTS:
+            for idx, (a, b) in enumerate(pairs):
+                got_n = base.invoke_under(driver, native[name], mode.mxcsr(), a, b)
+                got_l = base.invoke_under(driver, lifted[name], mode.mxcsr(), a, b)
+                want = cmp_reference(name, a, b, mode)
+                base.assert_equal_output("native", f"{name} [{mode.label()}]", idx, got_n, want)
+                base.assert_equal_output("lifted", f"{name} [{mode.label()}]", idx, got_l, want)
+                seen[(name, mode.rc, mode.daz, mode.ftz, idx)] = got_n
+    for (name, rc, daz, ftz, idx), got in seen.items():
+        if got != seen[(name, 0, daz, False, idx)]:
+            raise AssertionError(f"{name} case {idx}: rounding mode or FTZ changed a compare result")
+    for name in CMP_EXPORTS:
+        moved = sum(seen[(name, 0, True, False, i)] != seen[(name, 0, False, False, i)] for i in range(len(pairs)))
+        if bool(moved) == (name in DAZ_BLIND):
+            raise AssertionError(f"{name}: DAZ changed {moved} results, expected {'none' if name in DAZ_BLIND else 'some'}")
+    for quirk, name in CMP_QUIRKS:
+        mode = ref.Mode(ref.RN, True, False) if quirk == "ignore_daz" else ref.DEFAULT_MODE
+        caught = sum(
+            cmp_reference(name, a, b, mode, quirk) != seen[(name, mode.rc, mode.daz, mode.ftz, idx)]

P2 Badge Pass mutation names through the quirk parameter

cmp_reference takes altered before quirk, so this fifth positional argument never selects a mutation. Every label in CMP_QUIRKS is a truthy string, which instead enables altered and flips the predicate by 4 while ref.compare receives quirk=None. Consequently, all 14 negative controls pass simply by complementing the result, even if their mutation handlers are no-ops, and the success message falsely claims the NaN, signed-zero, mask-width and DAZ controls were exercised. Pass quirk=quirk so each intended wrong rule is actually evaluated.

AGENTS.md reference: AGENTS.md:L171-L171

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4678763558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#discussion_r4678763558). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T10:40:25Z. **Code review location:** `tests/cpu/sse_fp_pd_check.py`; line 167 ~~~~diff @@ -84,6 +88,91 @@ def arith_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None return bytes(out), bytes(wild) +def cmp_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None): + """Expected 32-byte output of a compare export: two 64-bit masks, the upper half keeps its fill. + The ALTER_IMM build assembles predicate (n xor 4).""" + pred = CMP_PREDICATE[name] ^ (4 if altered else 0) + source = {"op_cmppd_mem": b[0:16], "op_cmppd_mem_disp": b[16:32], "op_cmppd_self": a[0:16]}.get(name, b[0:16]) + return pk_q(*ref.compare(a[0:16], source, pred, mode, quirk)) + FILL[16:] + + +def check_cmp_differential(native_path, lifted_path, altered_path): + native = base.bind_exports(native_path, "", CMP_EXPORTS) + lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS) + altered = base.bind_exports(altered_path, "lifted_", CMP_EXPORTS) + pairs = arith_pairs() + for name in CMP_EXPORTS: + diverged = 0 + for idx, (a, b) in enumerate(pairs): + want = cmp_reference(name, a, b) + base.assert_equal_output("native", name, idx, base.invoke(native[name], a, b), want) + base.assert_equal_output("lifted", name, idx, base.invoke(lifted[name], a, b), want) + got_alt = base.invoke(altered[name], a, b) + base.assert_equal_output("altered", name, idx, got_alt, cmp_reference(name, a, b, altered=True)) + diverged += got_alt != want + if not diverged: + raise AssertionError(f"altered control {name} did not diverge from original") + want = cmp_reference("op_cmppd_0", *pairs[0]) + mutated = bytearray(want) + mutated[9] ^= 0x80 + try: + base.assert_equal_output("mutation", "op_cmppd_0", 0, bytes(mutated), want) + except AssertionError: + pass + else: + raise AssertionError("mutated compare mask was not caught by comparator") + print(f"{len(CMP_EXPORTS) * len(pairs)} native/lifted/reference packed double compare cases across " + f"{len(CMP_EXPORTS)} exports matched bit for bit; altered predicates diverged on every export") + + +# Each wrong rule must disagree with the processor on some call in the given mode. +CMP_QUIRKS = ( + ("nan_ordered", "op_cmppd_3"), ("nan_ordered", "op_cmppd_7"), ("nan_ordered", "op_cmppd_0"), + ("zero_signed", "op_cmppd_0"), ("zero_signed", "op_cmppd_1"), ("eq_for_neq", "op_cmppd_4"), + ("lt_for_le", "op_cmppd_2"), ("swap_ord", "op_cmppd_3"), ("swap_ord", "op_cmppd_7"), + ("mask32", "op_cmppd_0"), ("numeric", "op_cmppd_5"), ("ignore_daz", "op_cmppd_0"), + ("ignore_daz", "op_cmppd_1"), ("ignore_daz", "op_cmppd_6"), +) +# UNORD and ORD only look at NaN, and a register compared with itself is equal to itself under any DAZ: +# DAZ cannot change those exports. FTZ and rounding never matter to a compare. +DAZ_BLIND = ("op_cmppd_3", "op_cmppd_7", "op_cmppd_self") + + +def check_cmp_modes(native_path, lifted_path, harness_path): + driver = base.bind_mxcsr_driver(harness_path) + native = base.bind_exports(native_path, "", CMP_EXPORTS) + lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS) + pairs = arith_pairs() + seen = {} + modes = tuple(ref.Mode(rc, daz, ftz) for rc in range(4) for daz in (False, True) for ftz in (False, True)) + for mode in modes: + for name in CMP_EXPORTS: + for idx, (a, b) in enumerate(pairs): + got_n = base.invoke_under(driver, native[name], mode.mxcsr(), a, b) + got_l = base.invoke_under(driver, lifted[name], mode.mxcsr(), a, b) + want = cmp_reference(name, a, b, mode) + base.assert_equal_output("native", f"{name} [{mode.label()}]", idx, got_n, want) + base.assert_equal_output("lifted", f"{name} [{mode.label()}]", idx, got_l, want) + seen[(name, mode.rc, mode.daz, mode.ftz, idx)] = got_n + for (name, rc, daz, ftz, idx), got in seen.items(): + if got != seen[(name, 0, daz, False, idx)]: + raise AssertionError(f"{name} case {idx}: rounding mode or FTZ changed a compare result") + for name in CMP_EXPORTS: + moved = sum(seen[(name, 0, True, False, i)] != seen[(name, 0, False, False, i)] for i in range(len(pairs))) + if bool(moved) == (name in DAZ_BLIND): + raise AssertionError(f"{name}: DAZ changed {moved} results, expected {'none' if name in DAZ_BLIND else 'some'}") + for quirk, name in CMP_QUIRKS: + mode = ref.Mode(ref.RN, True, False) if quirk == "ignore_daz" else ref.DEFAULT_MODE + caught = sum( + cmp_reference(name, a, b, mode, quirk) != seen[(name, mode.rc, mode.daz, mode.ftz, idx)] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Pass mutation names through the quirk parameter** `cmp_reference` takes `altered` before `quirk`, so this fifth positional argument never selects a mutation. Every label in `CMP_QUIRKS` is a truthy string, which instead enables `altered` and flips the predicate by 4 while `ref.compare` receives `quirk=None`. Consequently, all 14 negative controls pass simply by complementing the result, even if their mutation handlers are no-ops, and the success message falsely claims the NaN, signed-zero, mask-width and DAZ controls were exercised. Pass `quirk=quirk` so each intended wrong rule is actually evaluated. AGENTS.md reference: [AGENTS.md:L171-L171](https://github.com/R0Y00/Xbox2Windows/blob/7a1470168570bfe51e7ce98f5ee0b7d8f0a80845/AGENTS.md#L171-L171) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 11:03:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:45:56Z.

Code review location: tests/cpu/sse_fp_pd_check.py; line 167

@@ -84,6 +88,91 @@ def arith_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None
     return bytes(out), bytes(wild)
 
 
+def cmp_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None):
+    """Expected 32-byte output of a compare export: two 64-bit masks, the upper half keeps its fill.
+    The ALTER_IMM build assembles predicate (n xor 4)."""
+    pred = CMP_PREDICATE[name] ^ (4 if altered else 0)
+    source = {"op_cmppd_mem": b[0:16], "op_cmppd_mem_disp": b[16:32], "op_cmppd_self": a[0:16]}.get(name, b[0:16])
+    return pk_q(*ref.compare(a[0:16], source, pred, mode, quirk)) + FILL[16:]
+
+
+def check_cmp_differential(native_path, lifted_path, altered_path):
+    native = base.bind_exports(native_path, "", CMP_EXPORTS)
+    lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS)
+    altered = base.bind_exports(altered_path, "lifted_", CMP_EXPORTS)
+    pairs = arith_pairs()
+    for name in CMP_EXPORTS:
+        diverged = 0
+        for idx, (a, b) in enumerate(pairs):
+            want = cmp_reference(name, a, b)
+            base.assert_equal_output("native", name, idx, base.invoke(native[name], a, b), want)
+            base.assert_equal_output("lifted", name, idx, base.invoke(lifted[name], a, b), want)
+            got_alt = base.invoke(altered[name], a, b)
+            base.assert_equal_output("altered", name, idx, got_alt, cmp_reference(name, a, b, altered=True))
+            diverged += got_alt != want
+        if not diverged:
+            raise AssertionError(f"altered control {name} did not diverge from original")
+    want = cmp_reference("op_cmppd_0", *pairs[0])
+    mutated = bytearray(want)
+    mutated[9] ^= 0x80
+    try:
+        base.assert_equal_output("mutation", "op_cmppd_0", 0, bytes(mutated), want)
+    except AssertionError:
+        pass
+    else:
+        raise AssertionError("mutated compare mask was not caught by comparator")
+    print(f"{len(CMP_EXPORTS) * len(pairs)} native/lifted/reference packed double compare cases across "
+          f"{len(CMP_EXPORTS)} exports matched bit for bit; altered predicates diverged on every export")
+
+
+# Each wrong rule must disagree with the processor on some call in the given mode.
+CMP_QUIRKS = (
+    ("nan_ordered", "op_cmppd_3"), ("nan_ordered", "op_cmppd_7"), ("nan_ordered", "op_cmppd_0"),
+    ("zero_signed", "op_cmppd_0"), ("zero_signed", "op_cmppd_1"), ("eq_for_neq", "op_cmppd_4"),
+    ("lt_for_le", "op_cmppd_2"), ("swap_ord", "op_cmppd_3"), ("swap_ord", "op_cmppd_7"),
+    ("mask32", "op_cmppd_0"), ("numeric", "op_cmppd_5"), ("ignore_daz", "op_cmppd_0"),
+    ("ignore_daz", "op_cmppd_1"), ("ignore_daz", "op_cmppd_6"),
+)
+# UNORD and ORD only look at NaN, and a register compared with itself is equal to itself under any DAZ:
+# DAZ cannot change those exports. FTZ and rounding never matter to a compare.
+DAZ_BLIND = ("op_cmppd_3", "op_cmppd_7", "op_cmppd_self")
+
+
+def check_cmp_modes(native_path, lifted_path, harness_path):
+    driver = base.bind_mxcsr_driver(harness_path)
+    native = base.bind_exports(native_path, "", CMP_EXPORTS)
+    lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS)
+    pairs = arith_pairs()
+    seen = {}
+    modes = tuple(ref.Mode(rc, daz, ftz) for rc in range(4) for daz in (False, True) for ftz in (False, True))
+    for mode in modes:
+        for name in CMP_EXPORTS:
+            for idx, (a, b) in enumerate(pairs):
+                got_n = base.invoke_under(driver, native[name], mode.mxcsr(), a, b)
+                got_l = base.invoke_under(driver, lifted[name], mode.mxcsr(), a, b)
+                want = cmp_reference(name, a, b, mode)
+                base.assert_equal_output("native", f"{name} [{mode.label()}]", idx, got_n, want)
+                base.assert_equal_output("lifted", f"{name} [{mode.label()}]", idx, got_l, want)
+                seen[(name, mode.rc, mode.daz, mode.ftz, idx)] = got_n
+    for (name, rc, daz, ftz, idx), got in seen.items():
+        if got != seen[(name, 0, daz, False, idx)]:
+            raise AssertionError(f"{name} case {idx}: rounding mode or FTZ changed a compare result")
+    for name in CMP_EXPORTS:
+        moved = sum(seen[(name, 0, True, False, i)] != seen[(name, 0, False, False, i)] for i in range(len(pairs)))
+        if bool(moved) == (name in DAZ_BLIND):
+            raise AssertionError(f"{name}: DAZ changed {moved} results, expected {'none' if name in DAZ_BLIND else 'some'}")
+    for quirk, name in CMP_QUIRKS:
+        mode = ref.Mode(ref.RN, True, False) if quirk == "ignore_daz" else ref.DEFAULT_MODE
+        caught = sum(
+            cmp_reference(name, a, b, mode, quirk) != seen[(name, mode.rc, mode.daz, mode.ftz, idx)]

Fixed in 0588fd7c: passed quirk=quirk explicitly to cmp_reference in check_cmp_modes (all other cmp_reference call sites checked). Verified locally that all 14 entries in CMP_QUIRKS diverge from quirk=None and Win2025 cpu_aot_sse_fp(_pd)? passed 2/2 in Debug & Release /O2.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4678835874 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1397#discussion_r4678835874). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:45:56Z. **Code review location:** `tests/cpu/sse_fp_pd_check.py`; line 167 ~~~~diff @@ -84,6 +88,91 @@ def arith_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None return bytes(out), bytes(wild) +def cmp_reference(name, a, b, mode=ref.DEFAULT_MODE, altered=False, quirk=None): + """Expected 32-byte output of a compare export: two 64-bit masks, the upper half keeps its fill. + The ALTER_IMM build assembles predicate (n xor 4).""" + pred = CMP_PREDICATE[name] ^ (4 if altered else 0) + source = {"op_cmppd_mem": b[0:16], "op_cmppd_mem_disp": b[16:32], "op_cmppd_self": a[0:16]}.get(name, b[0:16]) + return pk_q(*ref.compare(a[0:16], source, pred, mode, quirk)) + FILL[16:] + + +def check_cmp_differential(native_path, lifted_path, altered_path): + native = base.bind_exports(native_path, "", CMP_EXPORTS) + lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS) + altered = base.bind_exports(altered_path, "lifted_", CMP_EXPORTS) + pairs = arith_pairs() + for name in CMP_EXPORTS: + diverged = 0 + for idx, (a, b) in enumerate(pairs): + want = cmp_reference(name, a, b) + base.assert_equal_output("native", name, idx, base.invoke(native[name], a, b), want) + base.assert_equal_output("lifted", name, idx, base.invoke(lifted[name], a, b), want) + got_alt = base.invoke(altered[name], a, b) + base.assert_equal_output("altered", name, idx, got_alt, cmp_reference(name, a, b, altered=True)) + diverged += got_alt != want + if not diverged: + raise AssertionError(f"altered control {name} did not diverge from original") + want = cmp_reference("op_cmppd_0", *pairs[0]) + mutated = bytearray(want) + mutated[9] ^= 0x80 + try: + base.assert_equal_output("mutation", "op_cmppd_0", 0, bytes(mutated), want) + except AssertionError: + pass + else: + raise AssertionError("mutated compare mask was not caught by comparator") + print(f"{len(CMP_EXPORTS) * len(pairs)} native/lifted/reference packed double compare cases across " + f"{len(CMP_EXPORTS)} exports matched bit for bit; altered predicates diverged on every export") + + +# Each wrong rule must disagree with the processor on some call in the given mode. +CMP_QUIRKS = ( + ("nan_ordered", "op_cmppd_3"), ("nan_ordered", "op_cmppd_7"), ("nan_ordered", "op_cmppd_0"), + ("zero_signed", "op_cmppd_0"), ("zero_signed", "op_cmppd_1"), ("eq_for_neq", "op_cmppd_4"), + ("lt_for_le", "op_cmppd_2"), ("swap_ord", "op_cmppd_3"), ("swap_ord", "op_cmppd_7"), + ("mask32", "op_cmppd_0"), ("numeric", "op_cmppd_5"), ("ignore_daz", "op_cmppd_0"), + ("ignore_daz", "op_cmppd_1"), ("ignore_daz", "op_cmppd_6"), +) +# UNORD and ORD only look at NaN, and a register compared with itself is equal to itself under any DAZ: +# DAZ cannot change those exports. FTZ and rounding never matter to a compare. +DAZ_BLIND = ("op_cmppd_3", "op_cmppd_7", "op_cmppd_self") + + +def check_cmp_modes(native_path, lifted_path, harness_path): + driver = base.bind_mxcsr_driver(harness_path) + native = base.bind_exports(native_path, "", CMP_EXPORTS) + lifted = base.bind_exports(lifted_path, "lifted_", CMP_EXPORTS) + pairs = arith_pairs() + seen = {} + modes = tuple(ref.Mode(rc, daz, ftz) for rc in range(4) for daz in (False, True) for ftz in (False, True)) + for mode in modes: + for name in CMP_EXPORTS: + for idx, (a, b) in enumerate(pairs): + got_n = base.invoke_under(driver, native[name], mode.mxcsr(), a, b) + got_l = base.invoke_under(driver, lifted[name], mode.mxcsr(), a, b) + want = cmp_reference(name, a, b, mode) + base.assert_equal_output("native", f"{name} [{mode.label()}]", idx, got_n, want) + base.assert_equal_output("lifted", f"{name} [{mode.label()}]", idx, got_l, want) + seen[(name, mode.rc, mode.daz, mode.ftz, idx)] = got_n + for (name, rc, daz, ftz, idx), got in seen.items(): + if got != seen[(name, 0, daz, False, idx)]: + raise AssertionError(f"{name} case {idx}: rounding mode or FTZ changed a compare result") + for name in CMP_EXPORTS: + moved = sum(seen[(name, 0, True, False, i)] != seen[(name, 0, False, False, i)] for i in range(len(pairs))) + if bool(moved) == (name in DAZ_BLIND): + raise AssertionError(f"{name}: DAZ changed {moved} results, expected {'none' if name in DAZ_BLIND else 'some'}") + for quirk, name in CMP_QUIRKS: + mode = ref.Mode(ref.RN, True, False) if quirk == "ignore_daz" else ref.DEFAULT_MODE + caught = sum( + cmp_reference(name, a, b, mode, quirk) != seen[(name, mode.rc, mode.daz, mode.ftz, idx)] ~~~~ --- Fixed in 0588fd7c: passed `quirk=quirk` explicitly to `cmp_reference` in `check_cmp_modes` (all other `cmp_reference` call sites checked). Verified locally that all 14 entries in `CMP_QUIRKS` diverge from `quirk=None` and Win2025 `cpu_aot_sse_fp(_pd)?` passed 2/2 in Debug & Release `/O2`.
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!1390
No description provided.