cpu: lower FNINIT and FINIT in the checked x87 entry #904

Manually merged
github merged 1 commit from gh-pr/904/head into gh-pr/904/base 2026-11-26 22:27:14 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-23 16:37 UTC · original
denn0x:cpu/lower-x87-fninit → main · +103 −18 · 6 files · 1 commits · merged 2026-11-23 16:57 UTC

Refs #406

Adds fninit and finit to the checked x87 entry. The fixed profile still rejects both.

Behavior

  • fninit loads control word 0x037F, clears C0 to C3 and empties every register, so the depth after it is 0. finit decodes as wait and fninit. Every exception is masked, so none is pending and wait does nothing.
  • C0 to C3 are known after fninit, all zero, until the next x87 instruction. C1 is included, as after fprem (#893).
  • 0x037F has 64-bit precision. A function that runs fninit must restore 0x027F before it returns, otherwise it leaves with status 3, as for fldcw. It also counts as loading the control word for the call and edge rule, so a function with fninit and a call is rejected.
  • A store after fninit has emptied the stack is a stack underflow and is rejected.

Measurements

Commit 7217bf5 on 1f6c38a. The full suite and identity check ran on the same change at d2dc298, before a rebase over #404, which does not touch the x87 files. AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2), Windows 11 build 26300, MSVC x64, dev preset.

ctest --preset dev --no-tests=error -R '^cpu_aot_x87_fldcw$' -V

cpu_aot_x87_fldcw gains two exports and two controls:

  • cw_fninit runs fcom, so C0, C2 and C3 are set, then fninit under a loaded word, fnstsw ax, fnstcw, and a quotient under 0x037F.
  • cw_finit runs finit at depth 8, then returns without a restore, which gives status 3.
  • 17792 cases over 17 exports, previously 15944 over 15, matched the model in the checked translation: status, output block and guards, and *result.
  • Statuses: 16374 ok, 606 unmasked, 404 precision and 408 unrestored.
  • The 16782 native cases matched the model, including the control word each export left. After fninit the native and translated C0 to C3 are 0 and fnstcw stores 0x037F.
  • Twelve controls each mismatch. The two new ones are fninitword (fninit keeps the control word), with 1680, and fninitsw (fninit keeps C0 to C3), with 850. The other ten still mismatch.
  • Rejected, new: fninit in the fixed profile, fninit with a call, and a store after fninit. Translated, new: fninit with a value on the stack, then a restore.

Wider checks on the same commit:

  • ctest --preset dev --no-tests=error -R '^cpu_' at 7217bf5: 162/162 pass.
  • Full suite: 462 passed (19 of them capability skips) and 3 failed, out of 465. The 3 failures are the RX 9070 XT hardware results listed in #893 (dxr_opacity_hardware, gpu_alias_lookup_writes_hardware and pixel_aot_comparisons_hardware), from code this change does not touch.
  • Generated cpu_*.cpp versus main: 311 byte-identical and 3 more after removing the aot_source_sha256 line. The 11 cpu_x87_fldcw_* sources only gain lines, for the two new exports. The remaining 2 are the build-path-dependent cpu_exe_image_selector and cpu_image_data_lifted.
  • form_coverage_check, docs_links_check and bidi_controls_check pass.

docs/experiments.md updates the checked-entry paragraph and the cpu_aot_x87_fldcw results. The earlier Intel Core Ultra 7 358H result is kept and labelled as covering the 15 exports from before this change.

AI-assisted (Claude Code).

**@⁠denn0x** on GitHub · 2026-11-23 16:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/904) `denn0x:cpu/lower-x87-fninit` → `main` · +103 −18 · 6 files · 1 commits · merged 2026-11-23 16:57 UTC Refs #406 Adds `fninit` and `finit` to the checked x87 entry. The fixed profile still rejects both. ## Behavior - `fninit` loads control word `0x037F`, clears C0 to C3 and empties every register, so the depth after it is 0. `finit` decodes as `wait` and `fninit`. Every exception is masked, so none is pending and `wait` does nothing. - C0 to C3 are known after `fninit`, all zero, until the next x87 instruction. C1 is included, as after `fprem` (#893). - `0x037F` has 64-bit precision. A function that runs `fninit` must restore `0x027F` before it returns, otherwise it leaves with status 3, as for `fldcw`. It also counts as loading the control word for the call and edge rule, so a function with `fninit` and a call is rejected. - A store after `fninit` has emptied the stack is a stack underflow and is rejected. ## Measurements Commit `7217bf5` on `1f6c38a`. The full suite and identity check ran on the same change at `d2dc298`, before a rebase over #404, which does not touch the x87 files. AMD Ryzen 7 7700 (`AMD64 Family 25 Model 97 Stepping 2`), Windows 11 build 26300, MSVC x64, `dev` preset. ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_x87_fldcw$' -V ``` `cpu_aot_x87_fldcw` gains two exports and two controls: - `cw_fninit` runs `fcom`, so C0, C2 and C3 are set, then `fninit` under a loaded word, `fnstsw ax`, `fnstcw`, and a quotient under `0x037F`. - `cw_finit` runs `finit` at depth 8, then returns without a restore, which gives status 3. - 17792 cases over 17 exports, previously 15944 over 15, matched the model in the checked translation: status, output block and guards, and `*result`. - Statuses: 16374 ok, 606 unmasked, 404 precision and 408 unrestored. - The 16782 native cases matched the model, including the control word each export left. After `fninit` the native and translated C0 to C3 are 0 and `fnstcw` stores `0x037F`. - Twelve controls each mismatch. The two new ones are `fninitword` (`fninit` keeps the control word), with 1680, and `fninitsw` (`fninit` keeps C0 to C3), with 850. The other ten still mismatch. - Rejected, new: `fninit` in the fixed profile, `fninit` with a call, and a store after `fninit`. Translated, new: `fninit` with a value on the stack, then a restore. Wider checks on the same commit: - `ctest --preset dev --no-tests=error -R '^cpu_'` at `7217bf5`: 162/162 pass. - Full suite: 462 passed (19 of them capability skips) and 3 failed, out of 465. The 3 failures are the RX 9070 XT hardware results listed in #893 (`dxr_opacity_hardware`, `gpu_alias_lookup_writes_hardware` and `pixel_aot_comparisons_hardware`), from code this change does not touch. - Generated `cpu_*.cpp` versus `main`: 311 byte-identical and 3 more after removing the `aot_source_sha256` line. The 11 `cpu_x87_fldcw_*` sources only gain lines, for the two new exports. The remaining 2 are the build-path-dependent `cpu_exe_image_selector` and `cpu_image_data_lifted`. - `form_coverage_check`, `docs_links_check` and `bidi_controls_check` pass. `docs/experiments.md` updates the checked-entry paragraph and the `cpu_aot_x87_fldcw` results. The earlier Intel Core Ultra 7 358H result is kept and labelled as covering the 15 exports from before this change. AI-assisted (Claude Code).
FNINIT loads control word 0x037F, clears C0 to C3 and empties every
register, so the depth after it is 0. Only the checked entry accepts it:
the function must restore 0x027F before it returns (status 3 otherwise)
and it counts as loading the control word for the call and edge rule.
The fixed profile still rejects it.

cpu_aot_x87_fldcw gains cw_fninit (FCOM, FNINIT, FNSTSW AX and FNSTCW,
then a quotient under 64-bit precision) and cw_finit (FINIT at depth 8
and a return without a restore), two controls (fninitword, fninitsw),
three rejections and one accepted twin.

AI-assisted (Claude Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:27:12 +00:00
github manually merged commit 7217bf5e2c into gh-pr/904/base 2026-11-26 22:27:14 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 16:57 UTC · original

Independent Windows x64 review of 7217bf5 on Intel Family 6 Model 183 Stepping 1: cpu_aot_x87_fldcw passed in Debug and Release. Both new controls fired in each run (1,680 control-word and 850 condition-code mismatches), and the post-FNINIT stack underflow and fixed-entry refusals were observed. Precision-control 01 was recorded separately as a native observation.

**@⁠R0Y00** on GitHub · 2026-11-23 16:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/904#issuecomment-7107922083) Independent Windows x64 review of 7217bf5 on Intel Family 6 Model 183 Stepping 1: cpu_aot_x87_fldcw passed in Debug and Release. Both new controls fired in each run (1,680 control-word and 850 condition-code mismatches), and the post-FNINIT stack underflow and fixed-entry refusals were observed. Precision-control 01 was recorded separately as a native observation.
This discussion has been locked. Commenting is limited to contributors.
No description provided.