cpu: lower legacy SSE packed bitwise FP logic (ANDPS, ANDNPS, ORPS, XORPS) in cpu_sse_fp_aot #2077

Merged
Ammmae0x merged 3 commits from upstream-pr/2084 into main 2026-11-25 12:26:25 +00:00
Ammmae0x commented 2026-11-25 00:04:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T00:04:31Z.


Change

Lower legacy SSE packed bitwise FP logic instructions in tools/cpu_sse_fp_aot.py and add a source-built MASM fixture (tests/cpu/sse_fp_logic.asm, tests/cpu/sse_fp_logic.def), differential verification suite (tests/cpu/sse_fp_logic_check.py), and CTest registration (cpu_aot_sse_fp_logic in CMakeLists.txt):

  • Covered forms (docs/coverage/x64_zen2.tsv group SSE):
    • andps xmm, xmm/m128
    • andnps xmm, xmm/m128 (asymmetric (~dst) & src)
    • orps xmm, xmm/m128
    • xorps xmm, xmm/m128 (binary XOR and self-zeroing xorps xmmN, xmmN)
  • Semantics and safety guarantees:
    • Bitwise integer 64-bit lane operations preserve all 128 bits identically (sNaN/qNaN payloads, -0.0, +0.0, denormals, Inf).
    • Self-zeroing xorps xmmN, xmmN accepts an undefined volatile xmmN and lowers via const volatile Vec128 (op_zero_vec()) so /O2 never constant-folds downstream +0.0 + (-0.0) or bypasses MXCSR rules; andps, andnps, orps, and non-self xorps require a defined destination.
    • Memory m128 sources enforce 16-byte alignment (flat_address(alignment=16)) and volatile loads so /O2 never eliminates faulting discarded reads.
    • Rejects VEX/EVEX/XOP encodings, segment/LOCK/REP prefixes, unaligned memory displacements, RIP-relative/SIB addressing, nonvolatile XMM/GPR registers, non-r8 stores, undefined reads, and non-leaf branches.

Verification

Tested on commit 2253f858 (rebased onto upstream/main 6218beb2, Windows x64, MSVC 14.50, dev Debug and release /O2):

  1. cmake --build --preset dev --target 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_original cpu_sse_fp_original_lifted cpu_sse_fp_altered_lifted cpu_sse_fp_pd_original cpu_sse_fp_pd_original_lifted cpu_sse_fp_pd_altered_lifted cpu_sse_fp_harness
    • Result: succeeded with 0 errors, 0 warnings.
  2. cmake --build --preset release --target ... (same targets)
    • Result: succeeded with 0 errors, 0 warnings.
  3. ctest --preset dev -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure -V
    • Result: 3/3 Passed (cpu_aot_sse_fp, cpu_aot_sse_fp_logic, cpu_aot_sse_fp_pd).
    • cpu_aot_sse_fp_logic: rejections passed: 5 VEX/EVEX + 24 IR + 3 raw + 7 PE-patched + CLI; sse_fp_logic passed: 1060 lifted + 1060 /O2 cases across 20 exports; ALTER_IMM diverged on {'op_andps': 53, 'op_andnps': 53, 'op_andnps_mem': 53, 'op_orps': 53, 'op_xorps': 53, 'op_logic_pipeline': 52}. Capability skips: none.
  4. ctest --preset release -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure
    • Result: 3/3 Passed.
  5. .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
    • Result: form coverage checks passed (exit 0).
  6. .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
    • Result: Self-test passed. Checked 18 Markdown files and 393 links. (exit 0).
  7. .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
    • Result: Self-test passed. Checked 1416 tracked source, script and build/CI files: no bidirectional controls. (exit 0).

Evidence and follow-up

  • Fixture tests/cpu/sse_fp_logic.asm (; coverage: source cpu_aot_sse_fp_logic) and tests/cpu/sse_fp_logic.def are original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used.
  • Negative controls include 6 ALTER_IMM mutant exports (including swapped andnps operand order), a NULL-pointer discarded aligned m128 read fault check under both Debug and /O2, 5 VEX/EVEX rejections, 24 IR rejections, 3 raw-byte rejections, 7 PE-patched rejections, and CLI non-traceback / zero-leftover-file checks.

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:6593998165 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2084). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T00:04:31Z. --- ## Change Lower legacy SSE packed bitwise FP logic instructions in `tools/cpu_sse_fp_aot.py` and add a source-built MASM fixture (`tests/cpu/sse_fp_logic.asm`, `tests/cpu/sse_fp_logic.def`), differential verification suite (`tests/cpu/sse_fp_logic_check.py`), and CTest registration (`cpu_aot_sse_fp_logic` in `CMakeLists.txt`): - Covered forms (`docs/coverage/x64_zen2.tsv` group `SSE`): - `andps xmm, xmm/m128` - `andnps xmm, xmm/m128` (asymmetric `(~dst) & src`) - `orps xmm, xmm/m128` - `xorps xmm, xmm/m128` (binary XOR and self-zeroing `xorps xmmN, xmmN`) - Semantics and safety guarantees: - Bitwise integer 64-bit lane operations preserve all 128 bits identically (sNaN/qNaN payloads, `-0.0`, `+0.0`, denormals, Inf). - Self-zeroing `xorps xmmN, xmmN` accepts an undefined volatile `xmmN` and lowers via `const volatile Vec128` (`op_zero_vec()`) so `/O2` never constant-folds downstream `+0.0 + (-0.0)` or bypasses MXCSR rules; `andps`, `andnps`, `orps`, and non-self `xorps` require a defined destination. - Memory `m128` sources enforce 16-byte alignment (`flat_address(alignment=16)`) and volatile loads so `/O2` never eliminates faulting discarded reads. - Rejects VEX/EVEX/XOP encodings, segment/LOCK/REP prefixes, unaligned memory displacements, RIP-relative/SIB addressing, nonvolatile XMM/GPR registers, non-`r8` stores, undefined reads, and non-leaf branches. ## Verification Tested on commit `2253f858` (rebased onto `upstream/main` `6218beb2`, Windows x64, MSVC 14.50, `dev` Debug and `release` `/O2`): 1. `cmake --build --preset dev --target 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_original cpu_sse_fp_original_lifted cpu_sse_fp_altered_lifted cpu_sse_fp_pd_original cpu_sse_fp_pd_original_lifted cpu_sse_fp_pd_altered_lifted cpu_sse_fp_harness` - Result: succeeded with 0 errors, 0 warnings. 2. `cmake --build --preset release --target ...` (same targets) - Result: succeeded with 0 errors, 0 warnings. 3. `ctest --preset dev -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure -V` - Result: `3/3` Passed (`cpu_aot_sse_fp`, `cpu_aot_sse_fp_logic`, `cpu_aot_sse_fp_pd`). - `cpu_aot_sse_fp_logic`: `rejections passed: 5 VEX/EVEX + 24 IR + 3 raw + 7 PE-patched + CLI`; `sse_fp_logic passed: 1060 lifted + 1060 /O2 cases across 20 exports; ALTER_IMM diverged on {'op_andps': 53, 'op_andnps': 53, 'op_andnps_mem': 53, 'op_orps': 53, 'op_xorps': 53, 'op_logic_pipeline': 52}`. Capability skips: none. 4. `ctest --preset release -R "^cpu_aot_sse_fp(_logic|_pd)?$" --output-on-failure` - Result: `3/3` Passed. 5. `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py` - Result: `form coverage checks passed` (exit 0). 6. `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py` - Result: `Self-test passed. Checked 18 Markdown files and 393 links.` (exit 0). 7. `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py` - Result: `Self-test passed. Checked 1416 tracked source, script and build/CI files: no bidirectional controls.` (exit 0). ## Evidence and follow-up - Fixture `tests/cpu/sse_fp_logic.asm` (`; coverage: source cpu_aot_sse_fp_logic`) and `tests/cpu/sse_fp_logic.def` are original, source-built synthetic MASM fixtures under the repository MIT license; no external binaries or game files are used. - Negative controls include 6 `ALTER_IMM` mutant exports (including swapped `andnps` operand order), a `NULL`-pointer discarded aligned `m128` read fault check under both Debug and `/O2`, 5 VEX/EVEX rejections, 24 IR rejections, 3 raw-byte rejections, 7 PE-patched rejections, and CLI non-traceback / zero-leftover-file checks. ## 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.
tedin7 commented 2026-11-25 03:00:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:24:43Z.

Review: COMMENTED


Review of head 2253f8587a37f56ecb6d0e92868bc3b3eb855610.

Summary: No P1 or P2. Lowering of ANDPS/ANDNPS/ORPS/XORPS is correct and consistent with the existing arithmetic path.

Checked

  • tools/cpu_sse_fp_aot.py: ANDNPS is (~dst) & src (operand order matches the ISA). Bitwise ops run on the 2x64-bit lanes, so NaN payloads, -0.0 and denormals are preserved. Memory sources use vec_src128(..., alignment=16), like the sibling arithmetic forms.
  • Self-zero xorps xmmN, xmmN is the only form that accepts an undefined register. andps/orps xmmN, xmmN still require a defined register. This matches the PR text.
  • op_zero_vec() reads a volatile zero, so /O2 cannot fold it. This is the right way to protect the +0.0 + -0.0 case.
  • CMakeLists.txt: export list, ALTER_IMM variant and test registration follow the neighbouring cpu_sse_fp_pd block.
  • The test reference (_bit_op) is computed independently of the lifter. It includes asymmetric masks that tell (~d)&s apart from d&(~s).
  • CI at this head: Windows build+test pass, Linux Python checks pass, gfx1013 fixtures pass. "Build and test on Windows at /O2" is skipped, so /O2 evidence relies on the author's local run in the PR body.
  • Title and body are neutral. Mergeable.

Commands executed locally (Linux)

  • python3 tests/docs_links_check.py -> Self-test passed. Checked 18 Markdown files and 393 links.
  • python3 tests/bidi_controls_check.py -> no bidirectional controls
  • git diff --check origin/main...HEAD -> exit 0
  • git diff --stat origin/main...HEAD -> 5 files, +807

Not run: cpu_aot_sse_fp_logic and a mutation of the lowering. They need MSVC/MASM and iced_x86 (not available on this Linux host). I did not request a Win2025 run because the Windows CI job passed at this SHA. The PR's own ALTER_IMM divergence counts show the suite kills the swapped-op mutant, but I did not reproduce that here.

Nits (non-blocking)

  • P3: Consider enabling the /O2 CI job for this suite, or paste the release-preset ctest output. It is the only proof for the volatile self-zero path.
  • P3: andps xmmN, xmmN with an undefined xmmN is rejected. That is conservative and fine, but a one-line comment near the self-zero branch would say so.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050790808 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2084#pullrequestreview-6050790808). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:24:43Z. **Review:** COMMENTED --- Review of head `2253f8587a37f56ecb6d0e92868bc3b3eb855610`. **Summary:** No P1 or P2. Lowering of ANDPS/ANDNPS/ORPS/XORPS is correct and consistent with the existing arithmetic path. **Checked** - `tools/cpu_sse_fp_aot.py`: ANDNPS is `(~dst) & src` (operand order matches the ISA). Bitwise ops run on the 2x64-bit lanes, so NaN payloads, -0.0 and denormals are preserved. Memory sources use `vec_src128(..., alignment=16)`, like the sibling arithmetic forms. - Self-zero `xorps xmmN, xmmN` is the only form that accepts an undefined register. `andps/orps xmmN, xmmN` still require a defined register. This matches the PR text. - `op_zero_vec()` reads a `volatile` zero, so `/O2` cannot fold it. This is the right way to protect the +0.0 + -0.0 case. - `CMakeLists.txt`: export list, `ALTER_IMM` variant and test registration follow the neighbouring `cpu_sse_fp_pd` block. - The test reference (`_bit_op`) is computed independently of the lifter. It includes asymmetric masks that tell `(~d)&s` apart from `d&(~s)`. - CI at this head: Windows build+test pass, Linux Python checks pass, gfx1013 fixtures pass. "Build and test on Windows at /O2" is skipped, so `/O2` evidence relies on the author's local run in the PR body. - Title and body are neutral. Mergeable. **Commands executed locally (Linux)** - `python3 tests/docs_links_check.py` -> `Self-test passed. Checked 18 Markdown files and 393 links.` - `python3 tests/bidi_controls_check.py` -> `no bidirectional controls` - `git diff --check origin/main...HEAD` -> exit 0 - `git diff --stat origin/main...HEAD` -> 5 files, +807 **Not run:** `cpu_aot_sse_fp_logic` and a mutation of the lowering. They need MSVC/MASM and `iced_x86` (not available on this Linux host). I did not request a Win2025 run because the Windows CI job passed at this SHA. The PR's own `ALTER_IMM` divergence counts show the suite kills the swapped-op mutant, but I did not reproduce that here. **Nits (non-blocking)** - P3: Consider enabling the `/O2` CI job for this suite, or paste the release-preset ctest output. It is the only proof for the volatile self-zero path. - P3: `andps xmmN, xmmN` with an undefined `xmmN` is rejected. That is conservative and fine, but a one-line comment near the self-zero branch would say so. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 13:00:34 +00:00
tedin7 commented 2026-11-25 13:00:35 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 04c6ba382a962a3428c21078483d1f4fca20095c (5 files, +808/-0: CMakeLists.txt, tests/cpu/sse_fp_logic.{asm,def}, tests/cpu/sse_fp_logic_check.py, tools/cpu_sse_fp_aot.py).

Verdict: no P1, no P2. Looks correct; the one red check is not caused by this PR.

Commands run locally (worktree at the PR head):

  • git diff --stat origin/main...HEAD: 5 files, 808 insertions, 0 deletions.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files and 393 links checked.
  • python3 tests/bidi_controls_check.py: 1416 files, no bidirectional controls.
  • git merge-tree --write-tree HEAD origin/main: merges cleanly.
  • python3 tests/startup_run_sh_check.py on a clean origin/main (31f46857): fails with mutant 'watcher without --render' was not detected.

CI on this head:

  • Run platform-independent Python checks on Linux: fail. The only failing script is tests/startup_run_sh_check.py. It fails the same way on a clean origin/main and this PR does not touch it. Every other script in that job passed.
  • Build and test on Windows: pass (2m29s). Assemble and translate gfx1013 fixtures: pass. Build and test on Windows at /O2: skipped.

Review of the logic:

  • andps is d & s, andnps is (~d) & s, orps is d | s, xorps is d ^ s. All are done on both 64-bit halves, so NaN, -0.0 and denormal bits are kept exactly. That matches the ISA (bitwise, no FP exceptions, no MXCSR use).
  • The xorps xmmN, xmmN self-zero is special-cased and may read an undefined register. That is the correct dependency-breaking idiom. andps/orps/andnps self are not special-cased and still need a defined source, which is also correct (andnps x,x gives 0 but is not treated as an idiom, so it stays conservative).
  • op_zero_vec() uses volatile to stop /O2 constant folding. This is fine. It is a small cost, but it is only used for the self-zero case.
  • Memory sources go through vec_src128(..., alignment=16), so unaligned m128 is refused like the sibling arithmetic ops.
  • Fixture design follows the sibling sse_fp / sse_fp_pd tables: export list in CMake matches the .def, the .asm and the check's EXPORTS tuple (20 names in all three). The altered variant covers andps, andnps (register and memory), orps, xorps and the pipeline. The check also has an andnps symmetry mutant and a rejection set.

Nits (non-blocking):

  • N1: xorps self-zero is only covered by the new fixture. If tools/cpu_sse_fp_aot.py or the docs/coverage table lists supported SSE forms elsewhere (e.g. docs/coverage/x64_zen2.tsv rows for these four opcodes), update them in this PR or note that a follow-up does it.
  • N2: the /O2 build was skipped in CI for this head, so the volatile zero trick is only checked by the check's own compile_o2_and_verify step on Windows.

Not done, and why:

  • I did not run sse_fp_logic_check.py or a real mutation of the new lowering. It needs iced_x86, pefile and MASM-built Windows DLLs, which are not available on this Linux host. The check passed in the Windows CI job, and the Linux-only gates above are clean. No Win2025 run was queued: the change is CPU AOT C++, and the Windows CI job already covers it.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057438308 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2084#pullrequestreview-6057438308). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:16:41Z. **Review:** COMMENTED --- Review of head `04c6ba382a962a3428c21078483d1f4fca20095c` (5 files, +808/-0: CMakeLists.txt, tests/cpu/sse_fp_logic.{asm,def}, tests/cpu/sse_fp_logic_check.py, tools/cpu_sse_fp_aot.py). **Verdict: no P1, no P2. Looks correct; the one red check is not caused by this PR.** Commands run locally (worktree at the PR head): - `git diff --stat origin/main...HEAD`: 5 files, 808 insertions, 0 deletions. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: self-test passed, 18 Markdown files and 393 links checked. - `python3 tests/bidi_controls_check.py`: 1416 files, no bidirectional controls. - `git merge-tree --write-tree HEAD origin/main`: merges cleanly. - `python3 tests/startup_run_sh_check.py` on a clean `origin/main` (31f46857): fails with `mutant 'watcher without --render' was not detected`. CI on this head: - `Run platform-independent Python checks on Linux`: fail. The only failing script is `tests/startup_run_sh_check.py`. It fails the same way on a clean `origin/main` and this PR does not touch it. Every other script in that job passed. - `Build and test on Windows`: pass (2m29s). `Assemble and translate gfx1013 fixtures`: pass. `Build and test on Windows at /O2`: skipped. Review of the logic: - `andps` is `d & s`, `andnps` is `(~d) & s`, `orps` is `d | s`, `xorps` is `d ^ s`. All are done on both 64-bit halves, so NaN, -0.0 and denormal bits are kept exactly. That matches the ISA (bitwise, no FP exceptions, no MXCSR use). - The `xorps xmmN, xmmN` self-zero is special-cased and may read an undefined register. That is the correct dependency-breaking idiom. `andps`/`orps`/`andnps` self are not special-cased and still need a defined source, which is also correct (`andnps x,x` gives 0 but is not treated as an idiom, so it stays conservative). - `op_zero_vec()` uses `volatile` to stop /O2 constant folding. This is fine. It is a small cost, but it is only used for the self-zero case. - Memory sources go through `vec_src128(..., alignment=16)`, so unaligned m128 is refused like the sibling arithmetic ops. - Fixture design follows the sibling `sse_fp` / `sse_fp_pd` tables: export list in CMake matches the `.def`, the `.asm` and the check's `EXPORTS` tuple (20 names in all three). The altered variant covers `andps`, `andnps` (register and memory), `orps`, `xorps` and the pipeline. The check also has an `andnps` symmetry mutant and a rejection set. Nits (non-blocking): - N1: `xorps` self-zero is only covered by the new fixture. If `tools/cpu_sse_fp_aot.py` or the docs/coverage table lists supported SSE forms elsewhere (e.g. `docs/coverage/x64_zen2.tsv` rows for these four opcodes), update them in this PR or note that a follow-up does it. - N2: the /O2 build was skipped in CI for this head, so the `volatile` zero trick is only checked by the check's own `compile_o2_and_verify` step on Windows. Not done, and why: - I did not run `sse_fp_logic_check.py` or a real mutation of the new lowering. It needs `iced_x86`, `pefile` and MASM-built Windows DLLs, which are not available on this Linux host. The check passed in the Windows CI job, and the Linux-only gates above are clean. No Win2025 run was queued: the change is CPU AOT C++, and the Windows CI job already covers it. 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!2077
No description provided.