cpu: lower legacy SSE2 packed double bitwise logic (ANDPD, ANDNPD, ORPD, XORPD) in cpu_sse_fp_aot #2340

Merged
Ammmae0x merged 1 commit from upstream-pr/2348 into main 2026-11-25 13:27:54 +00:00
Ammmae0x commented 2026-11-25 13:10:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T13:10:54Z.


Change

Lower legacy SSE2 packed double bitwise logic instructions (ANDPD, ANDNPD, ORPD, XORPD) in tools/cpu_sse_fp_aot.py and add a dedicated source-built differential, /O2, mutation, and rejection test suite (tests/cpu/sse_fp_pd_logic.{asm,def}, tests/cpu/sse_fp_pd_logic_check.py, registered as cpu_aot_sse_fp_pd_logic in CMakeLists.txt):

  • Add Code.ANDPD_XMM_XMMM128, Code.ANDNPD_XMM_XMMM128, Code.ORPD_XMM_XMMM128, and Code.XORPD_XMM_XMMM128 to BITWISE_LOGIC_FUNCTIONS, reusing the 128-bit lane-exact bitwise helpers (op_andps, op_andnps, op_orps, op_xorps) for XMM0..XMM5 and 16-byte-aligned [rcx|rdx|r8 + disp] m128 operands.
  • Extend the self-zeroing idiom check to XORPD xmmN, xmmN so undefined XMM0..XMM5 self-zeroing lowers to op_zero_vec().
  • Update out-of-scope rejection controls in tests/cpu/sse_fp_check.py and tests/cpu/sse_fp_pd_check.py to replace the newly supported andpd/xorpd entries with still-rejected legacy SSE2 forms (cvtdq2pd, unpckhpd).

Verification

Verified on commit c606907f (rebased onto upstream/main 7bc59951):

  • cmake --build --preset dev --target cpu_sse_fp_original cpu_sse_fp_original_lifted cpu_sse_fp_altered cpu_sse_fp_altered_lifted cpu_sse_fp_logic_original cpu_sse_fp_logic_original_lifted cpu_sse_fp_logic_altered cpu_sse_fp_logic_altered_lifted cpu_sse_fp_pd_original cpu_sse_fp_pd_original_lifted cpu_sse_fp_pd_altered cpu_sse_fp_pd_altered_lifted cpu_sse_fp_pd_logic_original cpu_sse_fp_pd_logic_original_lifted cpu_sse_fp_pd_logic_altered cpu_sse_fp_pd_logic_altered_lifted cpu_sse_fp_harness -> succeeded (exit 0)
  • ctest --preset dev -R "^cpu_aot_sse_fp" -E "cpu_native_archive_" --output-on-failure -V -> 100% tests passed, 0 tests failed out of 4 (cpu_aot_sse_fp, cpu_aot_sse_fp_logic, cpu_aot_sse_fp_pd, cpu_aot_sse_fp_pd_logic)
  • cmake --build --preset release --target ... -> succeeded (exit 0)
  • ctest --preset release -R "^cpu_aot_sse_fp" -E "cpu_native_archive_" --output-on-failure -V -> 100% tests passed, 0 tests failed out of 4 (22.52 sec; cpu_aot_sse_fp_pd_logic: 5 alt + 5 VEX/EVEX + 27 IR + 3 raw + 9 PE-patched + CLI, 1060 lifted + 1060 /O2 cases across 20 exports, ALTER_IMM diverged on {'op_andpd': 53, 'op_andnpd': 53, 'op_andnpd_mem': 53, 'op_orpd': 53, 'op_xorpd': 52, 'op_pd_logic_pipeline': 50})
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 453 links. (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1641 tracked source, script and build/CI files: no bidirectional controls. (exit 0)

No capability skips (baseline SSE2).

Evidence and follow-up

  • tests/cpu/sse_fp_pd_logic.asm (; coverage: source cpu_aot_sse_fp_pd_logic) is a clean-room synthetic MASM fixture covering all 4 instructions across register, aligned [rdx], aligned [rdx+16], self-operand, self-zeroing xorpd feeding logic and double FP arithmetic, a chained pipeline, and a discarded aligned m128 read (verified to fault on NULL rdx under both Debug and /O2).
  • Negative and mutation controls cover ALTER_IMM divergence on 6 exports, andnpd (~dst) & src asymmetry, 1-bit output mutation detection, VEX/EVEX (VANDPD, VANDNPD, VORPD, VXORPD, EVEX VANDPD), unaligned m128 displacements (+1, +8, -4), nonvolatile XMM6..15, undefined non-self operands, non-r8 stores, segment/LOCK/REP/XOP prefixes, PE-patched DLLs, and CLI non-traceback rejection.

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.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6605251100 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2348). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T13:10:54Z. --- ## Change Lower legacy SSE2 packed double bitwise logic instructions (`ANDPD`, `ANDNPD`, `ORPD`, `XORPD`) in `tools/cpu_sse_fp_aot.py` and add a dedicated source-built differential, `/O2`, mutation, and rejection test suite (`tests/cpu/sse_fp_pd_logic.{asm,def}`, `tests/cpu/sse_fp_pd_logic_check.py`, registered as `cpu_aot_sse_fp_pd_logic` in `CMakeLists.txt`): - Add `Code.ANDPD_XMM_XMMM128`, `Code.ANDNPD_XMM_XMMM128`, `Code.ORPD_XMM_XMMM128`, and `Code.XORPD_XMM_XMMM128` to `BITWISE_LOGIC_FUNCTIONS`, reusing the 128-bit lane-exact bitwise helpers (`op_andps`, `op_andnps`, `op_orps`, `op_xorps`) for `XMM0..XMM5` and 16-byte-aligned `[rcx|rdx|r8 + disp]` `m128` operands. - Extend the self-zeroing idiom check to `XORPD xmmN, xmmN` so undefined `XMM0..XMM5` self-zeroing lowers to `op_zero_vec()`. - Update out-of-scope rejection controls in `tests/cpu/sse_fp_check.py` and `tests/cpu/sse_fp_pd_check.py` to replace the newly supported `andpd`/`xorpd` entries with still-rejected legacy SSE2 forms (`cvtdq2pd`, `unpckhpd`). ## Verification Verified on commit `c606907f` (rebased onto `upstream/main` `7bc59951`): - `cmake --build --preset dev --target cpu_sse_fp_original cpu_sse_fp_original_lifted cpu_sse_fp_altered cpu_sse_fp_altered_lifted cpu_sse_fp_logic_original cpu_sse_fp_logic_original_lifted cpu_sse_fp_logic_altered cpu_sse_fp_logic_altered_lifted cpu_sse_fp_pd_original cpu_sse_fp_pd_original_lifted cpu_sse_fp_pd_altered cpu_sse_fp_pd_altered_lifted cpu_sse_fp_pd_logic_original cpu_sse_fp_pd_logic_original_lifted cpu_sse_fp_pd_logic_altered cpu_sse_fp_pd_logic_altered_lifted cpu_sse_fp_harness` -> succeeded (exit 0) - `ctest --preset dev -R "^cpu_aot_sse_fp" -E "cpu_native_archive_" --output-on-failure -V` -> `100% tests passed, 0 tests failed out of 4` (`cpu_aot_sse_fp`, `cpu_aot_sse_fp_logic`, `cpu_aot_sse_fp_pd`, `cpu_aot_sse_fp_pd_logic`) - `cmake --build --preset release --target ...` -> succeeded (exit 0) - `ctest --preset release -R "^cpu_aot_sse_fp" -E "cpu_native_archive_" --output-on-failure -V` -> `100% tests passed, 0 tests failed out of 4` (`22.52 sec`; `cpu_aot_sse_fp_pd_logic`: `5 alt + 5 VEX/EVEX + 27 IR + 3 raw + 9 PE-patched + CLI`, `1060 lifted + 1060 /O2 cases across 20 exports`, `ALTER_IMM diverged on {'op_andpd': 53, 'op_andnpd': 53, 'op_andnpd_mem': 53, 'op_orpd': 53, 'op_xorpd': 52, 'op_pd_logic_pipeline': 50}`) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 453 links.` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1641 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) No capability skips (baseline SSE2). ## Evidence and follow-up - `tests/cpu/sse_fp_pd_logic.asm` (`; coverage: source cpu_aot_sse_fp_pd_logic`) is a clean-room synthetic MASM fixture covering all 4 instructions across register, aligned `[rdx]`, aligned `[rdx+16]`, self-operand, self-zeroing `xorpd` feeding logic and double FP arithmetic, a chained pipeline, and a discarded aligned `m128` read (verified to fault on NULL `rdx` under both Debug and `/O2`). - Negative and mutation controls cover `ALTER_IMM` divergence on 6 exports, `andnpd` `(~dst) & src` asymmetry, 1-bit output mutation detection, VEX/EVEX (`VANDPD`, `VANDNPD`, `VORPD`, `VXORPD`, EVEX `VANDPD`), unaligned `m128` displacements (`+1`, `+8`, `-4`), nonvolatile `XMM6..15`, undefined non-self operands, non-`r8` stores, segment/LOCK/REP/XOP prefixes, PE-patched DLLs, and CLI non-traceback rejection. ## 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. AI-assisted.
upstream-sync closed this pull request 2026-11-25 14:04:55 +00:00
tedin7 commented 2026-11-25 14:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:16:14Z.

Review: COMMENTED


Review of head c606907fa034c271946e02ff6a749b8e29be3217 (PR is 4 commits behind origin/main, MERGEABLE, title neutral, no clean-room concerns seen).

Verdict: no P1, no P2.

Commands executed locally (Linux worktree):

  • git diff --stat origin/main...HEAD: 7 files, +834/-6
  • git diff --check origin/main...HEAD: clean
  • python3 tests/docs_links_check.py: self-test passed, 19 files / 453 links
  • python3 tests/bidi_controls_check.py: self-test passed, 1641 files, no bidi controls
  • gh pr checks 2348: Linux Python checks, Windows build+test and gfx1013 fixtures pass; /O2 job skipped

Correctness (read against the diff):

  • tools/cpu_sse_fp_aot.py:80-83: ANDPD/ANDNPD/ORPD/XORPD map to the existing 128-bit lane-exact helpers. These ops are pure bitwise, so reusing the PS helpers is semantically exact. op_andnps is (~dst) & src, which matches ANDNPD (dst complemented).
  • tools/cpu_sse_fp_aot.py:~473: the self-zero idiom now covers xorpd xmmN, xmmN, same rules as xorps (undefined XMM0..XMM5 allowed).
  • The test reference _bit_op computes andn as (~d) & s, consistent with the ISA.
  • Rejection controls in sse_fp_check.py and sse_fp_pd_check.py correctly replace the now-supported andpd/xorpd with still-rejected cvtdq2pd/unpckhpd. The pe_patches list is updated to match.
  • CMake export list and test registration look consistent with sibling cpu_aot_sse_fp_* entries.

Not done / limits:

  • The new cpu_aot_sse_fp_pd_logic suite needs the Windows PE fixtures plus iced_x86/pefile, which are not available in this Linux worktree. I could not run it locally and I did not run a local mutation of the lifter. The PR's own suite includes an output-bit-flip mutation control and an ALTER_IMM variant, and the Windows CI job passed. Win2025 was not queued because the change is CPU AOT only (no gfx2hlsl or shader code).

Nits (non-blocking):

  • None that need a change.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058297558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2348#pullrequestreview-6058297558). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:16:14Z. **Review:** COMMENTED --- Review of head `c606907fa034c271946e02ff6a749b8e29be3217` (PR is 4 commits behind `origin/main`, MERGEABLE, title neutral, no clean-room concerns seen). **Verdict: no P1, no P2.** Commands executed locally (Linux worktree): - `git diff --stat origin/main...HEAD`: 7 files, +834/-6 - `git diff --check origin/main...HEAD`: clean - `python3 tests/docs_links_check.py`: self-test passed, 19 files / 453 links - `python3 tests/bidi_controls_check.py`: self-test passed, 1641 files, no bidi controls - `gh pr checks 2348`: Linux Python checks, Windows build+test and gfx1013 fixtures pass; /O2 job skipped Correctness (read against the diff): - `tools/cpu_sse_fp_aot.py:80-83`: ANDPD/ANDNPD/ORPD/XORPD map to the existing 128-bit lane-exact helpers. These ops are pure bitwise, so reusing the PS helpers is semantically exact. `op_andnps` is `(~dst) & src`, which matches ANDNPD (dst complemented). - `tools/cpu_sse_fp_aot.py:~473`: the self-zero idiom now covers `xorpd xmmN, xmmN`, same rules as `xorps` (undefined XMM0..XMM5 allowed). - The test reference `_bit_op` computes `andn` as `(~d) & s`, consistent with the ISA. - Rejection controls in `sse_fp_check.py` and `sse_fp_pd_check.py` correctly replace the now-supported `andpd`/`xorpd` with still-rejected `cvtdq2pd`/`unpckhpd`. The `pe_patches` list is updated to match. - CMake export list and test registration look consistent with sibling `cpu_aot_sse_fp_*` entries. Not done / limits: - The new `cpu_aot_sse_fp_pd_logic` suite needs the Windows PE fixtures plus `iced_x86`/`pefile`, which are not available in this Linux worktree. I could not run it locally and I did not run a local mutation of the lifter. The PR's own suite includes an output-bit-flip mutation control and an ALTER_IMM variant, and the Windows CI job passed. Win2025 was not queued because the change is CPU AOT only (no gfx2hlsl or shader code). Nits (non-blocking): - None that need a change. AI-assisted; commands listed were executed locally.
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!2340
No description provided.