cpu: lower baseline 128-bit SSE3 and SSE4.1 floating-point instructions #596

Merged
MarlomMedeiros merged 4 commits from upstream-pr/602 into main 2026-11-23 14:36:34 +00:00
MarlomMedeiros commented 2026-11-22 15:11:39 +00:00 (Migrated from github.com)

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


Summary

  • tools/ffx_version_query.py: lower 22 legacy-encoding 128-bit SSE3/SSE4.1 floating-point instructions for tracked xmm0-xmm2 (wide0-wide2): addsubps/pd, haddps/pd, hsubps/pd, movddup, movsldup, movshdup, lddqu, roundps/pd, roundss/sd, dpps, dppd, blendps/pd, blendvps/pd, insertps, extractps. FP arithmetic emits the matching host intrinsics; data movement is byte-level; upper YMM bytes are preserved. MMX, VEX, untracked XMM and movntdqa stay rejected.
  • tests/cpu/sse34_fp.{asm,def,py}: source-built MASM fixture with 33 exports, three-way differential check (native DLL, lifted DLL, independent IEEE-754 Fraction reference), NaN/denormal/-0.0 cases, immediate sweeps (all 256 insertps imm8 values, all blendps/blendpd immediates, 16+1 dppd and 18 representative dpps masks, all four rounding modes plus the MXCSR-select and NO_EXC bits), narrow memory widths (m32/m64/m128 guarded), 4 mutated lifted controls that must mismatch, rejection checks (MMX, VEX, xmm3+, movntdqa), and a CPUID SSE3+SSE4.1 probe that exits 77 on incapable hosts.
  • CMakeLists.txt: registers cpu_aot_sse34_fp with SKIP_RETURN_CODE 77, same shape as the SSE2 batches.
  • docs/experiments.md: records the forms, the fixture checks and the reproduction commands.

Test plan

Commit under test: 3ba5fec on cpu-sse34-fp (rebased on current main).

  • cmake --build --preset dev --target cpu_sse34_fp_lifted
  • ctest --preset dev --no-tests=error -R '^cpu_aot_sse34_fp$' -V → 1/1 Passed: 950 baseline 128-bit SSE3/SSE4.1 FP cases across 33 exports matched native DLL and reference; 4 mutated controls mismatched as required
  • Neighbours sharing lower(): ctest --preset dev --no-tests=error -R 'cpu_aot_(sse2_int|sse2_sat_mul|sse41|sse41_int|sse41_extend|sse41_42_misc|string_ops|version_query|wide_arith)' → 8/8 Passed.
  • Environment: x64 Windows, MSVC 19.52.37029.0 / ML64 14.52.37029.0, host CPU exposes SSE3+SSE4.1 (CPUID probe not skipped).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544007565 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-22T15:11:39Z. --- ## Summary - `tools/ffx_version_query.py`: lower 22 legacy-encoding 128-bit SSE3/SSE4.1 floating-point instructions for tracked `xmm0`-`xmm2` (`wide0`-`wide2`): `addsubps`/`pd`, `haddps`/`pd`, `hsubps`/`pd`, `movddup`, `movsldup`, `movshdup`, `lddqu`, `roundps`/`pd`, `roundss`/`sd`, `dpps`, `dppd`, `blendps`/`pd`, `blendvps`/`pd`, `insertps`, `extractps`. FP arithmetic emits the matching host intrinsics; data movement is byte-level; upper YMM bytes are preserved. MMX, VEX, untracked XMM and `movntdqa` stay rejected. - `tests/cpu/sse34_fp.{asm,def,py}`: source-built MASM fixture with 33 exports, three-way differential check (native DLL, lifted DLL, independent IEEE-754 `Fraction` reference), NaN/denormal/-0.0 cases, immediate sweeps (all 256 `insertps` imm8 values, all `blendps`/`blendpd` immediates, 16+1 `dppd` and 18 representative `dpps` masks, all four rounding modes plus the MXCSR-select and NO_EXC bits), narrow memory widths (m32/m64/m128 guarded), 4 mutated lifted controls that must mismatch, rejection checks (MMX, VEX, `xmm3`+, `movntdqa`), and a CPUID SSE3+SSE4.1 probe that exits 77 on incapable hosts. - `CMakeLists.txt`: registers `cpu_aot_sse34_fp` with `SKIP_RETURN_CODE 77`, same shape as the SSE2 batches. - `docs/experiments.md`: records the forms, the fixture checks and the reproduction commands. #### Test plan Commit under test: `3ba5fec` on `cpu-sse34-fp` (rebased on current `main`). - `cmake --build --preset dev --target cpu_sse34_fp_lifted` - `ctest --preset dev --no-tests=error -R '^cpu_aot_sse34_fp$' -V` → 1/1 Passed: `950 baseline 128-bit SSE3/SSE4.1 FP cases across 33 exports matched native DLL and reference; 4 mutated controls mismatched as required` - Neighbours sharing `lower()`: `ctest --preset dev --no-tests=error -R 'cpu_aot_(sse2_int|sse2_sat_mul|sse41|sse41_int|sse41_extend|sse41_42_misc|string_ops|version_query|wide_arith)'` → 8/8 Passed. - Environment: x64 Windows, MSVC 19.52.37029.0 / ML64 14.52.37029.0, host CPU exposes SSE3+SSE4.1 (CPUID probe not skipped).
upstream-sync closed this pull request 2026-11-24 06:43:53 +00:00
copilot-pull-request-reviewer[bot commented 2026-11-24 06:43:53 +00:00 (Migrated from github.com)

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

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:6012956408 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#pullrequestreview-6012956408). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-22T15:11:47Z. **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.
R0Y00 commented 2026-11-24 06:43:53 +00:00 (Migrated from github.com)

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

Review: DISMISSED


The improved dot-product reference is useful. The new packed memory path loads into an unaligned host temporary and then runs a register intrinsic, which can hide a guest alignment fault. A source-built native probe on an i9-14900HX (Windows build 26200) gave correct results for aligned DPPS and HADDPS sources, and both reported access violation reading 0xFFFFFFFFFFFFFFFF at a 4-byte misalignment inside readable storage. Please keep the register forms and the established narrow/unaligned moves, and restrict the packed memory forms unless their native alignment behavior is modeled and independently tested. Keep the existing width and NaN cases. This overlaps #375, so I am keeping the two changes in one review queue.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6017868776 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#pullrequestreview-6017868776). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T07:30:38Z. **Review:** DISMISSED --- The improved dot-product reference is useful. The new packed memory path loads into an unaligned host temporary and then runs a register intrinsic, which can hide a guest alignment fault. A source-built native probe on an i9-14900HX (Windows build 26200) gave correct results for aligned `DPPS` and `HADDPS` sources, and both reported `access violation reading 0xFFFFFFFFFFFFFFFF` at a 4-byte misalignment inside readable storage. Please keep the register forms and the established narrow/unaligned moves, and restrict the packed memory forms unless their native alignment behavior is modeled and independently tested. Keep the existing width and NaN cases. This overlaps #375, so I am keeping the two changes in one review queue.
legacy-code-archaeologist commented 2026-11-24 06:48:39 +00:00 (Migrated from github.com)

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


cpu_aot_sse34_fp fails at 3ba5fec on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. The other 113 cpu_ tests pass, with the usual cpu_aot_crypto_sha capability skip.

ctest --preset dev --no-tests=error -R cpu_aot_sse34_fp -V
AssertionError: dpps_op(arg3=0xf4): a=4523c17f0000807f2301807f000080ff b=2143c5ff0000807f0000803f00000000
  expected=00000000000000004523c17f00000000 native=00000000000000000000c0ff00000000 lifted=00000000000000000000c0ff00000000

Native and translated agree; only the Fraction reference differs. Decoded lanes (imm 0xf4: all four products, result in lane 2):

lane a b product
0 0x7fc12345 QNaN 0xffc54321 QNaN QNaN from a
1 0x7f800000 +inf 0x7f800000 +inf +inf
2 0x7f800123 SNaN 0x3f800000 1.0 quieted SNaN
3 0xff800000 −inf 0x00000000 0.0 invalid → indefinite
  • Reference: it sums (t0+t1)+(t2+t3) with "first NaN operand wins" and returns lane 0's NaN, 0x7fc12345.
  • Skylake: it returns the indefinite 0xffc00000 produced by the −inf × 0 lane. Which NaN DPPS returns when several lanes are NaN is therefore vendor-dependent, and the reference encodes one vendor's choice. The description does not name the CPU of the passing run. If it was AMD, this would be the Intel/AMD difference.

Two related observations:

  1. The generated translation lowers DPPS to _mm_dp_ps(...) (out/build/dev/cpu_sse34_fp_lifted.cpp), so it runs the host's own DPPS. Native and translated therefore always agree on DPPS on the same host. The real check is against the reference, and on another vendor the translated result follows that vendor rather than the reference.
  2. To keep the check portable, the multi-NaN DPPS cases could accept the vendor-dependent choice (for example, require that the result is a NaN that native and translated share), or move to a separate, documented vendor-specific case. If the reference is meant to pin the guest CPU's behavior, the translation would need its own NaN selection instead of _mm_dp_ps.

The head also no longer merges cleanly with main (git merge-tree).

AI-assisted: run and analyzed with Claude Code; outputs copied from the local run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7083777663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#issuecomment-7083777663). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T18:40:03Z. --- `cpu_aot_sse34_fp` **fails** at `3ba5fec` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. The other 113 `cpu_` tests pass, with the usual `cpu_aot_crypto_sha` capability skip. ```text ctest --preset dev --no-tests=error -R cpu_aot_sse34_fp -V AssertionError: dpps_op(arg3=0xf4): a=4523c17f0000807f2301807f000080ff b=2143c5ff0000807f0000803f00000000 expected=00000000000000004523c17f00000000 native=00000000000000000000c0ff00000000 lifted=00000000000000000000c0ff00000000 ``` Native and translated agree; only the `Fraction` reference differs. Decoded lanes (imm `0xf4`: all four products, result in lane 2): | lane | a | b | product | |---|---|---|---| | 0 | `0x7fc12345` QNaN | `0xffc54321` QNaN | QNaN from a | | 1 | `0x7f800000` +inf | `0x7f800000` +inf | +inf | | 2 | `0x7f800123` SNaN | `0x3f800000` 1.0 | quieted SNaN | | 3 | `0xff800000` −inf | `0x00000000` 0.0 | invalid → indefinite | - **Reference:** it sums `(t0+t1)+(t2+t3)` with "first NaN operand wins" and returns lane 0's NaN, `0x7fc12345`. - **Skylake:** it returns the indefinite `0xffc00000` produced by the `−inf × 0` lane. Which NaN DPPS returns when several lanes are NaN is therefore vendor-dependent, and the reference encodes one vendor's choice. The description does not name the CPU of the passing run. If it was AMD, this would be the Intel/AMD difference. Two related observations: 1. The generated translation lowers DPPS to `_mm_dp_ps(...)` (`out/build/dev/cpu_sse34_fp_lifted.cpp`), so it runs the host's own DPPS. Native and translated therefore always agree on DPPS on the same host. The real check is against the reference, and on another vendor the translated result follows that vendor rather than the reference. 2. To keep the check portable, the multi-NaN DPPS cases could accept the vendor-dependent choice (for example, require that the result is a NaN that native and translated share), or move to a separate, documented vendor-specific case. If the reference is meant to pin the guest CPU's behavior, the translation would need its own NaN selection instead of `_mm_dp_ps`. The head also no longer merges cleanly with `main` (`git merge-tree`). AI-assisted: run and analyzed with Claude Code; outputs copied from the local run.
MarlomMedeiros commented 2026-11-24 06:48:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MarlomMedeiros on 2026-11-22T19:15:05Z.


Confirmed, and thanks for the detailed report. The diagnosis was right: for dpps_op(arg3=0xf4) the product vector contains multiple NaN producers (0x7fc12345, 0x7fc00123 quieted sNaN, and 0xffc00000 from -inf * 0), and the Intel Core i7-6820HQ reduction picks a different legal NaN than the reference model's fixed "first NaN operand wins" order. Native and lifted agreed because the lifted code emits _mm_dp_ps; only the independent reference was over-strict.

Fix (pushed in e2526e1, rebased onto edc2e54): tests/cpu/sse34_fp.py now computes an allowable-result set for dpps_op/dppd_op. Disabled product lanes are masked to +0.0, then every operand ordering of each commutative multiply and of each pairwise add in the architectural (t0+t1)+(t2+t3) / t0+t1 trees is enumerated. The check requires: native output identical to lifted bit-for-bit, disabled destination lanes exactly +0.0, all enabled lanes holding one identical scalar, and that scalar inside the allowed set. For the reported inputs the set is {0x7fc00123, 0x7fc12345, 0xffc00000, 0xffc54321}, covering both the Skylake observation and the previous AMD result while still rejecting foreign payloads, unquieted sNaNs, disabled-lane leakage, and wrong reductions.

ctest --preset dev --no-tests=error -R '^cpu_aot_sse34_fp$' -V passes here: 950 baseline 128-bit SSE3/SSE4.1 FP cases across 33 exports matched native DLL and reference; 4 mutated controls mismatched as required (AMD Ryzen 7 5800X3D, native==lifted bit-exact). The rebase also resolved the CMakeLists.txt / docs/experiments.md / tools/ffx_version_query.py conflicts against current main.

AI-assisted: yes. All reported checks ran locally on the hardware listed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7084238080 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#issuecomment-7084238080). Originally posted by [MarlomMedeiros](https://github.com/MarlomMedeiros) on 2026-11-22T19:15:05Z. --- Confirmed, and thanks for the detailed report. The diagnosis was right: for `dpps_op(arg3=0xf4)` the product vector contains multiple NaN producers (`0x7fc12345`, `0x7fc00123` quieted sNaN, and `0xffc00000` from `-inf * 0`), and the Intel Core i7-6820HQ reduction picks a different legal NaN than the reference model's fixed "first NaN operand wins" order. Native and lifted agreed because the lifted code emits `_mm_dp_ps`; only the independent reference was over-strict. **Fix (pushed in `e2526e1`, rebased onto `edc2e54`)**: `tests/cpu/sse34_fp.py` now computes an allowable-result set for `dpps_op`/`dppd_op`. Disabled product lanes are masked to `+0.0`, then every operand ordering of each commutative multiply and of each pairwise add in the architectural `(t0+t1)+(t2+t3)` / `t0+t1` trees is enumerated. The check requires: native output identical to lifted bit-for-bit, disabled destination lanes exactly `+0.0`, all enabled lanes holding one identical scalar, and that scalar inside the allowed set. For the reported inputs the set is `{0x7fc00123, 0x7fc12345, 0xffc00000, 0xffc54321}`, covering both the Skylake observation and the previous AMD result while still rejecting foreign payloads, unquieted sNaNs, disabled-lane leakage, and wrong reductions. `ctest --preset dev --no-tests=error -R '^cpu_aot_sse34_fp$' -V` passes here: `950 baseline 128-bit SSE3/SSE4.1 FP cases across 33 exports matched native DLL and reference; 4 mutated controls mismatched as required` (AMD Ryzen 7 5800X3D, native==lifted bit-exact). The rebase also resolved the `CMakeLists.txt` / `docs/experiments.md` / `tools/ffx_version_query.py` conflicts against current `main`. AI-assisted: yes. All reported checks ran locally on the hardware listed.
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:16:25Z.


New independent evidence for e2526e1 after resolving the current main conflicts locally. On Windows build 26200.9974 (MSVC/ML64 19.51, dev preset), the native and lifted DPPS outputs agree at mask 0xff, but the test rejects their lane-specific NaNs. For a=4523c17f0000807f2301807f000080ff and b=2143c5ff0000807f0000803f00000000 both outputs were 4523c17f4523c17f0000c0ff2301c07f. The current check requires every enabled result lane to have the same payload. Please allow lane-specific quiet NaNs only for the already identified ambiguous multi-producer case, while continuing to compare native and lifted bits, disabled zero lanes and determinate results exactly.

I also expanded the original alignment probe with aligned and +4 pointers into readable storage. All 16 packed m128 arithmetic, duplication, rounding, dot-product and blend forms accepted the aligned pointer and raised access violation at +4. LDDQU accepted both. This supports keeping LDDQU and the narrow forms separate from the aligned full-width path. The existing changes request still applies.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7102300810 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#issuecomment-7102300810). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T13:16:25Z. --- New independent evidence for e2526e1 after resolving the current main conflicts locally. On Windows build 26200.9974 (MSVC/ML64 19.51, dev preset), the native and lifted DPPS outputs agree at mask 0xff, but the test rejects their lane-specific NaNs. For a=4523c17f0000807f2301807f000080ff and b=2143c5ff0000807f0000803f00000000 both outputs were 4523c17f4523c17f0000c0ff2301c07f. The current check requires every enabled result lane to have the same payload. Please allow lane-specific quiet NaNs only for the already identified ambiguous multi-producer case, while continuing to compare native and lifted bits, disabled zero lanes and determinate results exactly. I also expanded the original alignment probe with aligned and +4 pointers into readable storage. All 16 packed m128 arithmetic, duplication, rounding, dot-product and blend forms accepted the aligned pointer and raised access violation at +4. LDDQU accepted both. This supports keeping LDDQU and the narrow forms separate from the aligned full-width path. The existing changes request still applies.
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:29:53Z.


I pushed 3007320 to your branch. The full-width legacy SSE3/4.1 memory path checks the actual 16-byte alignment and reuses the existing Windows alignment-fault path. Four new +4 misalignment cases preserve the same native and translated read fault and the untouched output. LDDQU and narrow sources retain the previous behavior. The dot-product reference now checks each enabled lane against the allowed result set while keeping native/lifted equality and disabled-zero bits exact.

Windows dev and /O2 each passed the SSE3/4.1 fixture (950 comparisons, four mutations and the four new alignment controls) and the existing CMPXCHG fixture (120 comparisons plus its fault controls). The previous alignment review is resolved on this commit. GitHub CI is pending.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7102620367 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#issuecomment-7102620367). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T13:29:53Z. --- I pushed 3007320 to your branch. The full-width legacy SSE3/4.1 memory path checks the actual 16-byte alignment and reuses the existing Windows alignment-fault path. Four new +4 misalignment cases preserve the same native and translated read fault and the untouched output. LDDQU and narrow sources retain the previous behavior. The dot-product reference now checks each enabled lane against the allowed result set while keeping native/lifted equality and disabled-zero bits exact. Windows dev and /O2 each passed the SSE3/4.1 fixture (950 comparisons, four mutations and the four new alignment controls) and the existing CMPXCHG fixture (120 comparisons plus its fault controls). The previous alignment review is resolved on this commit. GitHub CI is pending.
R0Y00 commented 2026-11-24 06:49:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T14:07:10Z.


The Windows rerun passed the SSE and WARP facing checks, but failed in the existing RCX branch fixture. All 7,712 native/translated cases matched before a deliberately mutated zero-count guard let LOOPNE scan past its backing bytes. #858 bounds that scan and keeps all three negative controls, which now pass locally in both dev and release. I’ll refresh this branch and recheck Windows after that fix lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7103507992 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/602#issuecomment-7103507992). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T14:07:10Z. --- The Windows rerun passed the SSE and WARP facing checks, but failed in the existing RCX branch fixture. All 7,712 native/translated cases matched before a deliberately mutated zero-count guard let LOOPNE scan past its backing bytes. #858 bounds that scan and keeps all three negative controls, which now pass locally in both dev and release. I’ll refresh this branch and recheck Windows after that fix lands.
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!596
No description provided.