cpu: lower FXTRACT in the x87 profile #459
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/465"
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:25:49Z.
Change
Refs #406. This follows #462 (
frndint). It addsfxtractto the opt-in x87 profile inlower(..., x87=True).Semantics.
fxtractreplacesst(0)by its unbiased exponent and pushes its significand. Afterwardsst(0)is the significand andst(1)the exponent.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).{ X87Value e; const X87Value s = x87_xtract(x87_slot[top], e); x87_slot[top] = e; x87_slot[depth] = s; }.fxtracton an empty stack is an underflow and at depth 8 an overflow.Helper (
tools/x87_soft.h).x87_xtract(v, exponent)returns the significand and writes the exponent. It reusesx87_unpackfor the normalization andx87_from_integerfor the exponent.Fixture
tests/cpu/x87_xtract.asmand.defare generated bytests/cpu/x87_xtract.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_xtract). The 8 exports cover:Model. The model splits each value with
Fractionarithmetic and shares no code withtools/x87_soft.h. The addition export reuses theFractionmodel of the add test. The harness, input bytes, guards and live-value check are those of the earlier x87 PRs.Cases. 5895 cases:
cpu_aot_x87_add, and 400 random values over the whole exponent range;Negative controls. Six mutated translations must each mismatch:
zeroexpdenormalbiasedunsignedsnanorderRejections. Translation rejects 5 sequences with the expected diagnostic:
fxtracton an empty stack and at depth 8,fxtractwith only one result stored,frstorandfxrstor.Changes to existing tests: none.
Verification
Tested at
efffd90on54da9dd(the head of #462).mainhas since moved to5ee73e6, the merge of #462. None of the commits onmainthat54da9ddlacks touchtools/ffx_version_query.pyor any x87 file. This branch merges cleanly into5ee73e6. 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 185 passed, 1 failed and 2 capability skips out of 188. 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 atefffd90in the fork'sWindows checksrun 44987847314. Both Windows jobs ran and passed all eleven x87 tests (158 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 160 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 160 of 948 forms, and 159 withoutcpu_aot_x87_xtract. The added form isfxtract. These totals are atefffd90;mainnow also registers thecpu_aot_wide_arithmeticandcpu_aot_dead_dividesfixtures of #321, so its totals are higher.Not measured:
Overlap
I trial-merged this branch with all 87 open PRs. Each one conflicts in the same files against
mainand against this branch: the 10 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, a CMake block after thecpu_aot_x87_rndinttest, and the x87 section ofdocs/experiments.md.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocumentsfxtract, the encodings it was measured on, the controls and the reproduction command.Checklist
AI-assisted (Claude Code).