Shaders: lower v_div_scale_f64 and its lane mask #2975

Open
github-bot wants to merge 1 commit from github-bot/gh-2975 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 01:58 UTC · original
andrewpozdnakov7-jpg:codex2/div-scale-f64 → main · +446 −1 · 3 files · 1 commits · open

Summary

  • Lower the GFX10 VOP3B v_div_scale_f64 instruction and write its binary64 result and scale mask.
  • Apply the measured exponent thresholds, normalize subnormals as needed, and honor the four known f64 rounding modes. The lowering uses paired i32 words and keeps subnormals under VIctory's current f64 denormal model.

Verification

  • The same synthetic shader test fails on main at VOP3B opcode 0x16e. The patch matches all 68 result pairs and masks across 27 instruction forms on Agility WARP with DXIL validation. The cases cover both operand roles, explicit SGPR and VCC masks, directed rounding, special values, and modifiers.
  • WARP suites passed 35 VALU tests, 35 shader semantics tests (one ignored), and 33 lowerer tests. Default/all-features strict Clippy and asset policy passed.
  • Both division tests also passed with the exact #2953 head after retaining both lowerer entries and module declarations in a local composition.

References: RDNA2 hardware observations, directed downscale measurements, and clamp/OMOD characterization.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 01:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2975) `andrewpozdnakov7-jpg:codex2/div-scale-f64` → `main` · +446 −1 · 3 files · 1 commits · open ## Summary - Lower the GFX10 VOP3B v_div_scale_f64 instruction and write its binary64 result and scale mask. - Apply the measured exponent thresholds, normalize subnormals as needed, and honor the four known f64 rounding modes. The lowering uses paired i32 words and keeps subnormals under VIctory's current f64 denormal model. ## Verification - The same synthetic shader test fails on main at VOP3B opcode 0x16e. The patch matches all 68 result pairs and masks across 27 instruction forms on Agility WARP with DXIL validation. The cases cover both operand roles, explicit SGPR and VCC masks, directed rounding, special values, and modifiers. - WARP suites passed 35 VALU tests, 35 shader semantics tests (one ignored), and 33 lowerer tests. Default/all-features strict Clippy and asset policy passed. - Both division tests also passed with the exact #2953 head after retaining both lowerer entries and module declarations in a local composition. References: [RDNA2 hardware observations](https://github.com/boykopovar/AnyPS5/pull/474), [directed downscale measurements](https://github.com/boykopovar/AnyPS5/pull/24629), and [clamp/OMOD characterization](https://github.com/boykopovar/AnyPS5/pull/663).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:05 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:29 UTC · original

I ran v_div_scale_f64 from ce620efb and v_div_fixup_f64 from #2953 (f0f5fb5b) in the same wave32 compute shader. The scale result supplied the first operand of fixup. Both the physical RTX 5080 and Microsoft WARP matched all 5,688 lane records per adapter.

  • Restored EXEC and scale flags. I tried both operand roles and both mask destinations (VCC and s20), at numerator-minus-denominator exponent differences −769, −768, −767, 0, 767, 768 and 769. After executing both instructions on even lanes and restoring EXEC, v_cndmask_b32 read back 0x55555555 at both ±768 thresholds and zero at ±767. The inactive lanes retained both sentinel dwords. With full EXEC the corresponding masks were 0xffffffff and zero. All 1,792 records matched, including the quotient-sign repair.
  • Rounding across the two output dwords. I read back scale and fixup separately for 3,896 input/mode rows, covering both signs and all four rounding modes. These included normalization at every one of the 52 subnormal fraction-bit positions, downscaling across exponent fields 116–130, and halfway cases where rounding carries out of the low dword. For example, downscaling 0x08000001ffffffff gave 0x0008000100000000 for nearest-even and toward +∞, and 0x00080000ffffffff for toward zero and toward −∞. Both instructions returned those bits.

The rounding reference used exact rational power-of-two scaling and the adjacent binary64 values for directed rounding. For exponent field 116 I used the overflow behavior measured on the RX 6900 XT. These synthetic shaders exercise the handoff with a supplied preliminary quotient. Their DXIL validated and the containers requested neither double-precision instructions, double extensions nor int64. Related RDNA2 hardware measurement

**@⁠steven-seagull27** on GitHub · 2026-11-26 02:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2975#issuecomment-7180855094) I ran `v_div_scale_f64` from `ce620efb` and `v_div_fixup_f64` from #2953 (`f0f5fb5b`) in the same wave32 compute shader. The scale result supplied the first operand of fixup. Both the physical RTX 5080 and Microsoft WARP matched all 5,688 lane records per adapter. - **Restored EXEC and scale flags.** I tried both operand roles and both mask destinations (VCC and `s20`), at numerator-minus-denominator exponent differences −769, −768, −767, 0, 767, 768 and 769. After executing both instructions on even lanes and restoring EXEC, `v_cndmask_b32` read back `0x55555555` at both ±768 thresholds and zero at ±767. The inactive lanes retained both sentinel dwords. With full EXEC the corresponding masks were `0xffffffff` and zero. All 1,792 records matched, including the quotient-sign repair. - **Rounding across the two output dwords.** I read back scale and fixup separately for 3,896 input/mode rows, covering both signs and all four rounding modes. These included normalization at every one of the 52 subnormal fraction-bit positions, downscaling across exponent fields 116–130, and halfway cases where rounding carries out of the low dword. For example, downscaling `0x08000001ffffffff` gave `0x0008000100000000` for nearest-even and toward +∞, and `0x00080000ffffffff` for toward zero and toward −∞. Both instructions returned those bits. The rounding reference used exact rational power-of-two scaling and the adjacent binary64 values for directed rounding. For exponent field 116 I used the overflow behavior measured on the RX 6900 XT. These synthetic shaders exercise the handoff with a supplied preliminary quotient. Their DXIL validated and the containers requested neither double-precision instructions, double extensions nor int64. [Related RDNA2 hardware measurement](https://github.com/boykopovar/AnyPS5/pull/24629)
Author
Owner

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

Automated triage for the maintainers.

Merge candidate (recommending a look, not approving). This lowers v_div_scale_f64 (VOP3B 0x16e), which main refuses, in a new crates/victory-shader/src/emit/lower/div_scale.rs: it computes the ±128 exponent scale and the lane mask from the exponent difference (±768) and the denominator and numerator edge cases, handles zero inputs, normalizes and rounds subnormals under the f64 rounding mode, and applies clamp. I compared the cases with the ISA pseudocode. Where they differ (for example the mask on a zero denominator, or overflow below exponent 117), the new semantics_tests.rs test pins the values the PR cites from RDNA2 hardware measurements in the AnyPS5 oracle, which semantics_tests.rs on main already cites. A commenter ran it together with #2953 (v_div_fixup_f64) and got matching results, and the two PRs only touch neighbouring lines. CI check passes.

Small request: the comment As measured on RDNA2 (#663) in div_scale_f64 reads as VIctory issue #663; please write it as AnyPS5 #663, as the test does.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2975#issuecomment-7183481774) <!-- victory-triage v1 head=ce620efb6cdbba46f06a8d44c1e05a0958c54a10 verdict=merge-candidate at=2026-11-26T05:27:30Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not approving). This lowers `v_div_scale_f64` (VOP3B 0x16e), which `main` refuses, in a new `crates/victory-shader/src/emit/lower/div_scale.rs`: it computes the ±128 exponent scale and the lane mask from the exponent difference (±768) and the denominator and numerator edge cases, handles zero inputs, normalizes and rounds subnormals under the f64 rounding mode, and applies clamp. I compared the cases with the ISA pseudocode. Where they differ (for example the mask on a zero denominator, or overflow below exponent 117), the new `semantics_tests.rs` test pins the values the PR cites from RDNA2 hardware measurements in the AnyPS5 oracle, which `semantics_tests.rs` on `main` already cites. A commenter ran it together with #2953 (`v_div_fixup_f64`) and got matching results, and the two PRs only touch neighbouring lines. CI `check` passes. Small request: the comment `As measured on RDNA2 (#663)` in `div_scale_f64` reads as VIctory issue #663; please write it as AnyPS5 #663, as the test does. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
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/2975/head:github-bot/gh-2975'
git switch 'github-bot/gh-2975'

Merge

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