shader: lower v_min3/v_max3/v_med3 on 16-bit integers #65
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!65
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-65"
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 21:32 UTC · original
lcg007xd-c:shader-int16-min3-max3-med3→main· +115 −0 · 2 files · 1 commits · openWhat is broken
VOP3 0x352–0x359 decode, but none of them translates:
v_min3_i16v_min3_u16v_max3_i16v_max3_u16v_med3_i16v_med3_u16A program using any of them fails with
v_min3_i16 is not supported(and likewise for the others). I found these by translating a one-instruction program for every VOP3 opcode the decoder names. The 32-bit integer and f16 forms already lower; only the 16-bit integer forms were missing.The change (
emit/lower.rs, invalu16_opbeside the other 16-bit integer operations)It follows AMD's RDNA2 ISA (§12.12, opcodes 850–857):
op_selpicks. For_i16they are sign-extended.min3/max3: two min/max steps.med3: the middle value, computed asmax(min(a, b), min(max(a, b), c)). The ISA's form (find the max of the three, then take the max of the other two) gives the same value for integers.op_sel[3]. The other half is kept, as for every 16-bit VOP3 result on GFX10 (write_half).Tests
emit::lower::tests::int16_min3_max3_med3_translate(every host): each encoding decodes to its name, and a program that stores the result translates. The store keeps the instruction from being dropped as dead code. Without thelower.rschange it fails atv_min3_i16.valu_tests::v_min3_max3_med3_16bit_integer_forms_match_rdna2(Windows/GPU): three hand-computed cases per opcode. They include0x8000as both −32768 and 32768,0xFFFFas −1 and 65535, and a tie. The inputs' high halves are non-zero so a lowering that reads them would fail.opt+llirunning the emitted DXIL), plus oneop_selcase (src0 and src2 from the high halves, result to the high half). 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.
🤖 Generated with Claude Code
VOP3 0x352..=0x359 (v_min3_i16, v_min3_u16, v_max3_i16, v_max3_u16, v_med3_i16, v_med3_u16) decoded but failed to translate ("v_min3_i16 is not supported"). They now lower beside the other 16-bit integer operations: the three low (or op_sel-selected) halves, sign-extended for _i16, compared as the RDNA2 ISA defines (med3 is the middle value), and the result written to the destination's selected half, the other half kept. 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.