Shaders: lower v_trig_preop_f64 argument reduction #2988
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2988
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2988"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 02:25 UTC · original
andrewpozdnakov7-jpg:codex2/trig-preop-f64→main· +344 −1 · 3 files · 2 commits · openSummary
Lower v_trig_preop_f64 by reading the selected 53-bit window of 2/pi, applying the large-input scale and packing both binary64 words with truncation. The table uses the measured 1184-bit RDNA2 prefix. All operations use i32 DXIL under VIctory's current f64 denormal model.
Verification
Sources: AMD RDNA2 ISA guide, RDNA2 table measurements, and hardware result rows.
AI-assisted with Codex.
@oni-swr on GitHub · 2026-11-26 02:48 UTC · original
Independent test report: Windows, software WARP only, synthetic inputs only. Not a code review.
Head
9b0f44f0c3d62470cb25a23b1d2a6c052ccc9c84; exact parent63bcca43c6a00a758510398fa43096ce7e4f7df0.Setup:
VICTORY_WARP=1,VICTORY_D3D12_WARP=1,VICTORY_DXILset to the Windows SDK 10.0.26100.0 x64dxil.dll(1.8.2502.11), and a dedicatedCARGO_TARGET_DIR. Before any dispatch,cargo test -j 4 --locked -p victory-gpu --features diagnostics --lib -- --exact host::tests::warp_adapter_accepts_only_software --nocapturereportedEnumWarpAdapter: vendor=0x1414, flags=0x2(software). WithVICTORY_WARP=1,Host::newtakes the WARP device for both ofcheck()'s hosts, so the "hardware" label in the output is also WARP. No physical GPU was used.Results (
cargo test -j 4 --locked -p victory-shader --lib -- <test> --exact --nocapture --test-threads=1):binary64_trig_preop_returns_the_argument_reduction_segmentemit::semantics_tests::(whole module)not lowered: GFX10 code at 0x44/0x48/0x58: v_trig_preop_f64 is not supported, 2/2 runsIndependent reference: I wrote a Python model from the RDNA2 ISA pseudocode. Its 2/π bits come from mpmath at 1600 bits of precision, not from the PR's table. The model's rules:
(S1 & 31) * 53 + max(0, exp - 1077)It matches all 48 rows of the PR's test exactly.
Sweep: 16,704 rows, with the expected values taken from that model:
Limitation: table length. If the model uses the full 1201-bit table that the ISA text gives (
(2/PI)[1200:0]), 144 of the 16,704 rows differ from this head's WARP output. Those are exactly the rows whose 53-bit window reaches past fractional bit 1184. Two examples: exp 1968–1975 with selector 5, and exp 2040–2047 with selector 4. In each case the head returns zeros for the low bits. Truncating the model's table to 1184 bits removes every mismatch, which matches the PR's documented 1184-bit measured table. I can't confirm on RDNA2 silicon which length is right. The PR's own rows don't distinguish the two lengths: all 48 match both. A measured hardware row whose window reaches past bit 1184 (for example exp 1968, selector 5) would pin it.Disclosure: tested with Claude Code (Claude Opus 5.5).
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 03:05 UTC · original
Thanks for checking both tables. I also compared the 96 published trig results in AnyPS5 #447. Both models match those cells. The width comes from its separately reported Radeon 660M end-of-table sweep.
313acc3 adds three model-derived cases that distinguish the widths. I ran the same fixture on Agility WARP with the production table and with a temporary 1201-bit table.
The production table passed all 106 cases. The extended table failed these three cases in each modifier form. The table here contains model and WARP results. Direct RDNA2 observations for these three input pairs would provide a separate check of the reported tail width.
Original hardware sweep
@Marvisak on GitHub · 2026-11-26 05:44 UTC · original
Automated triage for the maintainers.
Verdict: merge candidate. This lowers
v_trig_preop_f64, whichmainrefuses, in a newemit/lower/trig_preop.rs. It's a new capability, and the evidence is stated: the RDNA2 ISA pseudocode plus published RDNA2 hardware rows.The lowering reads a 53-bit window of 2/pi starting at
(sel & 31) * 53 + max(0, exp - 1077), adds the +128 scale whenexp >= 1968, and packs the binary64 result, truncating subnormals. All of it is i32 DXIL, with no f64 ops needed. The table is the 1184-bit prefix the hardware sweep measured, not the ISA text's 1201 bits, and the code comment says so. The three tail cases added in313acc3pin that choice. An independent tester above matched 16,704 rows against an mpmath model.operand64_dwordsis split out of the existing 64-bit operand read without a behaviour change, apart from a checkedreg + 1.One point to check before merging: the source
Const(128..=208)arm uses 0 as the high word. For a 64-bit operand I'd expect the negative inline integers (193-208) to be sign-extended, giving a high word of0xffffffff(exponent 0x7ff). If so, those few forms should be refused or given that high word. No compiler is likely to emit them for this opcode.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.