Skip to content

shader: lower the binary64 conversion forms - #3628

Open
lambirou wants to merge 4 commits into
R0Y00:mainfrom
lambirou:shader/f64-conversions
Open

lambirou wants to merge 4 commits into
R0Y00:mainfrom
lambirou:shader/f64-conversions

Conversation

@lambirou

@lambirou lambirou commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of the f64 slice (P5).

This adds the five binary64 conversion forms: v_cvt_f64_i32_e64, v_cvt_f64_u32_e64, v_cvt_i32_f64_e64, v_cvt_u32_f64_e64 and v_cvt_f32_f64_e64.

  • int32/uint32 to f64 is exact: the translator builds both words from uint operations (sign bit, magnitude, exponent 1023 + highest-set-bit index, fraction bits), with no double, asdouble or rounding mode. Zero gives +0.0 and INT_MIN gives 0xc1e00000_00000000.
  • f64 to int32/uint32 truncates toward zero and refuses NaN, infinity and out-of-range values; f64 to f32 rounds to nearest even, with overflow to infinity and the subnormal range following the entry denormal profile.
  • Refusals: source modifiers, clamp/omod, DPP/SDWA, a destination that is not a two-register VGPR pair, an untracked or multi-dword source, and any use inside a masked region.

Tests

  • pixel_aot_cvt_f64_e64_warp and _hardware pass on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010).
  • The draw exports the pair words through the lossless R32G32B32A32_UINT readback and compares them with Python struct.pack('<d', ...); sentinels around the pair catch writes outside it. The rows cover 0, INT_MIN/MAX, -1, UINT_MAX and neighbours, 2^24 ± 1, 0x3f800000/0xbf800000 and the f64→f32 tie/overflow/subnormal cases; the mutations mismatch on both adapters.
  • form_coverage_check.py pins exactly the five forms and keeps the other f64 forms uncovered; the neighbouring draw-cvt-f64-* tests still pass.
  • Expected delta: +5 forms on gfx1013 and +5 on gfx1030. After the other open PRs and this one, the table reaches 1,738/1,968 and 1,640/1,863.

Limits

The desktop draws prove the translated shaders, not gfx1013 or the console. Binary64 arithmetic beyond these conversions remains unsupported. The high half of a 32-bit destination is not observed. No console measurement was made.

AI-assisted.

Merge with origin/main (2026-12-01)

Merged origin/main at a3bfd019 into this branch; head is c3e464d0. The shared CMake and test files keep both the #3607/#3623 additions and the PR additions. Local post-merge: pixel_aot_check.py, form_coverage_check.py and rdna2_tools_check.py pass (163 tests, 19 skips); CTest pixel_aot_cvt_f64_e64_warp and pixel_aot_f64_minmax_ldexp_warp pass.

@lambirou
lambirou force-pushed the shader/f64-conversions branch from 5afe42e to 781883a Compare November 30, 2026 17:28

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 781883a2 by reading the diff; not built or run.

Verdict: comment. No MUST. The arithmetic is right. Two SHOULDs on the new rounding slice of v_cvt_f32_f64 are worth settling before merge, because they change what #1606 approved.

  • SHOULD cvt_f32_f64_rne_bits refuses a nonzero binary32 subnormal result because MODE[5:4] has no declared profile (tools/pixel_aot.py:2872). It still accepts a value just below 2^-126 that rounds up to the smallest normal (:2910, e.g. 2^-126 − 2^-150). Whether that case gives 0x00800000 or a flushed zero depends on the same unmodelled binary32 denormal/flush mode, and on when the hardware detects tininess. For consistency with the docstring's reason, refuse it as well, or state the no-flush assumption in the docs.
  • SHOULD The docs still call this a "mode-independent slice (the slice the maintainer approved in #1606 and the follow-up that added rounding)". It also says "the shader reads neither the rounding nor the denormal mode". Rounding makes the result depend on the rounding mode. It is correct only because every accepted MODE write keeps MODE[1:0] at nearest even, and because the existing check (:4787) refuses any v_*_f64 form under round-toward-zero in MODE[3:2]. Please state that dependency. #1606 approved an exact-only slice, so widening it to rounding needs the maintainer's own sign-off rather than being described as already approved.
  • Checked, no finding:
    • RNE narrowing to 24 bits with a carry into the exponent, overflow to ±Inf from the 2^128 − 2^103 midpoint, f64 subnormal inputs to a signed zero, and the 2^-150 tie to even zero.
    • cvt_int_f64_bits: truncation toward zero, with NaN/Inf and out-of-range values refused.
    • f64_conversion_source: proven records, two statically known words, or an aligned SGPR pair (_e64 only). Modifiers fall through to the refusal.

Tests: the unit asserts pin the midpoints listed above. The draw compares the pair words against struct.pack, with sentinels around the pair. The controls run in the Linux LLVM job (passed). pixel_aot_cvt_f64_e64_{warp,hardware} are not in the Windows pr preset filter, so the draw has only the author's WARP + RX 9060 XT run. All results are translation-time constants, so the draw checks the emitted words, not a runtime path.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The green Linux check is misleading on e4dcf15f9. I ran python -B tests/form_coverage_check.py from that exact head and got exit 0 with no output. The file no longer has a module-level entry point. Its coverage call list and success print are indented inside check_f16_pack_cndmask_forms, and the list includes a call to that same function. Nine existing check definitions also disappear relative to main, including the f64 FMA/round, SMEM atomics and multiply-literal coverage. Please retain main's existing registrations, wire the new f64 conversion check into the actual entry point, and rerun the whole coverage script. A deliberately failing existing assertion is a useful negative control for the restored entry point.

@lambirou
lambirou force-pushed the shader/f64-conversions branch from e4dcf15 to be4f474 Compare December 3, 2026 00:25
Lower the five VOP3 (_e64) binary64 conversions in the pixel AOT path:
v_cvt_f64_i32_e64, v_cvt_f64_u32_e64, v_cvt_i32_f64_e64,
v_cvt_u32_f64_e64 and v_cvt_f32_f64_e64.

The integer widenings keep the exact uint lowering. The narrowings accept a
proven VGPR pair, or an aligned SGPR pair of tracked words in the VOP3
spelling. v_cvt_i32_f64_e64 and v_cvt_u32_f64_e64 truncate toward zero and
refuse NaN, infinity and out-of-range values. v_cvt_f32_f64_e64 rounds to
nearest even with a new integer helper, overflows to a signed infinity and
underflows to a signed zero; a nonzero binary32 subnormal result, NaN and
infinity are refused. Modifiers, clamp, omod and malformed destination pairs
are refused.

The new draw-cvt-f64-e64 fixture covers 0, +-1, INT_MIN/MAX, UINT_MAX, 2^53,
the range edges, truncation, rounding ties, overflow and subnormals with
wrong references. tests/form_coverage_check.py pins exactly the five VOP3
forms and tests/rdna2_tools_check.py checks the scanner agreement. The tests
pass on WARP and an AMD Radeon RX 9060 XT.
@lambirou
lambirou force-pushed the shader/f64-conversions branch from be4f474 to eb83362 Compare December 3, 2026 00:36

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rechecked the new head against current main. The module-level entry point and the previously missing function definitions are back, and the binary64 cases are in the active call list. The list still drops check_mullit_coverage even though that function remains defined. Please restore that call and rerun the full test directly before re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants