cpu: lower FTST, FXAM, FICOM, FICOMP, FNOP and FNCLEX in the x87 profile #621

Merged
danielradosa merged 1 commit from upstream-pr/627 into main 2026-11-23 00:28:32 +00:00
danielradosa commented 2026-11-22 16:21:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by danielradosa on 2026-11-22T16:21:01Z.


Change

The x87 leaf-function profile in tools/x87_lower.py now accepts:

  • ftst, which compares ST(0) with +0.0, and ficom and ficomp with an m16 or m32 integer, converted exactly as for fild. All three set C0, C2 and C3 as fcom does, and ficomp pops.
  • fxam, which sets C3, C2 and C0 from the class of the 80-bit encoding through the new x87_examine in tools/x87_soft.h. The classes are unsupported, NaN, normal, infinity, zero and denormal; a pseudo-denormal counts as a denormal. An empty ST(0) is known at translation time and gives C3 and C0. C1, which holds the sign, stays unknown, as it does for every instruction in the profile.
  • fnop and fnclex, which change nothing the profile models. fclex decodes as wait plus fnclex. Like every other x87 instruction, they leave C0, C2 and C3 undefined.

They add 7 x64 forms to the coverage chart: ftst, fxam, ficom, ficomp, fnop, fnclex and fclex.

Verification

cpu_aot_x87_examine (tests/cpu/x87_examine.asm, 4 exports) runs through the native harness, like the other x87 tests. It writes C0, C2 and C3 after each status-word writer and checks them against an independent model, which uses exact rationals for the comparisons and classifies the 80-bit encoding. The inputs cover every fxam class with both signs, including unnormals, pseudo-infinities, pseudo-NaNs and pseudo-denormals. They also cover the m16 and m32 integer bounds and values on either side of an integer. Three mutated controls must mismatch. Translation must reject ftst and ficomp on an empty stack, and a reader of C0 after fnop or fnclex.

Windows 11 build 26300.9974, Ryzen 5 7600, MSVC 19.51.36256, Python 3.14.4, on main at 9b0df70:

ctest --preset dev --no-tests=error -R '^cpu_aot_x87_examine$' -V
Check Result
native and translated DLLs, dev and release (/O2) 782 cases matched the model; every export returned with control 0x027f and an empty stack
control normal (a denormal reported as normal) 5/782 mismatches
control unsigned (the integer converted as unsigned) 136/782 mismatches
control positive (ftst compared with 1.0) 7/782 mismatches
rejections ftst and ficomp on an empty stack; C0 read after fnop and after fnclex
all 19 cpu_aot_x87_ tests, this one included passed
all cpu_ tests, dev 113 of 115 passed; the 2 failures are cpu_native_archive_reader and cpu_native_archive_blast, which need the Zig-built archive_reader.exe (ziglang is not installed on this machine)

The native run confirms the model on the edge cases: Zen 4 reports a pseudo-denormal as denormal and an unnormal as unsupported. Another CPU vendor may differ, which a reviewer's run would show.

Rejection cases in earlier tests

Seven earlier x87 tests used these instructions as examples of forms outside the profile. Their cases now use instructions that stay outside it, the way #513 swapped wait for ffree st(1) in cpu_aot_x87_add. Each test keeps the same number of rejection cases, and no key is duplicated:

Test Was Now
x87_add ftst fsin
x87_sub fxam fcos
x87_integers ficom m16 fyl2xp1
x87_compare ficomp m32, ftst, fxam, ficom m16 fprem1, f2xm1, fptan, fbstp m80
x87_iarith ficom m16, ficomp m32 fbld m80, fbstp m80
x87_fnstcw fnclex fdecstp
x87_status FTST, FXAM, FICOM m16 FSINCOS, FPATAN, FBSTP m80

The docs sentences that listed the old cases are updated to match.

Evidence and follow-up

fstsw ax stays uncovered. It decodes as wait and fnstsw ax, and the profile follows the SDM, under which wait leaves C0, C2 and C3 undefined, so a reader after fstsw would be rejected. fninit/finit change the control word to 0x037F and remain outside the fixed profile.

Companion PRs, independent of this one: fences and cache hints (#626), and cmpxchg8b/cmpxchg16b (#628). x64 coverage goes from 551 (the published chart for 9b0df70) to 573 of 948 with all three.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544739618 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/627). Originally posted by [danielradosa](https://github.com/danielradosa) on 2026-11-22T16:21:01Z. --- ## Change The x87 leaf-function profile in `tools/x87_lower.py` now accepts: - `ftst`, which compares ST(0) with +0.0, and `ficom` and `ficomp` with an m16 or m32 integer, converted exactly as for `fild`. All three set C0, C2 and C3 as `fcom` does, and `ficomp` pops. - `fxam`, which sets C3, C2 and C0 from the class of the 80-bit encoding through the new `x87_examine` in `tools/x87_soft.h`. The classes are unsupported, NaN, normal, infinity, zero and denormal; a pseudo-denormal counts as a denormal. An empty ST(0) is known at translation time and gives C3 and C0. C1, which holds the sign, stays unknown, as it does for every instruction in the profile. - `fnop` and `fnclex`, which change nothing the profile models. `fclex` decodes as `wait` plus `fnclex`. Like every other x87 instruction, they leave C0, C2 and C3 undefined. They add 7 x64 forms to the coverage chart: `ftst`, `fxam`, `ficom`, `ficomp`, `fnop`, `fnclex` and `fclex`. ## Verification `cpu_aot_x87_examine` (`tests/cpu/x87_examine.asm`, 4 exports) runs through the native harness, like the other x87 tests. It writes C0, C2 and C3 after each status-word writer and checks them against an independent model, which uses exact rationals for the comparisons and classifies the 80-bit encoding. The inputs cover every `fxam` class with both signs, including unnormals, pseudo-infinities, pseudo-NaNs and pseudo-denormals. They also cover the m16 and m32 integer bounds and values on either side of an integer. Three mutated controls must mismatch. Translation must reject `ftst` and `ficomp` on an empty stack, and a reader of C0 after `fnop` or `fnclex`. Windows 11 build 26300.9974, Ryzen 5 7600, MSVC 19.51.36256, Python 3.14.4, on `main` at 9b0df70: ```powershell ctest --preset dev --no-tests=error -R '^cpu_aot_x87_examine$' -V ``` | Check | Result | |---|---| | native and translated DLLs, `dev` and `release` (/O2) | 782 cases matched the model; every export returned with control 0x027f and an empty stack | | control `normal` (a denormal reported as normal) | 5/782 mismatches | | control `unsigned` (the integer converted as unsigned) | 136/782 mismatches | | control `positive` (`ftst` compared with 1.0) | 7/782 mismatches | | rejections | `ftst` and `ficomp` on an empty stack; C0 read after `fnop` and after `fnclex` | | all 19 `cpu_aot_x87_` tests, this one included | passed | | all `cpu_` tests, `dev` | 113 of 115 passed; the 2 failures are `cpu_native_archive_reader` and `cpu_native_archive_blast`, which need the Zig-built `archive_reader.exe` (`ziglang` is not installed on this machine) | The native run confirms the model on the edge cases: Zen 4 reports a pseudo-denormal as denormal and an unnormal as unsupported. Another CPU vendor may differ, which a reviewer's run would show. ## Rejection cases in earlier tests Seven earlier x87 tests used these instructions as examples of forms outside the profile. Their cases now use instructions that stay outside it, the way #513 swapped `wait` for `ffree st(1)` in `cpu_aot_x87_add`. Each test keeps the same number of rejection cases, and no key is duplicated: | Test | Was | Now | |---|---|---| | `x87_add` | `ftst` | `fsin` | | `x87_sub` | `fxam` | `fcos` | | `x87_integers` | `ficom m16` | `fyl2xp1` | | `x87_compare` | `ficomp m32`, `ftst`, `fxam`, `ficom m16` | `fprem1`, `f2xm1`, `fptan`, `fbstp m80` | | `x87_iarith` | `ficom m16`, `ficomp m32` | `fbld m80`, `fbstp m80` | | `x87_fnstcw` | `fnclex` | `fdecstp` | | `x87_status` | `FTST`, `FXAM`, `FICOM m16` | `FSINCOS`, `FPATAN`, `FBSTP m80` | The docs sentences that listed the old cases are updated to match. ## Evidence and follow-up `fstsw ax` stays uncovered. It decodes as `wait` and `fnstsw ax`, and the profile follows the SDM, under which `wait` leaves C0, C2 and C3 undefined, so a reader after `fstsw` would be rejected. `fninit`/`finit` change the control word to 0x037F and remain outside the fixed profile. Companion PRs, independent of this one: fences and cache hints (#626), and `cmpxchg8b`/`cmpxchg16b` (#628). x64 coverage goes from 551 (the published chart for 9b0df70) to 573 of 948 with all three. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:44:01 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:48:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-22T16:21:18Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T16:24:39.994787Z c91340b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7082008984 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/627#issuecomment-7082008984). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-22T16:21:18Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c91340be8a13f9ad3e57683f3f7d0f1671e585c0","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-22T16:24:39.994787Z">2026-11-22T16:24:39.994787Z</relative-time> | `c91340b` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
legacy-code-archaeologist commented 2026-11-24 06:48:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T18:25:23Z.


Verification of c91340b on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. It merges cleanly with main, and all 115 cpu_ tests pass, including every existing x87 test this PR touches:

ctest --preset dev --no-tests=error -R "x87_(examine|compare|status)" -V
cpu_aot_x87_examine: 782 cases over 4 exports matched the model in native and translated DLLs; FXAM classes ['denormal', 'infinity', 'nan', 'normal', 'unsupported', 'zero'] and empty; each export returned with control 0x027f and an empty stack

This answers the open point from the description, that another vendor may differ from Zen 4: on Intel Skylake the native DLL matches the same model, so it also classifies a pseudo-denormal as denormal and an unnormal as unsupported. All six FXAM classes plus the empty case match.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7083590663 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/627#issuecomment-7083590663). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T18:25:23Z. --- Verification of `c91340b` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. It merges cleanly with `main`, and all 115 `cpu_` tests pass, including every existing x87 test this PR touches: ```text ctest --preset dev --no-tests=error -R "x87_(examine|compare|status)" -V cpu_aot_x87_examine: 782 cases over 4 exports matched the model in native and translated DLLs; FXAM classes ['denormal', 'infinity', 'nan', 'normal', 'unsupported', 'zero'] and empty; each export returned with control 0x027f and an empty stack ``` This answers the open point from the description, that another vendor may differ from Zen 4: on Intel Skylake the native DLL matches the same model, so it also classifies a pseudo-denormal as denormal and an unnormal as unsupported. All six FXAM classes plus the empty case match. AI-assisted (Claude Code).
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!621
No description provided.