Skip to content

shader: lower quad-local DPP16 and DPP8 binary16 fmac, ldexp and int16 conversions in pixel_aot - #2485

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-cvt-fmac-ldexp
Nov 25, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-cvt-fmac-ldexp

Conversation

@KomaGuy

@KomaGuy KomaGuy commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What this changes

Extends the quad-local DPP16/DPP8 binary16 slice (#1971) to lower the six remaining contracted binary16 opcodes (+12 forms across gfx1013 and rdna2):

  • Fused multiply-add & exponent scaling (VOP2 DPP16 + DPP8): v_fmac_f16_dpp, v_ldexp_f16_dpp
  • 16-bit integer ↔ binary16 conversions (VOP1 DPP16 + DPP8): v_cvt_f16_i16_dpp, v_cvt_f16_u16_dpp, v_cvt_i16_f16_dpp, v_cvt_u16_f16_dpp

Lowering & contract (tools/pixel_aot.py)

  • Adds int16_dpp_source() alongside half16_dpp_source() under the existing #839 contracts:
    • src0 is quad-swizzled via emit_quad_swizzle_u32; src1 and the v_fmac_f16_dpp accumulator stay on the current lane.
    • DPP16 allows bit-15 abs/neg modifiers on float sources only (src0/src1 on v_fmac_f16_dpp, src0 on v_ldexp_f16_dpp and v_cvt_{i16,u16}_f16_dpp); DPP8 and integer operands refuse modifiers.
    • v_fmac_f16_dpp uses fma16_rne for single-rounding fused multiply-accumulate with overflow checked via f16_pk_fmac_lane_result.
    • v_ldexp_f16_dpp requires a statically proven signed 16-bit exponent in [-64, 64] and checks overflow via f16_ldexp_result.
    • v_cvt_f16_i16_dpp accepts runtime i16/low16 sources; v_cvt_f16_u16_dpp requires a static proof < 65520 (f16_cvt_int_result). Both tag destinations ("half16", alu) with proven bits when statically known.
    • v_cvt_{i16,u16}_f16_dpp truncates proven in-range binary16 values (f16_to_int_result) into ("low16", alu).
    • Explicit half_denorm="preserve" and HW_REG_MODE RNE remain required.

Tests & docs (tests/pixel_aot_check.py, tests/form_coverage_check.py, docs/experiments.md)

  • Extends pixel_aot_dpp_f16_{warp,hardware} with:
    • Four 4-channel programs (fmac_ldexp_dpp16, fmac_ldexp_dpp8, cvt_int16_dpp16, cvt_int16_dpp8) covering fused-vs-non-fused rounding (0x1c01 vs 0x1c00), subnormal preservation (in both default denorm mode and -denorm ftz), ties-to-even rounding, the 65519 max finite u16 boundary, truncation toward zero, half16/low16 chaining, noisy upper-16 halves, preloaded sentinels, and DPP16 -/|.| modifiers, plus 13 numerically distinct mutations (none relying on a signed-zero-only delta).
    • A per-lane runtime quad-routing witness (DPP_F16_CVT_I16_LANES) for v_cvt_f16_i16_dpp over signed 16-bit lane values {-4, -3, -2, -1} with noisy upper halves (0x1234) across both DPP16 AcrossX and DPP8 cyclic rotation, with permutation mutations.
  • Adds all five new programs to check_binary (for LLVM 15 assembly/disassembly round-trip in CI).
  • Updates check_dpp_f16_contract_controls and existing plain f16 control lists, adds check_dpp_f16_cvt_fmac_ldexp_forms() in tests/form_coverage_check.py, and documents the slice in docs/experiments.md.

Verification (Linux)

  • python3 tests/pixel_aot_check.py: PASS (including check_dpp_f16_contract_controls and all updated f16 controls).
  • form_coverage_check (check_dpp_f16_cvt_fmac_ldexp_forms, check_dpp_f16_arith_round_forms, check_f16_fmac_ldexp_forms, check_f16_cvt_int16_forms, check_f16_to_int16_forms): PASS (exact +12 forms in gfx1013.tsv and rdna2.tsv, unlowered neighbours excluded).
  • python3 tests/docs_links_check.py: PASS (19 files, 466 links).
  • python3 tests/bidi_controls_check.py: PASS (1,726 files).
  • python3 tests/rdna2_tools_check.py: PASS (156 tests OK, 19 skipped).
  • Independent Python simulation verified all 13 DPP_F16_CVT_FMAC_LDEXP_MUTATIONS produce non-zero-sign-only channel diffs.
  • git merge-tree --write-tree --name-only origin/main HEAD & git diff --check origin/main: clean.

Windows draws (pixel_aot_dpp_f16_{warp,hardware}) and LLVM 15 check_binary run in CI. Synthetic fixture coverage only; console behavior is not measured.

AI-assisted: yes.

…6 conversions in pixel_aot

Lower the quad-local DPP16 and DPP8 spellings of the six remaining
contracted binary16 opcodes (12 forms total across gfx1013 and rdna2):
- VOP2 fused/scale: v_fmac_f16_dpp, v_ldexp_f16_dpp
- VOP1 int16 <-> f16: v_cvt_f16_i16_dpp, v_cvt_f16_u16_dpp,
  v_cvt_i16_f16_dpp, v_cvt_u16_f16_dpp

Add int16_dpp_source() alongside half16_dpp_source() to enforce the
existing R0Y00#839 contracts:
- src0 is quad-swizzled via emit_quad_swizzle_u32 while src1 and the
  v_fmac_f16_dpp accumulator stay on the current lane.
- DPP16 allows bit-15 abs/neg modifiers on float sources only (src0/src1
  on v_fmac_f16_dpp, src0 on v_ldexp_f16_dpp and v_cvt_{i16,u16}_f16_dpp);
  DPP8 and integer operands refuse modifiers.
- v_fmac_f16_dpp uses fma16_rne for single-rounding fused multiply-add,
  v_ldexp_f16_dpp requires a proven signed 16-bit exponent in [-64, 64],
  v_cvt_f16_i16_dpp accepts runtime i16/low16 sources while
  v_cvt_f16_u16_dpp requires a static proof < 65520, and
  v_cvt_{i16,u16}_f16_dpp truncates proven in-range binary16 values into
  ("low16", alu).
- Explicit half_denorm="preserve" and HW_REG_MODE RNE remain required.

Extend pixel_aot_dpp_f16_{warp,hardware} with four 4-channel programs
(fmac_ldexp_dpp16, fmac_ldexp_dpp8, cvt_int16_dpp16, cvt_int16_dpp8) in
both default and -denorm ftz modes plus 13 numerically distinct mutations
and a per-lane runtime quad-routing witness (DPP_F16_CVT_I16_LANES), add
all five to check_binary, update check_dpp_f16_contract_controls and
docs/experiments.md, and add check_dpp_f16_cvt_fmac_ldexp_forms in
tests/form_coverage_check.py.
@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The modifier matrix the comment describes is exactly what the code does — I probed it instruction by instruction

check_binary needs llvm-mc with gfx1013, which I do not have here, so I drove the translator directly with hand-written instruction text through the test file's own translate_f16 helper (sources defined first, since the DPP sources must be written before they are read):

probe result
DPP16 v_fmac_f16_dpp v24, -v20, |v21| quad_perm:… accepted (neg on src0 and abs on src1)
DPP16 v_fmac_f16_dpp v25, v22, -v23 quad_perm:… accepted (neg on src1 alone)
DPP16 v_ldexp_f16_dpp v26, -v22, v28 quad_perm:… accepted (neg on src0)
DPP16 v_ldexp_f16_dpp v26, v22, -v28 quad_perm:… refused: Source modifiers are not allowed on -v28
DPP8 v_fmac_f16_dpp v24, -v20, v21 dpp8:[…] refused: Source modifiers are not allowed on -v20
DPP8 v_ldexp_f16_dpp v26, v25, -v28 dpp8:[…] refused: Source modifiers are not allowed on -v28
v_cvt_f16_i16_dpp v24, -v20 (integer source) refused: Source modifiers are not allowed on -v20
v_cvt_i16_f16_dpp v26, -v22 (float source) accepted

That is the whole rule as stated in the comment — "DPP16 allows bit-15 abs/neg modifiers on float sources (src0 and src1 for fmac, src0 only for ldexp); DPP8 and integer src1 refuse modifiers" — and every clause of it holds on the real code path, including the asymmetric one (fmac takes modifiers on both, ldexp only on src0) that is the easiest to get wrong and the hardest to notice.

The two "accepted" rows that end in a different error (Unsupported instruction … s_endpgm, Unexpected sample count or missing color export, ldexp exponent out of range: 15360) got past the modifier check — those messages come from later stages, which is the point: the modifier gate said yes.

What the fixture itself asserts beyond that

DPP_F16_CVT_FMAC_LDEXP_PROGRAMS is fed to check_binary as translation fixtures, so each program's lowered text is compared against a CPU model of the expected arithmetic — the modifier probes above only show the gate accepts, not that the arithmetic is right. That part I could not run.

One suggestion

The fmac_ldexp_dpp16 program exercises -v20 with |v21| in one instruction and -v23 alone in another, so abs-on-src1 and neg-on-src1 separately both appear. Worth checking whether abs alone on v_ldexp_f16_dpp's src1 is also covered — my probe only tried neg there, and the refusal message is generic (Source modifiers are not allowed on …), so a fixture case would pin that abs is refused for the same reason rather than by accident of the neg branch.

Docs

experiments.md grows by 4 lines; the capability claim matches what I measured. No AGENTS.md/CI-list entry is needed because the check rides on the existing pixel_aot registration.

AI-assisted; all eight probes were run locally on Windows 11 build 26300.9974 on the PR branch head, no GPU needed since this path is pure Python.

@KomaGuy

KomaGuy commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ChazY11 for probing the modifier matrix and the suggestion!

Pushed ef9c4340 adding explicit |v21| and abs(v21) refusal cases on v_ldexp_f16_dpp's integer src1 in check_dpp_f16_contract_controls alongside the existing -v21 refusal, so both abs spellings are pinned directly. Verified locally on Linux (pixel_aot_check.py and bidi_controls_check.py pass).

@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 408ce23 (comment only; the head is the PR branch updated with main, own change unchanged at ef9c434).

Checked against origin/main:

  • New v_fmac_f16_dpp, v_ldexp_f16_dpp, v_cvt_f16_{i16,u16}_dpp and v_cvt_{i16,u16}_f16_dpp lowerings in tools/pixel_aot.py follow the same static finite-proof contract as the sibling plain ops and the merged DPP binary16 ops (#419, #1971). DPP8 refuses float modifiers, integer sources refuse them too, the ldexp exponent needs a static proof within the limit, and overflow of the proven result is refused.
  • No other open or merged PR covers this slice.
  • The new fixtures are drawn in check_dpp_f16_draw (D3D12 WARP and hardware), with per-lane i16 routing and op/modifier mutations that must report a mismatch, in default and -denorm ftz modes.

Commands run:

  • Linux, on the PR head before the update: tests/pixel_aot_check.py PASS, tests/docs_links_check.py pass, tests/bidi_controls_check.py pass, git diff --check origin/main...HEAD clean. tests/form_coverage_check.py needs iced_x86, not available on Linux here; it passed on Win2025.
  • Mutation of the new cvt_i16_f16 lowering (trunc -> round): the Linux check FAILS.
  • Mutation of the new ldexp scale (127 + exponent -> 128 + exponent): the Linux check still passes, because the numeric result is only proven by the WARP draw. That draw is covered by the Win2025 run below (receipt on this head).
  • Win2025 dev and release on this head: ctest -R 'pixel_aot_dpp_f16|pixel_aot_dpp_cvt|pixel_aot_f16' 14/14 passed in both.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 408ce23 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 408ce23e7bb7c828fdb22278dfd0a21b8fa6e9f8:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 0.00s (configure 0.00s)
    • Test (ctest --preset dev -R 'pixel_aot_dpp_f16|pixel_aot_dpp_cvt|pixel_aot_f16' --parallel 2 --no-tests=error --output-on-failure): 14/14 passed (45.55s: pixel_aot_f16_arith_warp 6.56s, pixel_aot_f16_arith_hardware 6.63s, pixel_aot_f16_round_warp 4.68s, pixel_aot_dpp_f16_warp 7.72s, pixel_aot_f16_round_hardware 9.37s, pixel_aot_f16_fmac_ldexp_warp 8.24s, pixel_aot_f16_fmac_ldexp_hardware 4.23s, pixel_aot_dpp_cvt_warp 3.01s, pixel_aot_f16_cvt_int16_hardware 2.91s, pixel_aot_f16_cvt_int16_warp 2.97s, pixel_aot_f16_to_int16_hardware 7.20s, pixel_aot_dpp_cvt_hardware 7.73s, pixel_aot_f16_to_int16_warp 2.33s, pixel_aot_dpp_f16_hardware 9.16s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 0.00s (configure 0.00s)
    • Test (ctest --preset release -R 'pixel_aot_dpp_f16|pixel_aot_dpp_cvt|pixel_aot_f16' --parallel 2 --no-tests=error --output-on-failure): 14/14 passed (40.40s: pixel_aot_f16_round_warp 6.09s, pixel_aot_f16_arith_warp 8.69s, pixel_aot_f16_fmac_ldexp_warp 6.00s, pixel_aot_f16_cvt_int16_warp 3.78s, pixel_aot_dpp_cvt_warp 3.88s, pixel_aot_dpp_f16_warp 11.22s, pixel_aot_f16_to_int16_warp 3.15s, pixel_aot_dpp_cvt_hardware 3.98s, pixel_aot_f16_arith_hardware 8.63s, pixel_aot_dpp_f16_hardware 9.65s, pixel_aot_f16_fmac_ldexp_hardware 4.49s, pixel_aot_f16_round_hardware 5.31s, pixel_aot_f16_to_int16_hardware 2.22s, pixel_aot_f16_cvt_int16_hardware 3.01s)
  • Windows Python checks: tests/form_coverage_check.py ok (15.1s), tests/mesh_clip_cull_check.py ok (6.5s), tests/mesh_dynamic_geometry_check.py ok (0.3s), tests/mesh_heap_sampler_check.py ok (1.2s), tests/pso_readiness_check.py ok (1.3s), tests/rdna2_tools_check.py ok (3.4s), tests/startup_gfx2hlsl_cmp16_check.py ok (0.3s), tests/startup_gfx2hlsl_f32_lg_check.py ok (1.6s), tests/startup_gfx2hlsl_f32_nan_check.py ok (6.6s), tests/startup_gfx2hlsl_sop2_complement_check.py ok (10.2s), tests/startup_gfx2hlsl_vopc_sdwa_check.py ok (5.5s), tests/startup_image_load_d16_check.py ok (1.1s), tests/startup_image_sample_a16_check.py ok (0.2s), tests/vk_offscreen.py ok (1.6s)
  • sccache: 2/100 hits; wall 154.6s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 82421b8 into R0Y00:main Nov 25, 2026
5 checks passed
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