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

Merged
denn0x merged 1 commit from upstream-pr/904 into main 2026-11-23 16:57:11 +00:00
denn0x commented 2026-11-23 16:37:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-23T16:37:13Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6564022834 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/904). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-23T16:37:13Z. --- 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).
upstream-sync closed this pull request 2026-11-24 06:45:20 +00:00
R0Y00 commented 2026-11-24 06:49:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T16:57:02Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7107922083 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/904#issuecomment-7107922083). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T16:57:02Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!897
No description provided.