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

Manually merged
github merged 1 commit from gh-pr/1361/head into gh-pr/1361/base 2026-11-26 23:01:08 +00:00
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-24 09:15 UTC · original
legacy-code-archaeologist:cpu/x87-ffreep → main · +73 −9 · 6 files · 1 commits · merged 2026-11-24 09:27 UTC

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

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-24 09:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1361) `legacy-code-archaeologist:cpu/x87-ffreep` → `main` · +73 −9 · 6 files · 1 commits · merged 2026-11-24 09:27 UTC 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)
FFREEP ST(0) tags ST(0) empty and pops it, like FSTP ST(0) without a
store, so the depth drops by one and TOP moves up by one. On an empty
stack it is refused. FFREE, FFREEP ST(i) for i > 0, FINCSTP and FDECSTP
stay outside the profile, since the profile derives TOP from a contiguous
depth. C0 to C3 stay undefined after it.

cpu_aot_x87_examine gains ffreep_top: the input, 1.0 and 0.0 are pushed,
then FFREEP ST(0) runs at depths 3, 2 and 1; TOP after each FNSTSW AX
(AH masked to TOP) and the values left below are compared. Two controls
must mismatch (an FFREEP that also overwrites the deepest register, and a
TOP that the first FFREEP does not move), and eight new sequences must be
refused.

Windows 11 26100, ctest --preset dev --no-tests=error
-R '^cpu_aot_x87_examine$' -V: 850 cases over 6 exports matched in the
native and translated DLLs (TOP 5, 6, 7, 0); controls ffreep/fftop
33/34 mismatches; 14 sequences rejected. Release preset passes the same.

Refs #1338

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:01:06 +00:00
github manually merged commit b274877beb into gh-pr/1361/base 2026-11-26 23:01:08 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 09:30 UTC · original · reviewed

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).
**@⁠tedin7** on GitHub · 2026-11-24 09:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1361#pullrequestreview-6036718678) · **reviewed** 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`).
This discussion has been locked. Commenting is limited to contributors.
No description provided.