cpu: lower FNSTSW m16 where every status-word bit is known #1205
No reviewers
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!1205
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1205/head"
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?
@tedin7 on GitHub · 2026-11-24 03:33 UTC · original
tedin7:x2w-x87-lower-fnstsw-m16→main· +122 −22 · 10 files · 2 commits · merged 2026-11-24 05:19 UTCChange
Accepts
FNSTSW m16(andFSTSW m16, which assembles asWAITandFNSTSW m16) in the x87 leaf-function profile. Refs #406.Memory cannot record an unknown bit, so the store is accepted only where the status-word dataflow knows every bit but TOP on every path from the entry: C0 to C3, C1, IE to PE, SF, ES and the busy bit. Only
FNINIT(checked entry) leaves them all known, because it clears the whole word. Any other x87 instruction makes them unknown again (FCOMI,FPREMandFPREM1may raise an exception flag), integer instructions do not. Elsewhere the translation is rejected with the unknown bits named, and the fixed profile rejects it. The stored word is the status variable with TOP (8 minus the depth, modulo 8) in bits 11 to 13, written as a 2-byte guest store likeFNSTCW m16.FNSTSW AXis unchanged. No exception-flag emulation, no new status code.Touches
tools/x87_lower.pyonly in the lowerer; the checks extendtests/cpu/x87_fldcw.py(and its generated.asmand.def). Three earlier tests andcpu_aot_x87_compareasserted the rejection of anFNSTSW m16after a load by message; their needle now names the unknown bits and they still assert the rejection.Verification
Linux x86-64 (
llvm-ml19,lld-link19, MinGW g++ (GCC 14-posix) with a small shim for_udiv128and__assume, Wine; the shim and the driver are outside the repo):cw_fnstsw,cw_finit_fnstsw), 696 cases: 576 matched the model in the native and translated DLLs, 72 with an unmasked word ran only translated, 48 with precision control 01 are rejected. The model takes the word from the SDM (FNINITclears the status word) and the depth, not from the translation.x87_fldcwmatched in the translated DLL (statuses 16950, 678, 452, 408).tests/cpu/x87_fldcw.py emitfails withunsupported x87 operand at 0x119e: fnstsw [rdx+21h]. With this change it succeeds.fninitkeeping C0 to C3 now also trips on the new export (1028, was 850).check_rejections()of all 21 x87 test modules pass; every x87 test module still emits its fixture.python3 -B tests/docs_links_check.py: 15 files, 266 links.FNINITwithWAIT,FNSTCW,FNSTSW AX, a secondFNSTSW,FCOMIorFPREM, on a path that skipsFNINIT, and in the fixed profile) and three accepted cases (right afterFNINIT, after a flag-neutral store, after two paths that each runFNINIT).Not run:
cpu_aot_x87_fldcwis outside theprtest preset, so CI does not run it either. The comparison on Windows with MSVC and ML64 (ctest --preset dev --no-tests=error -R '^cpu_aot_x87_fldcw$' -V). I have no Windows machine, so CI is the first MSVC run. The native run of the other exports under Wine hit an unrelated Wine FP exception at thecw_subcase 1799 (not touched here), so only the two new exports were compared natively.Evidence and follow-up
Fixtures are generated from
tests/cpu/x87_fldcw.py(original source, MIT). Docs:docs/experiments.md(thecpu_aot_x87_fldcwparagraph, with the Linux-only numbers marked as such). Assumption: MinGW and Wine exercise the same translated C++, not MSVC code generation. Follow-up: a richer form needs a model of the exception flags (option (a) in the issue discussion).AI-assisted (Claude Code).
Checklist
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 03:38 UTC · original · edited 2026-11-24 04:09 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
726d232ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@ -229,2 +240,4 @@# FNINIT leaves C0 to C3 as FCOM set them."fninitsw": _mutate(r"(x87_cw = 0x037f;) x87_sw = 0;( // fninit)", r"\1\2"),# FNSTSW m16 stores a TOP of 7 instead of the depth-derived 0."swtop": _mutate(r"x87_sw \| 0x0000\)\); \} // fnstsw m16", "x87_sw | 0x3800)); } // fnstsw m16"),@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 03:43 UTC · original
In the repository's CMake/CTest path, none of
swtop,swbyte,swwide,swaddr, orswnoneis exercised:CMakeLists.txt:3186still enumerates only the pre-existing variants, andcheck()runs only the control DLLs supplied throughx87_fldcw_control_files. Consequently, the documentedcpu_aot_x87_fldcwreproduction omits these five new negative-control checks even though the experiment now specifies seventeen controls. Add the five variants to the CMake loop so the standard test builds and validates these regression guards.AGENTS.md reference: AGENTS.md:L163-L163
Useful? React with 👍 / 👎.
@ -229,2 +240,4 @@# FNINIT leaves C0 to C3 as FCOM set them."fninitsw": _mutate(r"(x87_cw = 0x037f;) x87_sw = 0;( // fninit)", r"\1\2"),# FNSTSW m16 stores a TOP of 7 instead of the depth-derived 0."swtop": _mutate(r"x87_sw \| 0x0000\)\); \} // fnstsw m16", "x87_sw | 0x3800)); } // fnstsw m16"),@tedin7 on GitHub · 2026-11-24 03:45 UTC · original
Fixed in
726d232e.@tedin7 on GitHub · 2026-11-24 03:45 UTC · original
AI-assisted: the five new FNSTSW m16 controls (swtop, swbyte, swwide, swaddr, swnone) are now in the CMake variant list, so
cpu_aot_x87_fldcwbuilds and runs all seventeen controls. The list now matches the test CONTROLS exactly, and every variant emits with at least one replacement.@tedin7 on GitHub · 2026-11-24 04:06 UTC · original
@codex review
AI-assisted: the inline findings are fixed and answered in their threads; please re-read the current head.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 04:09 UTC · original
Codex Review: Didn't find any major issues. Hooray!
Reviewed commit:
726d232e49ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@tedin7 on GitHub · 2026-11-24 04:54 UTC · original
Windows Server 2025 verification (
726d232e) — PASS (Debug + Release/O2)--preset dev) (87.73s build+test):cmake --build --preset dev -j 6 --target <cpu_x87_* targets>ctest --test-dir out\build\dev -j 6 -R "^cpu_aot_x87" --output-on-failure-> 21/21 passed (0 skipped, includingcpu_aot_x87_fldcw)/O2(--preset release) (87.39s configure+build+test):cmake --preset release && cmake --build --preset release -j 6 --target <cpu_x87_* targets>ctest --test-dir out\build\release -j 6 -R "^cpu_aot_x87" --output-on-failure-> 21/21 passed (0 skipped, 35.74s;cpu_aot_x87_fldcw12.71s)@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 03:43 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
beccc1ed03ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".