Repository navigation
rdna2spirv: v_madak_f32 and v_madmk_f32 flush f32 denormals like v_mad_f32 - #4189
Exopus-0x65f7ad0 wants to merge 1 commit into
Conversation
…d_f32 v_madak_f32/v_madmk_f32 are v_mad_f32 with a 32-bit literal: LLVM only forms them by shrinking a V_MAD_F32 (SIShrinkInstructions), and forms V_MAD_F32 only with f32 denormals flushed (isFMADLegal). The translator flushed v_mad_f32/v_mac_f32 (SHADER-118, measured on gfx1010) but not these two, so `v_madak_f32 v0, v1, v2, 0` with v1 = 0x00000001 and v2 = 2^31 gave 0x04800000. They now flush the operands, the rounded product and the sum through flush_f32 (VOP2 only: no clamp or omod). tests/semantic/test_madak_madmk_denorm.py: denormal operand, product, sum, literal and addend, plus normal/inf/NaN pass-through (10 cases fail on the old translator). test_valu_mad_lit.py's sabotage controls now match the add whether its first operand is the product or its flushed copy, so they still inject their faults. docs/design.md: the SHADER-118 row covers the two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested At The smallest positive subnormal times 2³¹ yielded +0. The negative counterpart with a −0 addend yielded 0x80000000. A subnormal product and sums just inside the positive and negative normal boundaries flushed to the expected signed zeros. Both forms preserved the smallest positive normal (0x00800000) and returned 11.0 for 2 × 3 + 5. These are translated Vulkan results; native GFX10.1 measurements remain open. AI-assisted verification. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 270b98c5 on Windows 11: python tests/semantic/test_madak_madmk_denorm.py -> 2 tests, OK; python tests/semantic/test_valu_mad_lit.py -> 15 tests, OK; git diff --check clean.
v_madak_f32/v_madmk_f32 now flush f32 denormals on both operands, on the rounded product and on the sum, matching v_mad_f32/v_mac_f32; the existing literal-operand order (madak = S0S1+K, madmk = S0K+S1) is unchanged. The new cases compare against the full v_mad_f32 path on subnormal inputs and results, and the 15 literal tests still pass. No blocking issue.
|
Code read + CPU tests, 270b98c: pass — Flushing f32 denormals in |
Flyander
left a comment
There was a problem hiding this comment.
The literal MAD lowering now applies the same denormal treatment at each binary32 rounding point as the existing MAD path, and the added cases cover operands, product, sum, signed zero, and normal-value control. I found no separate blocker.
Claim: #3918 (comment) (new SHADER item)
Problem
v_mad_f32/v_mac_f32/v_mad_legacy_f32flush f32 denormals (SHADER-118,Gen.flush_f32): a subnormal operand, the rounded product or the sum reads as a zero of its sign, measured natively on gfx1010 (SHADER-340).v_madak_f32andv_madmk_f32(tools/rdna2spirv.py, the("v_madak_f32", "v_madmk_f32")branch) are the same multiply-add with a 32-bit literal, but went through a plainOpFMul+OpFAdd, so denormals survived:v_madak_f32 v0, v1, v2, 0x0with v1 =0x00000001, v2 = 2^31 gave0x04800000(2^-118) instead of0.Why they share the rule: LLVM only forms
V_MADAK_F32/V_MADMK_F32by shrinking aV_MAD_F32whose operand is a literal (SIShrinkInstructions), and formsV_MAD_F32only when f32 denormals are flushed (SITargetLowering::isFMADLegal, the reference SHADER-118 cites). Both are GFX10.1 VOP2 opcodes likev_mac_f32, so, like it, they can't be run natively on the gfx1036 parts testers have.Change
flush_f32, asv_mad_f32does. VOP2 only, so there's noclamp/omodpath.flush_f32's docstring and the SHADER-118 row indocs/design.mdname the two ops (with the "not measured natively for these two" caveat).tests/semantic/test_valu_mad_lit.py: its two sabotage controls (swap multiplicand/addend, fuse intoFma) matched anOpFAddwhose first operand is theOpFMulresult. With the flush in between, they no longer injected anything. They now match the add whether it takes the product or its flushed copy (and still pass onmain's translator: checked withLEONIDA_TOOLS_DIR), so the controls keep catching what they were written for.Tests
tests/semantic/test_madak_madmk_denorm.py(new, hand-written assembly, CPU): for both ops, a denormal operand, a denormal product (2^-70 x 2^-70), a denormal sum (1.5·2^-126 - 2^-126), a denormal literal, a denormal addend, the sign of a zero result, and normal values, infinity and NaN passing through.test_madak_madmk_denorm.pymain's translatorFull
python -m unittest discover -s tests/semantic(Windows 11, Python 3.12): 7,458 tests, the same 9 failures/errors asmainaa2988cc(7,456 there; all red onmainand already taken: TEST-857, #3995, ...).test_*mad*(144 tests): OK.tests/test_design_contract_rows.py,test_docs_design_rows.py,test_docs_table_rows.py,test_docs_repo_paths.py: OK.Limitations
v_madak/v_madmk(needs an RDNA1/GFX10.1 part;tools/mad_denorm_probe.pycould take them).AI-assisted (Claude Code). CPU only.