Skip to content

Recompiler: v_sin / v_cos reduce the argument in turns before scaling (#796) - #818

Open
upipibi wants to merge 3 commits into
xcl-dev:mainfrom
upipibi:fix/sincos-turns
Open

upipibi wants to merge 3 commits into
xcl-dev:mainfrom
upipibi:fix/sincos-turns

Conversation

@upipibi

@upipibi upipibi commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

v_sin_* / v_cos_* take their argument in turns. XCL emitted sin(x * 6.2831853f), which rounds the phase away at radian scale before any reduction, so the error grows with the number of turns. ±MaxFloat overflows the product to infinity and gives NaN. The RDNA 2 ISA's functional examples (p.142 for f32, p.149 for f16) reduce in turns and accept every finite input: V_COS_F32(0.25) = 0, V_SIN_F32(-MaxFloat) = 0, V_COS_F32(-MaxFloat) = 1, V_SIN_F16(0x7bff) = 0. Mesa's ACO drops its explicit v_fract from GFX9 on ("before GFX9, v_sin_f32 and v_cos_f32 had a valid input domain of [-256, +256]").

Fixes #796.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: HLSL helpers sin_turns / cos_turns (and trig_nonfinite), used by v_sin_f32, v_cos_f32, v_sin_f16 and v_cos_f16.
    • They reduce with x - trunc(x), which is exact in f32, and then scale.
    • They return exact zeros at whole and half turns for sin and at quarter and three-quarter turns for cos, and keep sin(-0) = -0.
    • On the bits, ±inf gives the ISA's 0xFFC00000 and a NaN input gives itself, quiet. Without that guard, DXC's relaxed float math turned sin(±inf) into 0 on the 3070 (inf - trunc(inf) was lost).
    • The f16 forms use the same helpers on the exact f32 value of the input.
  • crates/xcl/src/gpu/recomp/tests.rs: GPU test gpu_sin_cos_reduce_in_turns.
    • It checks all 22 functional examples the ISA prints for the four instructions, bit-exact (NaN as NaN).
    • It adds ±MaxFloat, exact zeros at half and quarter turns (0.5, -0.75, 7.25, 12345.5, 8388607.5; f16 0.5 and 255), and a NaN input.
    • Large arguments (0.1, -3.3, 255.125, 100000.125, 1000000.125, -2097151.875; f16 255.125 and -100) are compared against f64 sin/cos(2π·(x - trunc(x))), within 2^-16 (f32) or 2^-10 (f16) absolute.
  • crates/xcl/src/gpu/dxil/prelude.rs, lower_valu.rs, lower_wide.rs (f73e6ea): the direct DXIL translator reduces in turns the same way. Lw::trig_turns mirrors sin_turns / cos_turns / trig_nonfinite op for op, for f32 and f16. Without it, lower_dxil::tests::f32_programs_on_the_gpu, which compares the two paths register for register, failed at v_sin_f32(-0.5) (direct -0 against HLSL +0), as DavidM1911 found. The direct cache keys on the gpu/dxil sources, so no version bump.

Tested

  • AMD, run by oni-swr (comment, thanks) at the exact head f73e6ea, as-is: Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Windows 11, debug, DXC 1.9.0.5512. gpu_sin_cos_reduce_in_turns (HLSL path), lower_dxil::tests::f32_programs_on_the_gpu (direct path; its f32-conversion case was SKIPPED on wave32 and wave64, per-lane form refused) and the new sin_and_cos_reduce_the_argument_in_turns pass; cargo test --workspace --no-fail-fast -- --test-threads=4: 1243 passed, 2 failed, 46 ignored. The 2 failures are not this PR's: fuzz_validate_and_gpu_1 fails the same way on main 1a0bbe3 there, and gpu_image_get_resinfo_past_last_level comes from this head's base, which predates main's fix ea088a5. Only the default translator selection was run, so the two paths are covered by the two test functions, not by forcing XCL_DIRECT_DXIL.

  • At f73e6ea (this PR rebased onto main 426a5a74, plus the direct DXIL commit), RTX 3070 (616.56): lower_dxil::tests::f32_programs_on_the_gpu passes 3 of 3 (it failed 3 of 3 with the previous head merged onto main 96331383), f16_programs_on_the_gpu passes, and gpu_sin_cos_reduce_in_turns passes with XCL_DIRECT_DXIL=0 and =1. gpu_ suite (--skip gpu_sparse_vram): 144 passed, 0 failed on both paths (main 426a5a74: 143).

  • NVIDIA GeForce RTX 3070, driver 616.56, AMD Ryzen 9 5950X, Windows 11 Pro 26100, rustc 1.100.0, debug, DXC 1.8.2502.11

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on baf0639: 705 passed, 0 failed, 41 ignored

  • SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64)

  • The new test fails on main (e50836b) with 21 mismatches, among them sin(100000.125) = 0.6716, sin(±MaxFloat) / cos(±MaxFloat) = NaN, cos(-0.75) = -1.9e-7, sin(12345.5) = 0.0061, V_SIN_F16(0x7bff) = 0xA648, V_COS_F16(0x7bff) = 0x3BFF. It passes with the change.

  • Open PR Tests: f32 and f16 transcendentals on the GPU against f64 references #643's gpu_transcendental_f32 / _f16 (its head 232ee73, applied locally on top) pass both on main and with this change. Worst errors on the 3070 from its own output:

    main this PR
    V_SIN_F32 6.8e-5 1.2e-7
    V_COS_F32 9.6e-5 6.0e-8
    V_SIN_F16 4.9e-4 2.6e-4
    V_COS_F16 4.9e-4 4.9e-4

    Tests: f32 and f16 transcendentals on the GPU against f64 references #643 can keep its tolerances. With this PR its 2^-10 absolute allowance for sin / cos could tighten to the D3D class it uses for the others, and its skip of inputs above 256 turns could go.

Regression run

Pair for the current head f73e6ea against main 426a5a7, run by ThiagoAlexsander on the retail title (comment, thanks): RTX 5080 16 GB, scripts/smoke.ps1 -Seconds 60. Pasted as printed.

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: b6841dce
seconds: 60
exit: 0x0
frames shown: 1529 (PresentX 1529)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15235 MB
xcl-smoke v1
commit: f73e6ea8bd94f9e143dd33933152bf20e2f9608b
gpu: NVIDIA GeForce RTX 5080
title: b6841dce
seconds: 60
exit: 0x0
frames shown: 1590 (PresentX 1590)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15145 MB

Earlier pair, for an earlier head, from Kalmarv's run (#818 (comment)), thanks:

main:

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1277 (PresentX 1277)
presents per 2 s (last 3): 11 23 43
device removals: 0
crashes: 0
peak commit: 27498 MB

PR:

xcl-smoke v1
commit: ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1215 (PresentX 1215)
presents per 2 s (last 3): 17 26 10
device removals: 0
crashes: 0
peak commit: 27517 MB

Related: #2168. The HLSL path's default fast-math changes v_sin/v_cos results on AMD, and the HLSL sin_turns/cos_turns helpers this PR adds aren't marked precise, so an AMD run of this head mattered; oni-swr's run above passes these tests.

Not tested

  • Retail titles (no smoke run, see above); on AMD, only oni-swr's run above (no forced XCL_DIRECT_DXIL); native wave64. The test's wave64 program ran in the split form on the 3070.
  • The sign of the exact zero at a half turn (sin(0.5)) and at a negative whole turn: the ISA prints none. This PR returns +0, matching V_SIN_F32(-MaxFloat) = 0x00000000.
  • The payload of a NaN input: the ISA prints no example. This PR keeps the input's payload and sets the quiet bit.
  • Shader cost: each v_sin / v_cos now does a trunc, a subtraction and two compares more.

AI use

🤖 Generated with Claude Code

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Independent native Windows NVIDIA RTX 5080 (wave32) + D3D12 debug layer build/test run and code review at head baf06391502166ef0ccec3204cd143ee3f10f10a.

Code Review

  • Clean turn-space reduction (x - trunc(x)) before scaling by 2π, exact zero handling at whole/half turns (sin) and quarter/three-quarter turns (cos), sin(-0) = -0 preservation, and explicit bit-level trig_nonfinite handling (±inf -> 0xFFC00000, quiet NaN preservation) avoiding DXC relaxed-float folding of inf - inf.
  • Verified gpu_sin_cos_reduce_in_turns covers all RDNA2 ISA examples for both f32 and f16 and passes on RTX 5080. No issues found.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), D3D12 debug layer installed (d3d12SDKLayers.dll), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 705 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific GPU test (ok, executed on RTX 5080, not skipped):
    • gpu::recomp::tests::gpu_sin_cos_reduce_in_turns
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • AMD/wave64 hardware, release build, and retail titles.

AI use: Antigravity (Gemini 4 Neon reviewed the diff; Gemini 4 Hydrogen ran the RTX 5080 workspace tests) drafted this report.

@MesshM

MesshM commented Nov 24, 2026 •

Copy link
Copy Markdown

Test run of baf06391502166ef0ccec3204cd143ee3f10f10a on AMD RDNA4. I merged it onto current main beaa245 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 714 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 673 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the new gpu_sin_cos_reduce_in_turns passes.

Review: Reducing in turns (x - trunc(x)) before scaling gives exact zeros at 0 / ±0.5 (sin) and 0.25 / 0.75 (cos) and 0 for |x| past 2^23, as the ISA's functional examples say, and ±inf / NaN give a quiet NaN while the sign of a zero input is kept. #643's transcendental test (open) leaves out |x| > 256, so the two do not conflict. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@eizispark

eizispark commented Nov 24, 2026 •

Copy link
Copy Markdown

Updated hardware check for new head ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd (previous check: baf0639; verified clean merge with current main 9e3831e): pass.

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (RDNA4, native wave32 + wave64, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 705 passed, 0 failed, 41 ignored (GPU tests skipped on this adapter: none), including gpu::recomp::tests::gpu_sin_cos_reduce_in_turns (with the hw f16 ±Inf -> 0xFE00 and 1-ulp native RDNA2 rows) and both native-wave64 tests (gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware, console_wave64_compute_through_the_pso_hook_dispatch_and_read_back)

Regression run
main (9e3831e1f570d3646e53ab753b19ec07eb8f1485):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14728 MB

PR (ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd):

xcl-smoke v1
commit: ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1657 (PresentX 1657)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14861 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); retail run under XCL_D3D12_DEBUG=1; gameplay past the menus

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) — ran the workspace test suite and 60 s retail smoke run on ce03d3e and updated this report.

@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

Regression runs for this PR's head baf0639 and for its base main e50836b, on a retail title (same title, 60 s each), made with scripts/smoke.ps1 (release, clean tree at each commit) and pasted unedited, for Regression run.

main:

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1648 (PresentX 1648)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16639 MB

this PR:

xcl-smoke v1
commit: baf06391502166ef0ccec3204cd143ee3f10f10a
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1620 (PresentX 1620)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16935 MB

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 581.80, wave32), Intel Core i9-14900KF, Windows 11 25H2 26200.9974, Rust 1.90.0

Not tested

  • the unit tests on this machine
  • whether the title reaches the changed code; this is a regression check only

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@SlopTart

Copy link
Copy Markdown

2|
3|AMD + native wave64 datapoint — the axis your row lists as not tested (your wave64 program ran in split form on the 3070).
4|
5|Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Wine = Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust 1.100.0 cross x86_64-pc-windows-gnu, release profile, XCL_NETWORK=0, native wave64 (no XCL_SPLIT_WAVE64). Same rig as my Linux rows in #42 / #718 / #772.
6|
7|Merged state: head baf063915 onto main beaa245, clean merge.
8|
9|Full suite, cargo test --workspace --release --no-fail-fast -- --test-threads=4: 707 passed, 7 failed, 41 ignored (17 suites) — exactly this rig's stable Wine-lane failure set (my #42 row), nothing new, and the #718 trio stayed clean this run. Your test passes on RDNA3 native wave64: gpu_sin_cos_reduce_in_turns ok.
10|
11|(First run of this head aborted mid-suite from a transient X/Wine hiccup on my desktop, not a test failure — rerun above completed all 17 suites.)
12|
13|Not tested: retail titles (none here), Windows, RDNA4.
14|Counts only, no game data.
15|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated gpu_sin_cos_reduce_in_turns with luckyteagirl's native RX 6800M (gfx1031) results from #796 (comment). The 0.125-turn rows come from the GPU's sine approximation and are compared within 1 ulp. This also fixes f16 ±Inf, which gave 0x7FFF and now gives 0xFE00, in ce03d3e. Full suite on an RTX 3070 (driver 616.56): 705 passed, 0 failed, 41 ignored.

AI-assisted (Claude Code).

@guinpereira

Copy link
Copy Markdown

Test report: NVIDIA RTX 5060 Ti (wave32), head ce03d3e: 706 passed, 0 failed, 41 ignored; the new gpu_sin_cos_reduce_in_turns runs and passes

Tested

  • NVIDIA GeForce RTX 5060 Ti 16 GB, driver 32.0.16.1714, 32-lane waves only. Ryzen 7 5700X, 32 GB RAM. Windows 11 Pro 25H2 (26200.9974), Rust 1.99.1 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (Windows SDK 10.0.26100.0). Debug build, no XCL_SAMPLE_*.
  • PR head ce03d3e as is (base e50836b, not rebased on current main), clean tree.
  • cargo build --workspace: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 706 passed, 0 failed, 41 ignored (lib: 664 passed, 21 ignored). SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the same as on main.
  • cargo test -p xcl --lib gpu_sin_cos_reduce_in_turns -- --nocapture: passed, no SKIPPED line, so it ran on the GPU (wave64 program split into 32-lane halves). All f32 and f16 rows match, including the 1-ulp Ulps rows on NVIDIA's sin() / cos().

Not tested

  • A retail title / scripts/smoke.ps1 (no title on this machine).
  • The PR rebased on current main.

AI use: Claude Code (Claude Opus 5.5) ran the commands above and wrote this report. No code changes.

@Cecerw

Cecerw commented Nov 24, 2026

Copy link
Copy Markdown

Tested on NVIDIA (32-lane waves): passes

Tree Passed Failed Ignored SKIPPED
Head ce03d3e 705 0 41 2 (no wave64)
Head merged into main 47efa2e 742 0 41 2 (no wave64)
  • RTX 3060 Ti 8 GB, driver 32.0.16.1088; i5-14600K; Windows 11 26300.9818; Rust 1.100.0, debug; DXC 1.9.2602.17
  • Head ce03d3e, no local changes: .\scripts\test.ps1 (cargo test --workspace -- --test-threads=4): 705 passed, 0 failed, 41 ignored
  • Head merged locally into main 47efa2e (no conflicts): 742 passed, 0 failed, 41 ignored
  • gpu_sin_cos_reduce_in_turns: ok in both, so the NVIDIA driver's sin / cos stay within the test's one-ulp rows
  • SKIPPED: 2 (no wave64), the usual two on this adapter

Not tested: AMD, any title (no smoke run).

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@eizispark @Anon64 thanks for the smoke pairs. Both were made on baf0639. After them I pushed ce03d3e (f16 sin / cos of ±Inf give 0xFE00, from the native RDNA2 results), so the description check needs a PR block on ce03d3e. If either of you has a minute, one 60 s smoke.ps1 run of ce03d3e would do; your main blocks can stay. Thanks @Cecerw for the RTX 3060 Ti suite run above.

AI-assisted (Claude Code).

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Regression pair for ce03d3e against main e50836b (this PR's base), for the Regression run section. Both runs pass: no device removal, no crash, 95 % of main's frames, 100 % of its peak commit.

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), AMD Ryzen 9 9950X, Windows 11 Pro 26200.
  • scripts/smoke.ps1, the same retail title for 60 s each: main at e50836b (this PR's base, 67 commits behind today's main) first, then this PR's head, one after the other on the same machine.

main e50836b:

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1277 (PresentX 1277)
presents per 2 s (last 3): 11 23 43
device removals: 0
crashes: 0
peak commit: 27498 MB

this PR, ce03d3e:

xcl-smoke v1
commit: ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1215 (PresentX 1215)
presents per 2 s (last 3): 17 26 10
device removals: 0
crashes: 0
peak commit: 27517 MB

Presents per 2 s over the whole run (from the activity (2 s) lines):

  • main: 0 23 60 50 33 55 60 60 60 60 60 60 60 60 59 45 53 61 60 60 54 47 40 8 0 8 5 11 23 43
  • PR: 0 23 59 36 32 52 60 39 60 60 60 60 60 60 60 56 41 60 60 60 60 46 36 9 3 1 9 17 26 10

Both runs are at the 60-a-window cap most of the time. The 63-frame gap is two single dips in the PR's run (36 against 50 at 6-8 s, 39 against 60 at 14-16 s) and a slow phase from about 44 s that both runs have (111 frames in the last 16 s against 138). On #1244 today the same slow phase gave one pair 87 % and the next 103 %, so one pair can't separate a few percent from run-to-run spread.

Not tested

  • Whether the title's shaders use v_sin / v_cos on the frames the run reaches: not counted.
  • World loading: a 60 s run ends before it.
  • A second pair, AMD, native wave64.

AI use: Claude Code (Claude Opus 5.5)

@JJAutoCompare

Copy link
Copy Markdown

Tested

The checked-in gpu_sin_cos_reduce_in_turns test passed through HLSL and DXC (cs_6_6) on clean PR #818 head ce03d3ee92abb6ba32a4b55efbc96a16ebc63fdd for #796. GitHub still showed the PR open at that head after the run.

Intel Arc A770 driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, and the unoptimized Cargo test profile with debug info disabled. The test logged dxcompiler and dxil 1.9.2609.5. The A770 capability probe reported an 8–32 lane range. The test used split wave64 and checked 64 logical lanes.

$env:CARGO_TARGET_DIR = 'L:/XclTooling/pr1512-tiling-edges-fddfa267/target'
$env:TEMP = 'L:/XclTooling/pr818/run-20261125-023707-153/temp'
$env:TMP = $env:TEMP
$env:CARGO_BUILD_JOBS = '2'
$env:CARGO_INCREMENTAL = '0'
$env:CARGO_PROFILE_DEV_DEBUG = '0'
$env:CARGO_PROFILE_TEST_DEBUG = '0'
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = "$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64"
cargo test -p xcl --lib --locked --no-run

The prebuild exited 0 outside the GPU lock. The following block ran in powershell.exe -NoProfile -ExecutionPolicy Bypass with the same TEMP, TMP and XCL settings.

& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    & 'L:/XclTooling/CapabilityProbe/capabilities.exe'
    & 'L:/XclTooling/pr1512-tiling-edges-fddfa267/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe' 'gpu::recomp::tests::gpu_sin_cos_reduce_in_turns' --exact --nocapture --test-threads=1
}
  • 1 passed, 0 failed, 0 ignored, 0 explicit skips, 684 filtered out. Probe, test and lock wrapper exited 0.
  • Both sine and cosine matched the checked-in expectations over 19 f32 and 12 f16 input cases, including large turn counts with fractional phase, exact axis values, negative zero, NaN, and both signs of infinity. The infinity cases matched the expected NaN bits 0xFFC00000 for f32 and 0xFE00 for f16.

Not tested

Native wave64, the old lowering on Arc, other GPUs, the full workspace suite, and retail-title smoke runs.

AI use

Codex in T3 Code (gpt-6.2-sol) verified the checkout, ran the test, and wrote this report.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/gpu/recomp/emit.rs
#	crates/xcl/src/gpu/recomp/tests.rs
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1098/1):
gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu
  panicked at lower_dxil.rs:727: f32 transcendentals, wave32: lane 0 v9: 0x80000000 against 0x0

A sign-bit difference (0x80000000 = -0.0/negative NaN vs +0.0) in an f32 transcendental on the GPU — likely a v_cvt/v_rsq/v_rcp sign or NaN propagation regression. Needs a fix before merge.

— Devin

upipibi and others added 3 commits November 25, 2026 05:30
…xcl-dev#796)

v_sin_* / v_cos_* take the argument in turns. XCL emitted
sin(x * 6.2831853f), which rounds the phase away at radian scale before
any reduction: on an RTX 3070 sin(100000.125) gave 0.6716 for 0.7071,
and ±MaxFloat gave NaN because the product overflows. The RDNA 2 ISA's
own examples (p.142, p.149) have sin(-MaxFloat) = 0, cos(-MaxFloat) = 1,
cos(0.25) = 0 and V_SIN_F16(0x7bff) = 0.

sin_turns / cos_turns reduce exactly with x - trunc(x) first, return
exact zeros at whole and half turns (sin) and quarter turns (cos), keep
sin(-0) = -0, and give ±inf the ISA's 0xFFC00000 and a NaN itself on the
bits (DXC's relaxed float math otherwise turned sin(inf) into 0 on the
3070). The f16 forms use the same helpers on the exact f32 value.

gpu_sin_cos_reduce_in_turns checks every functional example the ISA
prints for the four instructions plus whole, half and quarter turns and
large arguments; it fails on main with 21 mismatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e RDNA2 results

luckyteagirl measured the native instructions on an RX 6800M (gfx1031) in
xcl-dev#796 (comment).
gpu_sin_cos_reduce_in_turns now uses those results as hardware rows:

- f32: -0, 0.25 / -0.75, 0.5 / 8388607.5, ±MaxFloat, and ±Inf giving
  0xFFC00000. Rows that used to check only "near ±1" now check exact bits.
- f16: -0, 255, ±65504, and ±Inf giving 0xFE00.
- 0.125 turns (f32 at 0.125, 255.125, 100000.125, 1000000.125, giving
  0x3F3504F4 / 0x3F3504F3; f16 at 0.125, 255.125, giving 0x39A8): these
  values come from each GPU's own sine approximation, so they are
  compared within one ulp.

On the RTX 3070, v_sin_f16 / v_cos_f16 of ±Inf gave 0x7FFF, because
f32tof16 turns the f32 NaN into that value. They now take the infinity
from the source bits and give 0xFE00. With clamp the NaN saturates as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…path does

xcl-dev#818 moved the HLSL path's v_sin / v_cos (f32 and f16) to `sin_turns` / `cos_turns`: the
argument reduced exactly (x - trunc(x)) before the scaling to radians, exact zeros at whole
and half turns (sin, sin(±0) = x) and quarter turns (cos), and `trig_nonfinite` for ±inf
(0xFFC00000) and NaN (itself, quiet); f16 ±inf gives 0xFE00 without clamp. The direct
translator still took Sin / Cos of x · 2π, so `lower_dxil`'s `f32_programs_on_the_gpu`,
which compares the two backends register for register, failed at v_sin_f32(-0.5): -0 from
Sin(-3.1415927) on the direct path against the HLSL path's exact +0.

`Lw::trig_turns` (prelude.rs) builds the HLSL helpers operation for operation; lower_valu.rs
and lower_wide.rs lower the four instructions through it, the f16 path with the HLSL path's
0xFE00 select. No TRANSLATOR_VERSION bump: the direct translation cache keys on the hash of
the gpu/dxil sources (XCL_DIRECT_DXIL_SOURCE_ID). A non-GPU test checks the container
(validated when DXC's validator is present) for the Round_z, Sin / Cos and the selects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@DavidM1911 Thanks, reproduced and fixed. On an RTX 3070 the test failed 3 of 3 with #818 merged onto main (lane 0 v9: 0x80000000 against 0x0) and passed 3 of 3 on main.

Cause: #818 changed only the HLSL path, which now reduces v_sin / v_cos in turns (sin_turns / cos_turns). The direct DXIL translator still computed Sin(x * 6.2831853), and f32_programs_on_the_gpu compares the two paths register for register. Lane 0 takes v_sin_f32(-0.5): half a turn. The HLSL helper returns an exact +0 there, while the old direct form gave -0 on NVIDIA.

Fix: f73e6ea (rebased onto main 426a5a74) adds Lw::trig_turns in gpu/dxil/prelude.rs, used for f32 (lower_valu.rs) and f16 (lower_wide.rs). It mirrors the HLSL helpers op for op: the x - trunc(x) reduction, exact zeros at whole and half turns (sin) and quarter turns (cos), sin(±0) = x, ±inf → 0xFFC00000, quieted NaN, and the f16 0xFE00 for ±inf. The direct cache keys on the gpu/dxil sources, so no version bump is needed.

Tested on the RTX 3070 (616.56): f32_programs_on_the_gpu passes 3 of 3, f16_programs_on_the_gpu passes, and gpu_sin_cos_reduce_in_turns passes with XCL_DIRECT_DXIL=0 and =1. gpu_ suite: 144 passed, 0 failed with XCL_DIRECT_DXIL=0 and =1 (main 426a5a74: 143).

One thing nobody has measured, as far as I can find: which zero RDNA2 itself returns at a negative half turn. Both paths now give +0 there, following the HLSL helper.

AI-assisted (Claude Code). Synthetic tests only.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD synthetic GPU run of f73e6ea8bd94f9e143dd33933152bf20e2f9608b (exact PR head, tested as-is, not merged onto main; the diff touches the recompiler, the direct-DXIL lowering and their tests only). Synthetic Cargo tests only: no retail title, no smoke.ps1.

Tested

  • AMD Radeon RX 7800 XT (RDNA3, driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 Pro 26200, rustc 1.100.0 (2026-11-09), debug build, DXC 1.9.0.5512. Clean target dir; Compiling xcl v0.1.0 came from the PR checkout.
  • cargo build --workspace, then cargo test -p xcl --lib <name> -- --nocapture for each:
    • gpu::recomp::tests::gpu_sin_cos_reduce_in_turns (the HLSL path): ok.
    • gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu (the direct-DXIL path): ok. It printed 2 SKIPPED lines for the f32 conversions case (wave32 and wave64, per-lane form: refused, unsupported V_CVT_F16_F32). The other cases ran.
    • gpu::recomp::lower_dxil::tests::sin_and_cos_reduce_the_argument_in_turns (new in this PR): ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1243 passed, 2 failed, 46 ignored, 7 distinct SKIPPED lines. These are not coverage: f16 per-lane form refused (4), f32 conversions per-lane form refused (2) and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • The 2 failures are not in this PR's area:
    • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1. It fails the same way on main 1a0bbe3 on this machine.
    • gpu::recomp::tests::gpu_image_get_resinfo_past_last_level. This head does not contain main's commit ea088a5 ("image_get_resinfo past the last level gives 0 sizes on AMD too"), so it is probably fixed by rebasing. I did not run the merged tree.

Not tested

  • Retail title / scripts/smoke.ps1 regression run, NVIDIA, Intel, Wine/vkd3d.
  • The PR merged with current main.
  • Only the default translator selection was run. I did not force either path with an env var, so "both paths" means the two test functions above.

AI use
Claude Code, Claude Sonnet 5.5 ran the tests, checked the diff, and wrote this report.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: v_sin_f32 / v_cos_f32 scale to radians before reducing the argument, so large arguments lose their phase