cpu: accept FFREEP ST(0) on a nonempty stack in the x87 profile #1354

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/1361 into main 2026-11-24 09:27:23 +00:00
legacy-code-archaeologist commented 2026-11-24 09:15:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T09:15:01Z.


Refs #1338

What

The x87 profile (tools/x87_lower.py) now accepts FFREEP ST(0) on a nonempty stack. This follows the narrowed scope in #1338.

  • FFREEP ST(0) tags ST(0) empty and pops it, like FSTP ST(0) without a store. The depth drops by one and TOP moves up by one.
  • On an empty stack it is refused ("x87 stack underflow").
  • FFREE, FFREEP ST(i) for i > 0, FINCSTP and FDECSTP stay outside the profile. The profile derives TOP from a contiguous depth, so FFREE is left for the follow-up, as discussed.
  • C0 to C3 stay undefined afterwards, like every other x87 instruction. Readers of them are still refused.
  • No other export changes its generated code: FFREEP appears only in the new export.

Evidence

cpu_aot_x87_examine gains the export ffreep_top:

  • It pushes the input m80, 1.0 and 0.0, then runs ffreep st(0) at depths 3, 2 and 1.
  • After each step it records the physical TOP: fnstsw ax, and ah, 38h, then stores AH.
  • It stores the values left below. The input is stored raw, for all 34 encodings of the fixture: every class, both signs, and unsupported encodings.

The check fails in each of these cases:

  • Controls (must mismatch):
    • ffreep: FFREEP also overwrites the deepest register with the one above it. 33/850 mismatches; the input 1.0 hides it.
    • fftop: the first FFREEP leaves TOP at 5. 34/850.
  • New refusals:
    • ffreep on an empty stack;
    • a reader of C0 after ffreep, and a reader of C1 after it;
    • ffreep st(2);
    • ffree st(0) and ffree st(1);
    • fincstp and fdecstp.

Windows 11 Pro 26100.9168, Intel i7-6820HQ, MSVC 19.52, commit b274877b on 623e2112:

ctest --preset dev --no-tests=error -R '^cpu_aot_x87_examine$' -V

Result:

  • 850 cases over 6 exports matched the model in the native and translated DLLs. The native run gave TOP 5, 6, 7 and 0, and left the values below unchanged.
  • Controls normal/unsigned/positive/legacy/ffreep/fftop gave 5/136/7/34/33/34 mismatches.
  • 14 sequences were refused.
  • The release preset gives the same result.

Other runs:

  • Before the rebase, ctest --preset dev -E '_hardware$': 582/582.
  • After the rebase, ctest --preset dev -R '^cpu_' -E '_hardware$': 225/225.
  • Release -R '^cpu_aot_x87_': 21/21.
  • tools/form_coverage.py --gaps x64_zen2 no longer lists ffreep. ffree stays listed.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578474398 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1361). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T09:15:01Z. --- Refs #1338 ## What The x87 profile (`tools/x87_lower.py`) now accepts **FFREEP ST(0) on a nonempty stack**. This follows the narrowed scope in #1338. - FFREEP ST(0) tags ST(0) empty and pops it, like FSTP ST(0) without a store. The depth drops by one and TOP moves up by one. - On an empty stack it is refused ("x87 stack underflow"). - FFREE, FFREEP ST(i) for i > 0, FINCSTP and FDECSTP stay outside the profile. The profile derives TOP from a contiguous depth, so FFREE is left for the follow-up, as discussed. - C0 to C3 stay undefined afterwards, like every other x87 instruction. Readers of them are still refused. - No other export changes its generated code: FFREEP appears only in the new export. ## Evidence `cpu_aot_x87_examine` gains the export `ffreep_top`: - It pushes the input m80, 1.0 and 0.0, then runs `ffreep st(0)` at depths 3, 2 and 1. - After each step it records the physical TOP: `fnstsw ax`, `and ah, 38h`, then stores AH. - It stores the values left below. The input is stored raw, for all 34 encodings of the fixture: every class, both signs, and unsupported encodings. The check fails in each of these cases: - **Controls (must mismatch):** - `ffreep`: FFREEP also overwrites the deepest register with the one above it. 33/850 mismatches; the input 1.0 hides it. - `fftop`: the first FFREEP leaves TOP at 5. 34/850. - **New refusals:** - `ffreep` on an empty stack; - a reader of C0 after `ffreep`, and a reader of C1 after it; - `ffreep st(2)`; - `ffree st(0)` and `ffree st(1)`; - `fincstp` and `fdecstp`. Windows 11 Pro 26100.9168, Intel i7-6820HQ, MSVC 19.52, commit b274877b on 623e2112: ``` ctest --preset dev --no-tests=error -R '^cpu_aot_x87_examine$' -V ``` **Result:** - 850 cases over 6 exports matched the model in the native and translated DLLs. The native run gave TOP 5, 6, 7 and 0, and left the values below unchanged. - Controls normal/unsigned/positive/legacy/ffreep/fftop gave 5/136/7/34/33/34 mismatches. - 14 sequences were refused. - The `release` preset gives the same result. Other runs: - Before the rebase, `ctest --preset dev -E '_hardware$'`: 582/582. - After the rebase, `ctest --preset dev -R '^cpu_' -E '_hardware$'`: 225/225. - Release `-R '^cpu_aot_x87_'`: 21/21. - `tools/form_coverage.py --gaps x64_zen2` no longer lists `ffreep`. `ffree` stays listed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 10:02:30 +00:00
tedin7 commented 2026-11-24 10:02:30 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Technical peer review at commit b274877beba687e589d134e7225a4c25c99ccf88 (LGTM, no blocking findings):

Code audit:

  • tools/x87_lower.py: adds M.FFREEP to X87_OPS; _effect() accepts R.ST0 on a nonempty stack (depth > 0, returning depth - 1) and rejects non-ST0 operands (unsupported x87 operand) and empty stacks (x87 stack underflow); _statement() emits a no-op comment since the pop is the depth change, while C0–C3 remain undefined afterwards.
  • tests/cpu/x87_examine.{asm,def,py}, CMakeLists.txt, docs/experiments.md: adds ffreep_top (verifying physical TOP 5, 6, 7, 0 via fnstsw ax and preserved values below across 34 encodings), two new negative controls (ffreep and fftop mutated DLLs), and 8 new rejection cases (ffreep on empty stack, C0/C1 readers after ffreep, ffreep st(2), ffree st(0), ffree st(1), fincstp, fdecstp).

Checks:

  • Linux: docs_links_check.py (16 Markdown files, 301 links), bidi_controls_check.py (1145 files), py_compile on tools/x87_lower.py and tests/cpu/x87_examine.py, and x87_examine.check_rejections() (accepted 1, rejected 14 sequences) all passed; git diff --check clean.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207):
    • Debug (--preset dev): cpu_aot_x87_examine (0.51s) — 1/1 passed (0.58s).
    • Release /O2 (--preset release): cpu_aot_x87_examine (0.51s) — 1/1 passed (0.58s).
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036718678 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1361#pullrequestreview-6036718678). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:30:28Z. **Review:** COMMENTED --- Technical peer review at commit `b274877beba687e589d134e7225a4c25c99ccf88` (LGTM, no blocking findings): **Code audit:** - `tools/x87_lower.py`: adds `M.FFREEP` to `X87_OPS`; `_effect()` accepts `R.ST0` on a nonempty stack (`depth > 0`, returning `depth - 1`) and rejects non-`ST0` operands (`unsupported x87 operand`) and empty stacks (`x87 stack underflow`); `_statement()` emits a no-op comment since the pop is the depth change, while C0–C3 remain undefined afterwards. - `tests/cpu/x87_examine.{asm,def,py}`, `CMakeLists.txt`, `docs/experiments.md`: adds `ffreep_top` (verifying physical TOP 5, 6, 7, 0 via `fnstsw ax` and preserved values below across 34 encodings), two new negative controls (`ffreep` and `fftop` mutated DLLs), and 8 new rejection cases (`ffreep` on empty stack, C0/C1 readers after `ffreep`, `ffreep st(2)`, `ffree st(0)`, `ffree st(1)`, `fincstp`, `fdecstp`). **Checks:** - **Linux**: `docs_links_check.py` (16 Markdown files, 301 links), `bidi_controls_check.py` (1145 files), `py_compile` on `tools/x87_lower.py` and `tests/cpu/x87_examine.py`, and `x87_examine.check_rejections()` (accepted 1, rejected 14 sequences) all passed; `git diff --check` clean. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207)**: - Debug (`--preset dev`): `cpu_aot_x87_examine` (`0.51s`) — **1/1 passed** (`0.58s`). - Release `/O2` (`--preset release`): `cpu_aot_x87_examine` (`0.51s`) — **1/1 passed** (`0.58s`).
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!1354
No description provided.