Skip to content

shader: lower quad-local DPP16 and DPP8 binary16 arithmetic and rounding in pixel_aot - #1971

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-arith-round
Nov 24, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-arith-round

Conversation

@KomaGuy

@KomaGuy KomaGuy commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1941 lowering the quad-local DPP16 and DPP8 forms of the 8 binary16 arithmetic and rounding opcodes already contracted under #839 (+16 forms on gfx1013 and rdna2):

  • VOP2 binary16 arithmetic (8 forms): v_add_f16_dpp, v_sub_f16_dpp, v_subrev_f16_dpp, v_mul_f16_dpp (DPP16 + DPP8)
  • VOP1 binary16 rounding (8 forms): v_floor_f16_dpp, v_ceil_f16_dpp, v_trunc_f16_dpp, v_rndne_f16_dpp (DPP16 + DPP8)

Implementation Details

  • Added half16_dpp_source() in tools/pixel_aot.py: enforces the shared low-16-only and static finite-proof contract (known_ssa_bits or known_half, rejecting unproven runtime sources and non-finite halves), with bit-15 abs/neg modifiers allowed on DPP16 and refused on DPP8.
  • src0 is quad-swizzled via emit_quad_swizzle_u32 while src1 stays on the current lane; overflowing VOP2 results are refused via f16_vop2_result; destinations are tagged ("half16", alu) with proven low-16 bits recorded in known_half for chaining.
  • Explicit half_denorm="preserve" at shader entry and HW_REG_MODE RNE rounding remain enforced; WORD_1/whole-word reads, DPP8 source modifiers, bound_ctrl/fi, partial masks, cross-quad dpp8, and unlowered binary16 DPP neighbours (v_min/max_f16_dpp, v_fract_f16_dpp, v_fmac/ldexp_f16_dpp, transcendentals) stay refused.
  • Extended pixel_aot_dpp_f16_{warp,hardware} with four 4-channel programs (arith_dpp16, arith_dpp8, round_dpp16, round_dpp8) testing noisy upper-16 halves, destination sentinels, subnormals (in both default mode and -denorm ftz), -0.0, ties-to-even, half16 chaining, and 12 op/modifier mutations; added all 4 to check_binary, added check_dpp_f16_arith_round_forms() in tests/form_coverage_check.py, and updated docs/experiments.md.

Verification

  • Tested locally on Linux:
    • python3 -B tests/pixel_aot_check.py — passed
    • python3 -B tests/rdna2_tools_check.py — 152 tests OK
    • form_coverage_check: check_f16_arith_forms, check_f16_round_forms, check_dpp_f16_arith_round_forms, check_shader_records — all passed (+16 forms on gfx1013 and rdna2)
    • All 16 expected 16-bit results verified against f16_vop2_result / f16_round_result
    • Assembled all 4 programs with llvm-mc-19 -triple=amdgcn--amdpal -mcpu=gfx1013 and verified round-trip translation through both disasm_rdna2 and libLLVM-19.so
    • docs_links_check.py, bidi_controls_check.py, git diff --check — passed
  • Windows DXC / WARP draw execution (pixel_aot_dpp_f16_warp) and LLVM 15 fixture assembly are pending CI.

…ing in pixel_aot

Lower the quad-local DPP16 and DPP8 spellings of the eight already-contracted
binary16 arithmetic and rounding opcodes (16 forms total across gfx1013 and
rdna2):
- VOP2_F16: v_add_f16_dpp, v_sub_f16_dpp, v_subrev_f16_dpp, v_mul_f16_dpp
- VOP1_F16_ROUND: v_floor_f16_dpp, v_ceil_f16_dpp, v_trunc_f16_dpp, v_rndne_f16_dpp

Add half16_dpp_source() enforcing the same low-16-only and static finite-proof
contract (R0Y00#839) as plain e32/e64: VGPR sources must carry a statically proven
finite low half (known_ssa_bits or known_half), src0 is quad-swizzled via
emit_quad_swizzle_u32 while src1 stays on the current lane, DPP16 allows
bit-15 abs/neg modifiers on either source (refused on DPP8), overflowing
results are refused via f16_vop2_result, and destinations are tagged
("half16", alu) with proven low-16 bits for chaining. Explicit
half_denorm="preserve" and HW_REG_MODE RNE remain required.

Extend pixel_aot_dpp_f16_{warp,hardware} with four 4-channel programs
(arith_dpp16, arith_dpp8, round_dpp16, round_dpp8) verified in both default
and -denorm ftz modes plus op/modifier mutations, add all four to check_binary,
update check_dpp_f16_contract_controls and docs/experiments.md, and add
check_dpp_f16_arith_round_forms in tests/form_coverage_check.py.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head d8b51b5. Not mergeable yet.

P2 (blocking): the new pixel_aot_dpp_f16 test fails on Win2025, warp and hardware.
In check_dpp_f16_draw (tests/pixel_aot_check.py, around line 9841), one of the arith_round_mutations cases is expected to report mismatch but reports pass. The mutated shader gives the same readback as the original, so that mutation is not killed. Either the mutation does not change the result for the chosen constants or lane layout, or the expected words do not separate it. Please pick inputs that make each listed mutation visible, or drop the ones that cannot be seen.

Failing tests on Win2025 (Debug, ctest --preset dev -R ^pixel_aot): pixel_aot_dpp_f16_warp, pixel_aot_dpp_f16_hardware. The other 174 pixel_aot_* tests passed.
pixel_aot_attribute_sampled_{warp,hardware} also failed (whole_quad: unexpected result). That test is not touched by this PR, so I treat it as unrelated to this head.

Read the diff (tools/pixel_aot.py, tests, docs). The lowering looks consistent with the stated contract:

  • src0 is quad-swizzled and src1 stays on the current lane.
  • Modifiers are refused on DPP8.
  • Overflow, non-finite and unproven operands are refused.
  • Both branches require half_denorm="preserve".

No P1 found in the lowering. Clean-room: no concerns in the changed files.

Commands run locally, with results:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • gh pr checks 1971: Linux Python checks pass, Windows build pass, /O2 build skipped, gfx1013 fixtures pending.
  • python3 tests/docs_links_check.py: PASS (386 links).
  • python3 tests/bidi_controls_check.py: PASS.
  • git diff --check origin/main...HEAD: PASS.
  • python3 tests/form_coverage_check.py: could not run locally (iced_x86 missing on this host). CI Linux job passes, so this is not counted against the PR.
  • python3 tests/pixel_aot_check.py on Linux: exits 0 but runs no draws. Source mutations are only checked on Win2025.
  • x2w_pipe.py win2025 1971 --scope direct --regex '^pixel_aot' (Debug): FAIL as above. The default full-scope run could not start (PowerShell command too long), so I used the focused regex. Release /O2 was not run, because Debug already fails.
  • Local source mutations (drop a src1 line; swizzle src1): no draw runs on Linux, so they were not killed locally. I did not use them as evidence. Reverted with git checkout -- ..

No approval and no merge. Please fix the unkilled mutation and push a new head.

AI-assisted; commands listed were executed locally.

@KomaGuy

KomaGuy commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this on Win2025!

Found the unkilled mutation: in arith_dpp8, mutating v_add_f16_dpp v24, v20, v21 to v_sub_f16_dpp v24, v20, v21 operated on (-0.0, -0.0) where src0 came through QuadReadLaneAt (non-constant) and src1 folded to constant -0.0f, so DXC simplified fsub %x, -0.0 to %x and returned 0x8000 just like the original. Every other mutation in arith_round_mutations changes the numerical value by at least 1.0.

Pushed f1ade5b3 which:

  • Replaces the signed-zero-only arith_dpp8 mutation with numerically distinct mutations (v24 src1 v21 -> v22 giving -0.0 -> +1.0, v25 sub -> add giving -1.5 -> +3.5, plus mul -> add on v27 for both arith_dpp16 and arith_dpp8), so every mutation in DPP_F16_ARITH_ROUND_MUTATIONS changes an exported channel by at least 1.0.
  • Prints each mutation's batch status and includes (name, old, new) in the assertion message if any mutation escapes, matching check_f16_arith_draw.

Verified locally on Linux (pixel_aot_check.py, docs_links_check.py, bidi_controls_check.py, git diff --check, and a Python check confirming every listed mutation changes an exported channel by |delta| >= 1.0). Ready for another Win2025 check.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head f1ade5b348550f71ed7dba292ff6f1ea9384fbdc.

Scope: tools/pixel_aot.py, tests/pixel_aot_check.py, tests/form_coverage_check.py, docs/experiments.md. No CMake change. Lowering reuses the existing finite-proof, quad-swizzle and narrow16 helpers. Clean-room: no external code, no new tables.

Findings: P1 = 0, P2 = 0.

Semantics checked:

  • src0 is quad-swizzled and src1 stays on the current lane.
  • abs/neg are refused on DPP8.
  • Non-finite and overflowing results are refused.
  • Operands without a finite proof are refused.
  • HALF_RTZ is refused, and denorm "preserve" is required.
  • The destination is tagged ("half16", alu) with its proven bits.

Commands executed locally:

  • git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.
  • python3 tests/pixel_aot_check.py: PASS.
  • python3 tests/docs_links_check.py: PASS (386 links).
  • python3 tests/bidi_controls_check.py: PASS.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/form_coverage_check.py: not runnable locally (iced_x86 missing). The Linux CI job passed it.
  • python3 x2w_pipe.py win2025 1971 --regex '^pixel_aot_dpp_f16_warp$' --py-checks tests/pixel_aot_check.py: Debug --preset dev 1/1 passed; Release /O2 --preset release 1/1 passed; Windows pixel_aot_check.py ok.

Mutations (each reverted with git checkout -- .):

  1. VOP2_F16["subrev"] changed to {0} - {1}: pixel_aot_check.py fails (f16_arith_controls_no_ref). Killed.
  2. VOP1_F16_ROUND["ceil"] changed to floor({0}): fails (check_f16_round_controls). Killed.

AI-assisted; commands listed were executed locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants