cpu: clear OF in the x87 FCOMI lowering #528
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/534"
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-22T10:02:59Z.
Change
Refs #406.
fcomi,fcomip,fucomiandfucomipclear OF. The x87 profile lowered them before the integer lowering modelled OF, and #335 then added OF to the integer lowering. Since then the comparison statement set only ZF and CF and leftoverflowas the previous instruction set it. Onmain, this function translates and returns 1 where the processor returns 0 whenever theaddoverflows:x87_lower.statementnow emitsoverflow = false;with ZF and CF for the four comparisons. The docstring anddocs/experiments.mdsay so. Before,docs/experiments.mdsaid that readers of OF stay outside the profile, which stopped being true when #335 addedsetoandadox.Generated code. I compared every generated source against
main, built in the same build directory. 206 of the 222 are byte-identical, including 100 of the 116cpu_x87_*.cppfiles. The nine sources ofcpu_aot_x87_fcmovdiffer only in their twofcomistatements, which gainoverflow = false;. The seven sources ofcpu_aot_x87_comparegain it in every comparison statement and contain the new export, andcpu_x87_compare_keepof.cppis new.Fixture
cpu_aot_x87_comparegains one export,add_fcomi_of. It adds two input dwords, storesseto, loads two m80 values, runsfcomi st, st(1), and then storessetoandadoxof a zeroed register, both before the record, whoserclchanges OF. The 317 cases pair every seventh comparison pair of the test with dword pairs that overflow (7fffffff + 1,80000000 + 80000000,40000000 + 40000000,80000000 + ffffffff) or do not (1 + 2,ffffffff + 1). Theaddset OF in 211 of them, and the nativesetobefore the comparison agrees with the model in all 317.A seventh control,
keepof, removes the newoverflow = false;, which gives the lowering before this change. It must mismatch, and it does in 211/12230 cases, all inadd_fcomi_of. The six earlier controls keep their mutations; their counts grow with the new cases (3023, 7260, 13, 745, 33 and 812).Verification
Tested at
41b7415onmainat119bdd6. The machine runs Windows 11 build 26200, MSVC 19.50.35720, Windows SDK 10.0.26100.0 and Python 3.13 on an AMD Ryzen 7 7700 (AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD).41b7415(ctest --preset dev --no-tests=error -R '^cpu_aot_x87_').ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xmlgives 241 passed, 2 failed and 2 capability skips (bvh_wave64_warp,wave_shuffle_warp) out of 245 at41b7415. The run includes the GPU tests on an AMD Radeon RX 9070 XT. The two failures aregpu_alias_lookup_writes_hardware, the RDNA 4 array-atomics probe recorded in #369, anddxr_opacity_hardware, the RDNA 4 result recorded in #216.mainat119bdd6gives the same result in the same session. This change touches no GPU code.tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass at41b7415, locally and in the Linux job of the fork CI run below./O2build-and-test, Linux Python and gfx1013 LLVM jobs passed at41b7415in the fork'sWindows checksrun 45009547556. Both Windows jobs ran and passed all sixteen x87 tests (201 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 203 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 424 of 948 forms, as onmainin the same session. No form is added.Not measured: SF and AF, which the comparisons also clear. The integer lowering does not model them and rejects their readers.
Overlap
I trial-merged this branch with the 55 open PRs. Each one conflicts in the same files against
mainand againstmainwith this branch merged: the 6 that merge cleanly intomainalso merge cleanly with it, and this branch adds no conflict to the others. The change is one line oftools/x87_lower.pyand its docstring, one export oftests/cpu/x87_compare.py, one control inCMakeLists.txtand thecpu_aot_x87_compareparagraph ofdocs/experiments.md.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocuments the export, the control and the reproduction command.Checklist
AI-assisted (Claude Code).