Skip to content

Recompiler: v_frexp_mant_f32 / _f16 keep the input's sign (#580) - #587

Open
requiemsnkrp wants to merge 2 commits into
xcl-dev:mainfrom
requiemsnkrp:recomp-frexp-mant-sign
Open

requiemsnkrp wants to merge 2 commits into
xcl-dev:mainfrom
requiemsnkrp:recomp-frexp-mant-sign

Conversation

@requiemsnkrp

@requiemsnkrp requiemsnkrp commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

frexp_mant returned HLSL frexp()'s mantissa, which is unsigned, so v_frexp_mant_f32 gave 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_f16 goes 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 a Co-authored-by trailer. Fixes #580.

The direct DXIL backend, which came to main after this PR was opened, had the same bug in Lw::frexp_mant (gpu/dxil/prelude.rs): it takes its mantissa from frexp_dxc, which drops the sign like DXC's frexp. Its fix is @milesah3ad's patch from the review, taken as their own commit with git am; @zhouzhidong3-hash checked the same change independently on an RTX 5070. The branch is rebased onto main 568e7db.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: frexp_mant keeps the input's sign
  • crates/xcl/src/gpu/dxil/prelude.rs (@milesah3ad's commit): Lw::frexp_mant ORs the input's sign bit back onto frexp_dxc's mantissa before the inf / NaN pass-through
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_frexp_mant_f32_f16_keep_the_sign runs v_frexp_mant_f32 (VOP1, and VOP3 with NEG), v_frexp_exp_i32_f32 and v_frexp_mant_f16 on negative inputs, −0, +0 and −inf, bit for bit; with XCL_DIRECT_DXIL=1 it goes through the direct backend

Tested

  • NVIDIA GeForce RTX 3060 12 GB, driver 621.24 (32-lane waves); AMD Ryzen 5 5600X; Windows 11 Pro 26200; Rust 1.100.0 msvc; DXC 1.9.2602.17; debug for the tests, release for the regression runs
  • the new test, HLSL path: on main 9ce2070 without the fix it fails on the first negative input (v_frexp_mant_f32 0xc1220000: got 0x3f220000, want 0xbf220000); with the fix it passes
  • the new test, XCL_DIRECT_DXIL=1: on c5b2f6d (the HLSL fix only) it fails at lane 0 (got 0x3f220000, want 0xbf220000); on d0c5633 (with the direct fix) it passes. Without the variable it passes on both
  • the frexp tests (9) on d0c5633: 9 passed with XCL_DIRECT_DXIL unset and with XCL_DIRECT_DXIL=1
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on d0c5633 with no XCL_* variable set: 1155 passed, 0 failed, 46 ignored
  • SKIPPED: 20 tests for no wave64 (among them gpu_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:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1236 (PresentX 1236)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15204 MB

PR:

xcl-smoke v1
commit: d0c5633e9f363efa083a38696f6c3fd8b07fce69
gpu: NVIDIA GeForce RTX 3060
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15233 MB

Not tested

  • the f16 case failing before the fix: the test stops at the first f32 assertion; with the fix the f16 assertions pass
  • whether the title's shaders use v_frexp_mant_f32 / _f16 on negative inputs in those 60 s; the regression runs use the default (HLSL) path
  • AMD / wave64 hardware (joeypercia's RDNA2 numbers in Recompiler: v_frexp_mant_f32 drops the sign of negative inputs #580 cover the HLSL fix there with their randomized test)
  • joeypercia's gpu_f32_math_and_bit_scans_random (21 more instructions) is not included; it belongs in its own test PR

AI use

  • Claude Code with Claude Opus 5.5: wrote the test and this description, applied joeypercia's fix, rebased the branch, took milesah3ad's commit with git am, and ran the tests and the regression runs on the machine above; opened at my request.

@CryingLaughing

Copy link
Copy Markdown

I checked the f16 negative control listed under Not tested. On the RTX 4080, the same V_FREXP_MANT_F16 inputs lose their signs with the parent emitter and pass with the exact PR head d6d790653f64c4a8805115c9dfbd69ffbb757506.

f16 input bits Parent emitter result Expected mantissa
0xc910 0x3910 0xb910
0xbc00 0x3800 0xb800
0x8000 0x0000 0x8000

Tested

  • RTX 4080, NVIDIA driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC x64, DXC 1.8.2502.11, debug. XCL_ADAPTER=4080, XCL_REQUIRE_GPU=1, synthetic fixtures, all XCL_SAMPLE_* variables unset. Separate build directories.
  • cargo test -p xcl --lib --locked -j 4 gpu_frexp_mant_f32_f16_keep_the_sign -- --show-output passed 1/1 on the clean PR head, including all f16 and f32 assertions.
  • The same command with emit.rs restored to parent 9ce2070eccf436d7bd38601c90407da447df34f3 reported 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

  • Full workspace for this PR head, denormals, other adapters, release builds, or retail smoke on this machine.

AI use

  • OpenAI Codex (GPT-6 family, exact variant unavailable) prepared the local control, ran the commands, and drafted this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of d6d790653f64c4a8805115c9dfbd69ffbb757506 on AMD RDNA4 (native wave64); the PR and the follow-up check were on NVIDIA. The branch is based on 9ce2070, so I merged it onto current main cb868b2 locally (clean merge, emit.rs and tests.rs) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), 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
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) on the merge: 686 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 646 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_frexp_mant_f32_f16_keep_the_sign passes, as do gpu_frexp_f64_exp_and_mant and frexp_f64_instructions
  • negative control on this adapter: with only frexp_mant in emit.rs back to frexp(x, e) (not committed), the new test fails at lane 0 v_frexp_mant_f32 0xc1220000 with 0x3F220000 instead of 0xBF220000, the same failure the description reports on NVIDIA

Review: 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 skip frexp and pass through as before. The VOP3 NEG case 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 what frexp_mant_d already 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 onto main.

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

@alpz1000

Copy link
Copy Markdown

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.

  • Unmodified PR head d6d790653f64c4a8805115c9dfbd69ffbb757506: cargo test --locked -p xcl --lib frexp -- --test-threads=1 --nocapture passed all 3 tests, no skips.
  • On the same head, I temporarily restored only emit.rs from 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 --nocapture failed on lane 0 for v_frexp_mant_f16 input 0xc910: got 0x3910 (14608), expected 0xb910 (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

zhouzhidong3-hash commented Nov 24, 2026 •

Copy link
Copy Markdown

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: 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.

Instruction Input bits Base actual Expected
v_frexp_mant_f32 0xc1220000 0x3f220000 0xbf220000
v_frexp_mant_f16 0xc910 0x3910 0xb910

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.

Inputs f32 result f16 result (low 16 bits)
Smallest positive / negative subnormal 00000000 / 80000000 3800 / b800
Largest positive / negative subnormal 00000000 / 80000000 3bfe / bbfe
Smallest positive / negative normal 3f000000 / bf000000 3800 / b800
Quiet NaNs (f32 7fc01234 / ffc01234, f16 7e11 / fe11) 7fc01234 / ffc01234 7fff / 7fff

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.

@milesah3ad

Copy link
Copy Markdown

The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269: gpu_frexp_mant_f32_f16_keep_the_sign pass with XCL_DIRECT_DXIL=1 with the patch below. Without it they fail on the direct path.

frexp_mant in gpu/dxil/prelude.rs takes its mantissa from frexp_dxc, which, like DXC's frexp, drops the sign. So the direct path gave 0x3F220000 for 0xC1220000 (your test's lane 0) where the console gives 0xBF220000. The patch ORs the input's sign back in, as your HLSL change does and as frexp_mant_d already 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 onto main first (your commit rebases cleanly onto 7994cd1), then git am the patch below. Feel free to fold it into your PR with a Co-Authored-By: milesah3ad <360542007+milesah3ad@users.noreply.github.com> line. I didn't open a separate PR, so this doesn't add another review.

patch (1 commit, for git am)
From af7b26c7057f24ba2d1529efded73b027fe3e426 Mon Sep 17 00:00:00 2001
From: milesah3ad <360542007+milesah3ad@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:51:25 -0600
Subject: [PATCH] Direct DXIL: v_frexp_mant_f32 / _f16 keep the input's sign
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 #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
---
 crates/xcl/src/gpu/dxil/prelude.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/crates/xcl/src/gpu/dxil/prelude.rs b/crates/xcl/src/gpu/dxil/prelude.rs
index a171fd0..9b2e8e0 100644
--- a/crates/xcl/src/gpu/dxil/prelude.rs
+++ b/crates/xcl/src/gpu/dxil/prelude.rs
@@ -84,8 +84,14 @@ impl Lw {
         let mf = self.sel(nz, mf, z);
         (mf, ef)
     }
+    /// The ISA's mantissa keeps the input's sign (as `frexp_mant_d` does); DXC's `frexp` drops it.
     pub fn frexp_mant(&mut self, x: Value) -> Value {
         let (m, _) = self.frexp_dxc(x);
+        let mb = self.bits(m);
+        let xb = self.bits(x);
+        let sign = self.andc(xb, 0x8000_0000);
+        let mb = self.or(mb, sign);
+        let m = self.f(mb);
         let a = self.isinf(x);
         let b = self.isnan(x);
         let s = self.lor(a, b);
-- 
2.48.1.windows.1

Tested

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

Copy link
Copy Markdown
Member

Holding merge on d6d7906 until the direct-DXIL counterpart pointed out by @milesah3ad (frexp_mant in crates/xcl/src/gpu/dxil/prelude.rs also drops the sign bit under XCL_DIRECT_DXIL=1) is folded in after a quick rebase onto main.

@zhouzhidong3-hash

Copy link
Copy Markdown

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 unchanged gpu_frexp_mant_f32_f16_keep_the_sign test from #587 d6d7906 into that tree. Then applied only #587's HLSL frexp_mant expression change in gpu/recomp/emit.rs, leaving gpu/dxil/prelude.rs unchanged.

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.

Temporary runtime configuration HLSL (XCL_DIRECT_DXIL=0) Direct DXIL (all)
Original modern tree, added test only 0 passed, 1 failed 0 passed, 1 failed
Same tree plus #587 HLSL fix only 1 passed, 0 failed 0 passed, 1 failed

All three failing runs stop at lane 0, v_frexp_mant_f32 input 0xc1220000: actual 0x3f220000, expected 0xbf220000. 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-code returned 0.

Local logs: sign-0.log, sign-all.log, sign-hlslfix-0.log, sign-hlslfix-all.log under I:\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

Copy link
Copy Markdown

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.

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 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

Copy link
Copy Markdown

Follow-up: a local Direct DXIL counterpart passes the sign regression on RTX 5070.

Same base 7a1f5a2 and environment as my preceding reproduction. In addition to the original #587 test and HLSL fix, I changed only Lw::frexp_mant immediately after let (m, _) = self.frexp_dxc(x);:

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. frexp_dxc and the exponent helper are unchanged.

  • Original sign regression: HLSL (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.
  • Same compiled candidate binary, frexp --test-threads=1 --nocapture: 9 passed, 0 failed, 0 ignored, 964 filtered out in each configuration, no skips. Includes the six Recompiler: honor FP32 denormal mode in FREXP exponent #1994 denormal-mode cases.
  • Prior HLSL-only control passed HLSL but failed Direct DXIL at lane 0, input 0xc1220000, actual 0x3f220000 versus expected 0xbf220000.

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

Copy link
Copy Markdown

@zhouzhidong3-hash thanks, that's an independent check of the same fix: Lw::frexp_mant is gpu/dxil/prelude.rs:97 on main 6ea813a, the function my patch above changes in the same way (the sign bit of x ORed 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_0000 into the new high word), so v_frexp_mant_f64 doesn't need the same fix.

AI use: Claude Code (Claude Opus 5.5).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

On the two direct-DXIL frexp_mant patches above (milesah3ad's git am patch and zhouzhidong3-hash's snippet): they're the same change. Both put the input's sign bit back onto the mantissa in Lw::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:

  • f32 denormals when the mode keeps them (frexp_exp_f32 has a denormal-mode path, frexp_mant doesn't).
  • An f16 NaN comes back as 0x7fff, losing its sign and payload.

AI-assisted (Claude Code). Read from the diffs; no GPU run.

requiemsnkrp and others added 2 commits November 25, 2026 10:23
`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
@requiemsnkrp
requiemsnkrp force-pushed the recomp-frexp-mant-sign branch from d6d7906 to d0c5633 Compare November 25, 2026 09:34
@requiemsnkrp

Copy link
Copy Markdown
Contributor Author

@raylitebull done: the branch is rebased onto main 568e7db and @milesah3ad's direct-DXIL commit is in, taken with git am as 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_sign with XCL_DIRECT_DXIL=1 fails on c5b2f6d (the HLSL fix only) at lane 0 (0x3f220000 for 0xc1220000, want 0xbf220000) and passes on d0c5633; without the variable it passes on both. The 9 frexp tests pass in both settings, and the workspace suite on d0c5633 has 1155 passed, 0 failed, 46 ignored. The description has the new regression runs (568e7db and d0c5633: 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.

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_frexp_mant_f32 drops the sign of negative inputs

9 participants