cpu: lower FBSTP and FBLD in the x87 profile #909
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/916"
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 denn0x on 2026-11-23T17:03:43Z.
Refs #406
Adds
fbstpto both x87 profiles andfbldto the checked entry, as the follow-up to #904 agreed in #406.Behavior
fbstp m80rounds ST(0) to an integer by the rounding control and stores 18 packed BCD digits in bytes 0 to 8, two digits a byte with the lower digit in the low nibble, and the sign of ST(0) in bit 7 of byte 9. A negative value that rounds to zero keeps its sign. The precision control does not apply.0xC0,0xFF,0xFF), the masked invalid-operation response.fbld m80pushes the digits exactly, with the sign from bit 7 of byte 9. The other bits of that byte are ignored, and a zero keeps its sign. Only the checked entry accepts it. The SDM leaves the result undefined for a digit above 9, so that case leaves throughrejectwith the new status 6 (bcddigit) instead of a guessed value.x87_from_bcdchecks all 18 digits before it writes the register, and the function leaves before any later store. Statuses 1 to 5 are unchanged.x87_to_bcdandx87_from_bcdintools/x87_soft.hdo the conversions.x87_to_bcdreusesx87_to_integerfor the rounding.Measurements
Commit
86c5ae7onf19bcfc. AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2), Windows 11 build 26300, MSVC x64,devpreset.cpu_aot_x87_bcdhas 9 exports (3 in the fixed profile) and 21930 cases. The model usesFractionarithmetic and shares no code withtools/x87_soft.h. It agrees with 14 conversions worked by hand.The exports cover
fbstpfrom m80 values and fromfildintegers,fbstpat depth 8 and under each rounding control, plusfbldalone, both round trips, the sum of twofbldvalues, andfbldas the eighth value.Every case matched the model in the translation: status, output block and guards, and
*result. The statuses were 21342 ok and 588bcddigit, and 4391 cases stored the packed BCD indefinite.The 21342 native cases matched the model, with control word
0x027Fand an empty stack after each export.Hardware observation, not part of the pass condition: native
fbldwith a digit above 9 gave the sum of the digits times their powers of ten in all 588 cases.Nine controls each mismatch:
rcnearest0x027Finstead of the loaded wordrangebeforethresholdzerosignindefinite0x80, as for integers, instead of0xC0bstpnibblesbldnibblessignbitsnodigitcheckRejected:
fbldin the fixed profile,fbldat depth 8,fbstpon an empty stack, a store of the valuefbstppopped, andfbldwith a value left at the return.Translated:
fbstpin the fixed profile,fbldandfbstpin the checked entry, andfbldas the eighth value.Five tests used
fbstpas their example of a form outside the profile. Each now uses a form that stays outside it:cpu_aot_x87_movesfnstenvcpu_aot_x87_integersfnsavecpu_aot_x87_comparefrstorcpu_aot_x87_iarithfsincoscpu_aot_x87_statusfldenvWider checks:
ctest --preset dev --no-tests=error -R '^cpu_aot_x87': 21/21 pass. The same with--preset releaseran at11a6549, the same change before the rebase ontof19bcfc, whose merges do not touch the x87 files: 21/21 pass. Both configurations rejectfbldin the fixed profile, and both run the five replacement rejection cases.pe_package_import_closurefails the same way onmainhere: creating a symbolic link needs a privilege this account does not hold (WinError 1314).cpu_*.cppversusmainatf19bcfc: 181 byte-identical, and 150 more after removing theaot_source_sha256line and the 38 added lines ofx87_soft.hthat each embeds. The remaining 2 are the build-path-dependentcpu_exe_image_selectorandcpu_image_data_lifted.docs/experiments.mdaddsfbstpto the profile paragraph,fbldand status 6 to the checked entry, acpu_aot_x87_bcdparagraph, and the new rejection forms.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:12:51Z.
Independent check of
86c5ae7on Intel Family 6 Model 183 Stepping 1: cpu_aot_x87_bcd passed in Debug and Release. All 21,930 translated cases and 21,342 specified native comparisons matched, including signed zero and the packed indefinite; all nine mutations fired. Intel's 588 native invalid-digit observations are kept separate from the checked profile's required status 6.