Recompiler: v_div_fmas_f32 scales by VCC and v_div_fixup_f32 handles NaN/zero/sign #1135
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1144"
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?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T12:32:18Z.
v_div_fmas_f32emittedmad(s0, s1, s2)and ignored its implicitVCCoperand, so lanes withVCC == 1never got the2^32scale (ldexp_f(..., 32)).div_fixup(v_div_fixup_f32) returnedqunchanged whenqwasNaN(overflow in the division sequence), whenn == ±0.0with finited, whenexp(n) - exp(d) < -150(underflow), and without setting the result sign tosign(d) ^ sign(n). This replacesdiv_fixupwith an IEEE-754 bit-level implementation covering NaN (numerator before denominator),0/0,Inf/Inf,x/0,Inf/x,x/Inf,0/x,exp(n) - exp(d) < -150underflow,q = NaNoverflow, andcopysign(q, sign(d) ^ sign(n)).What is in it
crates/xcl/src/gpu/recomp/emit.rs: scalev_div_fmas_f32by2^32vialdexp_ffor lanes withVCC == 1; updatediv_fixupfor NaN priority (numerator before denominator), zero/inf,exp(n) - exp(d) < -150underflow,q = NaNoverflow, and sign.crates/xcl/src/gpu/recomp/tests.rs: add GPU testsgpu_div_fmas_f32_scales_by_vccandgpu_div_fixup_f32_special_cases_and_sign(17 cases including numerator-over-denominator NaN priority and the-151/-150exponent difference boundary) across wave32 and split wave64 (verified failing before the fix).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 753 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib gpu_div_fmas_f32_scales_by_vccandgpu_div_fixup_f32_special_cases_and_sign: both pass across wave32 and split wave64 (both failed on the GPU before the fix)Regression run
main:
PR:
Not tested
AI use
emit.rs, wrote the fix and GPU tests, addressed the PortBridge hardware-probe feedback (nNaN priority andexp(n) - exp(d) < -150), ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T12:53:07Z.
Independent verification on current
main384f7f7(branch already contains it — clean).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC 1.8.2502.11.
cargo test -p xcl --lib div_fmas: 1 passed, 0 failed —gpu_div_fmas_f32_scales_by_vcccovers VCC scaling and the NaN/zero/sign fixup cases on real hardware.AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Imported from ivall/xcl. Originally posted by TobiasFornell on 2026-11-24T12:57:01Z.
AMD / Linux data point – the PR was tested on NVIDIA only, where native wave64 is not available.
Tested: RX 9070 XT (RDNA4, native wave64), Mesa RADV 26.3.1, CachyOS (kernel 7.3), Proton Experimental
11.0-20261112Wine with vkd3d-proton v3.1 (scripts/linuxbuild), DXC 1.9.2609,x86_64-pc-windows-msvccross-build, release. Head2aa8211merged ontomain47efa2e(clean), together with #1158.gpu_div_fmas_f32_scales_by_vccandgpu_div_fixup_f32_special_cases_and_sign: pass, including the native wave64 path.emit.rschange reverted (tests kept): both fail, e.g.wave64 lane 1 (vcc=true) v_div_fmas_f32–left: 1088421888, right: 1356857344. So the fix is confirmed on AMD hardware too.Testing and write-up assisted by Claude Code (Claude Opus 5.5); runs on my own hardware, checked by me.
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T13:54:36Z.
Thanks @akimfomin! Updated \
eac652c\ to check numerator NaN before denominator NaN and apply \exp(n) - exp(d) < -150\ underflow before quotient NaN, added GPU test cases for both (including the -151\ vs -150\ boundary), re-ran the full test suite (753 passed, 0 failed, 41 ignored) and refreshed the 60 s smoke block.Imported from ivall/xcl. Originally posted by akimfomin on 2026-11-24T13:47:21Z.
PortBridge linked this to Lyrnc’s gfx1036 probe in VIctory #200 and Continued #762’s translator tests. I compiled the exact
div_fixuphelper from2aa8211in an isolated dispatch and read its output on WARP (DXC 1.9.2602.17).(q,d,n)=(0x40000000,0x5d800000,0x12000000)the exponent difference is −151. The helper returned0x40000000; the AMD probe and Continued returned0x00000000.nwith0x12800000gives −150. All three preserved0x40000000.Across 14 vectors, including 10 from the hardware probe, the Continued translator plus CPU interpreter matched 14/14. The exact XCL helper matched 9/14. A local HLSL control that prioritizes numerator NaN and applies
exp(n)-exp(d)<-150before handling quotient NaN matched all 14 on WARP. This was a helper-level check. PortBridge case. Synthetic inputs, AI-assisted with Codex.I independently reran the same WARP probe on the published fix at
eac652c. It matched 14/14 on the original vectors, up from 9/14 on2aa8211. I also replayed the 17 rows in the updatedgpu_div_fixup_f32_special_cases_and_signfixture through the isolated helper. The updated helper matched 17/17, including the NaN payload checks and both signed zero cases, up from 13/17 on the earlier helper. Thanks for adding the regression cases.Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:05:27Z.
A run on Linux with vkd3d-proton, where the shaders go through dxil-spirv to Vulkan instead of a Windows driver's DXIL compiler.
Tested
x86_64-pc-windows-gnu.eac652cas it is (based on930e8b4), no uncommitted changes. The lib test binary runs under Wine, one test per process (--exact).gpu::recomp::tests::gpu_div_fmas_f32_scales_by_vcc: ok, no SKIPPED.gpu::recomp::tests::gpu_div_fixup_f32_special_cases_and_sign: ok, no SKIPPED.Not tested
AI use
Imported from ivall/xcl. Originally posted by TobiasFornell on 2026-11-24T14:11:48Z.
Re-tested the updated head
eac652c(merged ontomain47efa2e, clean) on the same AMD setup: RX 9070 XT (RDNA4, native wave64), RADV 26.3.1, Proton Experimental11.0-20261112Wine, vkd3d-proton v3.1 (scripts/linuxbuild), release.gpu_div_fixup_f32_special_cases_and_sign(incl. the new −151/−150 underflow and NaN-order cases),gpu_div_fmas_f32_scales_by_vcc,gpu_divergence_through_exec: 3 passed, 0 failed, native wave64 path included.Testing and write-up assisted by Claude Code (Claude Opus 5.5); runs on my own hardware, checked by me.
Imported from ivall/xcl. Originally posted by regiumlepidi on 2026-11-24T23:42:15Z.
RTX 5070 Ti:
eac652cmerged intomain20cf130passes its two tests on the default path; both still fail withXCL_DIRECT_DXIL=1Tested
XCL_SAMPLE_*cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture, one run per cell; PR headeac652c3d11927169ea46739249ebcc188ad800emerged locally into20cf13022f764208384c610c2ae6a3f4eed201a2, no conflicts (passed / failed / ignored):XCL_DIRECT_DXIL=1main20cf130gpu_div_fmas_f32_scales_by_vccandgpu_div_fixup_f32_special_cases_and_signpass. The 4 failures arefuzz_validate_and_gpu_0to_3, which fail the same way onmainwith this driver (#1905)XCL_DIRECT_DXIL=1: those 4,offline_compute_pipeline_is_reused_by_a_second_process(fails onmaintoo), and both new tests:gpu_div_fmas_f32_scales_by_vcc:wave32 lane 1 (vcc=true), left1088421888, right1356857344gpu_div_fixup_f32_special_cases_and_sign:wave32 lane 0 v_div_fixup_f32(q=0x7fc00000, d=0x1e3ce508, n=0x7e967699) = 0x7fc00000, want 0x7f800000tests.rschanges applied tomain20cf130: both new tests fail on both paths with the values aboveXCL_DIRECT_DXIL=1the merged tree returns the same values for these two cases asmaindoes (the PR's diff touchesrecomp/emit.rsandrecomp/tests.rs)SKIPPEDlines in the default run, 18 of them no wave64; none names the new testsNot tested
gpu_waves()runs wave32 only on this adapter), release build, any retail title, other GPUs or driversAI use
Imported from ivall/xcl. Originally posted by regiumlepidi on 2026-11-25T00:00:48Z.
@b3IKK as in my report above, this PR's two tests still fail with
XCL_DIRECT_DXIL=1: the direct translator has the same two bugs indxil/lower_valu.rsanddxil/prelude.rs. I wrote the matching change for it (below):v_div_fmas_f32scales by 2^32 where VCC is set (also in programs that direct f32 rounding), anddiv_fixupworks on the bits in the same order as your HLSL helper.Measured on an RTX 5070 Ti, driver 617.42, debug, with this PR's commit and the patch on
main62265d3: both new tests pass with and withoutXCL_DIRECT_DXIL=1;cargo test --workspace --locked --no-fail-fast -- --test-threads=4gives 984 / 4 / 45 (default) and 983 / 5 / 45 (direct), the failures being the fourfuzz_validate_and_gpu_*of #1905 and, on direct,offline_compute_pipeline_is_reused_by_a_second_process, which fail onmainhere too. Not tested: wave64, av_div_fmas_f32in a directed-rounding program, any retail title.Take it into this PR if you like, or say if you would rather it go in a separate PR stacked on this one.
Patch for the direct translator (applies with
git applyon this PR merged intomain8e87fc7)Claude Code with Claude Opus 5.5 wrote the patch, ran the tests and wrote this comment.
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T03:32:43Z.
Tested
eac652c3d11927169ea46739249ebcc188ad800eon Windows 11 build 26200, AMD Radeon RX 6800M (driver30.0.13002.13003), Ryzen 9 5980HX, Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5.XCL_ADAPTER=6800MandXCL_REQUIRE_GPU=1were set.cargo test --locked -p xcl --lib -j 2 gpu_div_fmas_f32_scales_by_vcc -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, no explicit skip.gpu_div_fixup_f32_special_cases_and_sign: 1 passed, 0 failed, 0 ignored, no explicit skip. This test includes 17 NaN, zero, infinity, sign, and exponent-boundary cases.Coverage note
Both tests call
gpu_waves()andrun_wave(). The latter translates to HLSL withOptions { wave64, ..Default::default() }; neither test setssplit_wave64: true. Thus these runs establish HLSL GPU coverage on AMD, but the current tests do not explicitly exercise split wave64, despite the PR description's claim. They run wave32 and, if the adapter reports native wave64, native wave64. I did not instrument which native mode the adapter chose.Not tested
AI use
OpenAI Codex (GPT-6, exact variant not exposed in this session) reviewed the exact diff and test helpers, ran both focused GPU tests, checked the logs, and drafted this report.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T03:54:15Z.
PR #1144 on Intel Arc A770
Tested
x86_64-pc-windows-msvc), unoptimized test profile with debuginfo disabled. Both test stderr logs confirmed loaded DXC and DXIL 1.9.2609.5.eac652c3d11927169ea46739249ebcc188ad800ebefore and after the run. UpstreamAGENTS.mdandCONTRIBUTING.mdwere read frommainatcbc296ab65a2661a61e3e2da109134bcd5319f60. I found no equivalent Arc result in the PR discussion or issue #42.cargo test --locked -p xcl --lib --no-runsucceeded outside the Arc mutex.CARGO_TARGET_DIR=L:/XclTooling/pr1512-tiling-edges-fddfa267/target,CARGO_BUILD_JOBS=2,CARGO_INCREMENTAL=0,CARGO_PROFILE_DEV_DEBUG=0,CARGO_PROFILE_TEST_DEBUG=0.TEMPandTMPpointed atL:/XclTooling/pr1144/run-20261125T034636736Z/temp.powershell.exe -NoProfile -ExecutionPolicy RemoteSignedprocess under& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { ... }, withXCL_ADAPTER=A770andXCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64. The build, each test executable invocation, and each mutex wrapper have separate stdout and stderr files next to this report.gpu_div_fmas_f32_scales_by_vccgpu_div_fixup_f32_special_cases_and_signThe first invocation of each fixture also reported a pass, and both mutex releases were logged. PowerShell's
Start-Processlost access to the exit status of the fast child processes. I reran the same two fixtures with exit status captured throughSystem.Diagnostics.Process. The table uses the reruns and their.verified.*logs. Both reruns acquired and released the Arc mutex.Both fixtures assemble synthetic RDNA2 instructions and run HLSL compiled by DXC for
cs_6_6.gpu_waves()selects wave32 and adds a native wave64 run only when the adapter exposes 64 lanes. The A770 with this driver reports an 8–32 lane range in the existing D3D12 probe, so coverage here was wave32.kernel_wave()leavessplit_wave64at its defaultfalsefor both fixtures. Arc A770 capability probe2 × 3 + 1, the 16 even lanes with VCC clear returned7.0and the 16 odd lanes with VCC set returned7.0 × 2^32. A second instruction checked positive zero in all 32 lanes under the same VCC pattern.(q, d, n)vectors. They cover signed infinity for a NaN quotient on overflow, signed zeros and infinities for zero or infinite operands, finite sign correction, NaN classification for0/0andInf/Inf, exact quiet-NaN payloads with numerator priority, and the exponent-difference boundary at −151 and −150. The −151 rows include both signs of zero and precedence over a NaN quotient. At −150 the supplied finite quotient is preserved.Not tested
AI use
gpt-6.2-sol) checked the PR and stock fixtures, ran the tests, and wrote this report.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T03:40:59Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-27T06:50:36Z.
@b3IKK, a heads-up on
v_div_fmas_f32ineac652c3, which also applies to @regiumlepidi's direct-DXIL version (7148039461) and to the patch in #2952 (7209397473). All three scale by2^32(ldexp_f(..., 32)) when VCC is set, following the RDNA 2/3 ISA PDF's2.0F ** 32 * fma(S0, S1, S2).That PDF line appears to be wrong for the hardware:
gpu_div_fmas_f32_scales_by_vcc:S0 = 2.0, S1 = 3.0, S2 = 1.0, VCC set. They expect7.0 * 2^-64, not7.0 * 2^32(test_vop3.pytest_div_fmas_f32_scale_down). WithS2 = 2.0(scale_up), they expect* 2^64._pcode_fixes):D0 = exponent(S2) > 127 ? 2^64 * fma(S0,S1,S2) : 2^-64 * fma(S0,S1,S2).v_div_scale_f32'sldexp(.., ±64). A fixed2^32leaves any division that takes the scaled path off by2^32or2^96. It doesn't show today only becausev_div_scale_f32never sets VCC in either path.The
div_fixupside ofeac652c3agrees with the same table (isNAN(S0) ? ±INF : ...). Separately, we have a local direct-DXIL change that implements all three (div_scalewith its VCC,div_fmaswith the ±64 rule applied inside the fused op, and fixup) and checks the whole LLVMfdiv.f32sequence against the host's IEEE quotient. Its GPU runs are pending. We'll report how it compares, or fold whatever helps into this PR if you prefer.AI use: Gemini (Antigravity) found the sites and the tinygrad tests; Claude Code (Claude Opus 5.5) checked the test vectors in both trees and wrote this comment.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:55:09Z.
Triage (#1607) – head
eac652c#3312 also rewrites the HLSL
div_fixuphelper inemit.rs, with a different approach. It falls back ton / dfor NaN, Inf or zero quotients, scales huge denominators and changes the direct-DXIL prelude as well. This PR implements the per-bit special cases instead (NaN propagation, sign, exponent-difference underflow) and makesv_div_fmas_f32scale by 2^32 when VCC is set. #823 covers only the f64 ops.On main,
v_div_scale_f32always writes VCC = 0, so thev_div_fmas_f32change only matters for VCC set by other code. A quotient that the unscaled sequence flushes to 0 (for example 3e38 / 3e38) still returns 0 here, while #3312 handles that case. The PR conflicts with main.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.