cpu: accept FFREE of a statically empty register in the x87 profile #1412

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/1419 into main 2026-11-24 11:33:58 +00:00
legacy-code-archaeologist commented 2026-11-24 11:08:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T11:08:57Z.


Refs #1338

What

The x87 profile (tools/x87_lower.py) now accepts FFREE ST(i) when ST(i) is statically known to be empty, that is when i is at least the depth. This is the slice approved in #1338.

  • Occupancy, TOP and every occupied slot stay unchanged. C0 to C3 become undefined, and readers of them stay refused.
  • FFREE of an occupied register is refused with "frees an occupied register". That covers the deepest register (TOP would stay while the stack shrinks) and any other (a hole).
  • Unchanged by this PR: FFREEP ST(i) for i > 0, FINCSTP and FDECSTP stay outside the profile, and TOP only changes as it did before.

Existing tests changed (please check)

tests/cpu/x87_add.py and tests/cpu/x87_moves.py each had the rejection case ffree st(1) after one fld. ST(1) is empty at depth 1, so this PR accepts that sequence. Both cases now use ffree st(0) on the occupied ST(0) and still expect a refusal, now with the "frees an occupied register" message.

Evidence

cpu_aot_x87_examine gains the export ffree_empty:

  • It runs ffree st(0) and ffree st(7) at depth 0.
  • It runs ffree st(1), st(4) and st(7) at depth 1.
  • At depth 7 it runs ffree st(7), then the final legal push to depth 8.
  • After each group it records the physical TOP (fnstsw ax, and ah, 38h, store AH).
  • From depth 8 it stores the pushed 0.0, the 1.0 below it, and the input at the bottom, for all 34 m80 encodings of the fixture.

The check fails in each of these cases:

  • Controls (must mismatch):
    • ffree: ffree st(7) frees ST(0) instead. 34/884 mismatches.
    • freetop: FFREE moves TOP as a pop does, so the status word at depth 1 reads TOP 0. 68/884 mismatches; the literal also matches the depth-1 status read of ffreep_top.
  • New refusals:
    • a reader of C0 after fld1; ftst; ffree st(1) (the same sequence without FFREE is accepted);
    • ffree st(0) and ffree st(1) on occupied registers.

Windows 11 Pro 26100.9168, Intel i7-6820HQ, MSVC 19.52, commit c6571ee9 on 153bb5f6:

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

Result:

  • 884 cases over 7 exports matched the model in the native and translated DLLs. The native run gave TOP 0, 7 and 0. The push from depth 7 did not overflow, and the values were unchanged.
  • Controls normal/unsigned/positive/legacy/ffreep/fftop/ffree/freetop gave 5/136/7/34/33/34/34/68 mismatches.
  • 15 sequences were refused.
  • cpu_aot_x87_add and cpu_aot_x87_moves pass.
  • The release preset gives the same result.

Other runs:

  • Before the rebase, ctest --preset dev -E '_hardware$': 630/630.
  • Release -R '^cpu_aot_x87_': 21/21.
  • tools/form_coverage.py --gaps x64_zen2 no longer lists ffree.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580425229 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1419). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T11:08:57Z. --- Refs #1338 ## What The x87 profile (`tools/x87_lower.py`) now accepts **FFREE ST(i) when ST(i) is statically known to be empty**, that is when `i` is at least the depth. This is the slice approved in #1338. - Occupancy, TOP and every occupied slot stay unchanged. C0 to C3 become undefined, and readers of them stay refused. - FFREE of an occupied register is refused with "frees an occupied register". That covers the deepest register (TOP would stay while the stack shrinks) and any other (a hole). - Unchanged by this PR: FFREEP ST(i) for i > 0, FINCSTP and FDECSTP stay outside the profile, and TOP only changes as it did before. ## Existing tests changed (please check) `tests/cpu/x87_add.py` and `tests/cpu/x87_moves.py` each had the rejection case `ffree st(1)` after one `fld`. ST(1) is empty at depth 1, so this PR accepts that sequence. Both cases now use `ffree st(0)` on the occupied ST(0) and still expect a refusal, now with the "frees an occupied register" message. ## Evidence `cpu_aot_x87_examine` gains the export `ffree_empty`: - It runs `ffree st(0)` and `ffree st(7)` at depth 0. - It runs `ffree st(1)`, `st(4)` and `st(7)` at depth 1. - At depth 7 it runs `ffree st(7)`, then the final legal push to depth 8. - After each group it records the physical TOP (`fnstsw ax`, `and ah, 38h`, store AH). - From depth 8 it stores the pushed 0.0, the 1.0 below it, and the input at the bottom, for all 34 m80 encodings of the fixture. The check fails in each of these cases: - **Controls (must mismatch):** - `ffree`: `ffree st(7)` frees ST(0) instead. 34/884 mismatches. - `freetop`: FFREE moves TOP as a pop does, so the status word at depth 1 reads TOP 0. 68/884 mismatches; the literal also matches the depth-1 status read of `ffreep_top`. - **New refusals:** - a reader of C0 after `fld1; ftst; ffree st(1)` (the same sequence without FFREE is accepted); - `ffree st(0)` and `ffree st(1)` on occupied registers. Windows 11 Pro 26100.9168, Intel i7-6820HQ, MSVC 19.52, commit c6571ee9 on 153bb5f6: ``` ctest --preset dev --no-tests=error -R '^cpu_aot_x87_examine$' -V ``` **Result:** - 884 cases over 7 exports matched the model in the native and translated DLLs. The native run gave TOP 0, 7 and 0. The push from depth 7 did not overflow, and the values were unchanged. - Controls normal/unsigned/positive/legacy/ffreep/fftop/ffree/freetop gave 5/136/7/34/33/34/34/68 mismatches. - 15 sequences were refused. - `cpu_aot_x87_add` and `cpu_aot_x87_moves` pass. - The `release` preset gives the same result. Other runs: - Before the rebase, `ctest --preset dev -E '_hardware$'`: 630/630. - Release `-R '^cpu_aot_x87_'`: 21/21. - `tools/form_coverage.py --gaps x64_zen2` no longer lists `ffree`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 12:02:52 +00:00
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!1412
No description provided.