Shaders: lower binary64 frexp exponent and significand #2348

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2350 into main
andrewpozdnakov7-jpg commented 2026-11-25 11:25:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T11:25:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6603406488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2350). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T11:25:18Z. --- 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7160838748) 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.
DenRakEiw commented 2026-11-25 11:30:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:30:21Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6056810215 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6056810215). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:30:21Z. **Review:** APPROVED --- 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).
catminou4 commented 2026-11-25 11:51:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:51:54Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057088740 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6057088740). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:51:54Z. **Review:** APPROVED --- 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.
Marvisak commented 2026-11-25 16:09:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:33:48Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167035314 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2350#issuecomment-7167035314). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:33:48Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-26 16:38:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:38:45Z.

Review: APPROVED


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).
<!-- greyfinch-sync:Marvisak/VIctory:review:6077676425 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2350#pullrequestreview-6077676425). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T16:38:45Z. **Review:** APPROVED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2350:upstream-pr/2350'
git switch 'upstream-pr/2350'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2350'
git switch 'upstream-pr/2350'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2350'
git switch 'upstream-pr/2350'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2350'
git switch 'main'
git merge --squash 'upstream-pr/2350'
git switch 'main'
git merge --ff-only 'upstream-pr/2350'
git switch 'main'
git merge 'upstream-pr/2350'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2348
No description provided.