cpu: lower FTST, FXAM, FICOM, FICOMP, FNOP and FNCLEX in the x87 profile #621
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/627"
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 danielradosa on 2026-11-22T16:21:01Z.
Change
The x87 leaf-function profile in
tools/x87_lower.pynow accepts:ftst, which compares ST(0) with +0.0, andficomandficompwith an m16 or m32 integer, converted exactly as forfild. All three set C0, C2 and C3 asfcomdoes, andficomppops.fxam, which sets C3, C2 and C0 from the class of the 80-bit encoding through the newx87_examineintools/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.fnopandfnclex, which change nothing the profile models.fclexdecodes aswaitplusfnclex. 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,fnclexandfclex.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 everyfxamclass 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 rejectftstandficompon an empty stack, and a reader of C0 afterfnoporfnclex.Windows 11 build 26300.9974, Ryzen 5 7600, MSVC 19.51.36256, Python 3.14.4, on
mainat9b0df70:devandrelease(/O2)normal(a denormal reported as normal)unsigned(the integer converted as unsigned)positive(ftstcompared with 1.0)ftstandficompon an empty stack; C0 read afterfnopand afterfnclexcpu_aot_x87_tests, this one includedcpu_tests,devcpu_native_archive_readerandcpu_native_archive_blast, which need the Zig-builtarchive_reader.exe(ziglangis 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
waitforffree st(1)incpu_aot_x87_add. Each test keeps the same number of rejection cases, and no key is duplicated:x87_addftstfsinx87_subfxamfcosx87_integersficom m16fyl2xp1x87_compareficomp m32,ftst,fxam,ficom m16fprem1,f2xm1,fptan,fbstp m80x87_iarithficom m16,ficomp m32fbld m80,fbstp m80x87_fnstcwfnclexfdecstpx87_statusFTST,FXAM,FICOM m16FSINCOS,FPATAN,FBSTP m80The docs sentences that listed the old cases are updated to match.
Evidence and follow-up
fstsw axstays uncovered. It decodes aswaitandfnstsw ax, and the profile follows the SDM, under whichwaitleaves C0, C2 and C3 undefined, so a reader afterfstswwould be rejected.fninit/finitchange 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 for9b0df70) to 573 of 948 with all three.AI-assisted.
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.
c91340bℹ️ 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 legacy-code-archaeologist on 2026-11-22T18:25:23Z.
Verification of
c91340bon an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029,devpreset. It merges cleanly withmain, and all 115cpu_tests pass, including every existing x87 test this PR touches: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).