cpu: lower PF consumers after VEX scalar compares #1181

Merged
Batushn merged 2 commits from upstream-pr/1188 into main 2026-11-24 13:58:02 +00:00
Batushn commented 2026-11-24 02:59:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-24T02:59:34Z.


Change

Fixes #1153.

Allow PF consumers (SETP, SETNP, CMOVP, CMOVNP alongside JP, JNP, FCMOVU, FCMOVNU) after modeled PF producers, including the four scalar VEX compares (VCOMISS, VUCOMISS, VCOMISD, VUCOMISD), whenever x87_lower.check_flags proves a reaching modeled PF definition at every use.

  • tools/x87_lower.py: Added SETP, SETNP, CMOVP, CMOVNP to GATED; added VEX_SCALAR_COMPARES (VCOMISS, VUCOMISS, VCOMISD, VUCOMISD) and already-lowered PF_CLEARED instructions (RDRAND, RDSEED, PTEST, VPTEST, VTESTPS, VTESTPD, PCMPESTRI, PCMPESTRM, PCMPISTRI, PCMPISTRM) to assigns_parity(i); threaded skip_lahf and host_ops into _after, states, and check_flags; preserved existing error prefixes (reads PF, which the integer lowering models only after ...).
  • tools/ffx_version_query.py: Gated SETP/SETNP/CMOVP/CMOVNP on x87_lower.check_flags (rejecting indirect branches and wrapping non-x87 ValueError in "unsupported query operation: ..." so integer_flags_check stays intact) and lowered CMOVP/CMOVNP and SETP/SETNP using existing write / guest eager-read & 32-bit zero-extension paths. Functions without PF consumers keep unchanged parity-free C++.
  • tests/cpu/vex_parity.asm, tests/cpu/vex_parity.def, tests/cpu/vex_parity.py, CMakeLists.txt: Added cpu_aot_vex_parity differential fixture comparing native, translated, and /O2 DLLs across 14 exports and 1618 cases.
  • tests/cpu/x87_compare.py, tests/cpu/x87_parity.py, docs/experiments.md: Updated setp/cmovp expectations after fucomi and documented cpu_aot_vex_parity.

Verification

Commit e132e45 (based on main 063df2c) on AMD64 Family 25 Model 116 Stepping 1, AuthenticAMD (Windows, VS 2022 BuildTools cl 19.44.35229.0):

  • ctest --preset dev --no-tests=error -R "^cpu_aot_(vex_parity|x87_parity|x87_compare|x87_status|x87_fcmov|integer_flags|avx_scalar_fp|cmov_setcc|lower_dead_reads)$" --output-on-failure: 9/9 passed (cpu_aot_vex_parity + all related flag/parity/AVX/CMOV/fault tests).
  • ctest --preset release --no-tests=error -R "^cpu_aot_vex_parity$" -V: 1/1 passed:
    • rejected 13 negative PF cases, accepted 4 positive sequences, and preserved parity-free lowering
    • control stalepf: caught 3 deliberate PF mismatches
    • control swap: caught 5 deliberate PF mismatches
    • 1618 VEX scalar compare / PF consumer cases (masked MXCSR 0x1f80, qNaN/sNaN in both operands, 32/64/16-bit CMOVP/CMOVNP, fault checks, CFG joins) matched native, translated, and /O2 DLLs
  • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: passed.
  • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: Checked 15 Markdown files and 255 links.
  • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: Checked 951 tracked source, script and build/CI files: no bidirectional controls.

Evidence and follow-up

  • tests/cpu/vex_parity.asm and tests/cpu/vex_parity.py are original synthetic tests under repository conventions (; coverage: source cpu_aot_vex_parity).
  • Register and memory RHS forms for vcomiss, vucomiss, vcomisd, vucomisd are checked under documented masked MXCSR = 0x1F80 (saved/restored via host_exchange_mxcsr), with quiet and signaling NaNs in each operand, +/-0.0, +/-inf, subnormals, and ordered pairs (<, ==, >). Floating-point exception behavior outside vex_parity is unchanged.
  • cmovp/cmovnp are verified for both PF outcomes at 32-bit (upper 32 bits cleared even when condition is false), 64-bit, and 16-bit widths, plus unconditional memory reads (0xC0000005 on PAGE_NOACCESS and NULL via cpu_guarded_call) for both PF=0 and PF=1 in Debug, Release, and /O2.
  • Mutated C++ controls (stalepf dropping parity = unordered;, swap reversing PF consumer conditions) both fail as required, and 13 negative lowering cases (entry/no writer, add, cmp, inc, 32-bit test, shl, call, ambiguous/uninitialized joins, indirect branch, host_ops) remain rejected.

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: yes

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6573616875 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1188). Originally posted by [Batushn](https://github.com/Batushn) on 2026-11-24T02:59:34Z. --- ## Change Fixes #1153. Allow PF consumers (`SETP`, `SETNP`, `CMOVP`, `CMOVNP` alongside `JP`, `JNP`, `FCMOVU`, `FCMOVNU`) after modeled PF producers, including the four scalar VEX compares (`VCOMISS`, `VUCOMISS`, `VCOMISD`, `VUCOMISD`), whenever `x87_lower.check_flags` proves a reaching modeled PF definition at every use. - [tools/x87_lower.py](tools/x87_lower.py): Added `SETP`, `SETNP`, `CMOVP`, `CMOVNP` to `GATED`; added `VEX_SCALAR_COMPARES` (`VCOMISS`, `VUCOMISS`, `VCOMISD`, `VUCOMISD`) and already-lowered `PF_CLEARED` instructions (`RDRAND`, `RDSEED`, `PTEST`, `VPTEST`, `VTESTPS`, `VTESTPD`, `PCMPESTRI`, `PCMPESTRM`, `PCMPISTRI`, `PCMPISTRM`) to `assigns_parity(i)`; threaded `skip_lahf` and `host_ops` into `_after`, `states`, and `check_flags`; preserved existing error prefixes (`reads PF, which the integer lowering models only after ...`). - [tools/ffx_version_query.py](tools/ffx_version_query.py): Gated `SETP`/`SETNP`/`CMOVP`/`CMOVNP` on `x87_lower.check_flags` (rejecting indirect branches and wrapping non-x87 `ValueError` in `"unsupported query operation: ..."` so `integer_flags_check` stays intact) and lowered `CMOVP`/`CMOVNP` and `SETP`/`SETNP` using existing `write` / `guest` eager-read & 32-bit zero-extension paths. Functions without PF consumers keep unchanged parity-free C++. - [tests/cpu/vex_parity.asm](tests/cpu/vex_parity.asm), [tests/cpu/vex_parity.def](tests/cpu/vex_parity.def), [tests/cpu/vex_parity.py](tests/cpu/vex_parity.py), [CMakeLists.txt](CMakeLists.txt): Added `cpu_aot_vex_parity` differential fixture comparing native, translated, and `/O2` DLLs across 14 exports and 1618 cases. - [tests/cpu/x87_compare.py](tests/cpu/x87_compare.py), [tests/cpu/x87_parity.py](tests/cpu/x87_parity.py), [docs/experiments.md](docs/experiments.md): Updated `setp`/`cmovp` expectations after `fucomi` and documented `cpu_aot_vex_parity`. ## Verification Commit `e132e45` (based on `main` `063df2c`) on `AMD64 Family 25 Model 116 Stepping 1, AuthenticAMD` (Windows, VS 2022 BuildTools `cl` 19.44.35229.0): - `ctest --preset dev --no-tests=error -R "^cpu_aot_(vex_parity|x87_parity|x87_compare|x87_status|x87_fcmov|integer_flags|avx_scalar_fp|cmov_setcc|lower_dead_reads)$" --output-on-failure`: **9/9 passed** (`cpu_aot_vex_parity` + all related flag/parity/AVX/CMOV/fault tests). - `ctest --preset release --no-tests=error -R "^cpu_aot_vex_parity$" -V`: **1/1 passed**: - `rejected 13 negative PF cases, accepted 4 positive sequences, and preserved parity-free lowering` - `control stalepf: caught 3 deliberate PF mismatches` - `control swap: caught 5 deliberate PF mismatches` - `1618 VEX scalar compare / PF consumer cases (masked MXCSR 0x1f80, qNaN/sNaN in both operands, 32/64/16-bit CMOVP/CMOVNP, fault checks, CFG joins) matched native, translated, and /O2 DLLs` - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: passed. - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: `Checked 15 Markdown files and 255 links.` - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: `Checked 951 tracked source, script and build/CI files: no bidirectional controls.` ## Evidence and follow-up - [tests/cpu/vex_parity.asm](tests/cpu/vex_parity.asm) and [tests/cpu/vex_parity.py](tests/cpu/vex_parity.py) are original synthetic tests under repository conventions (`; coverage: source cpu_aot_vex_parity`). - Register and memory RHS forms for `vcomiss`, `vucomiss`, `vcomisd`, `vucomisd` are checked under documented masked `MXCSR = 0x1F80` (saved/restored via `host_exchange_mxcsr`), with quiet and signaling NaNs in each operand, `+/-0.0`, `+/-inf`, subnormals, and ordered pairs (`<`, `==`, `>`). Floating-point exception behavior outside `vex_parity` is unchanged. - `cmovp`/`cmovnp` are verified for both PF outcomes at 32-bit (upper 32 bits cleared even when condition is false), 64-bit, and 16-bit widths, plus unconditional memory reads (`0xC0000005` on `PAGE_NOACCESS` and `NULL` via `cpu_guarded_call`) for both `PF=0` and `PF=1` in Debug, Release, and `/O2`. - Mutated C++ controls (`stalepf` dropping `parity = unordered;`, `swap` reversing PF consumer conditions) both fail as required, and 13 negative lowering cases (entry/no writer, `add`, `cmp`, `inc`, 32-bit `test`, `shl`, `call`, ambiguous/uninitialized joins, indirect branch, `host_ops`) remain rejected. ## 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: yes
tedin7 commented 2026-11-24 06:46:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:15:33Z.

Review: COMMENTED


Audited diff (e132e457) and ran platform-independent checks on Linux (no Windows/MSVC build or iced_x86 environment locally, so cpu_aot_vex_parity and form_coverage_check.py were not executed).

Linux checks run on e132e457:

  • python3 -B tests/docs_links_check.py: passed (Checked 15 Markdown files and 255 links.)
  • python3 -B tests/bidi_controls_check.py: passed (Checked 951 tracked source, script and build/CI files: no bidirectional controls.)
  • python3 -B tests/rdna2_tools_check.py: passed (Ran 109 tests in 2.398s, OK (skipped=10))

Code audit:

  • tools/x87_lower.py: SETP, SETNP, CMOVP, CMOVNP are gated, VEX_SCALAR_COMPARES (VCOMISS, VUCOMISS, VCOMISD, VUCOMISD) and PF_CLEARED (RDRAND, RDSEED, PTEST, VPTEST, VTESTPS, VTESTPD, PCMPESTRI, PCMPESTRM, PCMPISTRI, PCMPISTRM) are recognized by assigns_parity, and host_ops invalidates tracked flags/PF in _after.
  • tools/ffx_version_query.py: Confirmed that all PF_CLEARED instructions already emit parity = false; when parity is enabled, VCOMISS/VUCOMISS/VCOMISD/VUCOMISD compute unordered from operand bits and assign zero, carry, parity accordingly, SETP/SETNP preserve upper bits via write, and CMOVP/CMOVNP eagerly read memory operands via guest() and zero-extend 32-bit register destinations via write_register even when not taken.
  • AGENTS.md compliance: title-neutral wording, docs/experiments.md updated, and negative controls (stalepf, swap, and 13 rejected lowering cases) are present.

Windows cpu_aot_vex_parity and form_coverage_check.py results remain unverified locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6033139408 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1188#pullrequestreview-6033139408). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T03:15:33Z. **Review:** COMMENTED --- Audited diff (`e132e457`) and ran platform-independent checks on Linux (no Windows/MSVC build or `iced_x86` environment locally, so `cpu_aot_vex_parity` and `form_coverage_check.py` were not executed). **Linux checks run on `e132e457`:** - `python3 -B tests/docs_links_check.py`: passed (`Checked 15 Markdown files and 255 links.`) - `python3 -B tests/bidi_controls_check.py`: passed (`Checked 951 tracked source, script and build/CI files: no bidirectional controls.`) - `python3 -B tests/rdna2_tools_check.py`: passed (`Ran 109 tests in 2.398s`, `OK (skipped=10)`) **Code audit:** - `tools/x87_lower.py`: `SETP`, `SETNP`, `CMOVP`, `CMOVNP` are gated, `VEX_SCALAR_COMPARES` (`VCOMISS`, `VUCOMISS`, `VCOMISD`, `VUCOMISD`) and `PF_CLEARED` (`RDRAND`, `RDSEED`, `PTEST`, `VPTEST`, `VTESTPS`, `VTESTPD`, `PCMPESTRI`, `PCMPESTRM`, `PCMPISTRI`, `PCMPISTRM`) are recognized by `assigns_parity`, and `host_ops` invalidates tracked flags/PF in `_after`. - `tools/ffx_version_query.py`: Confirmed that all `PF_CLEARED` instructions already emit `parity = false;` when `parity` is enabled, `VCOMISS`/`VUCOMISS`/`VCOMISD`/`VUCOMISD` compute `unordered` from operand bits and assign `zero`, `carry`, `parity` accordingly, `SETP`/`SETNP` preserve upper bits via `write`, and `CMOVP`/`CMOVNP` eagerly read memory operands via `guest()` and zero-extend 32-bit register destinations via `write_register` even when not taken. - `AGENTS.md` compliance: title-neutral wording, `docs/experiments.md` updated, and negative controls (`stalepf`, `swap`, and 13 rejected lowering cases) are present. Windows `cpu_aot_vex_parity` and `form_coverage_check.py` results remain unverified locally.
R0Y00 commented 2026-11-24 06:50:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T03:42:52Z.


Thanks for this work. The shared PF lowering landed in #1193 along with the native and optimized comparisons. Your distinct source-built cases are welcome as a focused follow-up against current main. Please keep the existing shared proof in place and point out any accepted or refused case the landed fixture does not exercise.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7121351271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1188#issuecomment-7121351271). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T03:42:52Z. --- Thanks for this work. The shared PF lowering landed in #1193 along with the native and optimized comparisons. Your distinct source-built cases are welcome as a focused follow-up against current main. Please keep the existing shared proof in place and point out any accepted or refused case the landed fixture does not exercise.
upstream-sync closed this pull request 2026-11-24 14:02:41 +00:00
R0Y00 commented 2026-11-24 14:03:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T13:51:21Z.


At 64d451e3 this PR builds on the #1193 lowering already in main and retains the independent MASM/native/optimized test, adjusted to exercise current PF refusals. Windows Release matched all 1,618 native and lifted cases and detected the stale-PF and swapped-operand controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133437177 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1188#issuecomment-7133437177). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T13:51:21Z. --- At 64d451e3 this PR builds on the #1193 lowering already in main and retains the independent MASM/native/optimized test, adjusted to exercise current PF refusals. Windows Release matched all 1,618 native and lifted cases and detected the stale-PF and swapped-operand controls.
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!1181
No description provided.