cpu: lower the integer-operand arithmetic of the x87 profile #493
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/499"
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-22T07:51:43Z.
Change
Refs #406. This is the next x87 step after #476 (
fcmovcc), which has merged. It adds the integer-operand arithmetic to the opt-in x87 profile inlower(..., x87=True):fiadd,fisub,fisubr,fimul,fidivandfidivrwith an m16 or m32 integer operand.Semantics. Each form converts the integer exactly, as
filddoes, then behaves like its floating-point form withst(0)as the destination.fisubrcomputes the integer minusst(0), andfidivrthe integer divided byst(0).faddwith an m64 operand.-0 + 0is +0 and-0 - 0is -0.fadd,fsub,fmulandfdiv. An integer is never a NaN, so onlyst(0)supplies one.The native runs confirm each of these rules.
Out of scope:
ficomandficompwrite the status word, which the profile does not model, so they remain rejected.Lowering (
tools/x87_lower.py).x87_slot[top] = x87_add(x87_slot[top], x87_from_integer(static_cast<int16_t>(load<uint16_t>(a))));, with the form's helper and width. An empty stack is an underflow, and the depth is unchanged. No helper is added totools/x87_soft.h.Fixture
tests/cpu/x87_iarith.asmand.defare generated bytests/cpu/x87_iarith.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_iarith). The 15 exports cover:fimulwith an m32 integer on an m64 value stored back to m64;fiaddwith an m32 integer followed byfisubwith an m16 integer;fidivrat depth 8, with all eight values stored.Model. The model converts the integer with the
fildmodel ofcpu_aot_x87_integersand applies theFractionmodels of the add, subtract, multiply and divide tests. It shares no code withtools/x87_soft.h. The harness, input bytes, guards and live-value check are those of the earlier x87 PRs.Cases. 28512 cases:
st(0)values whose low significand bits sit at or beside a 53-bit rounding tie, full 64-bit significands, values at the edges of the exponent range, denormals and random values, with every third edge integer;The two bytes after each m16 integer are never its sign extension.
Negative controls. Six mutated translations must each mismatch:
subrevfisubcomputes the integer minusst(0)divrevfidivdivides the integer byst(0)zext16zext32wide16pc64Rejections. Translation rejects 5 sequences with the expected diagnostic:
ficom m16,ficomp m32,fiadd m32andfidivr m16on an empty stack, andfisub m32that leaves a value at the return.Changes to existing tests. The rejection lists of four tests used the new forms. Each case is replaced by an instruction that stays outside the profile, and each list keeps its length:
cpu_aot_x87_divfidiv m32,fidivr m16,fiadd m32fldenv,fdecstp,fincstpcpu_aot_x87_mulfimul m32,fimul m16,fiadd m32fldenv,fdecstp,fincstpcpu_aot_x87_subfisub m32,fisubr m16fldenv,fdecstpcpu_aot_x87_integersfiadd m32fldenvTheir case and control counts are unchanged. The matching sentences in
docs/experiments.mdname the new instructions.Verification
Tested at
3b7f87a, one commit on7f13b7f(main).mainhas since moved to329510f, and the branch merges into it without conflicts. Of the files those seven commits change, onlyCMakeLists.txtanddocs/experiments.mdare also changed here, and in other sections. The machine is 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 regressions: all fourteen x87 tests pass at
3b7f87a(ctest --preset dev --no-tests=error -R '^cpu_aot_x87_'), including the four with replaced rejection cases.Full suite:
ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xmlgives 213 passed, 2 failed and 2 capability skips (bvh_wave64_warp,wave_shuffle_warp) out of 217 at3b7f87a. The run includes the GPU tests on an RX 9070 XT. Both failures are RDNA 4 results thatdocs/experiments.mdrecords as failing by design:gpu_alias_lookup_writes_hardware, the array-atomics probe of #369;dxr_opacity_hardware, withcommitted_t_plus_tmin=43as described in #216. It fails the same way on7f13b7fitself (run).This change touches no GPU code.
Pure-Python checks:
tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass at3b7f87alocally and in the Linux job of the fork CI run below.Fork CI: the Windows build-and-test, Windows
/O2build-and-test, Linux Python and gfx1013 LLVM jobs passed at3b7f87ain the fork'sWindows checksrun 44999346622. Both Windows jobs ran and passed all fourteen x87 tests (179 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 181 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 195 of 948 forms, and 189 withoutcpu_aot_x87_iarith. The added forms arefiadd,fisub,fisubr,fimul,fidivandfidivr.Not measured:
fldcw.Overlap
I trial-merged this branch with all 83 open PRs. Each one conflicts in the same files against
mainand against this branch: the 48 that merge cleanly intomainalso merge cleanly here, and this branch adds no conflict to the others. The changes stay insidetools/x87_lower.py, the new fixture, the rejection lists of four x87 tests, a CMake block after thecpu_aot_x87_fcmovtest, and the x87 section ofdocs/experiments.md.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocuments the six forms, the controls and the reproduction command.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T08:10:52Z.
Review: APPROVED
Reviewed
3b7f87aand reproduced cpu_aot_x87_iarith on Intel64 Family 6 Model 183 Stepping 1 with x64 MSVC 19.51. All 28,512 inputs across 15 exports matched the independent reference in both native and translated DLLs. Each returned with the expected control word and empty stack. All six mutations produced mismatches, and all five unsupported sequences were rejected. This independently adds an Intel result to the author's AMD measurement.