shader: lower v_frexp_exp_i32_f64 and v_frexp_mant_f64 in direct compute #3634
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3634"
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 R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-30T18:40:48Z.
What changed
Exact binary64 frexp with pure 32-bit integer operations only, following the
v_frexp_*_f32shape and thev_ldexp_f64subnormal normalizer: no DXILdouble, noi64, nofcmp, and neitherDoublePrecisionFloatShaderOpsnorInt64ShaderOps.v_frexp_exp_i32_f64(VOP10x3c, VOP30x1bc) writes one 32-bit VGPR (v255allowed) with the signed exponentewherex = m * 2^eand|m|in[0.5, 1).v_frexp_mant_f64(VOP10x3d, VOP30x1bd) writes a 64-bit VGPR pair (v255refused) with the normalized significandmin(-1, -0.5] U [0.5, 1), keeping the input sign afterabs/neg.exp - 1022and a mantissa with biased exponent1022(0x3FE00000). A subnormal is normalized by the same 6-step shift search asv_ldexp_f64({32, 16, 8, 4, 2, 1}, every shift amount a constant in[0, 31]), giving1 - steps - 1022and the normalized field. Thek == 32step testsmh == 0 && ml < 2097152:2097151takes the 32-shift and2097152does not, pinned by the boundary values.0and pass the mantissa unchanged afterabs/neg, so NaN payloads survive (mantissa compared bit-for-bit in IR and by class on hardware).0(128->+0.0) and the inline binary64 constants240..247(lo = 0). Only under the default MODE for the shared f16/f64 fields (denormals kept); the binary16 MODE tracking now also covers both ops.v[d:d+1]invalidates lane spills on both halves (clear_vector_spills, mantissa op only); the exponent op writes onlyv[d], so it succeeds over a symbolic lane spill inv[d+1].Tests
tests/native_frexp_f64_check.py model|ir|controls|hardware(ctest --preset dev --no-tests=error -R '^native_frexp_f64_' -V). Details indocs/experiments/native-direct-frexp-f64.md.model: 90 boundary values (incl.±0.0,±MIN_SUB(exp -1073), lo-only subnormals2^-1073..2^-1043, the cross-word boundary0x00000000_00200000,±MAX_SUB,±MIN_NORM,±0.5,±(1 - 1ulp),±1.0,±1.5,±2.0,±DBL_MAX,±Inf,sNaN,qNaN) x 2 ops x abs/neg/abs+neg cross-checked againstmath.frexp; 11 self-mutations killed.ir: boundary values + seeded sweep of 100 random doubles through the IR interpreter in chunks of at most 1024 stores (theF.store12-bit offset wrap is why the dumps are split), e64 forms (SGPR pairs, inline128/240..247, abs/neg/abs+neg,v255exponent destination), wave64 container text-only (no@waveExchange,{i32 64, i32 1, i32 1}metadata), and the exponent op succeeding over a symbolic lane spill inv11.controls: 23 refusals with exact error substrings and non-zero exit codes (modifiers incl. clamp on both ops, source/dst guards incl.v255mantissa destination, MODE, symbolic spill overwrites), plus the positive control that the exponent op compiles over a spill inv11.hardware: 4 programs x 4 cases x 3 words per lane; mantissa NaN pairs compared by class, exponent words exact; returns 77 on missing hardware caps.Linux results (this host cannot compile the translation unit or run DXC, so
ir/controls/hardwarerun in the WIN-VERIFY round):Mutation audit
Every C++ guard/constant is pinned by a killing test (see the docs note for the full mapping): modifier and MODE gates by the controls refusals; the
half_binaryMODE-loop addition by the conditionals_denorm_moderefusal; destination/source pair acceptance by the controls refusals and the ir e64 chunk;abs/negby the ir modifier cases and the hardware e64 program; the1022/1074biases, thek == 32threshold (2097151vs2097152), the low-word normalizer path, the 20-bit field mask, the sign, the keep rule and the abs-before-neg order by the model values/mutations and the ir boundary values. Theclear_vector_spillspair entry is for the mantissa op only;write()checkshas_spill(r)on the pre-instruction state, so the controls spill refusals pin that bothvector_writecalls executewrite()for the mantissa op, while the ir spill dump and the controls positive control pin that the exponent op writes onlyv[d].Notes
256 + vdst), so the destination guard's SGPR half is defense in depth; the encodable half is pinned by thev255mantissa refusal and thev255exponent acceptance inir.Refs #2935, #3518
Windows verification (
ec737728)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T19:48:15Z.
Review: APPROVED
Reviewed
ec737728by reading the diff; not built or run.Verdict: approve. The lowering matches binary64 frexp for every input class, and the guards match the existing f64 ops. No MUST.
tests/native_frexp_f64_check.py:535), but the lowering uses only integer ops, so the payload (including sNaN0x7FF4000000000001inHW_SPECIAL) should survive bit-for-bit on any device. An exact compare would make the hardware run pin the keep path too. Today onlymodelandircover it (nan_canon).gfx1013_direct_compute.inl:2547): after the search, the field is in[2^52, 2^53), sox = (f·2^s / 2^53) · 2^(53 − s − 1074)ande = 53 − steps − 1074is right. Thek == 32step (mh == 0 && ml < 2^21) never pushes the high word past bit 20, and the other steps reach every shift from 21 to 31 when the top bit is inlo[21..31].exp − 1022, and the mantissa high word issign | 0x3FE00000 | field. Zero/Inf/NaN go throughkeep, after abs/neg, likev_ldexp_f64.lo/hiare read before both writes).0x8000ccgate asv_ldexp_f64/v_min_f64. Both ops added tohalf_binary(:5623).clear_vector_spillspair entry only for the mantissa op (gfx1013_compute_native.cpp:643), so the exponent op over a spill inv[d+1]stays legal.Tests:
modelchecks the model againstmath.frexp;irruns the real lowering on the boundary values, sweep and e64 forms;controlsreaches every refusal;hardwarechecks 16 cases on a device. CI ran onlymodel(Linux Python checks). Thenative_frexp_f64_*CTest entries are not in the Windowsprpreset filter, soir/controls/hardwareonly have the author's local run at this head (RTX 4050, dev + release).