Repository navigation
Recompiler: v_frexp_mant_f32 / _f16 keep the input's sign (#580) - #587
requiemsnkrp wants to merge 2 commits into
Conversation
|
I checked the f16 negative control listed under Not tested. On the RTX 4080, the same
Tested
Not tested
AI use
|
|
Test run of Tested
Review: ORing the input's sign bit into HLSL Not tested: no retail title or regression run (I have no unpacked game), no Run and report by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code. |
|
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;
Not tested: full workspace or retail titles. AI use: OpenAI Codex (GPT-6) ran both checks and drafted this report. |
Independent RTX 5070 verification of XCL PR #587Tested 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: 9ce2070. 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: d6d7906. 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 9ce2070 and 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. |
|
The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269:
How to take it: this PR predates the direct backend on patch (1 commit, for
|
|
Holding merge on |
|
RTX 5070 reproduction of the Direct DXIL sign issue, using a modern tree. Base tree: Windows x64, RTX 5070 driver 591.86, Rust 1.100.0 MSVC debug, DXC/DXIL 1.8.2502.11, local Agility SDK, explicit Command:
All three failing runs stop at lane 0, 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 Local logs: 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. |
|
Tested Clean detached PR head 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. cargo test --locked -p xcl --lib --no-run
# Prebuilt fixture ran with XCL_ADAPTER=A770 and XCL_DIRECT_DXIL=0.
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
& 'L:/XclTooling/pr1778-2e2ee55-20261125-020159/target/debug/build/xcl/00e28da3621caf64/out/xcl-00e28da3621caf64.exe' gpu::recomp::tests::gpu_frexp_mant_f32_f16_keep_the_sign --exact --nocapture --test-threads=1
}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 Not tested Native wave64, direct DXIL, a parent-commit control, the workspace suite, and retail titles. AI use T3 Code / Codex ( |
|
Follow-up: a local Direct DXIL counterpart passes the sign regression on RTX 5070. Same base let xb = self.bits(x);
let sign = self.andc(xb, 0x8000_0000);
let mb = self.bits(m);
let signed = self.or(mb, sign);
let m = self.f(signed);The existing infinity/NaN selection remains after this.
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. |
|
@zhouzhidong3-hash thanks, that's an independent check of the same fix: AI use: Claude Code (Claude Opus 5.5). |
|
On the two direct-DXIL milesah3ad's is the one to fold in: it's a complete commit that still applies to current Two gaps they share predate both and fit a follow-up, not this PR:
AI-assisted (Claude Code). Read from the diffs; no GPU run. |
`frexp_mant` returned HLSL frexp()'s mantissa, which is unsigned: a negative input gave a positive mantissa (-10.125 -> +0.6328125) and -0 gave +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_f16 goes through the same helper. Fix and diagnosis by joeypercia in xcl-dev#580. The test runs v_frexp_mant_f32 (also with the NEG modifier), v_frexp_exp_i32_f32 and v_frexp_mant_f16 on negative inputs, -0, +0 and -inf: before, it failed on the first negative input (+0.6328125 for -10.125); after, it passes. Fixes xcl-dev#580 Co-authored-by: joeypercia <81598667+joeypercia@users.noreply.github.com> Assisted-by: Claude Code (Claude Opus 5.5)
frexp_mant took its mantissa from frexp_dxc, which, like DXC's frexp, drops the sign, so a negative input came back positive (0xC1220000 gave 0x3F220000, not 0xBF220000). The ISA's mantissa keeps the sign, as frexp_mant_d already does for f64 and as xcl-dev#587 makes the HLSL path do. The sign bit is ORed back in; ┬▒inf and NaN still return the input. gpu_frexp_mant_f32_f16_keep_the_sign now passes with XCL_DIRECT_DXIL=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS
d6d7906 to
d0c5633
Compare
|
@raylitebull done: the branch is rebased onto On the RTX 3060 (32-lane waves, 621.24), AI use: Claude Code (Claude Opus 5.5) did the rebase, took the patch, ran the tests and wrote this. |
|
Needs an exact-head AMD GPU verification pass on |
|
RTX 5070 follow-up observations on integrated head 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). #[test]
fn local_nvidia_frexp_boundary_observations() {
assert!(gpu_ready(), "a real GPU and DXC are required");
let inputs = [1u32, 3, 0x007f_ffff, 0x8000_0001, 0x807f_ffff, 0x0080_0000, 0x7fc0_1234, 0xffc0_1234];
let halves = [1u32, 3, 0x03ff, 0x8001, 0x83ff, 0x0400, 0x7e11, 0xfe11];
for mode in [12u64, 15] {
let code = prog(&[
("S_DENORM_MODE", "ENC_SOPP", &[("SIMM16", mode)], None),
("V_FREXP_MANT_F32", "ENC_VOP1", &[("VDST", 4), ("SRC0", V)], None),
("V_FREXP_EXP_I32_F32", "ENC_VOP1", &[("VDST", 5), ("SRC0", V)], None),
("V_FREXP_MANT_F16", "ENC_VOP1", &[("VDST", 6), ("SRC0", V + 1)], None),
]);
let mut state = KernelState::default();
for (lane, regs) in state.vgpr.iter_mut().enumerate() {
regs[0] = inputs[lane % inputs.len()];
regs[1] = halves[lane % halves.len()];
}
let (result, lanes) = run_wave(&code, &state, false);
for lane in 0..inputs.len() {
let regs = &result.vgpr[lane];
println!("FREXP mode={mode} f32={:08x} mant={:08x} exp={} f16={:04x} mant16={:04x}", inputs[lane], regs[4], regs[5] as i32, halves[lane], regs[6] & 0xffff);
}
for lane in inputs.len()..lanes {
assert_eq!(&result.vgpr[lane][4..7], &result.vgpr[lane % inputs.len()][4..7]);
}
}
}
|
frexp_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
main9ce2070 without the fix it fails on the first negative input (v_frexp_mant_f32 0xc1220000: got0x3f220000, want0xbf220000); with the fix it passesXCL_DIRECT_DXIL=1: on c5b2f6d (the HLSL fix only) it fails at lane 0 (got0x3f220000, want0xbf220000); on d0c5633 (with the direct fix) it passes. Without the variable it passes on bothfrexptests (9) on d0c5633: 9 passed withXCL_DIRECT_DXILunset and withXCL_DIRECT_DXIL=1cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on d0c5633 with 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: gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #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.