Shaders: lower binary64 reciprocal square root with dwords #2811

Open
github-bot wants to merge 2 commits from github-bot/gh-2811 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 21:14 UTC · original
andrewpozdnakov7-jpg:codex2/rsq-f64 → main · +465 −47 · 3 files · 2 commits · open

Main stops translation on V_RSQ_F64. This lowering normalizes a binary64 input, computes the square root of its significand to 28 bits, and divides to obtain a 26-bit reciprocal. The 32-bit DXIL arithmetic retains the known rounding direction and input-denormal mode, handles signed zeros and infinities, and quiets NaNs. AMD specifies a 2^29 binary64 ULP bound for this instruction. RDNA 2 ISA reference

Both synthetic shaders stop on unsupported v_rsq_f64 at 13f91ca. The same tests pass all 112 cases on app-local WARP SM 6.6 with the DXIL validator. They cover VOP1 VGPR and VOP3 SGPR sources, all four rounding modes, input-subnormal modes, special values, and the two-dword normalization boundary. Feature-flag checks confirm the 32-bit lowering. An independent integer model stayed within the bound for all 327,520 CPU comparisons across the finite exponent fields.

The paired full shader suite moved from 268 passed, 5 failed and 3 ignored to 270 passed, 3 failed and 3 ignored. The other three failures were the same gather-at-level, lane-permute and edge-flagged-triangle tests in both runs. All 33 patched VALU tests including runtime identity passed. Strict shader Clippy and staged asset policy passed.

The mode analysis follows the same approach as #2743, #2791 and #2799. Coordination claim

Please retain the Git author on cherry-pick or rebase. If you fold this change into another commit, please include Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 21:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2811) `andrewpozdnakov7-jpg:codex2/rsq-f64` → `main` · +465 −47 · 3 files · 2 commits · open Main stops translation on `V_RSQ_F64`. This lowering normalizes a binary64 input, computes the square root of its significand to 28 bits, and divides to obtain a 26-bit reciprocal. The 32-bit DXIL arithmetic retains the known rounding direction and input-denormal mode, handles signed zeros and infinities, and quiets NaNs. AMD specifies a 2^29 binary64 ULP bound for this instruction. [RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) Both synthetic shaders stop on unsupported `v_rsq_f64` at `13f91ca`. The same tests pass all 112 cases on app-local WARP SM 6.6 with the DXIL validator. They cover VOP1 VGPR and VOP3 SGPR sources, all four rounding modes, input-subnormal modes, special values, and the two-dword normalization boundary. Feature-flag checks confirm the 32-bit lowering. An independent integer model stayed within the bound for all 327,520 CPU comparisons across the finite exponent fields. The paired full shader suite moved from 268 passed, 5 failed and 3 ignored to 270 passed, 3 failed and 3 ignored. The other three failures were the same gather-at-level, lane-permute and edge-flagged-triangle tests in both runs. All 33 patched VALU tests including runtime identity passed. Strict shader Clippy and staged asset policy passed. The mode analysis follows the same approach as #2743, #2791 and #2799. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please retain the Git author on cherry-pick or rebase. If you fold this change into another commit, please include `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:49 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:33 UTC · original

Verified e1de9799 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll):

  • cargo xtask policy: 185 files ok; cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default & --features host): 0 warnings.
  • cargo test -p victory-shader --features host --lib --locked -- valu_tests::: 32/32 passed on RTX 5090 + WARP + dxil.dll, including rsqrt_f64_tracks_binary64_range_and_rounding and rsqrt_f64_obeys_the_input_denormal_mode (and SFI0 & 0x8001 == 0 confirms pure 32-bit DXIL with no double/int64 flags).
  • Code review of lower/rsqrt.rs: special values (±0.0 -> ±Inf, negative/-Inf -> qNaN, +Inf -> +0.0, sNaN quieted preserving sign/payload, MODE[7:6] input denormal flush vs normalize via unaryBits.i32 op 33), 28-bit integer sqrt + opposite-direction rounding + 26-bit long division, and modifier rejection (clamp/omod/sdwa/dpp, abs before neg, 32-bit literal as high dword) all check out.
  • Merge notes via git merge-tree: clean against origin/main 13f91ca and #2812; conflicts with #2743/#2791/#2799 in lower.rs on the shared FpMode16 refactor, and shares the same Lower::mode16 -> FpMode16 compile interaction with #2782 (lower.rs:3384 needs self.mode16.round.ok_or(...) if both land).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2811#issuecomment-7175228676) Verified `e1de9799` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`): - `cargo xtask policy`: 185 files ok; `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default & `--features host`): 0 warnings. - `cargo test -p victory-shader --features host --lib --locked -- valu_tests::`: 32/32 passed on RTX 5090 + WARP + `dxil.dll`, including `rsqrt_f64_tracks_binary64_range_and_rounding` and `rsqrt_f64_obeys_the_input_denormal_mode` (and `SFI0 & 0x8001 == 0` confirms pure 32-bit DXIL with no double/int64 flags). - Code review of `lower/rsqrt.rs`: special values (`±0.0 -> ±Inf`, negative/`-Inf -> qNaN`, `+Inf -> +0.0`, sNaN quieted preserving sign/payload, `MODE[7:6]` input denormal flush vs normalize via `unaryBits.i32` op 33), 28-bit integer sqrt + opposite-direction rounding + 26-bit long division, and modifier rejection (`clamp`/`omod`/`sdwa`/`dpp`, `abs` before `neg`, 32-bit literal as high dword) all check out. - Merge notes via `git merge-tree`: clean against `origin/main` `13f91ca` and #2812; conflicts with #2743/#2791/#2799 in `lower.rs` on the shared `FpMode16` refactor, and shares the same `Lower::mode16 -> FpMode16` compile interaction with #2782 (`lower.rs:3384` needs `self.mode16.round.ok_or(...)` if both land).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:19 UTC · original

Automated triage for the maintainers.

This lowers v_rsq_f64, which translation refuses today, in 32-bit integer DXIL (emit/lower/rsqrt.rs): it normalizes the input, takes a 28-bit integer square root of the significand, then divides. It handles signed zeros, infinities, negative inputs and NaN quieting, and refuses the modifiers it does not model. It also generalizes round16 into FpMode16, which now tracks the f64/f16 denorm bits (MODE 7:6) as well as the round mode. I read the mode tracking: s_denorm_mode's bits 3:2 and the s_setreg field arithmetic are right, and an unknown mode is refused rather than guessed. The accuracy target is AMD's public RDNA2 ISA bound, and the tests run on hardware and WARP. Note that it overlaps the FpMode16 refactor in #2743/#2791/#2799, so whichever lands second needs a rebase.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2811#issuecomment-7180697753) <!-- victory-triage v1 head=f6a7d2159dcf0427e97e12a5654499baa6aaeb78 verdict=merge-candidate at=2026-11-26T02:19:42Z --> Automated triage for the maintainers. This lowers `v_rsq_f64`, which translation refuses today, in 32-bit integer DXIL (`emit/lower/rsqrt.rs`): it normalizes the input, takes a 28-bit integer square root of the significand, then divides. It handles signed zeros, infinities, negative inputs and NaN quieting, and refuses the modifiers it does not model. It also generalizes `round16` into `FpMode16`, which now tracks the f64/f16 denorm bits (MODE 7:6) as well as the round mode. I read the mode tracking: `s_denorm_mode`'s bits 3:2 and the `s_setreg` field arithmetic are right, and an unknown mode is refused rather than guessed. The accuracy target is AMD's public RDNA2 ISA bound, and the tests run on hardware and WARP. Note that it overlaps the `FpMode16` refactor in #2743/#2791/#2799, so whichever lands second needs a rebase. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2811/head:github-bot/gh-2811'
git switch 'github-bot/gh-2811'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2811'
git switch 'github-bot/gh-2811'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2811'
git switch 'github-bot/gh-2811'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2811'
git switch 'main'
git merge --squash 'github-bot/gh-2811'
git switch 'main'
git merge --ff-only 'github-bot/gh-2811'
git switch 'main'
git merge 'github-bot/gh-2811'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2811
No description provided.