Repository navigation
xshader: lower exact f16 frexp/ldexp and normalized 16-bit packs - #287
Merged
Merged
Conversation
Add v_frexp_mant_f16, v_frexp_exp_i16_f16, v_ldexp_f16, v_cvt_pknorm_i16_f16, v_cvt_pknorm_u16_f16 and v_cvt_pknorm_i16_f32 in a new half_exact module. They work on the stored bits and follow MODE: the f16 round field, f16 denormals and IEEE NaN quieting. The f16 packs reuse tb_norm_f16; the new tb_norm_f32 rounds the exact product once. Plain VGPR operands, compute only. Fix v_cvt_pknorm_u16_f32, which rounded x * 65535 to float before rounding to an integer and could be off by one near a tie. It now uses tb_norm_f32 as well. Native RDNA2 execution under all 1024 MODE values (tools/native_rdna2/check_half.py) settled the details: v_ldexp_f16 takes a signed 16-bit exponent from the low half of S1, frexp and ldexp keep the high destination half, and the packs ignore MODE apart from f16 input denormals. 180,224 comparisons with the exact model, no mismatches, including the existing v_cvt_pknorm_u16_f32. tools/check_half_exact_gpu.py runs the translated shaders on a D3D12 GPU under eleven MODE values: 4,368 inputs, 39,312 results, zero mismatches. The old float rounding fails 102 of 312 dispatches, a 32-bit ldexp exponent 294, and full-word frexp/ldexp writes all 312. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NhDbTJdTcjebsL5u7pwFoY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds six half-precision and normalized-pack forms that the translator refused:
v_frexp_mant_f16,v_frexp_exp_i16_f16,v_ldexp_f16,v_cvt_pknorm_i16_f16,v_cvt_pknorm_u16_f16andv_cvt_pknorm_i16_f32.Fix:
v_cvt_pknorm_u16_f32was sometimes off by one near a rounding tie.round(saturate(x) * 65535.0)rounds the product to f32 first, which can create a false tie, the same problemtb_norm_f16already avoids. It now usestb_norm_f32. The native hardware agrees with the exact model.They live in a new module,
half_exact.rs, and work on the stored bits with integer arithmetic, like the f64 forms. They follow MODE: the f16 round field (bits 3:2), the f16 denormal fields (bits 7:6) and IEEE NaN quieting (bit 9). The f16 packs reuse the existing exacttb_norm_f16. Forv_cvt_pknorm_i16_f32, the newtb_norm_f32rounds the exact product once. They accept plain VGPR operands (VOP1/VOP2 without SDWA or DPP, or VOP3 without modifiers or op_sel), in compute shaders only.Semantics from native execution
tools/native_rdna2/check_half.pyruns the instructions natively on an RX 6950 XT under all 1024 MODE[9:0] values and works out which MODE bits change any result. It then compares an exact rational reference model on every combination of those bits: 180,224 comparisons, no mismatches. It also covers the existingv_cvt_pknorm_u16_f32. The hardware settled these details:v_ldexp_f16takes the exponent from the low 16 bits of S1, as a signed number. For example,0xffff0003scales by 2^3.v_ldexp_f16round according to the MODE round field, and the denormal flush tests tininess after rounding.GPU control
tools/check_half_exact_gpu.pyruns the translated shaders on a D3D12 GPU against the same model. It uses eleven MODE values written withs_setreg_imm32_b32, VOP1/VOP2 and VOP3 encodings, dynamic stale destinations, and frexp/ldexp forms that write over their own source. Result on the RX 6950 XT: 4,368 inputs and 39,312 results, all correct.v_cvt_pknorm_u16_f32fails 102 of 312 dispatches. That is the previous translator's behaviour for that form. A 32-bit ldexp exponent fails 294 of 312, and frexp/ldexp without the kept high half fail 312 of 312.Coverage of single decodable ALU instructions goes from 498 to 504 translated.
half-exactis now part oftools/check_translator_gpu.py.python tuxbox.py checkon the RX 6950 XT passes completely: Lanes, the D3D12 regression controls and all translator checks. There is no run on an NVIDIA card yet.Evidence:
evidence/native-rdna2-half.json,evidence/half-exact-control.json.AI-assisted.