cpu: accept FFREE ST(0) followed by FINCSTP as a pop in the x87 profile #2211
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2219"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T05:43:16Z.
Refs #1338.
Change
The x87 profile (
tools/x87_lower.py) now accepts FFREE ST(0) directly followed by FINCSTP on a nonempty stack, the slice proposed in #1338 (https://github.com/R0Y00/Xbox2Windows/issues/1338#issuecomment-7153304825). It does not need a TOP or tag model: FFREE tags ST(0) empty and FINCSTP moves TOP up by one, so the pair pops ST(0) like FFREEP ST(0) without a store. The stack stays contiguous at depth d - 1 and TOP is again 8 minus the depth.fincstpandfdecstprejection cases incpu_aot_x87_div,cpu_aot_x87_mul,cpu_aot_x87_moves,cpu_aot_x87_sub,cpu_aot_x87_fnstcwandcpu_aot_x87_examinekeep their message (unsupported x87 operation), and so do theffree st(0)cases ofcpu_aot_x87_addandcpu_aot_x87_moves(frees an occupied register).#1663 and #2098 also change
tools/x87_lower.py; this branch merges without conflicts with the current heads of both and withmainatf7e08a5e(git merge-tree).Verification
cpu_aot_x87_examinegains the exportffree_fincstp(tests/cpu/x87_examine.asm):fld1, the last legal push;fnstsw ax,and ah, 38h, store AH);Controls (must mismatch):
nopop: the status read after each pair reports TOP as if the pair had not popped. 34/952 mismatches.twopop: the same read reports TOP as if the pair had popped twice. 34/952 mismatches.A lowering that kept the depth after the pair, or dropped it by two, does not translate the export at all (a later load overflows or a store underflows; checked with a patched lowerer outside this branch), so these two controls change the status reads of the emitted code instead.
New refusals in
check_rejections: a reader of C0 afterfld1; ftst; ffree st(0); fincstp, a reader of C1 after the pair, the pair on an empty stack,ffree st(1); fincstp,ffree st(0); fnop; fincstp,fincstp; ffree st(0), and ajeto the FINCSTP (the same code with thejeto the FFREE is accepted).Windows 11 Home 25H2 (build 26200), Intel Core i7-10700, MSVC 19.44.35230, commit
ae25887fona4ee28a8:Result:
freetopwent from 102 to 136 becauseffree_fincstpalso reads TOP 7 at depth 1.releasepreset gives the same result.Fail-first: with
tools/x87_lower.pyfroma4ee28a8and this branch's tests, the dev build fails while emitting the fixture (ffree st(0) frees an occupied registerat the first pair), andcpu_aot_x87_examinefails becausecheck_rejectionsrefuses the accepted branch case with the same message.Other runs:
ctest --preset dev --no-tests=error -R '^cpu_aot_x87_'and the same with--preset release: 21/21 each.ctest --preset dev --no-tests=error -R '^cpu_' -E '_hardware$'after a full dev build: 0 failures out of 246, of which 3 are capability skips (77) (cpu_aot_switch_fsgsbase_rdpid,cpu_aot_fences_hints_clwb,cpu_aot_crypto_sha).git diff --checkis clean.Not run: the Linux and macOS jobs (this change has no pure-Python check), and the
_hardwaretests.Evidence and follow-up
The fixture is source-built MASM in this repository (MIT); no external data.
The occupied-slot cases that need a model of TOP and tags stay open in #1338: FFREE of an occupied register without the FINCSTP (deepest register or a hole), and FINCSTP or FDECSTP on their own.
Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:46:02Z.
Review: COMMENTED
Review of head
ae25887f169ff3b6d413f487250c5a47fb9d48dc(comment only, no approval).Verdict
No P1, no P2. The lowering matches the stated semantics: FFREE ST(0) tags ST(0) empty and FINCSTP moves TOP up by one, so the pair pops one slot with no store. Depth goes d to d-1, and the pair on an empty stack is an underflow.
What I checked
git diff --stat origin/main...HEAD). Title is neutral, the PR is not a draft and is MERGEABLE, and there is nothing non-clean-room._discard_pairs/depths: the pair is detected only when the FINCSTP is the next instruction. The branch guardpairs[target] != i.iplets the FFREE fall through into its own FINCSTP and refuses any other edge into it. A branch to the FFREE is still accepted._statementpassespaired=Truefor every FFREE ST(0) and every FINCSTP. This is safe becausedepths()has already rejected the unpaired forms, and an unpaired FINCSTP still hits the oldunsupported x87 operationpath.docs/experiments.md) and theCMakeLists.txtvariant list (nopop twopop) match the new test.Commands run locally (Linux)
python3 tests/docs_links_check.py->Checked 18 Markdown files and 408 links.python3 tests/bidi_controls_check.py->no bidirectional controls.git diff --check origin/main...HEAD-> clean.check_rejections()fromtests/cpu/x87_examine.py(needs iced-x86 and pefile):accepted 2 and rejected 23 sequences, passes.Mutations (reverted with
git checkout -- .)depths->AssertionError: translation accepted a branch into ffree st(0), fincstp. Killed.depthinstead ofdepth - 1->x87 stack not empty at return. Killed.ffree st(0), fnop, fincstpcase fails on its message. Killed.Not run
ffree_fincstp(952 cases, controlsnopopandtwopopeach needing at least one mismatch) needs the Windows harness. I did not run it here. At review time the CI "Build and test on Windows" and gfx1013 jobs were still pending, so that part is unverified by me.Nits (non-blocking)
tools/x87_lower.py(_statement): thepairedargument isTruefor any FFREE ST(0) or FINCSTP. A one-line comment saying it relies ondepths()having already filtered would help later edits. The existing comment mostly says this.tools/x87_lower.py. A rebase is likely, andX87_OPSand_effectare the hot spots.AI-assisted; commands listed were executed locally.