cpu:lower baseline 128-bit SSE packed single-precision arithmetic instructions #575
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!575
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/575/head"
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?
@stan495 on GitHub · 2026-11-22 13:24 UTC · original
stan495:cpu/sse-float-arith→main· +433 −3 · 6 files · 1 commits · closed without mergingChange
This change lowers the baseline 128-bit legacy SSE packed single-precision floating-point arithmetic instructions (
addps,subps,mulps,divps) intools/ffx_version_query.py. It maps each operation across all four 32-bit float lanes while preserving the upper 128 bits of the destination YMM register.This advances x64 Zen 2 instruction-form coverage by adding 4 previously uncovered forms to the
SSEgroup indocs/coverage/dashboard.svg.Verification
Tested on Windows 11 x64 with an AMD Ryzen 7 7800X3D (Zen 4) CPU and MSVC 19.44 / CMake 3.31 at commit
9386d7a.Result: Succeeded without diagnostics.
Result:
Result: All passed (
Checked 10 Markdown files and 119 links. Self-test passed.).Evidence and follow-up
tests/cpu/sse_float_arith.asmis a new source-built synthetic MASM fixture submitted under the MIT License. It defines 7 exports exercising:addps,subps,mulps,divpsaddps xmm0, xmm0(doubling),subps xmm0, xmm0(zeroing idiom), andmulps xmm0, xmm0(squaring)The test vectors evaluate 5 input sets including positive/negative normals, signed zeros (
+0.0/-0.0), extreme magnitudes, and infinities (inf/-inf).Negative control:
check_rejections()asserts that EVEX encodings (vaddps,vsubps,vmulps,vdivps) and legacy XMM memory forms without an alignment contract are explicitly rejected withValueError.Reproduction notes and build commands are documented in
docs/experiments.md. Follow-up PRs can lower the remaining SSE packed single-precision forms: bitwise logic (andps,andnps,orps,xorps) and comparisons/approximations (minps,maxps,sqrtps,rsqrtps,rcpps).This change was AI-assisted.
Checklist
@R0Y00 on GitHub · 2026-11-22 14:39 UTC · original
Please keep the native 16-byte output contract and establish this profile's MXCSR at entry: exceptions masked, nearest-even rounding, DAZ and FTZ off (control bits matching
0x1f80, with existing sticky bits allowed). Keep the register-only scope and leave code that reads or exports exception status to a separate change. Compare all four lanes as raw words against native SSE under normal and/O2Windows builds. Use both operand orders and single and double qNaN/sNaN cases with distinct signs and payloads. Matching Windows intrinsics are a good candidate if they pass those comparisons.@stan495 on GitHub · 2026-11-22 15:00 UTC · original
Updated and rebased onto
upstream/main(f8d11ad):Profile MXCSR & Scope:
_mm_setcsr((_mm_getcsr() & 0x3fu) | 0x1f80u): exceptions masked, nearest-even rounding, DAZ and FTZ off (control mask0xffc0matches0x1f80, while preserving caller sticky bits in bits 0-5).NaN Propagation & MSVC
/O2Commutativity:/O2; compiler optimizations reorder the commutative intrinsics (_mm_add_ps/_mm_mul_ps), swapping destination/source registers and failing double-NaN comparisons by returning the source payload instead of the destination payload.sse_arith_f32intools/ffx_version_query.pyfollowing the architectural x86 SSE NaN selection rules (matchingtools/cpu_sse_aot.py): destination quieted NaN on destination NaN, otherwise source quieted NaN, and default signed NaN (0xffc00000) on invalid operations.Expanded Test Matrix:
(va, vb)and(vb, va)for all binary arithmetic operations.0x1fbf).devpreset) and/O2(releasepreset) Windows builds.@stan495 on GitHub · 2026-11-23 00:59 UTC · original
Thanks @MarlomMedeiros for the detailed independent review, hardware verification, and helpful findings!
I have addressed all the feedback and rebased the branch onto current
upstream/main(67edabe):Lifted
_mm_setcsrVerification (Finding 1):tests/cpu/sse_float_arith.pythat pre-sets a non-profile MXCSR state (0x9fa5, FTZ bit 15 set, caller sticky bits0x25in bits 0-5) immediately prior to invoking the lifted function._mm_setcsrrestores control bits 6-15 to profile contract0x1f80(FTZ/DAZ cleared, exceptions masked) while strictly preserving caller sticky bits. Confirmed that removing the emitted line fails this assertion.Caller FP Environment Mutation Contract (Finding 2):
docs/experiments.mddocumenting that the emitted_mm_setcsrestablishes the guest profile on the calling thread without restoring previous host MXCSR control bits, treating the guest FP profile as the persistent execution contract for lifted functions containing packed SSE arithmetic.Coverage Asymmetries &
/fp:preciseIndependence (Finding 3):divps_self_op: Added to MASM fixture and test harness, validating self-division across normals as well as 0/0 and inf/inf invalid operations producing indefinite QNaN0xffc00000.addps_xmm1_dst_opandaddps_xmm2_dst_opto exercise and verifywide1andwide2destination lowering paths against native execution.x != x) insse_arith_f32with bitwise helperis_nan_f32(u)((u & 0x7f800000u) == 0x7f800000u && (u & 0x007fffffu) != 0), eliminating dependency on/fp:precise.dev) and/O2(release) presets.Rebase & Integration:
main, cleanly integrating with #725 (cpu_aot_float_packed) while preserving the dedicated baseline 128-bit legacy SSE contract.@stan495 on GitHub · 2026-11-23 01:59 UTC · original
Closing this PR as the lowering for ADDPS, SUBPS, MULPS, and DIVPS (along with the broader packed float instruction set) has been addressed and merged in #725. Thank you @R0Y00 and @MarlomMedeiros for the detailed reviews, guidance, and hardware verification!
@MarlomMedeiros on GitHub · 2026-11-22 19:31 UTC · original · reviewed
Independent run on AMD Ryzen 7 5800X3D, Windows 11 build 26300.10075, MSVC 14.52.37025, SDK 10.0.26100.0, on
ff84027:Second AMD datapoint (author used a 7600): both confirm the destination-NaN-wins selection, which also matches the architected rule in SDM Vol.1 Table 4-7 for non-MIN/MAX SSE arithmetic, so the pinned
a | quietorder is the right model, and if silicon ever deviated the differential would fail loudly as designed.Semantic review of
sse_arith_f32: every branch checks out.x != xcorrectly isolates NaN inputs before the generated-NaN override,a|quiet/b|quietquiet sNaNs preserving sign+payload,subpsdoes not negate a source NaN, and0xffc00000is exactly the SP QNaN indefinite hardware produces for masked invalid ops. Denormals run on host SSE under the same forced MXCSR as native, DAZ/FTZ off. The VEX/EVEX/memory rejection paths behave as the test asserts (distinct iced mnemonics fall to the generic reject;addps xmm,[mem]raises the expected diagnostic).divps_self_opbeing absent looks deliberate (x/x is uninformative) but is worth noting below.Three findings, none blocking:
The lifted-side
_mm_setcsris unverifiable by this test.tools/ffx_version_query.pyemits_mm_setcsr(...)at function entry, butcheck()sets the same MXCSR on the thread before every round vialifted.set_mxcsr, so deleting the emitted line would still pass the whole suite. If "establishing the profile's MXCSR at entry" is a claimed guarantee, consider a case that pre-sets a non-profile MXCSR (e.g. FTZ on) immediately before a lifted call and reads it back after, which would exercise the emitted line directly._mm_setcsrmutates the caller thread's FP environment permanently (clears DAZ/FTZ, forces round-nearest, preserves sticky bits) with no restore. Native leaves it alone. For this fixture that's masked by the test's own set/restore, butlower()is also used bygenerate()for real images, so a lifted function containing these ops silently reprograms host FP state for the remainder of its run. Probably intended (the guest profile is the contract) but worth an explicit sentence in the docs.Coverage asymmetries:
divps_self_opis missing (the one self-op that exercises 0/0 and inf/inf invalid paths), every export writesxmm0sowide1/wide2destination paths are emitted but never executed, and only 16 output bytes are observable, so upper-wideNcorruption would be invisible. Alsox != xdepends on/fp:precise(fine under the presets today, would break under/fp:fast).Integration note: the base (
2f1f832) predatessse2_shift_pack_ops,fma_packed, andavx2_perm_opsin the samehas_widechain, plus new lowering arms and theCMakeLists.txt/experiments.mdanchors this PR touches, so a rebase will conflict in all three files; resolutions look mechanical. It also lands adjacent to #602'ssse34_fp_opsin the same regions, so whichever merges second will need the same trivial union.AI-assisted: yes. All reported checks ran locally on the hardware listed.
Pull request closed