cpu: lower FNSTSW m16 where every status-word bit is known #1198
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1205"
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 tedin7 on 2026-11-24T03:33:08Z.
Change
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
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:43:55Z.
Review: COMMENTED
💡 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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:45:45Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:45:47Z.
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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:06:09Z.
@codex review
AI-assisted: the inline findings are fixed and answered in their threads; please re-read the current head.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T04:09:55Z.
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".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:38:02Z.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T04:54:09Z.
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)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T03:43:55Z.
Code review location:
tests/cpu/x87_fldcw.py; line 243In 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T03:45:45Z.
Code review location:
tests/cpu/x87_fldcw.py; line 243Fixed in
726d232e.upstream-sync referenced this pull request2026-11-24 13:00:54 +00:00