shader: lower the f64 conversions to and from f32, i32 and u32 #101
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!101
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-101"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:51 UTC · original
lcg007xd-c:shader-f64-cvt→main· +268 −0 · 2 files · 1 commits · openWhat is broken
The f64 conversions decode, but a program using one fails to translate with
v_cvt_f64_f32 is not supported(or the matching name):v_cvt_f64_f32v_cvt_f64_i32v_cvt_f64_u32v_cvt_i32_f64v_cvt_u32_f64Only
v_cvt_f32_f64lowers today. It is built on the bits, without host doubles (f64_to_f32_bits), and these now follow the same approach.Semantics (AMD's RDNA2 ISA, §12.8, opcodes 3, 4, 16, 21, 22)
The change (
emit/lower.rs)f32_to_f64_bits: rebiases a normal f32. A denormal is normalized from its leading one (DXILFirstbitHi). Zero and infinity carry over. A NaN keeps its payload and comes out quiet.i32_to_f64_bits: the magnitude's leading one becomes the implicit bit, with exponent1054 − lz.|i32::MIN|= 2³¹ is handled as unsigned.f64_bits_to_i32: the 53-bit significand is shifted right by1075 − ein i64. Below 1 the result is 0. 2³¹ and up (signed) or 2³² and up (unsigned), infinities included, saturate. Negatives give 0 for the unsigned form, and NaN gives 0.DOUBLESfeature. The f64→int path usesINT64.Tests
emit::lower::tests::f64_conversions_translate(every host): all five decode, and a program that stores the result translates (for an f64 result, its high dword). Without thelower.rschange it fails:v_cvt_f64_f32 [7e0a2101, 7e000306]: GFX10 code at 0x24: v_cvt_f64_f32 is not supported.valu_tests::f64_conversions_match_ieee(Windows/GPU): both dwords of each to-f64 conversion for 8 inputs (0, 1,i32::MIN, −1/u32::MAX, 1.5f, a denormal, inf, a pattern). The from-f64 conversions get 14 inputs (±0, ±2.9, thei32/u32edges just inside and outside, ±inf, NaN, tiny), checked against Rust'sas, which has the same truncate/saturate/NaN→0 rule.lli. I compared both dwords against Rust'sf64::fromon 96 inputs (including f32 denormals and a signalling NaN, which comes out quiet as on x86), and againstason 81 f64 values. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
VOP1 0x10, 0x04, 0x16, 0x03 and 0x15 (v_cvt_f64_f32, v_cvt_f64_i32, v_cvt_f64_u32, v_cvt_i32_f64, v_cvt_u32_f64) decoded but failed to translate ("v_cvt_f64_f32 is not supported"); v_cvt_f32_f64 already lowers, on the bits and without host doubles. These now do the same. To f64 the conversion is exact (AMD's RDNA2 ISA: 0 ULP, denormals supported): an f32 is rebiased (a denormal normalized from its leading one, a NaN made quiet with its payload), an integer's leading one becomes the implicit bit. From f64 it truncates toward zero, saturates out of range (infinities too) and gives 0 for NaN, as the ISA says; the clamp bit there only selects the INEXACT exception. Co-Authored-By: Claude Opus 5.5 <[email protected]>@lmouz823-lang on GitHub · 2026-11-27 14:59 UTC · original
I can take the native Windows/NVIDIA validation of the two conversion tests at exact head
9e19fa0973b6239e06fbbb6746fb61ec627aef95:f64_conversions_translateandf64_conversions_match_ieee. I will run the unmodified head first on an RTX 4060 Laptop (8 GiB, driver 610.88), Windows 11/MSVC, with the SDK DXIL validator and strict test mode; I will report hardware and WARP execution and the tested input limits here.AI-assisted with Codex.
@lmouz823-lang on GitHub · 2026-11-27 15:04 UTC · original
Completed native Windows/NVIDIA validation on the unchanged head
9e19fa0973b6239e06fbbb6746fb61ec627aef95. Both exact tests pass:Environment: Windows 11 build 26200, RTX 4060 Laptop 8 GiB, driver 610.88, Rust 1.98.1 MSVC.
VICTORY_STRICT_TESTS=1;VICTORY_WARPunset;VICTORY_DXILexplicitly set to the Windows SDKdxil.dll1.8.2502.11. WARP is the additional backend exercised by the test; the physical NVIDIA adapter also executed. No device skips were printed. The helper's validator-loading branch remains optional; this reports the explicit configuration and actual GPU result, not a change to that helper.Commands, in an isolated worktree after a package-only rebuild of
victory-shaderto avoid reusing another worktree's shared target artifact:This checks the five conversion instructions and the authored input set (76 result-word comparisons per backend). It does not establish AMD behavior, source-register overlap cases, or all conversion boundary cases. No source patch was needed; I did not run the game or the full workspace suite.
AI-assisted validation with Codex.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.