shader: lower v_frexp_mant/v_frexp_exp for f32 and f16 #76
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!76
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-76"
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:53 UTC · original
lcg007xd-c:shader-frexp→main· +199 −0 · 2 files · 1 commits · openWhat is broken
The four frexp instructions decode, but a program using any of them fails to translate with
v_frexp_mant_f32 is not supported(or the matching name):v_frexp_exp_i32_f32v_frexp_mant_f32v_frexp_mant_f16v_frexp_exp_i16_f16I found them by translating a one-instruction program for every opcode the decoder names. Compilers emit them for HLSL's
frexpand inside log/pow/division expansions.Semantics (AMD's RDNA2 ISA, §12.8, opcodes 63, 64, 89, 90)
x = significand · 2^exponentwith the significand in[0.5, 1)and the input's sign, as C'sfrexpdoes.2⁻¹⁴⁹gives(0.5, −148).The change (
emit/lower.rs)frexp(bits, half), worked on the float's bits in integers:field − (bias − 1).FirstbitHi) moves to the implicit bit. Its exponent comes from that bit's position.valu_op):omod/clamp on the significand go throughwrite_f, as for any float result.valu16_op):abs/negare applied to the sign bit. The result is written to the selected 16-bit half.omod/clamp onv_frexp_mant_f16go through the usual f16 result path.Tests
emit::lower::tests::frexp_translates(every host): all four in both VOP1 and VOP3 form decode to their names, and a program that stores the result translates. Without thelower.rschange it fails:v_frexp_mant_f32 [7e008101, 7e000000]: GFX10 code at 0x24: v_frexp_mant_f32 is not supported.valu_tests::v_frexp_split_floats_like_c_frexp(Windows/GPU): hand-computed significand and exponent pairs. They cover 8, −3, 0.75, 1,f32::MAX, the smallest normal, three denormals, ±0, +inf and NaN, plus the f16 equivalents (65504,2⁻¹⁴,2⁻²⁴, −0, inf, NaN).CPU run: I ran these on Linux through the CPU harness of #62, which runs the emitted DXIL with LLVM's
lli. I also compared against an independent f64 reference:neg(f32),abs(f16), andomod ×2(f16 significand).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. I also have no RDNA2 hardware, so the sNaN case follows the ISA's text (the bits pass through) and is not checked on a card.
🤖 Generated with Claude Code
VOP1 0x3F/0x40/0x59/0x5A (and their VOP3 forms) decoded but failed to translate ("v_frexp_mant_f32 is not supported"). They split a float as C's frexp does (AMD's RDNA2 ISA): the significand in [0.5, 1) with the input's sign, and the exponent, so x = significand * 2^exponent. Infinities and NaNs keep their bits with exponent 0, as the ISA says; zero likewise. Both are worked out on the float's bits in integers: a normal value's exponent field becomes 0.5's; a denormal is normalized from its leading one (FirstbitHi), so the result does not depend on whether the host flushes denormals. The f16 forms write a 16-bit half; omod and clamp on v_frexp_mant_f16 go through the usual f16 result path. 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.