cpu: verify x87 FNSTENV/FNSAVE after FNINIT and wait-prefixed refusal (Part of #870) #2091
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2098"
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-25T00:14:06Z.
Part of #870
What this unblocks: x87 code that saves the FPU environment (
fnstenv,fnsave) right afterfninitnow translates in the checked profile instead of being refused as environment access.Summary:
tools/x87_lower.py: acceptfnstenv(28 bytes) andfnsave(108 bytes) in the 32-bit protected-mode layout. They follow the existingfnstsw m16rule: only where the whole status word is known, which is right afterfninit. There the stack is empty, the status word is 0, the tag word is 0xFFFF and the pointers are zero, so the stored words are exact.fnsavestores ST(0) to ST(7) from the model's slots (the SDM does not define an empty register's bytes), then initializes asfninitdoes, so the function must restore control word 0x027F. Only the checked entry acceptsfnsave.fstenvandfsave(WAIT plus the store) are still refused, with the unknown bits named: the existing rule says WAIT leaves C0 to C3 undefined (cpu_aot_x87_statustests this forfstsw), so the stored word is not known.finitthenfnstenvis accepted. I did not change that rule.tests/cpu/x87_environment_check.py, registered ascpu_x87_environment_controlsinCMakeLists.txt: pure Python. It compares the emitted stores with the SDM layout built in the test, and checks the refusals.docs/experiments.mdand the module docstring describe the rule.Open question: if the project wants
fstenv/fsaveaccepted, the WAIT rule has to change forfstsw m16too (its existing rejection case intests/cpu/x87_status.pywould flip). That is a separate decision.Verification:
python3 -B tests/cpu/x87_environment_check.py: fails on main (unsupported x87 operation ... fnstenv), passes with the change.check_rejections()ofx87_status.py,x87_fldcw.py,x87_bcd.py,x87_parity.py,x87_examine.py: pass.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:21:46Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
f0a5fb87d7ℹ️ 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-25T00:14:16Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
f0a5fb8ℹ️ 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 R0Y00 on 2026-11-25T00:52:18Z.
Independent Windows confirmation of the existing review finding: on Core i9-14900HX, a source-built x64 MASM procedure saved the host FPU state, ran FNINIT plus FNSTENV or FNSAVE, then restored the host state. Both wrote 0xffff at environment halfword offsets 2, 6, 10 and 26; both retained guard bytes outside their respective 28- and 108-byte destinations. The full-layout zero expectation in the Python fixture therefore disagrees on this host too. Please pair the representation change with an actual native/AOT full-environment comparison and retain the existing non-empty-stack refusals. A second CPU family would help establish the supported profile for those reserved words.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:21:46Z.
Code review location:
tools/x87_lower.py; line 665When an accepted function reads back the complete saved environment, these dword stores expose different bytes from native execution. On the inspected Intel Xeon Platinum 8370C/Linux x86-64 host, both
fninit; fnstenvandfninit; fnsavewrite0xffffat halfword offsets 2, 6, 10 and 26, whereas the emitted stores write zero. Consequently, reading the first dword after saving the environment returns0x0000037finstead of0xffff037f. The newenvironment()oracle repeats the zero-padding assumption and marks all 28 bytes as defined, missing all eight differing bytes. Match the native representation, or reject observations of unmodeled reserved fields rather than treating every stored byte as exact.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T00:21:46Z.
Code review location:
tools/x87_lower.py; line 252The existing FNSTENV cases in
tests/cpu/x87_sub.py,tests/cpu/x87_moves.py,tests/cpu/x87_constants.pyandtests/cpu/x87_rndint.pyexecute the store with a non-empty stack and require a rejection containingunsupported x87 operation. This branch now raisesstores the tag word of a non-empty x87 stack, so all four registered CPU tests fail incheck_rejections()even if their native/translated execution comparisons succeed. Update those expectations alongside the new diagnostic while retaining the negative cases.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:05:01Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:05:03Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:36:42Z.
@R0Y00 Update for commit
3ee66b25:0xffff.tests/cpu/x87_environment_check.pywere updated to match.Verification on Windows Server 2025 (build 26100, MSVC 14.44.35207), head
3ee66b25a6fbc5b0e97426de91d394a98dfece39, run through the repo Win2025 pipeline with focused targets (cpu_x87_harnessplus thesub,moves,constantsandrndintfixtures and their variants):--preset dev):ctest -R 'cpu_(aot_x87_(sub|moves|constants|rndint)|x87_environment_controls)'gave 5/5 passed (7.39s)./O2(--preset release): same regex, 5/5 passed (5.93s).tests/cpu/x87_environment_check.py: ok (0.5s).Limit: I have not run a second CPU family or a native full-environment comparison locally. The
0xffffvalues come from the documented FNSTENV layout and the current checks, not from a cross-CPU comparison.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:05:01Z.
Code review location:
tools/x87_lower.py; line 665Fixed in 65c11183 (rebased on current main, pending push to this branch). The environment store now writes 0xffff in the reserved halfwords at 2, 6, 10 and 26, matching a native fninit; fnstenv and fninit; fnsave on x86-64 Linux (dwords ffff037f ffff0000 ffffffff 0 0 0 ffff0000), and the oracle in tests/cpu/x87_environment_check.py uses the same bytes. The FNSTENV refusal checks in x87_sub, x87_moves, x87_constants and x87_rndint expect the new diagnostic.
AI-assisted; commands listed were executed locally: python3 -B tests/cpu/x87_environment_check.py, check_rejections() of x87_sub, x87_moves, x87_rndint and x87_constants. The full x87 CPU runs need Windows and were not run.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:05:03Z.
Code review location:
tools/x87_lower.py; line 252Fixed in 65c11183 (rebased on current main, pending push to this branch). The environment store now writes 0xffff in the reserved halfwords at 2, 6, 10 and 26, matching a native fninit; fnstenv and fninit; fnsave on x86-64 Linux (dwords ffff037f ffff0000 ffffffff 0 0 0 ffff0000), and the oracle in tests/cpu/x87_environment_check.py uses the same bytes. The FNSTENV refusal checks in x87_sub, x87_moves, x87_constants and x87_rndint expect the new diagnostic.
AI-assisted; commands listed were executed locally: python3 -B tests/cpu/x87_environment_check.py, check_rejections() of x87_sub, x87_moves, x87_rndint and x87_constants. The full x87 CPU runs need Windows and were not run.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:02:06Z.
Code review location:
tools/x87_lower.py; line 665Re-checked on current head
3ee66b25: x87 environment saves write native 0xffff reserved halfwords and the FNSTENV refusal text and checks are updated (3ee66b25). Resolving. AI-assisted; commands listed were executed locally.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:02:09Z.
Code review location:
tools/x87_lower.py; line 252Re-checked on current head
3ee66b25: x87 environment saves write native 0xffff reserved halfwords and the FNSTENV refusal text and checks are updated (3ee66b25). Resolving. AI-assisted; commands listed were executed locally.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:02:06Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:02:09Z.
Review: COMMENTED
No description provided.