Recompiler: v_ldexp_f16 keeps ±0 and ±inf for any exponent (#658) #672
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!672
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-672"
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?
@joeypercia on GitHub · 2026-11-24 03:15 UTC · original
joeypercia:recompiler-ldexp-f16→main· +36 −4 · 3 files · 2 commits · openv_ldexp_f16was emitted as HLSLldexp(x, (float)n), which DXC computes asx * exp2(n). For |n| beyond the f32 exponent rangeexp2(n)is inf or 0, so ±0 with a large positive n and ±inf with a large negative n gave0 · inf= NaN; the ISA keeps ±0 and ±inf. It now uses the exactldexp_fhelper thatv_ldexp_f32already uses. The direct DXIL backend (#1426) had the samex * exp2(n)lowering and gets the same fix in a second commit. Fixes #658.On AMD this is also what #1227's
gpu_f16_rounding_and_frexp_ldexpneeds: itsv_ldexp_f16(-0)case gives+0onmainon RDNA2 and RDNA4 (Toons29's run there), and passes with this PR merged (RDNA2 iGPU; NVIDIA passes either way).What is in it
crates/xcl/src/gpu/recomp/emit.rs:v_ldexp_f16goes throughldexp_fcrates/xcl/src/gpu/dxil/lower_wide.rs: the direct backend'sv_ldexp_f16goes through itsldexp_fhelper too, like itsv_ldexp_f32crates/xcl/src/gpu/recomp/tests.rs:gpu_ldexp_f16_zero_inf_and_large_exponents, 11 cases: ±0 and ±inf with exponents up to ±32767, NaN, underflow to 0, a subnormal scaled to a normal, an exact scalingTested
cargo test --workspace --no-fail-fast -- --test-threads=4on32bcaef(rebased on main3da2abb): RTX 4070 Ti 1112 passed, 0 failed, 46 ignored; RDNA2 1111 passed, 1 failed, 46 ignored. The failure isfuzz_validate_and_gpu_1(seed 540,res[833] = 0x7, CPU0x6), which fails the same way onmainon this iGPUSKIPPED: RTX 4070 Ti: the wave64 cases oflower/lower_dxilGPU tests,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows); RDNA2: the mesh-shader tests (no mesh shaders); both:pso_measurement_compiles_an_exact_synthetic_record(needs Developer Mode) and thelower_dxilf16 / conversion cases the direct backend refusesXCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_ldexp_f16: passes on both GPUs; withlower_wide.rsback tomainit fails 6 of 11 cases (0x7ffffor ±0 / ±inf with large exponents)emit.rsback tomain, the new test fails on 6 of 11 cases on the RTX 4070 Ti (NaN0x7fff) and 7 of 11 on RDNA2 (NaN0xfe00, andldexp(-0, -32768)gives +0)gfx1031, rawv_ldexp_f16on the hardware): ±0 and ±inf come back unchanged for exponents up to ±32767, as this PR doesRegression run
RTX 4070 Ti (driver 616.56), release builds, 60 s each,
scripts/smoke.ps1 -Title retail-titleon the newer retail title, mainaa9ab8aand this PR's head32bcaef(no uncommitted changes). (@Anon64's earlier runs, on an RTX 3060 for the previous head6ec4036, were equally clean.)main:
PR:
Not tested
shaders.rpf(xcl shaders --json, 26 503 shaders) has nov_ldexp_f16, so this does not change that title.XCL_DIRECT_DXIL=1; CI does not set it, so the test covers it only when run that waymainthe f16 result is narrowed toward zero (#111), so 1.0 · 2^20 gives0x7bff, not inf; that belongs to the #111 fixAI use
@Anon64 on GitHub · 2026-11-24 03:24 UTC · original
Regression runs for this PR's head
6ec4036and for its basemaindd2ae9a, on a retail title (same title, 60 s each), made withscripts/smoke.ps1and pasted unedited. Feel free to copy both blocks into Regression run.main:
this PR:
Tested
cargo build --release -p xclfor both smoke runs, clean tree at each commitcargo test --workspace --no-fail-fast -- --test-threads=4(debug) on6ec4036: 690 passed, 1 failed, 41 ignored.gpu_ldexp_f16_zero_inf_and_large_exponentspasses. The one failure ishle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, which fails the same way onmaindd2ae9aon this machine (#650 / #656).SKIPPED:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)Not tested
v_ldexp_f16with these inputs; this is a regression check onlyReport written with Claude Code (Claude Opus 5.5) from runs on this machine.
@MesshM on GitHub · 2026-11-24 03:43 UTC · original
Test run of
6ec4036d1208eee1b496d7c47c4df57c8d3614b3on AMD RDNA4. I merged it onto currentmain91f9a5elocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 693 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 653 passed, 0 failed, 21 ignoredSKIPPED;gpu_ldexp_f16_zero_inf_and_large_exponentspasses.Review: Using the exact
ldexp_fhelper thatv_ldexp_f32already uses keeps ±0 and ±inf for any exponent, instead ofx * exp2(n)giving 0·inf = NaN. 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 ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@lordon1a on GitHub · 2026-11-24 03:58 UTC · original
Independent test report on
6ec4036:Tested
616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200),rustc 1.100.0(x86_64-pc-windows-gnullvm), debug build, DXC1.9.2609.5(01b62ad4)cargo test -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents -- --nocapture0.63s(gpu_ldexp_f16_zero_inf_and_large_exponentsok)Not tested
AI use
6ec4036in a detached worktree, audited the diff, ran the test, and posted this report.@eizispark on GitHub · 2026-11-24 04:00 UTC · original
Hardware check of
6ec4036d1208eee1b496d7c47c4df57c8d3614b3(verified clean merge withmainf4ce27c): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:691 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none— native wave64 and mesh shader tests included)cargo test -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents:1 passed, 0 failedRegression run
main(f4ce27c):PR (
6ec4036):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.@upipibi on GitHub · 2026-11-24 05:00 UTC · original
The ±0 / ±inf fix looks right. One remaining issue on
6ec4036, from reading the code (not run): the result still goes throughfr→to_f16_expr, which in the default mode isf32tof16(emit.rs:450), and #696 measured that as rounding toward zero.ldexp_fis exact in binary32 for a binary16 input, so only that last narrowing rounds, and it rounds the wrong way when the result overflows or lands in the binary16 denormal range:ldexp_f16(0x7BFF, 1): 131008 should be+inf(0x7C00); toward zero gives 65504 (0x7BFF).ldexp_f16(0x3C03, -15): 2^-15 · (1 + 3·2^-10) = 513.5 denormal steps should round to even, 514 (0x0202); toward zero gives 513 (0x0201).The test's
(0x0001, 10)and(0x3C00, -30)cases are exact or flush to 0, so they don't exercise this. Adding"v_ldexp_f16"to theto_f16_rounded_exprbranch, as #696 does for add / sub (one rounding of an exact binary32 value, so no double-rounding question), would cover both, and the two cases above could go into the test.AI-assisted (Claude Code), read-only review.
@joeypercia on GitHub · 2026-11-24 05:01 UTC · original
Thanks @upipibi, both cases are right (513.5 denormal steps → 514 under nearest-even; 131008 → inf). I left that out on purpose: it's the default-mode narrowing from #111 / #685, not the 0·inf NaN, and the Not tested section notes the overflow case for that reason. #696 changes the same
matches!line invalu16, so addingv_ldexp_f16here would conflict with it.Once #696 is in, I'll do the follow-up for the remaining f16 results that still narrow toward zero (
v_ldexp_f16,v_sqrt_f16,v_rcp_f16,v_rsq_f16,v_exp_f16,v_log_f16, withv_fract_f16's clamp kept below 1.0, see #655), and your two cases will go into its test.Written with Claude Code (Claude Opus 5.5).
@luckyteagirl on GitHub · 2026-11-24 05:59 UTC · original
Native RDNA2 reference for #658
I measured
v_ldexp_f16directly on a Radeon RX 6800M (gfx1031), Windows 11 build 26200, display driver30.0.13002.13003, and AMD OpenCL3302.6 (PAL,LC). The inline ISA probe checked the raw input bits and got the same output from four work-items per case. The wave's defaultHW_REG_MODEread back as0x000003F0.0x0000(+0)0x00000x8000(−0)0x80000x7C00(+Inf) /0xFC00(−Inf)0x3C00(+1) /0xBC00(−1)0x7C00/0xFC000xBC00(−1)0x80000x0400(minimum normal)0x02000x0001/0x0003(subnormal ties)0x0000/0x00020x8001(negative subnormal tie)0x8000The signed zeros and infinities agree with the cases addressed by this PR. The native finite-overflow and subnormal-tie results give reference values for the rounding cases discussed under #111.
Not tested
The PR's HLSL on this adapter, alternate hardware rounding modes, and retail titles.
AI use
OpenAI Codex (GPT-6 family, exact model variant unavailable) wrote and ran the probe and drafted this report.
@SlopTart on GitHub · 2026-11-24 06:40 UTC · original
2|
3|Release-build full-suite datapoint — the axis your row lists as not tested.
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. Same rig as my Linux rows in #42 / #718.6|
7|Merged state: head
6ec4036d1onto mainbeaa245, clean merge.8|
9|Full suite,
cargo test --workspace --release --no-fail-fast -- --test-threads=4: 704 passed, 10 failed, 41 ignored (17 suites). Of the 10: 7 are this rig's stable Wine-lane failures (my #42 row) and 3 were the known #718 flaky trio (placed_title_textures_share_vram_and_preserve_pixels+ the two poisoned-lock deaths) — that trio hits ~2 of 5 threads=4 runs on this rig regardless of PRs, nothing to do with yours. Your tests pass:gpu_ldexp_f16_zero_inf_and_large_exponents,gpu_ldexp_f32,gpu_ldexp_f64.10|
11|Not tested: retail titles (none here), Windows, the overflow-to-inf case you deliberately left out (#111).
12|Counts only, no game data.
13|AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@zhouzhidong3-hash on GitHub · 2026-11-24 03:19 UTC · original · edited 2026-11-24 07:13 UTC
Independent Release-mode result for the unmodified PR head 6ec4036d1208eee1b496d7c47c4df57c8d3614b3. On an RTX 5070 with Windows 10, Rust 1.100.0 MSVC, DXC 1.8.2502.11 and the D3D12 Agility SDK, the focused GPU test passed all 11 synthetic cases.
Command:
cargo test --locked --release -p xcl --lib gpu_ldexp_f16_zero_inf_and_large_exponents -- --nocapture. Adapter selection:XCL_ADAPTER=5070. The optimized build ran one test, 0 failed, 0 ignored, 671 filtered out; no runtime skip appeared. Scope: this PR-head test only. No parent control, full Release suite, wave64 or retail smoke on this machine for this report.AI assistance: OpenAI Codex prepared and ran the test and summarized the log.
Follow-up baseline for the planned narrowing fix. I ran the 11 input/exponent pairs from the native RX 6800M report through the same Release wave32 fixture at 6ec4036 on the RTX 5070, changing the case table and logging each low halfword. Eight results matched bit-for-bit. All three mismatches are listed below (hexadecimal binary16 bits).
The original PR test passed; this expanded comparison fails on the already scoped-out finite overflow and subnormal rounding cases. Only the default-mode fixture was exercised. This baseline can be reused when the unary narrowing change lands.
Full Release workspace follow-up on 6ec4036 using a fresh target directory: cargo build --locked --release --workspace followed by cargo test --locked --release --workspace --no-fail-fast -- --test-threads=4 --nocapture. Both exited 0. Aggregate harness counts: 691 passed, 0 failed, 41 ignored. Four explicit runtime skips counted among passes: two wave64 checks and two D3D12 debug-layer checks. Optional retail sample variables were unset. The separately instrumented native-comparison probe was absent from this run.
@raylitebull on GitHub · 2026-11-25 02:01 UTC · original
Diff audit and Windows
Build and testpassed on32bcaef(ldexp_fin bothemit.rsanddxil/lower_wide.rs, preserving ±0 / ±inf across extreme exponents).Remaining before merge: update the
PR descriptionsoRegression runuses a matchingxcl-smoke v1pair for current head32bcaef(theRegression runblock currently references previous head6ec4036andtitle: retail-title), plus an independent NVIDIA check on32bcaef(AMD RDNA2 + RTX 4070 Ti are from the PR author).@upipibi on GitHub · 2026-11-25 03:26 UTC · original
NVIDIA check at
32bcaef, as asked: RTX 3070 (Ampere, 32-lane waves, driver 616.56), Windows 11, debug.gpu_ldexp_f16_zero_inf_and_large_exponentspasses withXCL_DIRECT_DXIL=0and1.gpu_tests: 128 passed withXCL_DIRECT_DXIL=0; 126 passed and 2 failed with1. The 2 fail on this PR's base too and are fixed elsewhere:gpu_fmt_encode_int_sat_and_f16_rtz(#2043, merged) andgpu_image_get_resinfo_1d_array(#2046).The two rounding cases from my earlier comment, measured by adding them to the test locally (not pushed), give the same results on both backends:
ldexp_f16(0x3C03, -15)=0x0201, round-to-nearest-even gives0x0202.ldexp_f16(0x7BFF, 1)=0x7BFF, round-to-nearest-even gives0x7C00.The test leaves overflow to #111. The denormal case comes from the same rounding of the narrowing, so it fits there too. Neither blocks this PR.
AI-assisted (Claude Code). Synthetic tests only.
@JJAutoCompare on GitHub · 2026-11-25 01:43 UTC · original · edited 2026-11-25 03:59 UTC
Independent Intel Arc A770 verification of PR #672 for #658. The checked-in regression passed on clean head
6ec4036d1208eee1b496d7c47c4df57c8d3614b3. The PR was open at that head before and after the run.Tested
Intel Arc A770, driver
32.0.101.9175, AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 25H2 build26200.9974, Rust/Cargo1.100.0MSVC x64, unoptimized test profile. D3D12 reported wave sizes 8–32. The fixture ran as wave32.Prebuilt outside the GPU lock with
cargo test --locked -p xcl --lib -j 2 --no-runandCARGO_INCREMENTAL=0,CARGO_PROFILE_DEV_DEBUG=0,CARGO_PROFILE_TEST_DEBUG=0. Cargo exited 0.Set
XCL_ADAPTER=A770,XCL_REQUIRE_GPU=wave64to make missing GPU or DXC a failure, andXCL_DXC_DIR=%LOCALAPPDATA%\XclTooling\dxc-1.9.2609\bin\x64. The test loaded DXC/DXIL1.9.2609.5(DXC01b62ad4) and used the fixture's HLSLcs_6_6compiler path. Ran this exact command insideL:/XclTooling/Invoke-ArcTest.ps1:1 passed, 0 failed, 0 ignored, 0 skipped, 671 filtered out, 0.80 s, exit 0. All 11 checked-in assertions passed after GPU readback: four signed-zero cases, three signed-infinity cases (with exponents up to the signed 16-bit endpoints across those seven cases), one NaN classification check, and three finite cases. The finite cases check underflow to +0, scaling the minimum subnormal to the minimum normal, and scaling 1 to 8.
Not tested
AI use
gpt-6.2-sol) verified the live revision, ran the checked-in test, and wrote this report.Follow-up on
32bcaefThe PR was open at
32bcaef6fcbefore and after testing, and the reused checkout was clean and detached at that exact SHA. This run covered HLSL/DXC and direct DXIL.Tested
STOR-WINLAB, Windows 11 Enterprise Evaluation 25H2 build
26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 (driver32.0.101.9175), Rust and Cargo1.100.0(x86_64-pc-windows-msvc), unoptimized test profile with debug info disabled. Both fixture stderr logs reported DXC/DXIL1.9.2609.5(DXC01b62ad4).Prebuilt outside the Arc mutex with
cargo test --locked -p xcl --lib --no-run(exit 0, 1m 38s). Environment usedCARGO_TARGET_DIR=L:/XclTooling/pr2014-1c971de6/target,CARGO_BUILD_JOBS=2,CARGO_INCREMENTAL=0,CARGO_PROFILE_DEV_DEBUG=0, andCARGO_PROFILE_TEST_DEBUG=0.Ran the exact command below in separate native processes under
L:/XclTooling/Invoke-ArcTest.ps1, launched withpowershell.exe -NoProfile -ExecutionPolicy RemoteSigned. SetXCL_ADAPTER=A770,XCL_DXC_DIR=$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64, andXCL_REQUIRE_GPU=wave64to fail on an unavailable GPU or DXC. Each process had a separate TEMP/TMP directory. Mode1selects the fixture's direct DXIL path without HLSL fallback.Both native wave32 runs satisfied all 11 GPU readback assertions. Inputs and results below are binary16 bit patterns, with signed decimal exponents. The NaN check accepts any NaN encoding.
0x0000, +200 → 0x0000;0x8000, +300 → 0x8000;0x0000, +32767 → 0x0000;0x8000, −32768 → 0x80000x7C00, −200 → 0x7C00;0xFC00, −300 → 0xFC00;0x7C00, −32768 → 0x7C000x7E00, +5 → NaN0x3C00, −30 → 0x0000(underflow to +0);0x0001, +10 → 0x0400(minimum subnormal to minimum normal);0x3C00, +3 → 0x4800(1 to 8)Not tested
Native or split wave64, other adapters, finite overflow, subnormal ties, alternate rounding modes, release or workspace suites, fuzzing, retail smoke, or a pre-fix baseline.
AI use
T3 Code / Codex (gpt-6.2-sol) verified the revision, ran both fixture invocations, and wrote this report.
@DavidM1911 on GitHub · 2026-11-25 12:20 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
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.