xshader: follow the card's MODE rules in the division steps #614
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/614"
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-01T09:33:20Z.
The f64 arithmetic, the division steps and
v_trig_preop_f64had only unit tests and a GPU check over five fixed inputs under MODE 0xc0, against Python floats. This adds a check that compares the translation with the card itself, and fixes the faults it found that the measurements settle.The check
tools/native_rdna2/arith64.hipruns each form natively on a gfx1030 under all 1024 MODE values, over 4,096 seeded records: edge and random values, products and sums near the smallest normal, and quotients whose exponents are far apart.check_translated.pythen translates one LLVM-assembled program with every form for each of 17 MODE values, runs it through D3D12 over 960 of those records, and compares every result word with the native one. No reference model is involved, so a difference can only come from the translation. The README has a section on it, and the receipt isevidence/native-rdna2-translated-arith64.json.v_add_f64,v_mul_f64andv_fma_f64already matched in every word.What the card does, and the fixes
v_div_fmas_f64with VCC set scales by 2^128 when the exponent of S2 is at least 1024 (|S2| ≥ 2), else by 2^-128. The translation always scaled by 2^64. The card scales the exact result before its one rounding: in 438 lanes only a single rounding matched, and in none did only a double rounding match. The newtb_f64_fma_scaledadds the exponent beforetb_f64_norm128, andtb_f64_fmacalls it with k = 0.v_div_fmas_f64keeps denormal sources. MODE bit 0x40 doesn't change any of its results, so the helper passesmode | 0x40.v_div_fmas_f32scales by 2^64 or 2^-64 by the same rule. Only the direction is fixed; this form still rounds twice and still ignores MODE (see below).v_trig_preop_f64flushes a denormal result when MODE bit 0x80 is clear. The translation always rounded with MODE 0xc0.v_dot2c_f32_f16, andv_dot2_f32_f16, which uses the same helper) return a NaN result quiet under every MODE value.Differing words, out of 16,320 per form, on main and with this change:
v_div_fmas_f64, VCC setv_div_fmas_f64, VCC clearv_div_fmas_f32, VCC setv_div_fixup_f64v_div_fixup_f32v_div_fixup_f16v_trig_preop_f64v_dot2c_f32_f16Main is
717a74c4. The emitter on main is the negative control: the same inputs and MODE values, through the same check.Still open
None of the remaining differences come from these rules:
v_div_scale_*scales and sets VCC for quotients the ISA text calls normal, so its thresholds need measuring.v_div_fmas_f32needs an exact f32 fma that follows MODE.v_trig_preop_f64: the 15 remaining differences all come from one input.v_rcp_f64,v_rsq_f64andv_sqrt_f64are approximate on the card. The receipt reports their differences, but they don't fail the check.Tests
division_steps_follow_the_measured_mode_rulesfails without the change.cargo test --lib: 706 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.