Recompiler: v_frexp_mant_f32 / _f16 keep the input's sign (#580) #587
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!587
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/587/head"
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?
@requiemsnkrp on GitHub · 2026-11-24 02:11 UTC · original
requiemsnkrp:recomp-frexp-mant-sign→main· +51 −1 · 3 files · 2 commits · merged 2026-11-25 18:23 UTCfrexp_mantreturned HLSLfrexp()'s mantissa, which is unsigned, sov_frexp_mant_f32gave a positive mantissa for a negative input (−10.125 → +0.6328125) and +0 for −0. The ISA keeps the sign, as XCL's f64 path (frexp_mant_d) already does. The helper now ORs the input's sign bit back in;v_frexp_mant_f16goes through the same helper. The diagnosis and the one-line fix are @joeypercia's (#580), who has no title for the regression run; they are credited with aCo-authored-bytrailer. Fixes #580.The direct DXIL backend, which came to
mainafter this PR was opened, had the same bug inLw::frexp_mant(gpu/dxil/prelude.rs): it takes its mantissa fromfrexp_dxc, which drops the sign like DXC'sfrexp. Its fix is @milesah3ad's patch from the review, taken as their own commit withgit am; @zhouzhidong3-hash checked the same change independently on an RTX 5070. The branch is rebased ontomain568e7db.What is in it
crates/xcl/src/gpu/recomp/emit.rs:frexp_mantkeeps the input's signcrates/xcl/src/gpu/dxil/prelude.rs(@milesah3ad's commit):Lw::frexp_mantORs the input's sign bit back ontofrexp_dxc's mantissa before the inf / NaN pass-throughcrates/xcl/src/gpu/recomp/tests.rs:gpu_frexp_mant_f32_f16_keep_the_signrunsv_frexp_mant_f32(VOP1, and VOP3 with NEG),v_frexp_exp_i32_f32andv_frexp_mant_f16on negative inputs, −0, +0 and −inf, bit for bit; withXCL_DIRECT_DXIL=1it goes through the direct backendTested
main9ce2070without the fix it fails on the first negative input (v_frexp_mant_f32 0xc1220000: got0x3f220000, want0xbf220000); with the fix it passesXCL_DIRECT_DXIL=1: onc5b2f6d(the HLSL fix only) it fails at lane 0 (got0x3f220000, want0xbf220000); ond0c5633(with the direct fix) it passes. Without the variable it passes on bothfrexptests (9) ond0c5633: 9 passed withXCL_DIRECT_DXILunset and withXCL_DIRECT_DXIL=1cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4ond0c5633with noXCL_*variable set: 1155 passed, 0 failed, 46 ignoredgpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware), 3 per-lane f16 cases refused (V_MUL_F16,V_PK_MUL_F16,V_CVT_F16_F32: #1426 semantics),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows),pso_measurement_compiles_an_exact_synthetic_record(the driver cache cannot be disabled without Windows Developer Mode,0x887A002D)Regression run
main:
PR:
Not tested
v_frexp_mant_f32/_f16on negative inputs in those 60 s; the regression runs use the default (HLSL) pathgpu_f32_math_and_bit_scans_random(21 more instructions) is not included; it belongs in its own test PRAI use
git am, and ran the tests and the regression runs on the machine above; opened at my request.@CryingLaughing on GitHub · 2026-11-24 02:17 UTC · original
I checked the f16 negative control listed under Not tested. On the RTX 4080, the same
V_FREXP_MANT_F16inputs lose their signs with the parent emitter and pass with the exact PR headd6d790653f64c4a8805115c9dfbd69ffbb757506.0xc9100x39100xb9100xbc000x38000xb8000x80000x00000x8000Tested
XCL_ADAPTER=4080,XCL_REQUIRE_GPU=1, synthetic fixtures, allXCL_SAMPLE_*variables unset. Separate build directories.cargo test -p xcl --lib --locked -j 4 gpu_frexp_mant_f32_f16_keep_the_sign -- --show-outputpassed 1/1 on the clean PR head, including all f16 and f32 assertions.emit.rsrestored to parent9ce2070eccf436d7bd38601c90407da447df34f3reported 0 passed, 1 failed. The control evaluates all f16 outputs before the first f32 assertion, with identical shader instructions and input bits. The log showed sign loss for all three negative input cases and counted 48 mismatches across 64 lanes. Both focused runs executed without a capability skip.Not tested
AI use
@MesshM on GitHub · 2026-11-24 02:31 UTC · original
Test run of
d6d790653f64c4a8805115c9dfbd69ffbb757506on AMD RDNA4 (native wave64); the PR and the follow-up check were on NVIDIA. The branch is based on9ce2070, so I merged it onto currentmaincb868b2locally (clean merge,emit.rsandtests.rs) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debug.\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4) on the merge: 686 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 646 passed, 0 failed, 21 ignoredSKIPPED;gpu_frexp_mant_f32_f16_keep_the_signpasses, as dogpu_frexp_f64_exp_and_mantandfrexp_f64_instructionsfrexp_mantinemit.rsback tofrexp(x, e)(not committed), the new test fails atlane 0 v_frexp_mant_f32 0xc1220000with0x3F220000instead of0xBF220000, the same failure the description reports on NVIDIAReview: ORing the input's sign bit into HLSL
frexp()'s mantissa gives the ISA result for every case the test covers: negative normals, −0 (→ −0), +0, and ±inf / NaN, which skipfrexpand pass through as before. The VOP3NEGcase checks the modifier is applied before the helper, and the f16 path reaches the same helper through its f32 conversion, so −0 and the signs survive there too. It matches whatfrexp_mant_dalready does for f64. I found nothing to change. Not covered by the test (and not touched by the change): denormal inputs and the sign of a NaN.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 report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@alpz1000 on GitHub · 2026-11-24 02:51 UTC · original
Independent check of the f16 before-fix case listed under Not tested. RTX 3060 12 GB (driver 610.88), Core i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, SDK DXC 1.9.2602.17, debug;
XCL_ADAPTER=3060.d6d790653f64c4a8805115c9dfbd69ffbb757506:cargo test --locked -p xcl --lib frexp -- --test-threads=1 --nocapturepassed all 3 tests, no skips.emit.rsfrom its parent and removed the three f32 assertions from the new test so the f16 assertion could run first.cargo test --locked -p xcl --lib gpu_frexp_mant_f32_f16_keep_the_sign -- --test-threads=1 --nocapturefailed on lane 0 forv_frexp_mant_f16input0xc910: got0x3910(14608), expected0xb910(47376). This independently reproduces the sign loss for f16 as well. Temporary changes were reverted.Not tested: full workspace or retail titles. AI use: OpenAI Codex (GPT-6) ran both checks and drafted this report.
@zhouzhidong3-hash on GitHub · 2026-11-24 02:51 UTC · original · edited 2026-11-24 03:13 UTC
Independent RTX 5070 verification of XCL PR #587
Tested on Windows 10 build 19045, Intel i7-12700KF, NVIDIA RTX 5070 driver 591.86, Rust 1.100.0 MSVC debug build and DXC 1.8.2502.11 with a local D3D12 Agility SDK.
Base implementation:
9ce2070ecc. Used the PR regression harness on the parent emitter. For the separate half-precision run, only the preceding f32 assertions were gated; the program and GPU input state were identical.Head: d6d790653f64c4a8805115c9dfbd69ffbb757506. With the original, unmodified test and emitter restored, the combined bitwise GPU regression passed (1 passed, 0 failed, no skip). No tracked source differences from HEAD after verification.
Workspace: cargo build --locked --workspace succeeded. cargo test --locked --workspace -- --test-threads=4 --nocapture reported 685 passed, 0 failed, 41 ignored. The harness counts runtime skips among passes. Two wave64 tests and two D3D12 debug-layer tests explicitly reported SKIPPED. Optional sample-dependent tests lacked retail inputs. No retail game smoke run was performed. This evidence covers instruction semantics on this GPU.
Logs: base-f32.log, base-f16.log, head-frexp.log, head-build.log, head-suite.log. Local harness: verify.py. AI assistance: Codex (GPT-6.2 Astra) prepared the local assertion gate, executed the comparison and summarized the logs.
Additional edge observations on the same RTX 5070 and PR head. A synthetic kernel executed the unmodified VOP1 f32 and f16 mantissa paths on eight input pairs repeated over 64 lanes. Every repeated lane agreed. Hex digits below are raw bits.
These are observations of this build. No comparison with native guest instructions or alternate denormal modes was performed, so this alone does not establish a regression or an ISA mismatch.
Parent-emitter control for the edge table: same synthetic kernel and inputs on the same adapter, with only emit.rs switched between
9ce2070and d6d7906. Both runs executed. For each precision, only the three negative finite inputs changed (smallest and largest subnormal, smallest normal), and each output changed by exactly the sign bit. Both f16 quiet NaNs already returned 0x7fff on the parent. The f32 subnormal magnitudes were already zero there. This isolates the PR effect on these inputs.@milesah3ad on GitHub · 2026-11-25 01:01 UTC · original
The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269:
gpu_frexp_mant_f32_f16_keep_the_signpass withXCL_DIRECT_DXIL=1with the patch below. Without it they fail on the direct path.frexp_mantingpu/dxil/prelude.rstakes its mantissa fromfrexp_dxc, which, like DXC'sfrexp, drops the sign. So the direct path gave0x3F220000for0xC1220000(your test's lane 0) where the console gives0xBF220000. The patch ORs the input's sign back in, as your HLSL change does and asfrexp_mant_dalready does for f64. The f16 form goes through the same helper.How to take it: this PR predates the direct backend on
main, so rebase it ontomainfirst (your commit rebases cleanly onto7994cd1), thengit amthe patch below. Feel free to fold it into your PR with aCo-Authored-By: milesah3ad <[email protected]>line. I didn't open a separate PR, so this doesn't add another review.patch (1 commit, for
git am)Tested
main7994cd1plus this patch:gpu_frexp_mant_f32_f16_keep_the_signpass with and withoutXCL_DIRECT_DXIL=1.cargo test -p xcl --lib --no-fail-fast -- --test-threads=4onmain7994cd1with #587, #686, #1159 and #1296 all merged and the four direct patches applied: 948 passed, 4 failed, 25 ignored, the same in both settings. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3, which fail the same way on plainmainhere (944 passed, 4 failed). The +4 are the PRs' own tests.Not tested: wave64 hardware (the wave64 cases SKIP here), AMD, any title, the full workspace suite (lib only).
AI use: Claude Code (Claude Opus 5.5) wrote the fix and ran the tests on the machine above. I checked the results.
@raylitebull on GitHub · 2026-11-25 01:08 UTC · original
Holding merge on
d6d7906until the direct-DXIL counterpart pointed out by @milesah3ad (frexp_mantincrates/xcl/src/gpu/dxil/prelude.rsalso drops the sign bit underXCL_DIRECT_DXIL=1) is folded in after a quick rebase ontomain.@zhouzhidong3-hash on GitHub · 2026-11-25 01:14 UTC · original
RTX 5070 reproduction of the Direct DXIL sign issue, using a modern tree.
Base tree:
7a1f5a2e6541c9fa0ef921e319fa81a2fdc2e42f(#1994). This is not a test of a rebased #587 head. Temporarily copied the unchangedgpu_frexp_mant_f32_f16_keep_the_signtest from #587d6d7906into that tree. Then applied only #587's HLSLfrexp_mantexpression change ingpu/recomp/emit.rs, leavinggpu/dxil/prelude.rsunchanged.Windows x64, RTX 5070 driver 591.86, Rust 1.100.0 MSVC debug, DXC/DXIL 1.8.2502.11, local Agility SDK, explicit
XCL_ADAPTER=5070.Command:
cargo test --locked -p xcl --lib gpu_frexp_mant_f32_f16_keep_the_sign -- --test-threads=1 --nocapture.XCL_DIRECT_DXIL=0)all)All three failing runs stop at lane 0,
v_frexp_mant_f32input0xc1220000: actual0x3f220000, expected0xbf220000. No test skips. The Direct DXIL run still returns the positive mantissa after the HLSL-only change makes its control pass.The failing assertion precedes the f16 assertions, so these failing runs do not establish f16 behavior. No proposed Direct DXIL fix, full suite, Release, native RDNA2 or retail validation in this experiment. All temporary source edits were restored and
git diff --exit-codereturned 0.Local logs:
sign-0.log,sign-all.log,sign-hlslfix-0.log,sign-hlslfix-all.logunderI:\neospace\work\xcl-1994-5070.AI assistance: OpenAI Codex moved the existing regression test temporarily, applied the existing HLSL expression as a control, ran the tests, restored source and drafted this report.
@JJAutoCompare on GitHub · 2026-11-25 04:46 UTC · original
Tested
Clean detached PR head
d6d790653f64c4a8805115c9dfbd69ffbb757506.Windows 11 Enterprise Evaluation 25H2 x64 (26200.9974), Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust/Cargo 1.100.0 x86_64-pc-windows-msvc, DXC/DXIL 1.9.2609.5. Unoptimized test profile on STOR-WINLAB.
The build ran outside the mutex and exited 0. HLSL/DXC ran in 0.70 s with 1 passed, 0 failed, 0 ignored, 0 skipped, 665 filtered out, exit 0. The mutex logged release.
All 256 assertions passed across 64 logical lanes (two hardware wave32s). The fixture checked FP32 mantissa sign bits with and without
NEG, FP32 exponents for finite inputs, signed zeros, and negative infinity, and FP16 mantissa bits for signed finite inputs and negative zero.Not tested
Native wave64, direct DXIL, a parent-commit control, the workspace suite, and retail titles.
AI use
T3 Code / Codex (
gpt-6.2-sol) ran the checked-in fixture and prepared this report.@zhouzhidong3-hash on GitHub · 2026-11-25 06:11 UTC · original
Follow-up: a local Direct DXIL counterpart passes the sign regression on RTX 5070.
Same base
7a1f5a2and environment as my preceding reproduction. In addition to the original #587 test and HLSL fix, I changed onlyLw::frexp_mantimmediately afterlet (m, _) = self.frexp_dxc(x);:The existing infinity/NaN selection remains after this.
frexp_dxcand the exponent helper are unchanged.XCL_DIRECT_DXIL=0) 1 passed, 0 failed; Direct DXIL (all) 1 passed, 0 failed. No skips. All four per-lane assertions execute across 64 logical lanes, including f32 sign/NEG/exponent and f16 sign.frexp --test-threads=1 --nocapture: 9 passed, 0 failed, 0 ignored, 964 filtered out in each configuration, no skips. Includes the six #1994 denormal-mode cases.0xc1220000, actual0x3f220000versus expected0xbf220000.This is a local candidate on #1994's original tree, not an updated #587 head or a merge-ready runtime change. Full workspace, Release, native RDNA2, wave64, additional edge inputs and retail smoke were not tested. Source was restored byte-for-byte, and git diff is empty.
Local patch: sign-candidate.patch. Logs: sign-candidate-0.log, sign-candidate-all.log, sign-candidate-frexp-0.log, sign-candidate-frexp-all.log under I:\neospace\work\xcl-1994-5070. Tested binary SHA256: 8559d6dbcacde3c7c8f139901b62f1a62f2ecd03f768e41f066a6719762ba761.
AI assistance: OpenAI Codex prepared the five-line candidate, ran the synthetic GPU checks, restored source and wrote this report.
@milesah3ad on GitHub · 2026-11-25 06:13 UTC · original
@zhouzhidong3-hash thanks, that's an independent check of the same fix:
Lw::frexp_mantisgpu/dxil/prelude.rs:97onmain6ea813a, the function my patch above changes in the same way (the sign bit ofxORed back onto DXC's mantissa before the inf/NaN select). So the two candidates are one change, and whichever is easier to fold in will do. I also checked the f64 path:frexp_mant_d(lower_wide.rs) already keeps the sign (s = h & 0x8000_0000into the new high word), sov_frexp_mant_f64doesn't need the same fix.AI use: Claude Code (Claude Opus 5.5).
@upipibi on GitHub · 2026-11-25 06:28 UTC · original
On the two direct-DXIL
frexp_mantpatches above (milesah3ad'sgit ampatch and zhouzhidong3-hash's snippet): they're the same change. Both put the input's sign bit back onto the mantissa inLw::frexp_mant(dxil/prelude.rs:97), before the existing inf / NaN pass-through. They differ only in instruction order, and both match this PR's HLSL change. Negative normals and -0 come out right, ±inf and NaN still pass through, and f16 goes through the same f32 helper.milesah3ad's is the one to fold in: it's a complete commit that still applies to current
main(git apply --check). zhouzhidong3-hash's 9/9 frexp tests in both modes are independent confirmation of the same code.Two gaps they share predate both and fit a follow-up, not this PR:
frexp_exp_f32has a denormal-mode path,frexp_mantdoesn't).0x7fff, losing its sign and payload.AI-assisted (Claude Code). Read from the diffs; no GPU run.
@requiemsnkrp on GitHub · 2026-11-25 09:35 UTC · original
@raylitebull done: the branch is rebased onto
main568e7dband @milesah3ad's direct-DXIL commit is in, taken withgit amas their own commit (d0c5633). @zhouzhidong3-hash's check of the same change is credited in the description.On the RTX 3060 (32-lane waves, 621.24),
gpu_frexp_mant_f32_f16_keep_the_signwithXCL_DIRECT_DXIL=1fails onc5b2f6d(the HLSL fix only) at lane 0 (0x3f220000for0xc1220000, want0xbf220000) and passes ond0c5633; without the variable it passes on both. The 9frexptests pass in both settings, and the workspace suite ond0c5633has 1155 passed, 0 failed, 46 ignored. The description has the new regression runs (568e7dbandd0c5633: 0 device removals, 0 crashes, 60 presents per 2 s at the end of both).AI use: Claude Code (Claude Opus 5.5) did the rebase, took the patch, ran the tests and wrote this.
@raylitebull on GitHub · 2026-11-25 10:46 UTC · original
d0c5633isMERGEABLE/CLEANwith green CI and cleanly folds@milesah3ad's direct-DXILfrexp_mantfix intoprelude.rs.Needs an exact-head AMD GPU verification pass on
d0c5633(alongside the NVIDIA pass) before merge.@zhouzhidong3-hash on GitHub · 2026-11-25 11:13 UTC · original
RTX 5070 follow-up observations on integrated head
d0c5633e9f363efa083a38696f6c3fd8b07fce69, for the two pre-existing follow-up gaps identified above. No runtime modifications were made; appended an observation test temporarily and restored it afterwards.Windows 10 x64, i7-12700KF, RTX 5070 591.86, Rust 1.100.0 MSVC debug, DXC/DXIL 1.8.2502.11, local Agility SDK, XCL_ADAPTER=5070.
The synthetic wave32 program writes S_DENORM_MODE, then evaluates V_FREXP_MANT_F32 (v0 to v4), V_FREXP_EXP_I32_F32 (v0 to v5), and V_FREXP_MANT_F16 (v1 to v6). Eight input pairs are repeated over the 32 lanes; repeated lanes agreed. Run with XCL_DIRECT_DXIL=all, then 0; both produced the same raw bits below.
Under mode 15, the observed mantissa/exponent pair for input 00000001 cannot reconstruct its nonzero input. This is a synthetic host observation, not a new comparison with native RDNA2 instructions. Signed output zeros now retain their sign, consistent with this PR's intended fix.
f16 quiet-NaN inputs 7e11 and fe11 both returned mantissa 7fff under modes 12 and 15 in both backends. This records canonicalization; it does not establish which payload/quieting behavior the console requires. The matching f32 NaNs retained their input bits in this experiment.
Observation test required real GPU/DXC and checked lane-repeat consistency; its pass status is not an ISA-conformance verdict. No skips. No full suite, Release, native wave64 or retail run. These observations do not establish a regression introduced by this PR or a GTA VI rendering failure.
Probe and logs locally: nvidia-followup-probes.rs, nvidia-pr587-head-all.log and nvidia-pr587-head-0.log under I:\neospace\work\xcl-1994-5070. Source restored byte-for-byte; git diff empty.
AI assistance: OpenAI Codex prepared the observation test, executed both paths and drafted this report.
Reproduction test appended to crates/xcl/src/gpu/recomp/tests.rs at the commit above (uses that module's helpers).
@DavidM1911 on GitHub · 2026-11-25 13:18 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!
@thiagocalile on GitHub · 2026-11-25 16:44 UTC · original
Independent test report for head
d0c5633e9f363efa083a38696f6c3fd8b07fce69on an AMD Radeon RX 6600 (8 GB VRAM, RDNA2, native wave64).Tested
32.0.21045.29003,XCL_ADAPTER=radeon), AMD Ryzen 7 5700X3D, 47.9 GB RAM, Windows 11 (10.0.26200.0), Rust1.100.0(stable-x86_64-pc-windows-msvc), DXC1.8.2502.11.XCL_ADAPTER=radeon XCL_DIRECT_DXIL=0 cargo test --no-fail-fast -p xcl --lib -- frexp --test-threads=1: 9 passed, 0 failed, 0 ignored (0skipped).XCL_ADAPTER=radeon XCL_DIRECT_DXIL=1 cargo test --no-fail-fast -p xcl --lib -- frexp --test-threads=1: 9 passed, 0 failed, 0 ignored (0skipped).Regression run (
scripts/smoke.ps1 -Seconds 60, release builds,XCL_ADAPTER=radeon)main(06c9f55):PR
#587(d0c5633):Not tested: full workspace test suite on this head, NVIDIA/Intel GPUs, Linux/Wine, or world load past the 60 s smoke window.
AI use: Antigravity (Gemini 4 Neon) ran the builds, tests, and smoke runs and drafted this report; the account owner reviewed and approved posting.
@oni-swr on GitHub · 2026-11-25 18:05 UTC · original
AMD RX 7800 XT run of
d0c5633e9f363efa083a38696f6c3fd8b07fce69(PR head, as-is, including the direct-DXILfrexp_mantchange inprelude.rs).Tested
cargo test --workspace --no-fail-fast -- --test-threads=4: lib 1098 passed, 1 failed, 26 ignored; every other test binary passed.gpu::recomp::tests::gpu_frexp_mant_f32_f16_keep_the_signpassed.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1fails (seed 722:res[30] = 0x1, CPU 0x7fffffff); it fails the same way onmainin my run, so it is not caused by this PR.main(origin/main68a284a596bd558b6bd9db6eedda6d6aa178c360) in the same setup: 1218 passed, 2 failed (the fuzz test andlower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier).Not tested
scripts/smoke.ps1regression run on a real title, so the runtime-change requirement is not met by this report.XCL_DIRECT_DXIL=1was not run separately.AI use
@DavidM1911 on GitHub · 2026-11-26 03:00 UTC · original
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