cpu: lower FRNDINT in the x87 profile #456
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/462"
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-22T05:11:53Z.
Change
Refs #406. This follows #460 (
fsqrt). It addsfrndintto the opt-in x87 profile inlower(..., x87=True).Semantics.
frndintroundsst(0)to an integral value under the rounding control, which the profile fixes at round to nearest-even. The result stays in the extended format.trunc53below).Out of scope:
fscale,fxtract,fprem,fprem1and every control-word access. They remain rejected.Lowering (
tools/x87_lower.py).x87_slot[top] = x87_rndint(x87_slot[top]);, with an empty stack rejected as an underflow. It shares the one-operand path offsqrt.Helper (
tools/x87_soft.h).x87_rndintshifts the significand right by the number of fraction bits. It rounds to nearest-even from the bits shifted out, or rounds to zero when the value is below one half. It then renormalizes with a leading-zero count. It does not callx87_round, because the precision control does not apply.Fixture
tests/cpu/x87_rndint.asmand.defare generated bytests/cpu/x87_rndint.py asm, andemitchecks that every decoded x87 instruction is the form its sequence names. The.asmregisters its test on its first line (; coverage: source cpu_aot_x87_rndint). The 8 exports cover:x - rndint(x), usingfld st(0)andfsubp;frndintbeforefistpm64;frndintat depth 8, with all eight values stored.Model. The model rounds with
Fractionarithmetic and shares no code withtools/x87_soft.h. The harness, input bytes, guards and live-value check are those of the earlier x87 PRs.Cases. 7760 cases:
cpu_aot_x87_integers: integers, halves, quarter steps, and values just past a half, around zero and each integer width's limits;Negative controls. Five mutated translations must each mismatch:
choptiesawayzerosigntrunc53snanRejections. Translation rejects 5 sequences with the expected diagnostic:
frndinton an empty stack,fnstenv,fldenv,fbldandfxsave.Changes to existing tests.
cpu_aot_x87_subusedfrndintas a rejection case. It becomesfxsave, a state save that the profile will not lower, so the test keeps its number of rejections. Its case and control counts are unchanged.Verification
Tested at
54da9ddon44b3707(the head of #460).mainhas since moved tod5af443(the merges of #460, #457, #454 and #321), and none of those touchtools/ffx_version_query.pyor any x87 file beyond #460 itself. This branch merges cleanly intod5af443. Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0, Python 3.13, AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD).x87_add,x87_mul,x87_div,x87_sub,x87_moves,x87_constants,x87_integers,x87_compare,x87_sqrt,x87_rndint).ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xmlgives 184 passed, 1 failed and 2 capability skips out of 187. The run includes the GPU tests. The failure isgpu_alias_lookup_writes_hardware, the RDNA 4 array-atomics probe recorded in #369, which fails the same way onmain. This change touches no GPU code.tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass./O2build-and-test, Linux Python and gfx1013 LLVM jobs passed at54da9ddin the fork'sWindows checksrun 44987344719. Both Windows jobs ran and passed all ten x87 tests (157 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 159 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 159 of 948 forms, and 158 withoutcpu_aot_x87_rndint. The added form isfrndint.Not measured:
fldcw.Overlap
I trial-merged this branch with all 85 open PRs, against
mainmerged with this branch. Each one conflicts in the same files againstmainand against this branch: the 8 that merge cleanly intomainalso merge cleanly here, and this branch adds no conflict to the others. The changes stay inside the x87 files, the new fixture, one rejection case oftests/cpu/x87_sub.py, a CMake block after thecpu_aot_x87_sqrttest, and the x87 section ofdocs/experiments.md.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocumentsfrndint, the precision-control measurement, the controls and the reproduction command.Checklist
AI-assisted (Claude Code).