Shaders: lower binary64 frexp exponent and significand #2350

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

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:25 UTC · original
andrewpozdnakov7-jpg:codex2/shader-f64-frexp → main · +211 −0 · 3 files · 2 commits · open

Shaders using v_frexp_exp_i32_f64 or v_frexp_mant_f64 fail lowering on current main. The emitter now extracts the two binary64 words, computes the signed exponent, and normalizes the significand with 32-bit integer operations. It preserves signed zeros and the original infinity and NaN bits in the significand. Subnormal normalization carries bits across the two words. AMD RDNA 2 ISA, VOP1

The three synthetic tests were all rejected as Unsupported on 940d32f. On the patch, Microsoft DXIL validation and WARP confirm 44 dispatch results, including subnormal shifts of 31, 32 and 33, both zero signs, NaN payloads, register pairs, an inline integer and a negated literal. The tests verify that the DXIL does not require doubles or 64-bit integers. All 31 VALU tests pass. Strict shader Clippy and the staged asset policy pass.

Output clamp and omod are refused by name. The tests cover the translated output on WARP. The corresponding RDNA hardware behavior has not been measured here.

Coordination claim

Please retain the Git author when reapplying this change. If you fold it into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted. Synthetic tests only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 11:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2350) `andrewpozdnakov7-jpg:codex2/shader-f64-frexp` → `main` · +211 −0 · 3 files · 2 commits · open Shaders using `v_frexp_exp_i32_f64` or `v_frexp_mant_f64` fail lowering on current `main`. The emitter now extracts the two binary64 words, computes the signed exponent, and normalizes the significand with 32-bit integer operations. It preserves signed zeros and the original infinity and NaN bits in the significand. Subnormal normalization carries bits across the two words. [AMD RDNA 2 ISA, VOP1](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) The three synthetic tests were all rejected as `Unsupported` on `940d32f`. On the patch, Microsoft DXIL validation and WARP confirm 44 dispatch results, including subnormal shifts of 31, 32 and 33, both zero signs, NaN payloads, register pairs, an inline integer and a negated literal. The tests verify that the DXIL does not require doubles or 64-bit integers. All 31 VALU tests pass. Strict shader Clippy and the staged asset policy pass. Output `clamp` and `omod` are refused by name. The tests cover the translated output on WARP. The corresponding RDNA hardware behavior has not been measured here. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please retain the Git author when reapplying this change. If you fold it into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted. Synthetic tests only.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:07 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:33 UTC · original · edited 2026-11-26 03:23 UTC

Automated triage for the maintainers.

Verdict: merge candidate (unchanged). The new head merges main and moves Lower::frexp64 into a child module, crates/victory-shader/src/emit/lower/frexp.rs. lower.rs keeps only mod frexp; and the dispatch arm for v_frexp_exp_i32_f64 / v_frexp_mant_f64. I compared the moved function with the one reviewed at 92efc68. The only differences are the pub(super) visibility and the imports; the logic is unchanged, and so are the tests in valu_tests.rs.

Note for maintainers: #2713 (same author) adds mod directed; at the same line of lower.rs. The two PRs conflict with each other there, and the conflict is trivial.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2350#issuecomment-7167035314) · edited 2026-11-26 03:23 UTC <!-- victory-triage v1 head=d30794e6e97ce92acdb2de18cb0958f1f6e63c9c verdict=merge-candidate at=2026-11-26T03:23:22Z --> Automated triage for the maintainers. **Verdict: merge candidate (unchanged).** The new head merges `main` and moves `Lower::frexp64` into a child module, `crates/victory-shader/src/emit/lower/frexp.rs`. `lower.rs` keeps only `mod frexp;` and the dispatch arm for `v_frexp_exp_i32_f64` / `v_frexp_mant_f64`. I compared the moved function with the one reviewed at `92efc68`. The only differences are the `pub(super)` visibility and the imports; the logic is unchanged, and so are the tests in `valu_tests.rs`. Note for maintainers: #2713 (same author) adds `mod directed;` at the same line of `lower.rs`. The two PRs conflict with each other there, and the conflict is trivial. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 11:30 UTC · original · approved these changes

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Clean lowering of binary64 v_frexp_exp_i32_f64 and v_frexp_mant_f64 including binary64 immediates and sign modifiers.
  • cargo test -p victory-shader frexp: 3/3 passed on RTX 5090, 3/3 passed on WARP (v_frexp_exp_i32_f64_extracts_the_exponent, v_frexp_mant_f64_extracts_the_significand, v_frexp_f64_uses_binary64_immediates_and_sign_modifiers).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 11:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6056810215) · **approved these changes** Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Clean lowering of binary64 `v_frexp_exp_i32_f64` and `v_frexp_mant_f64` including binary64 immediates and sign modifiers. - `cargo test -p victory-shader frexp`: 3/3 passed on RTX 5090, 3/3 passed on WARP (`v_frexp_exp_i32_f64_extracts_the_exponent`, `v_frexp_mant_f64_extracts_the_significand`, `v_frexp_f64_uses_binary64_immediates_and_sign_modifiers`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 11:51 UTC · original · approved these changes

Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — binary64 frexp exponent and significand lowered.

**@⁠catminou4** on GitHub · 2026-11-25 11:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6057088740) · **approved these changes** Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — binary64 frexp exponent and significand lowered.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:38 UTC · original · approved these changes

Reviewed d30794e6e97ce92acdb2de18cb0958f1f6e63c9c (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll).

The 32-bit two-dword normalization is bit-exact across normal values, subnormals (including the shift = 31 / 32 / 33 / 52 cross-word boundary), signed zeros, infinities, and NaNs without requiring native f64 or i64 DXIL capabilities (verified across 50,318 bit patterns), and moving frexp64 into emit/lower/frexp.rs keeps emit/lower.rs growth to just +96 B (520,659 B, 3,629 B below the 512 KiB cap).

Optional follow-up notes:

  • If guest MODE tracking for IEEE / f64 input-denorm-flush is added later, note that RDNA2 quiets sNaN in v_frexp_mant_f64 under IEEE=1 and flushes subnormals to signed zero under input denorm flush.
  • Adding a test checking inline 248 (1/(2pi) low dword 0x6dc9_c882, exponent -2) and asserting zero SFI0 doubles/int64 flags on a dynamic-register shader (not just immediate inputs) would tighten coverage further.

Verification

  • cargo run -p xtask -- policy (191 files ok), cargo clippy (default & --all-features) clean, changed lines rustfmt-clean.
  • emit::valu_tests (38/38 passed) and emit::census_tests (1/1 passed) on both RTX 5090 and WARP with dxil.dll active (PR head and merged onto 63bcca43).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6077676425) · **approved these changes** Reviewed `d30794e6e97ce92acdb2de18cb0958f1f6e63c9c` (merged cleanly onto `63bcca43c6a00a758510398fa43096ce7e4f7df0`) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + `dxil.dll`). The 32-bit two-dword normalization is bit-exact across normal values, subnormals (including the `shift = 31 / 32 / 33 / 52` cross-word boundary), signed zeros, infinities, and NaNs without requiring native `f64` or `i64` DXIL capabilities (verified across 50,318 bit patterns), and moving `frexp64` into `emit/lower/frexp.rs` keeps `emit/lower.rs` growth to just `+96 B` (`520,659 B`, `3,629 B` below the 512 KiB cap). Optional follow-up notes: - If guest `MODE` tracking for `IEEE` / f64 input-denorm-flush is added later, note that RDNA2 quiets sNaN in `v_frexp_mant_f64` under `IEEE=1` and flushes subnormals to signed zero under input denorm flush. - Adding a test checking inline `248` (`1/(2pi)` low dword `0x6dc9_c882`, exponent `-2`) and asserting zero `SFI0` `doubles`/`int64` flags on a dynamic-register shader (not just immediate inputs) would tighten coverage further. ### Verification - `cargo run -p xtask -- policy` (`191 files ok`), `cargo clippy` (default & `--all-features`) clean, changed lines `rustfmt`-clean. - `emit::valu_tests` (**38/38 passed**) and `emit::census_tests` (**1/1 passed**) on both RTX 5090 and WARP with `dxil.dll` active (PR head and merged onto `63bcca43`).
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/2350/head:github-bot/gh-2350'
git switch 'github-bot/gh-2350'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2350'
git switch 'github-bot/gh-2350'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2350'
git switch 'github-bot/gh-2350'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2350'
git switch 'main'
git merge --squash 'github-bot/gh-2350'
git switch 'main'
git merge --ff-only 'github-bot/gh-2350'
git switch 'main'
git merge 'github-bot/gh-2350'
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!2350
No description provided.