xshader: match the card in every exact division step and f16 dot product #615
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/615"
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?
Imported from brcly/TuxBox. Originally posted by JohnVonWells on 2026-12-01T10:21:18Z.
This follows #614: it closes every difference that PR's check still found. Every form that check compares now matches the card's word, except the three the card itself only approximates. Each rule below was measured natively on a gfx1030 and is now in the translation. Builds on #614; until that merges, this branch also holds its commit.
What the card does
v_div_scale_f32/_f64. Measured over all 65,536 f32 exponent pairs with edge and random mantissas (1,572,864 words), and over every f64 exponent against each boundary region plus 100,000 random pairs (4,535,808 words). The final model reproduces every word.0xffc00000(f64:0xfff8…), with VCC still from the exponents.v_div_fixup_*. Fits all 4,096 records under all 1,024 MODE values, in each width.v_div_fmas_f32scales by 2^±64 before its one rounding, keeps denormal sources and follows MODE, like the f64 form in #614. It had been a nativemadand a multiply. The newtb_f32_fma_scaledis exact, on the 128-bit helpers of the f64 code.v_fma_f64,v_mul_f64,v_add_f64with f64 output denormals off. The new boundary inputs and the round modes with flushing (0x004,0x008,0x00c) found three faults intb_f64_norm128and the shortcuts:0 + band0 * x + cflush a denormal b or c.v_fma_f64: zero times infinity gives the default NaN even when S2 is a NaN. This was measured with true zeros, signaling NaNs and under every MODE value.v_trig_preop_f64holds 1,184 bits of 2/π, where the translation's table had 1,216. Over 25,600 extra inputs, 1,184 bits gave 0 differences and 1,216 gave 35.v_dot2_f32_f16/v_dot2c_f32_f16. MODE doesn't change any result.The model matched all 4,096 records under three MODE values, plus 19,200 extra cases: zeros, signs, f16 denormals and tiny results. The new helper needs the f64 helpers, so
output.rsadds them when an f16 dot product is present. The VOP3P form with negation, op_sel or clamp still takes the float path.The check
Changes to
check_translated.py:Results, in words differing out of 93,840 per form:
v_add_f64v_mul_f64v_fma_f64v_div_scale_f64(value, VCC; numerator and denominator forms)v_div_scale_f32(same)v_div_fmas_f64, VCC clear / setv_div_fmas_f32, VCC clear / setv_div_fixup_f64/_f32/_f16v_trig_preop_f64v_dot2c_f32_f16,v_dot2_f32_f16The main column is the negative control: main's emitter (
717a74c4), through the same inputs and MODE values.v_rcp_f64,v_rsq_f64andv_sqrt_f64are approximate on the card and still differ; the check reports them without failing.Tests
division_scale_follows_the_measured_thresholds,division_fixup_follows_the_measured_rangesandf64_arithmetic_flushes_after_roundingfail without the change.division_steps_follow_the_measured_mode_rulesis updated for the exact f32 fma, the shorter table and the exact dot product.cargo test --lib: 709 passed.python tuxbox.py checkon an RX 6950 XT: all 17 steps passed, including the shader translator GPU checksf64andrdna2-gaps.Run on AMD only. A run on an NVIDIA card is still missing.
AI-assisted.
Imported from brcly/TuxBox. Originally posted by 1093i3511 on 2026-12-01T17:20:35Z.
@JohnVonWells
Since #615 (
7327dab4), 3 ProjectScarlett programs fail to compile (12 requests) in a Series S prepare onfb17e160:DOT_HELPERS(text/helper_code.rs) is pasted into every program that uses anyv_dot*. Since #615 it holdstb_dot2_f16, which calls thetb_u128_*helpers andtb_f32_norm128. Those come fromfloat64_arith::HELPERS, whichemitter/output.rsadds only forv_dot2_f32_f16andv_dot2c_f32_f16. A program with only other dot products (here the integer ones) getstb_dot2_f16without them, and DXC rejects the undeclared names even though nothing calls the function. Translating one of them (7baa6a35…) showstb_dot2_f16at line 157 and notb_u128_*definition anywhere.The other two are
6da9859f…and1d52e9cf…. Two possible fixes: addfloat64_arith::HELPERSwheneverDOT_HELPERSgoes in, or movetb_dot2_f16out ofDOT_HELPERSinto the block that is added for the f32 dot products. The morning prepare on717a74c4(before #615) had 0 failures.Imported from brcly/TuxBox. Originally posted by JohnVonWells on 2026-12-01T17:56:43Z.
@1093i3511 Thanks, you're right, and sorry for the breakage. The fix is in #631.