cpu: model PF of FCOMI and lower FCMOVU and FCMOVNU in the x87 profile #542
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/548"
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:46:19Z.
Change
Refs #406. This follows #535 (the status word), whose PF rule it extends. It adds the PF of
fcomi,fcomip,fucomiandfucomip, and the two conditional moves that read it,fcmovuandfcmovnu, to the opt-in x87 profile. That PR deferred these to a follow-up.Semantics. The four comparisons set ZF, PF and CF to
1 1 1for unordered, and PF to 0 otherwise. They also clear OF, SF and AF, which the integer lowering has no reader for.fcmovu st, st(i)copiesst(i)intost(0)when PF is set, andfcmovnuwhen it is clear. Like the other moves, the copy keeps the whole 80-bit encoding, so a signaling NaN stays signaling.Lowering.
tools/ffx_version_query.pydeclares the integer lowering'sparityin a function withjp,jnp,fcmovuorfcmovnu, as it already did forjpandjnp.x87_lower.statementemitsparity = r == 3;for each of the four comparisons. Functions without such a reader keep their generated code.assigns_paritycounts the four comparisons as writers of PF. Ajp,jnp,fcmovuorfcmovnutherefore translates when one of them,sahfor an 8-bittestorandwrote PF last on every path. After any other writer, for examplecmp,incoradd, it is still rejected.fcmovuandfcmovnujoin the table of conditional moves, with the conditionsparityand!parity.Generated code. I compared every generated source against
mainat075413d, built in the same build directory:cpu_x87_*.cppfiles.cpu_aot_x87_statusdiffer in two lines each. Thefcomiandfucomipstatements offcom_fcomiandfucom_fucomipnow also setparity, because their functions containjp. Thesahfafter them writes PF again before any reader, so the counts of that test are unchanged.Fixture
tests/cpu/x87_parity.asmand.defare generated bytests/cpu/x87_parity.py asm, andemitchecks every decoded x87 instruction against its sequence. A record stores whetherjp,jnp,jeandjbare taken, with only flag-neutralmovs in between.The 16 exports cover:
st(1), read through the record;fcmovuandfcmovnuafterfucomi,fcomi,fucomip st, st(2)andfcomip, andfcmovuwithst(7)at depth 8;fucomip; fstp st(0); jp; jne, and a classification into unordered, equal and neither byjnpandje;fucomiaftersahf,sahfafterfucomi, andtest al, alafterfucomi;fcmovuaftersahfon all 256 AH values loaded bymov;fucomipath and anfcom; fnstsw ax; sahfpath.Model. The model compares with the
Fractionmodel ofcpu_aot_x87_compareand copies raw encodings. 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. 17672 cases:
In the four records,
jpwas taken in 2124 of 6624 cases. The moves read PF set in 2361 cases and clear in 4675.Negative controls. Five mutated translations must each mismatch, and each must mismatch in a named export:
pfneverequal_branchpfequalclassifypfkeepsahf_fucomiuinvertfcmovumoves on a clear PFfucomi_fcmovunuinvertfcmovnumoves on a set PFfcomi_fcmovnupfkeepcan mismatch insahf_fucomionly where thesahfbeforefucomileft a different PF, which separates it frompfnever.Rejections. Translation rejects 10 sequences with the expected diagnostic:
fcmovubefore any flag writer;fcmovnuaftertest eax, eax,fcmovuafterfucomiandinc eax, andjpafterfucomiandadd eax, 1;fcmovuafter a call;fucomipath and acmppath;sahfonfnstsw axwithout a comparison, thenfcmovu(the status-word diagnostic);fcmovu st, st(2)with two values andfcmovnu st, st(1)with one value;setpafterfucomi, which the integer lowering does not implement.Five twins must still translate:
fcmovuafterfucomi;fcmovnuafterfucomiandmov eax, [rcx];jpafterfucomipandfstp st(0);fucomipath and asahfpath;fcmovuafterfucomiandlea.Changes to existing tests. Rejection cases that the profile now accepts are replaced by sequences that stay outside it, and each list keeps its length:
cpu_aot_x87_comparejpandjnpafterfucomijpandjnpafterfucomiandinc eaxcpu_aot_x87_statusjpafterfucomijpafterfucomiandinc eaxcpu_aot_x87_fcmovfcmovuandfcmovnu(unsupported operation)cmp, now rejected by the PF rulecpu_aot_x87_comparejoafterfucomicmovsafterfucomijowas rejected only because the integer lowering has nojo. Since #534 the comparisons clear OF, whichsetoandadoxread.cmovsreads SF, which the comparisons do not model, so the list again names a reader of an unmodelled flag. The PF diagnostic now names the four comparisons, and the needle incpu_aot_x87_statusfollows it. Case and control counts of these tests are unchanged. The matching sentences indocs/experiments.mdare updated.Verification
Tested at
9332372onmainat075413d. 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).9332372(ctest --preset dev --no-tests=error -R '^cpu_aot_x87_'), including the three with replaced rejection cases.ctest --preset dev --no-tests=error -j 8 --output-junit test-results.xmlgives 251 passed, 2 failed and 2 capability skips (bvh_wave64_warp,wave_shuffle_warp) out of 255 at9332372. 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.mainat075413dgives 250 passed, with the same two failures and skips, out of 254 in the same session. This change touches no GPU code.tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass at9332372, locally and in the Linux job of the fork CI run below./O2build-and-test, Linux Python and gfx1013 LLVM jobs passed at9332372in the fork'sWindows checksrun 45013424622. Both Windows jobs ran and passed all eighteen x87 tests (208 passed and 2 capability skips,bvh_wave64_warpandwave_shuffle_warp, out of 210 in each).Coverage.
python tools/form_coverage.py out/build/dev/test-results.xmlgives x64 460 of 948 forms, against 458 onmainin the same session. The added forms arefcmovuandfcmovnu.Not measured:
setp,setnp,cmovpandcmovnp, which the integer lowering does not implement.Overlap
I trial-merged this branch with the 56 open PRs. Each one conflicts in the same files against
mainand againstmainwith this branch merged: the 8 that merge cleanly intomainalso merge cleanly with it, and this branch adds no conflict to the others.Evidence
The fixture is synthetic and original to this repository (MIT).
docs/experiments.mddocuments the forms, the controls and the reproduction command.Checklist
AI-assisted (Claude Code).