cpu: FFREE and FFREEP in the x87 profile where the stack stays contiguous #1338
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#1338
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@legacy-code-archaeologist on GitHub · 2026-11-24 08:30 UTC · original
The x87 profile (
tools/x87_lower.py) tracks a contiguous stack depth. It refuses FFREE, FFREEP, FINCSTP and FDECSTP as outside the profile.form_coverage --gaps x64_zen2one3193607lists all four as unobserved. I'd like to take a small slice that keeps the contiguous-depth model.Proposed acceptance, with depth
dbefore the instruction (all others refused):d >= 1: tags ST(0) empty and pops. The depth becomesd - 1, the same as FSTP ST(0) without storing anything. Atd = 0it is refused, because the pop would change TOP while the depth stays 0.i = d - 1(the deepest occupied register): the depth becomesd - 1and TOP stays the same. The remaining registers stay contiguous.i >= d(an already empty register): no effect.i < d - 1, which would leave a hole the depth model cannot represent;i > 0;check_flagsthen keeps refusing readers of those bits. TOP stays known from the depth.Fixture plan (source-built MASM, native vs translated, plus
/O2):ffree st(7), then load one more value. Natively this must not overflow (the result is not the indefinite NaN). It shows the freed slot is really free.ffreep st(0)drops ST(0); the values below it are stored and compared.ffree st(1)at depth 3 (hole),ffreep st(0)at depth 0,ffreep st(2),fincstp,fdecstp.Two questions:
i >= dbe accepted as a no-op, or refused to keep the profile narrow?@R0Y00 on GitHub · 2026-11-24 08:39 UTC · original
Please start with FFREEP ST(0) on a known nonempty stack. An explicit refusal on empty depth is appropriate for this profile. Compare the remaining values and physical TOP and keep readers of undefined condition bits rejected. Leave FFREE for a follow-up. Freeing the deepest slot changes occupancy without moving TOP, so a model that derives TOP from depth would report the wrong status word even when its register values look right. Freeing an already empty slot can be considered with that follow-up and should preserve TOP and test any observable condition bits. A full-stack refill alone would miss this error.
@R0Y00 on GitHub · 2026-11-24 09:28 UTC · original
#1361 is on main at
b9c9f624. The Windows Release native/AOT fixture passed with the FFREEP and physical-TOP mutation controls. This covers FFREEP ST(0) on a known nonempty stack. Keeping this issue open for FFREE, where freeing a slot does not move TOP.@legacy-code-archaeologist on GitHub · 2026-11-24 10:07 UTC · original
Proposal for the FFREE follow-up. The two FFREE cases differ in how much of the model they need.
1. FFREE ST(i) with
i >= depth(an already empty register). Occupancy and TOP stay as they are, so the depth model stays exact. I'd accept this now:ffree st(i)for every emptyiat depths 0, 1 and 7. After each one, record the physical TOP (fnstsw ax; and ah, 38h) and the values still on the stack. At depth 7,ffree st(7)is followed by one morefld, which must not overflow natively (the loaded value, not the indefinite NaN).2. FFREE ST(depth - 1) (the deepest occupied register). TOP stays and the occupied range shrinks from the bottom. The profile would then need a second number next to the depth, the count of registers freed below the stack, so that
TOP = (8 - depth - freed) mod 8and pushes and pops keep TOP right.The catch is the return. With
freed > 0and an empty stack, TOP is not 0. The profile requires TOP 0 at the entry and the return, and FINCSTP and FDECSTP are outside it. So this case could only be accepted together with FINCSTP/FDECSTP, or with a refusal at the return, which would leave almost nothing usable. I'd keep it refused for now, with a refusal test, and leave it to whoever takes FINCSTP and FDECSTP.Refused in this slice:
i < depth(a hole, or the deepest register);Should I build case 1 like this?
@R0Y00 on GitHub · 2026-11-24 10:25 UTC · original
Please take the already-empty-slot case as the next slice. Require that the slot is statically known empty, preserve TOP and all occupied slots, and treat C0–C3 as unknown. Compare native and AOT at depths 0, 1 and 7, including the final legal push from depth 7 and the pop/wrong-slot controls. Keep occupied-slot FFREE and changes to TOP outside this patch. The issue stays open for those cases.
@R0Y00 on GitHub · 2026-11-24 11:42 UTC · original
The already-empty FFREE slice landed in #1419 at
81446f94. Windows Release passed the native/AOT examination, add and move checks (3/3). The examination fixture tests depths 0, 1 and 7 and checks physical TOP, the last legal push and two mutation controls. Keeping this issue open for occupied-slot behavior, which needs a model of TOP and tags.@roansystemlabs on GitHub · 2026-11-25 04:56 UTC · original
I'd like to take the next occupied-slot piece of this issue, scoped so it does not need a TOP or tag model yet: FFREE ST(0) immediately followed by FINCSTP in the same block, the classic discard-top idiom.
Scope:
Evidence: a source-built native/AOT comparison at depths 1, 2 and 8 that checks the remaining values and the physical TOP (fnstsw ax), plus the last legal push after the pair at depth 8; mutation controls that treat the pair as no pop or as two pops must fail; negative controls for FFREE ST(0) without FINCSTP, FINCSTP alone and a jump into the pair. Windows 11, MSVC, Release and Debug.
If you would rather have the full TOP and tag model here, or if someone already has this in progress, I'll step back and review.
AI-assisted.