shader: lower v_cvt_pknorm_i16_f16 and v_cvt_pknorm_u16_f16 #80
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!80
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-80"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:03 UTC · original
lcg007xd-c:shader-pknorm-f16→main· +90 −3 · 2 files · 1 commits · openWhat is broken
v_cvt_pknorm_i16_f16(VOP3 0x312) andv_cvt_pknorm_u16_f16(VOP3 0x313) decode, but a program using either fails to translate withv_cvt_pknorm_i16_f16 is not supported(or theu16name). I found them by translating a one-instruction program for every VOP3 opcode the decoder names. Mesa's ACO selects exactly these two for NIR'spack_snorm_2x16/pack_unorm_2x16on 16-bit sources (aco_select_nir_alu.cpp), so they appear in normal compiler output for packing two halves into an SNORM16/UNORM16 pair.Semantics
AMD's RDNA2 ISA (§12.12, opcodes 786 and 787) gives
D = {(snorm)S1.f16, (snorm)S0.f16}and the same withunorm: two f16 values converted to normalized 16-bit integers, src0 in the low half.The change (
emit/lower.rs)v_cvt_norm_i16_f16/v_cvt_norm_u16_f16already use (cvt_norm16): clamped to [−1, 1] or [0, 1], scaled by 32767 or 65535, rounded to nearest even once from the exact product, NaN → 0. No new arithmetic.cvt_norm16_of(inst, src, signed): the conversion now takes which source to read, so each source'sop_selhalf,absandnegapply.cvt_norm16calls it with source 0, so the existing instructions are unchanged.Tests
emit::lower::tests::f16_norm_packs_translate(every host): both encodings decode to their names, and a program that stores the result translates. Without thelower.rschange it fails:v_cvt_pknorm_i16_f16: GFX10 code at 0x24: v_cvt_pknorm_i16_f16 is not supported.valu_tests::v_cvt_pknorm_i16_and_u16_f16_pack_two_norm_conversions(Windows/GPU): about 140 pairs of f16 patterns per opcode, checked against the existingcvt_norm16_reference. They include ±1, 0.5 (a tie), ±inf, NaN and the smallest denormal. The sources carry junk high halves.lli. I used an independent f64 reference over every 331st f16 pattern plus edges, anop_selcase (both sources from the high halves), andnegon src1. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine. The f32 forms (
v_cvt_pknorm_*_f32, 0x368/0x369) are left for a separate change. Their rounding (an exact product, or Mesa's f32-product definition) needs its own decision.🤖 Generated with Claude Code
VOP3 0x312 and 0x313 decoded but failed to translate ("v_cvt_pknorm_i16_f16 is not supported"). Each packs two f16 values converted to normalized 16-bit integers (src0 low, src1 high; AMD's RDNA2 ISA), with the conversion v_cvt_norm_i16_f16/v_cvt_norm_u16_f16 already use here; that helper now takes the source to read, so op_sel, abs and neg apply per source. Mesa's ACO selects these two for NIR's pack_snorm_2x16/pack_unorm_2x16 on 16-bit sources. Co-Authored-By: Claude Opus 5.5 <[email protected]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.