shader: accept a literal source in gfx2hlsl v_pk_mul_f16 #3490
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!3490
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3488"
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?
@Leyukaka on GitHub · 2026-11-29 17:31 UTC · original
Leyukaka:shader-gfx2hlsl-pk-mul-literal→main· +22 −4 · 3 files · 1 commits · merged 2026-11-30 08:45 UTCRefs #2022 (item claimed there). Replaces the earlier attempt in the closed draft #2930.
What changes
tools/startup/gfx2hlsl.py:v_pk_mul_f16now accepts a 32-bit hex literal (0xplus 1 to 8 hex digits) as a source operand. Nothing else in the lowering changes: the literal is emitted as a full 32-bit word (gfx2hlsl.py:2698) and each half is picked byop_sel/op_sel_hiexactly as for a VGPR (gfx2hlsl.py:10132), then goes through the existingf16tof32and rounding path.Still refused, each with a test:
s20), bare inline0, inline floats (2.0)0x100000000)clamp,neg_lo/neg_hi, negated source (-v0)v_pk_add_f16andv_pk_fma_f16Why
In one long local run of the application with only the Python path active, one compute program using a literal source for this instruction accounted for about 847,000 dispatches, none translated.
Tests
tests/startup_gfx2hlsl_f16_alu_check.py:v_pk_mul_f16 v3, v0, 0x4000moves from the refusal list to a positive case (v0= (3, 3) gives0x00004600: the high lane uses the literal's high half, 0).0xc4003e00(+1.5 low, -4 high) andv0 = 0x42003c01(1+2^-10 low, 3 high):0xca003e02. The low product is halfway between0x3e01and0x3e02and rounds to even.op_sel:[0,1] op_sel_hi:[1,0]):0x4480c401.0, 9-digit hex, literal destination, literal withclamp).Expected values were worked out by hand.
tests/startup_gfx2hlsl_pk_minmax_check.pydropsmulfrom its "literal is not a single VGPR" refusal loop, because that refusal is now wrong formul. Theaddandfmaentries stay.Passing:
startup_gfx2hlsl_f16_alu_check,startup_gfx2hlsl_pk_minmax_check,startup_gfx2hlsl_compute_check(no arguments),startup_gfx2hlsl_pack_b32_f16_check,startup_gfx2hlsl_fma_mix_check,startup_gfx2hlsl_refusals_check.Mutations, each reverted afterwards:
f16_alu_checkfails on the 3 literal casesf16_alu_checkfails onrefuses v_pk_mul_f16 v3, s20, v0Not covered
startup_gfx2hlsl_compute_checkinbinarymode needsllvm-mcand was not run.@lukaslw-lab on GitHub · 2026-11-30 08:16 UTC · original · approved these changes
Reviewed
e9014c09by reading the diff; not built or run. I also disassembled the two synthetic words with llvm-mc 15 (-mcpu=gfx1013).Verdict: approve. The literal uses the lowering
v_pk_min/max_f16already use for hex words, and LLVM agrees with the test encodings. No MUST.0xcc104003 0x180200ffgivesv_pk_mul_f16 v3, 0xc4003e00, v0, and0xcc105003 0x0801ff00givesv_pk_mul_f16 v3, v0, 0xc4003e00 op_sel:[0,1] op_sel_hi:[1,0]. Assemblingv_pk_mul_f16 v3, v0, 0xc4003e00keeps the full 32-bit literal word. So LLVM also models the VOP3P literal as one 32-bit value whose halvesop_sel/op_sel_hipick, aspacked_halfdoes (gfx2hlsl.py:10132-10137). That partly covers the "not checked against the ISA document" item; hardware is still unverified.gfx2hlsl.py:10117) runs after theselect_bitsbranch, so min/max are unchanged.iexcludes the destination. Add and fma still refuse, as the keptpk_minmaxloop shows.v_pk_mul_f16 v3, v0, 0x4000is a form the disassembler never prints. LLVM encodes0x4000there as the inline constant2.0(0xe9), not as a literal. It tests the parser only; the two decoded words are the cases that match real code.Tests:
f16_alu_checknow covers both literal positions, the round-to-even half, and five new refusals. The mutations show it catches swapped halves and an SGPR that slips through. CI did not run it:startup_gfx2hlsl_f16_alu(CMakeLists.txt:3886) is not in theprpreset's list, and the Linux Python job does not include it. Onlypk_minmax_checkran there (passed). The local run in the body is the only run off16_alu_checkat this head.