Skip to content

Shaders: lower binary64 frexp exponent and significand - #2350

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/shader-f64-frexp
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/shader-f64-frexp

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 <andrewpozdnakov7-jpg@users.noreply.github.com>.

AI-assisted. Synthetic tests only.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Tested locally: merged into main 940d32f, 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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants