cpu: cover FSTSW AX in the x87 examine fixture #1854
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1861"
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 Asimmimx on 2026-11-24T19:43:01Z.
Change
fstswis listed indocs/coverage/x64_zen2.tsv, but no MASM fixture spells it, sotools/form_coverage.pyreports it as uncovered. This adds an export that does to thecpu_aot_x87_examinefixture. Refs #406.ML64 assembles
fstsw axaswait(9B) followed byfnstsw ax(DF E0), and iced decodes those bytes as two instructions. The profile already acceptswaitandfnstsw ax. Per the SDM,waitleaves C0 to C3 undefined, so afterfstsw axonly TOP is known. A reader of C0, C2 or C3 is rejected, butand ah, 38h(TOP only) is accepted. The translator is unchanged.tests/cpu/x87_examine.asm/.def: a new eighth export,fstsw_top, readsfstsw axat depth 0, at depth 1 afterfld tbyte ptr [rcx], and at depth 2 afterfld1andftst. Each read masks AH to TOP and stores it. The export then stores the input m80. It follows the layout offfreep_topandffree_empty, and the generated source shows; // waitbefore each of the threefnstsw axstatements.tests/cpu/x87_examine.py: adds the export to the model (TOP 0, 7, 6, then the input) and its cases (34, one per input value). It adds a ninth control,fstsw, which makes eachfnstsw axthat follows awaitread TOP 0. It also adds a rejection case: the acceptedftstreader sequence with awaitin front offnstsw axmust be rejected with "not known".CMakeLists.txt: addsfstswto thex87_examinecontrol variant list.docs/experiments.md: one paragraph after theffree_emptyparagraph.FSTSW m16 (
9B DD /7) is not covered here, because the profile does not accept it anywhere. Thewaitmakes C0 to C3 unknown even right afterfninit, andfnstswm16 needs every bit except TOP to be known. Before writing the fixture I checked this directly withlower():db e3 9b dd 3a c3in the checked entry is rejected: "fnstsw [rdx] at 0x1003 stores status-word bits 0xc7ff, which are not known on every path from the entry".db e3 dd 3a c3is accepted.The existing
cpu_aot_x87_fldcwrejection case "fnstsw m16 after fninit and wait (fstsw m16)" already covers this. The coverage row is the mnemonicfstsw, so FSTSW AX is enough to cover it.Overlap: #1663 touches
CMakeLists.txt(hunk near line 4568) anddocs/experiments.md(near line 1621). This PR changes lines 4745 and 4747 and adds a paragraph after line 1747, so the textual merge should be clean. #1663 does not touch thex87_examinefiles.Verification
Base
106555ab(origin/main), commit6ff0afbb. Windows 11 Pro 26300.9974, AMD Ryzen 5 5500, MSVC 19.51.36260, ML64 14.51.36260.0, Ninja.Before this change the check had 884 cases over 7 exports.
fftopandfreetopnow also hit the depth-2 and depth-1 reads offstsw_top, so their counts rose from 34 and 68 to 68 and 102. The newfstswcontrol changes onlyfstsw_top, because no other export hasfnstsw axright after await.Coverage effect, from the JUnit file of that run:
fstswis no longer in the gap list.masm_mnemonics(x87_examine.asm)now includesfstsw, and onmainnotests/cpu/*.asmspells it.Pure-Python checks:
No
_hardwaretests were run, and none are affected.Evidence and follow-up
The fixture is hand-written MASM in this repository (MIT). The model takes TOP from the depth (8 minus the depth, modulo 8, since a function enters at TOP 0) and does not depend on the translation. The native DLL ran on the Ryzen 5 5500 above. Negative controls: the new
fstswmutation (34 mismatches, one perfstsw_topcase), the existingfftopandfreetopmutations, which now also cover this export, and the new rejection case, which shows thatfstsw axexposes no condition bit afterftst.This covers the
fstswmnemonic through FSTSW AX only. It does not cover every operand form. Covering FSTSW m16 would need a status-word model in whichwaitkeeps C0 to C3, and the docs say this deliberately follows the SDM rather than iced. That would be a separate translator change.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:50:55Z.
Review: COMMENTED
Peer review of head
6ff0afbb5c28255395fce26e8f0a8e2d13ec639a(PRODUCTION_REVIEW_ONLY, technical comment only).No P1 and no P2 found in the local (Linux) verification. The native-versus-translated comparison needs a Windows run, which I did not do.
What the change does: adds an eighth export
fstsw_topto tests/cpu/x87_examine.asm, its model inreference(), a ninth controlfstsw, and one new rejection case. I read all five files.FSTSW AXanalysis:fld, and afterfld1+ftst. This matches the model inreference().ftst, so the modelled status word still carries a comparison result there. The mask is what makes the fixture independent of it, which is the point of the case.fstp st(0)andfstp tbyte ptr [rdx+16], so the stack is empty and the return value is 0.mov byte ptr [rdx+n], ahneeds no REX prefix.ffx_version_query.lower(..., x87=True). The lowered code reads TOP 0, 7 and 6 at the threefnstsw axsites, each preceded by// wait. Thefstswcontrol's pattern matches exactly those three sites in the lowered text, so the control changes something, as the script requires, and it cannot match the plainfnstswof the other exports.fftopandfreetopcontrols now also hit the new export; the PR text and comments say so. The CMake change adds thefstswvariant to the control list.New rejection case:
fld1; ftst; wait; fnstsw ax; test ah,1must be rejected as "not known". It runs on Linux and passes. Mutation (tools/x87_lower.py_after,elif not (is_x87(i) or call) or op == M.WAIT:, so WAIT keeps C0 to C3 known):check_rejectionsfails with "translation accepted fstsw ax after ftst then a reader of C0" (rc=1). The tree was restored withgit checkout -- ..A second mutation of the AX-state tracking (dropping
| TOP_BITSfrom the known bits of AX after FNSTSW AX) is not caught by the rejection cases. That is expected, since the value comparison covers it, and it is only exercised on Windows.For the Windows run (not done by me):
cpu_aot_x87_examine(regex^cpu_aot_x87_examine$), built fromcpu_x87_examine,cpu_x87_harnessand the controlscpu_x87_examine_{lifted,normal,unsigned,positive,legacy,ffreep,fftop,ffree,freetop,fstsw}.stack_top = (8 - depth) & 7changed to(7 - depth) & 7in the FNSTSW emission. The check should then mismatch onfstsw_topand on the other exports that read TOP.Commands run (Linux):
git diff --check <merge-base>...HEAD: cleantests/docs_links_check.py: passtests/bidi_controls_check.py: passcheck_rejections()from tests/cpu/x87_examine.py: pass (accepted 1, rejected 16)ffx_version_query.lower, and the control's regex against the result (3 matches)mainhas no content conflicts (git merge-tree).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:12:10Z.
Built it and ran it — after three of the variant DLLs turned out stale
At the PR head, Windows 11 build 26300.9974, MSVC 19.44:
A warning for anyone repeating this, because it cost me two red runs that were mine: the check takes eleven DLLs, and if
only some variants are rebuilt the rest keep their old exports. Mine failed with
and probing the exports showed
cpu_x87_examine_fftop,_ffreeand_freetopstill at the pre-checkout timestamp (04:11 vs05:09). Building those three turned the run green with no change to the PR. A partial build here reads exactly like a broken
fixture.
What the new export pins
fstsw_topreads the status at depth 0, 1 and 2 and masks AH to TOP before storing, so the fixture checks only the part of thestatus word
waitleaves defined. Two independent controls back that up:fftoprewrites the depth-2 read tox87_sw | 0x2800(TOP 5 instead of 6) — its comment says the literal also matchesfstsw_top's depth-2 read, so both exports mismatch.freetoprewrites the depth-1 read to TOP 0 — the comment says it matches the depth-1 reads offfreep_topandfstsw_top, so all three mismatch.That is the right construction: one mutated literal invalidates several exports at once, so the fixture proves the model is
compared per export rather than a single scalar being right by luck.
The
fstswcontrol is the subtler one — it makes everyfnstsw axthat follows awaitread TOP 0, which is what a translatorwould produce if it treated the pair as
fnstswalone. Having that as a required mismatch is what keeps thewaitin thepicture at all.
Verdict
Reviewed. The fixture is source-built, the export list and
.defagree, the model covers three depths plus the control, and thewhole check passes here. No objections.
Notes