cpu: lower FSCALE in the x87 profile #465
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/471"
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:43:13Z.
Change
Refs #406. This follows #465 (
fxtract). It addsfscaleto the opt-in x87 profile inlower(..., x87=True).Semantics.
fscalemultipliesst(0)by 2^n, where n isst(1)truncated toward zero.st(1)stays on the stack.pc53below).st(1): -inf gives a zero and +inf an infinity, both with the sign ofst(0). An infinitest(0)scaled by -inf and a zero scaled by +inf give the indefinite.st(0): otherwise unchanged.fadd.The native runs confirm each of these rules.
Out of scope:
fprem,fprem1, the transcendental instructions and every control-word access. They remain rejected.Lowering (
tools/x87_lower.py).x87_slot[top] = x87_scale(x87_slot[top], x87_slot[top - 1]);. Fewer than two values is an underflow, and the depth is unchanged.Helper (
tools/x87_soft.h).x87_scale(a, b)handles the special operands first. It then truncatesst(1)from its unpacked significand and clamps the result to 2^20 in magnitude, far beyond the exponent range, so that adding it to the exponent cannot overflow anint. Finally it rounds through the existingx87_roundwith a 64-bit format.Fixture
tests/cpu/x87_scale.asmand.defare generated bytests/cpu/x87_scale.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_scale). The 8 exports cover:fild;fxtract; fscale;Every export also stores
st(1), so a translation that changes or pops it mismatches.Model. The model scales with
Fractionarithmetic and shares no code withtools/x87_soft.h. It reuses thefxtractmodel of #465 and the integer conversions ofcpu_aot_x87_integers. The harness, input bytes, guards and live-value check are those of the earlier x87 PRs.Cases. 43003 cases:
Negative controls. Six mutated translations must each mismatch:
pc53chopfloorneginfst(0)zeroinfswapRejections. Translation rejects 5 sequences with the expected diagnostic:
fscaleon an empty stack and with one value,fscalethat leavesst(1)at the return,fnsaveandfxrstor.Changes to existing tests.
cpu_aot_x87_subusedfscaleas a rejection case. It becomesfnstenv, an environment store that the profile will not lower, so the test keeps 10 rejections. Its case and control counts are unchanged.Verification
Tested at
c2a3d6conefffd90(the head of #465).mainhas since moved to86dff9f, after the merge of #465. None of the commits onmainthatefffd90lacks touchtools/ffx_version_query.pyor any x87 file. This branch merges cleanly into86dff9f. 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).ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xmlgives 186 passed, 1 failed and 2 capability skips out of 189. 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 atc2a3d6cin the fork'sWindows checksrun 44987849706. Both Windows jobs ran and passed all twelve x87 tests (159 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 161 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 161 of 948 forms, and 160 withoutcpu_aot_x87_scale. The added form isfscale. These totals are atc2a3d6c;mainnow also registers thecpu_aot_wide_arithmeticandcpu_aot_dead_dividesfixtures of #321, so its totals are higher.Not measured:
fldcw.Overlap
I trial-merged this branch with all 86 open PRs. Each one conflicts in the same files against
mainand against this branch: the 9 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_xtracttest, and the x87 section ofdocs/experiments.md.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocumentsfscale, the precision-control measurement, the controls and the reproduction command.Checklist
AI-assisted (Claude Code).