Recompiler: the HLSL backend's fast-math loses -0 in f16 results and changes v_sin/v_cos on AMD #2168

Open
opened 2026-11-26 05:21:37 +00:00 by github-bot · 5 comments
Owner

@⁠alexdeliu on GitHub · 2026-11-25 07:01 UTC · original

The HLSL backend and the direct-DXIL backend give different results for the same instruction on six instructions. The results agree bit for bit on an RX 9070 (RDNA4) and on a gfx1036 iGPU (RDNA2). Compiling the HLSL kernels with DXC's -Gis (IEEE strictness) removes all six differences. So the cause looks like DXC's default fast-math flags (nsz, etc.) on the HLSL path, which the AMD driver then uses. XCL's dxc::compile passes no -Gis.

Found with a cross-backend / cross-device VALU fuzzer: one VOP3/VOP3P instruction per wave64 kernel, 256 edge and random inputs. A PR is coming; it is test-only.

instruction differ (of 256) example sources HLSL direct DXIL
v_mul_f16 26 0x0001 × 0x8000 (+denorm × -0) 0x0000 0x8000
v_pk_mul_f16 49 hi 0x8000 × 0x0001 0x0000… 0x8000…
v_ldexp_f16 19 ldexp(0x8000, 1) 0x0000 0x8000
v_sin_f16 4 sin(0x8000) 0x0000 0x8000
v_sin_f32 7 0x7f7fffff (FLT_MAX) 0x00000000 0xffc00000
v_cos_f32 8 0x47bcfc00 (96760.0) 0x3f800000 0x3f7fb10e
  • f16: IEEE gives -0 for every f16 example (a product or ldexp of -0, sin(-0)). The direct backend keeps it; the HLSL backend returns +0. This is not the rounding difference that DIFFERS_ON_1426 in recomp/lower.rs lists for V_MUL_F16 / V_PK_MUL_F16 (RTZ vs RNE). It is the sign of zero, and it shows up on the default (HLSL) path.
  • sin/cos: both backends emit sin(x * 2π) / cos(x * 2π). Without -Gis the AMD driver seems to compile the HLSL one differently: it gives 1.0 for cos of a whole number of turns and 0 for sin(FLT_MAX), where the direct backend gives the radian result and NaN. These inputs are outside the [-256, 256] input range the RDNA ISA gives for v_sin/v_cos, so what the console returns there is worth checking separately.
  • Separately, v_dot2_f32_f16 differs between the two GPUs on both backends: 7 of 256 results, mostly 1-3 ulp, plus a denormal result that RDNA4 keeps (0x00000001) and RDNA2 flushes (0x00000000). The console is RDNA2, so the iGPU's results are presumably the console's.

Reproduce: the fuzzer PR adds valu_fuzz_backends_agree (ignored). Run cargo test -p xcl --lib valu_fuzz -- --ignored --nocapture --test-threads=1, and again with XCL_FUZZ_DXC_GIS=1.

Not tested: NVIDIA, the cost of -Gis on real shaders, and a retail title (I have no title here).

AI use: found, analysed and written with Claude Code (Claude Opus 5.5). The runs above are real runs on the hardware named, on main f5c5bdf.

**@⁠alexdeliu** on GitHub · 2026-11-25 07:01 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168) The HLSL backend and the direct-DXIL backend give different results for the same instruction on six instructions. The results agree bit for bit on an RX 9070 (RDNA4) and on a gfx1036 iGPU (RDNA2). Compiling the HLSL kernels with DXC's `-Gis` (IEEE strictness) removes all six differences. So the cause looks like DXC's default fast-math flags (`nsz`, etc.) on the HLSL path, which the AMD driver then uses. XCL's `dxc::compile` passes no `-Gis`. Found with a cross-backend / cross-device VALU fuzzer: one VOP3/VOP3P instruction per wave64 kernel, 256 edge and random inputs. A PR is coming; it is test-only. | instruction | differ (of 256) | example sources | HLSL | direct DXIL | |---|---|---|---|---| | `v_mul_f16` | 26 | `0x0001` × `0x8000` (+denorm × -0) | `0x0000` | `0x8000` | | `v_pk_mul_f16` | 49 | hi `0x8000` × `0x0001` | `0x0000…` | `0x8000…` | | `v_ldexp_f16` | 19 | `ldexp(0x8000, 1)` | `0x0000` | `0x8000` | | `v_sin_f16` | 4 | `sin(0x8000)` | `0x0000` | `0x8000` | | `v_sin_f32` | 7 | `0x7f7fffff` (FLT_MAX) | `0x00000000` | `0xffc00000` | | `v_cos_f32` | 8 | `0x47bcfc00` (96760.0) | `0x3f800000` | `0x3f7fb10e` | - **f16:** IEEE gives -0 for every f16 example (a product or `ldexp` of -0, `sin(-0)`). The direct backend keeps it; the HLSL backend returns +0. This is not the rounding difference that `DIFFERS_ON_1426` in `recomp/lower.rs` lists for `V_MUL_F16` / `V_PK_MUL_F16` (RTZ vs RNE). It is the sign of zero, and it shows up on the default (HLSL) path. - **sin/cos:** both backends emit `sin(x * 2π)` / `cos(x * 2π)`. Without `-Gis` the AMD driver seems to compile the HLSL one differently: it gives 1.0 for cos of a whole number of turns and 0 for sin(FLT_MAX), where the direct backend gives the radian result and NaN. These inputs are outside the [-256, 256] input range the RDNA ISA gives for v_sin/v_cos, so what the console returns there is worth checking separately. - Separately, `v_dot2_f32_f16` differs **between the two GPUs** on both backends: 7 of 256 results, mostly 1-3 ulp, plus a denormal result that RDNA4 keeps (`0x00000001`) and RDNA2 flushes (`0x00000000`). The console is RDNA2, so the iGPU's results are presumably the console's. Reproduce: the fuzzer PR adds `valu_fuzz_backends_agree` (ignored). Run `cargo test -p xcl --lib valu_fuzz -- --ignored --nocapture --test-threads=1`, and again with `XCL_FUZZ_DXC_GIS=1`. Not tested: NVIDIA, the cost of `-Gis` on real shaders, and a retail title (I have no title here). AI use: found, analysed and written with Claude Code (Claude Opus 5.5). The runs above are real runs on the hardware named, on `main` f5c5bdf.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:21:37 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 07:37 UTC · original

NVIDIA data point (listed as untested here): on an RTX 3060 (driver 32.0.16.1088, Windows, so the split wave64 form), valu_fuzz_backends_agree from #2169 finds none of these six differences. HLSL and direct DXIL agree on v_mul_f16, v_pk_mul_f16, v_ldexp_f16, v_sin_f16, v_sin_f32 and v_cos_f32 for all 256 inputs. On an RX 9070 XT in the same run the six reproduce with the counts above. So the HLSL fast-math difference shows up through the AMD driver only.

The 3060 has one difference of its own, v_cubetc_f32 (58 of 256): the HLSL result is a signed zero where the direct result keeps an f32 denormal, which looks like the same fast-math family (denormal flush instead of the sign of zero). Details and the cross-GPU comparison are in the run on #2169.

Head e792e6b on main 568e7db, debug. AI use: Claude Code (Claude Opus 5.5) ran the fuzzer on this machine and wrote this comment.

**@⁠DarkPanda69** on GitHub · 2026-11-25 07:37 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168#issuecomment-7156061308) NVIDIA data point (listed as untested here): on an RTX 3060 (driver 32.0.16.1088, Windows, so the split wave64 form), `valu_fuzz_backends_agree` from #2169 finds **none** of these six differences. HLSL and direct DXIL agree on `v_mul_f16`, `v_pk_mul_f16`, `v_ldexp_f16`, `v_sin_f16`, `v_sin_f32` and `v_cos_f32` for all 256 inputs. On an RX 9070 XT in the same run the six reproduce with the counts above. So the HLSL fast-math difference shows up through the AMD driver only. The 3060 has one difference of its own, `v_cubetc_f32` (58 of 256): the HLSL result is a signed zero where the direct result keeps an f32 denormal, which looks like the same fast-math family (denormal flush instead of the sign of zero). Details and the cross-GPU comparison are in the run on #2169. Head `e792e6b` on `main` `568e7db`, debug. AI use: Claude Code (Claude Opus 5.5) ran the fuzzer on this machine and wrote this comment.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 07:50 UTC · original

RX 6800M (RDNA2) follow-up on #2169's exact head e792e6b: I reproduced this issue's six default-HLSL differences with the same 8/19/26/49/4/7 counts (of 256 inputs per instruction). XCL_FUZZ_DXC_GIS=1 removed all six, but introduced differences in eight FMA-family instructions that matched without -Gis: V_DIV_FMAS_F32 (2), V_FMAC_F32 (2), V_FMAC_LEGACY_F32 (4), V_FMA_F16 (6), V_FMA_F32 (1), V_FMA_MIXHI_F16 (7), V_FMA_MIXLO_F16 (6), and V_PK_FMA_F16 (14), each out of 256. A focused rerun of those eight gave 0 differing instructions by default and 8 with -Gis, with identical per-instruction counts.

So -Gis is not a complete cross-backend parity fix on this GPU. The fuzzer compares HLSL with direct DXIL; this run did not check console reference results for the FMA cases. Full setup, logs summary, and limitations are in the #2169 report.

AI use: OpenAI Codex ran and repeated the tests and prepared this note.

**@⁠luckyteagirl** on GitHub · 2026-11-25 07:50 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168#issuecomment-7156304945) RX 6800M (RDNA2) follow-up on #2169's exact head `e792e6b`: I reproduced this issue's six default-HLSL differences with the same 8/19/26/49/4/7 counts (of 256 inputs per instruction). `XCL_FUZZ_DXC_GIS=1` removed all six, but introduced differences in **eight FMA-family instructions** that matched without `-Gis`: `V_DIV_FMAS_F32` (2), `V_FMAC_F32` (2), `V_FMAC_LEGACY_F32` (4), `V_FMA_F16` (6), `V_FMA_F32` (1), `V_FMA_MIXHI_F16` (7), `V_FMA_MIXLO_F16` (6), and `V_PK_FMA_F16` (14), each out of 256. A focused rerun of those eight gave 0 differing instructions by default and 8 with `-Gis`, with identical per-instruction counts. So `-Gis` is not a complete cross-backend parity fix on this GPU. The fuzzer compares HLSL with direct DXIL; this run did not check console reference results for the FMA cases. [Full setup, logs summary, and limitations are in the #2169 report](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2169). AI use: OpenAI Codex ran and repeated the tests and prepared this note.
Author
Owner

@⁠YaBulochka on GitHub · 2026-11-25 07:55 UTC · original

Linux status for this one, stated plainly: the cross-backend check cannot run here, so this is "not applicable", not a confirmation.

The comparison is done by executing the generated HLSL and the direct-DXIL form on a device (runner::run in crates/xcl/src/gpu/recomp/lower_dxil.rs, and runner::wave32_supported() gating in fuzz_tests.rs). On Linux our XCL builds are x86_64-pc-windows-gnu and there is no D3D12 device in the path - Wine has no WARP, and vkd3d-proton would be the "device", which is not what the test measures. So runner::wave32_supported() is false and the GPU half of these tests is skipped.

What I could do and did not, to be explicit: compile the same kernels with and without -Gis through DXC and diff the DXIL bytes. That would show whether the flag changes the module, but it would not answer your question - the difference you measured is in the executed result (-0 in f16, v_sin/v_cos), which needs the card.

If a Windows host is available to you, the useful extra data point would be the same fuzzer on RDNA3 natively: your data is RDNA4 (9070) and RDNA2 (gfx1036), and RDNA3 is the generation in between.

**@⁠YaBulochka** on GitHub · 2026-11-25 07:55 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168#issuecomment-7156402385) Linux status for this one, stated plainly: the cross-backend check cannot run here, so this is "not applicable", not a confirmation. The comparison is done by executing the generated HLSL and the direct-DXIL form on a device (`runner::run` in `crates/xcl/src/gpu/recomp/lower_dxil.rs`, and `runner::wave32_supported()` gating in `fuzz_tests.rs`). On Linux our XCL builds are `x86_64-pc-windows-gnu` and there is no D3D12 device in the path - Wine has no WARP, and vkd3d-proton would be the "device", which is not what the test measures. So `runner::wave32_supported()` is false and the GPU half of these tests is skipped. What I could do and did not, to be explicit: compile the same kernels with and without `-Gis` through DXC and diff the DXIL bytes. That would show whether the flag changes the module, but it would not answer your question - the difference you measured is in the executed result (`-0` in f16, v_sin/v_cos), which needs the card. If a Windows host is available to you, the useful extra data point would be the same fuzzer on RDNA3 natively: your data is RDNA4 (9070) and RDNA2 (gfx1036), and RDNA3 is the generation in between.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-25 10:43 UTC · original

Correction to this issue, with thanks to @⁠luckyteagirl for the full-run data: -Gis is not the fix. My -Gis check covered only the six differing instructions. The whole run on the RX 9070, at #2169's head e792e6b on 568e7db, shows the same as the RX 6800M:

HLSL build instructions differing from direct DXIL
default 6: v_cos_f32 8, v_ldexp_f16 19, v_mul_f16 26, v_pk_mul_f16 49, v_sin_f16 4, v_sin_f32 7
-Gis 9, all FMA-family: v_fma_f32 1, v_fmac_f32 2, v_fmac_legacy_f32 4, v_div_fmas_f32 2, v_fma_f16 6, v_pk_fma_f16 14, v_fma_mixlo_f16 6, v_fma_mixhi_f16 7, v_dot2_f32_f16 7

-Gis makes HLSL's mad an unfused multiply-add, so it trades the sign-of-zero differences for rounding ones in every fused op. A narrower direction would leave fusion alone: precise only on the f16 multiply / ldexp / sin results (or only where a zero can come out), so nsz cannot drop their sign. I have not measured that yet. The NVIDIA data above (no default-build differences on an RTX 3060) suggests the sign drop comes from AMD's compiler using nsz.

AI use: Claude Code (Claude Opus 5.5) ran both fuzzer builds on this machine and wrote this comment.

**@⁠alexdeliu** on GitHub · 2026-11-25 10:43 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168#issuecomment-7160086011) Correction to this issue, with thanks to @⁠luckyteagirl for the full-run data: **`-Gis` is not the fix.** My `-Gis` check covered only the six differing instructions. The whole run on the RX 9070, at #2169's head `e792e6b` on `568e7db`, shows the same as the RX 6800M: | HLSL build | instructions differing from direct DXIL | |---|---| | default | 6: `v_cos_f32` 8, `v_ldexp_f16` 19, `v_mul_f16` 26, `v_pk_mul_f16` 49, `v_sin_f16` 4, `v_sin_f32` 7 | | `-Gis` | 9, all FMA-family: `v_fma_f32` 1, `v_fmac_f32` 2, `v_fmac_legacy_f32` 4, `v_div_fmas_f32` 2, `v_fma_f16` 6, `v_pk_fma_f16` 14, `v_fma_mixlo_f16` 6, `v_fma_mixhi_f16` 7, `v_dot2_f32_f16` 7 | `-Gis` makes HLSL's `mad` an unfused multiply-add, so it trades the sign-of-zero differences for rounding ones in every fused op. A narrower direction would leave fusion alone: `precise` only on the f16 multiply / `ldexp` / `sin` results (or only where a zero can come out), so `nsz` cannot drop their sign. I have not measured that yet. The NVIDIA data above (no default-build differences on an RTX 3060) suggests the sign drop comes from AMD's compiler using `nsz`. AI use: Claude Code (Claude Opus 5.5) ran both fuzzer builds on this machine and wrote this comment.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-25 10:55 UTC · original

Measured the narrower direction from my last comment: precise only on the affected HLSL expressions, no -Gis. With it, the HLSL and direct-DXIL backends agree on every instruction on both AMD GPUs, and the FMA-family ops stay fused.

build RX 9070 (RDNA4) gfx1036 (RDNA2)
default 6 differ 6 differ
-Gis 9 differ (FMA family) (RX 6800M: 8, @⁠luckyteagirl)
precise helpers below 0 differ 0 differ

valu_fuzz_backends_agree from #2169 at e792e6b on 568e7db: 341 instructions, 333 compared, 8 refused by both. cargo test --workspace -- --test-threads=4 with the change (RX 9070): 1152 passed, 2 failed (seeds 722 / 1599, as on main), 48 ignored.

The change: four small helpers whose result is precise (so nsz / reassociation cannot touch it), used by v_mul_f16, v_pk_mul_f16, v_ldexp_f16 and v_sin / v_cos (f16 and f32):

--- a/crates/xcl/src/gpu/recomp/emit.rs
+++ b/crates/xcl/src/gpu/recomp/emit.rs
@@ -3199,7 +3199,7 @@ impl Em {
             let curh = if hi { format!("({cur} >> 16)") } else { format!("({cur} & 0xFFFFu)") };
             Some(match name {
                 "v_pk_add_f16" => fr(format!("{} + {}", fh(0, hi), fh(1, hi))),
-                "v_pk_mul_f16" => fr(format!("{} * {}", fh(0, hi), fh(1, hi))),
+                "v_pk_mul_f16" => fr(format!("xcl_pmul({}, {})", fh(0, hi), fh(1, hi))),
                 "v_pk_fma_f16" => fr(format!("mad({}, {}, {})", fh(0, hi), fh(1, hi), fh(2, hi))),
                 "v_pk_fmac_f16" => fr(format!("mad({}, {}, f16tof32({curh}))", fh(0, hi), fh(1, hi))),
                 "v_pk_min_f16" => fr(format!("min({}, {})", fh(0, hi), fh(1, hi))),
@@ -3389,7 +3389,7 @@ impl Em {
             "v_add_f16" => fr(format!("{} + {}", fh(0), fh(1))),
             "v_sub_f16" => fr(format!("{} - {}", fh(0), fh(1))),
             "v_subrev_f16" => fr(format!("{} - {}", fh(1), fh(0))),
-            "v_mul_f16" => fr(format!("{} * {}", fh(0), fh(1))),
+            "v_mul_f16" => fr(format!("xcl_pmul({}, {})", fh(0), fh(1))),
             "v_min_f16" => fr(format!("min({}, {})", fh(0), fh(1))),
             "v_max_f16" => fr(format!("max({}, {})", fh(0), fh(1))),
             "v_fma_f16" => fr(format!("mad({}, {}, {})", fh(0), fh(1), fh(2))),
@@ -3413,14 +3413,14 @@ impl Em {
             "v_fmac_f16" => fr(format!("mad({}, {}, f16tof32({curh}))", fh(0), fh(1))),
             "v_fmamk_f16" => fr(format!("mad({}, f16tof32({} & 0xFFFFu), {})", fh(0), u[1], fh(2))),
             "v_fmaak_f16" => fr(format!("mad({}, {}, f16tof32({} & 0xFFFFu))", fh(0), fh(1), u[2])),
-            "v_ldexp_f16" => fr(format!("ldexp({}, (float){})", fh(0), si(1))),
+            "v_ldexp_f16" => fr(format!("xcl_pldexp({}, (float){})", fh(0), si(1))),
             "v_rcp_f16" => fr(format!("rcp({})", fh(0))),
             "v_rsq_f16" => fr(format!("rsqrt({})", fh(0))),
             "v_sqrt_f16" => fr(format!("sqrt({})", fh(0))),
             "v_log_f16" => fr(format!("log2({})", fh(0))),
             "v_exp_f16" => fr(format!("exp2({})", fh(0))),
-            "v_sin_f16" => fr(format!("sin({} * 6.2831853f)", fh(0))),
-            "v_cos_f16" => fr(format!("cos({} * 6.2831853f)", fh(0))),
+            "v_sin_f16" => fr(format!("xcl_psin({})", fh(0))),
+            "v_cos_f16" => fr(format!("xcl_pcos({})", fh(0))),
             "v_fract_f16" => fr(format!("fract_f({})", fh(0))),
             "v_floor_f16" => fr(format!("floor({})", fh(0))),
             "v_ceil_f16" => fr(format!("ceil({})", fh(0))),
@@ -3757,8 +3757,8 @@ impl Em {
             "v_sqrt_f32" => fr(format!("sqrt({})", fs(0))),
             "v_exp_f32" => fr(format!("exp2({})", fs(0))),
             "v_log_f32" => fr(format!("log2({})", fs(0))),
-            "v_sin_f32" => fr(format!("sin({} * 6.2831853f)", fs(0))),
-            "v_cos_f32" => fr(format!("cos({} * 6.2831853f)", fs(0))),
+            "v_sin_f32" => fr(format!("xcl_psin({})", fs(0))),
+            "v_cos_f32" => fr(format!("xcl_pcos({})", fs(0))),
             "v_fract_f32" => fr(format!("fract_f({})", fs(0))),
             "v_trunc_f32" => fr(format!("trunc({})", fs(0))),
             "v_floor_f32" => fr(format!("floor({})", fs(0))),
@@ -5829,6 +5829,10 @@ void put_bits(inout uint4 r, uint off, uint w, uint v) {
     or_at4(r, i, v << s);
     if (s != 0u && s + w > 32u && i < 3u) or_at4(r, i + 1u, v >> (32u - s));
 }
+float xcl_pmul(float a, float b) { precise float r = a * b; return r; }
+float xcl_pldexp(float a, float b) { precise float r = ldexp(a, b); return r; }
+float xcl_psin(float a) { precise float r = sin(a * 6.2831853f); return r; }
+float xcl_pcos(float a) { precise float r = cos(a * 6.2831853f); return r; }
 uint f16_rtz(float f) { uint h = f32tof16(f) & 0xFFFFu; return h - (uint)and(and(!isnan(f), (h & 0x7FFFu) != 0u), abs(f16tof32(h)) > abs(f)); }
 uint fmt_encode(uint x, uint info, uint c) {
     uint ty = (info >> 3) & 7u; uint w = (info >> (8u + 6u * c)) & 63u; float f = asfloat(x);

It touches recomp/emit.rs, so a PR needs a smoke run on a real title, which I cannot do here. Anyone with a title is welcome to take it, or I can open it once someone runs scripts/smoke.ps1 on it. Not tested: NVIDIA (the RTX 3060 run above already had no default-build differences), and the shader-size or performance cost of precise on real shaders.

AI use: Claude Code (Claude Opus 5.5) wrote the change, ran both fuzzer builds and the suite on this machine, and wrote this comment.

**@⁠alexdeliu** on GitHub · 2026-11-25 10:55 UTC · [original](https://github.com/xcl-dev/xcl/issues/2168#issuecomment-7160343662) Measured the narrower direction from my last comment: **`precise` only on the affected HLSL expressions, no `-Gis`**. With it, the HLSL and direct-DXIL backends agree on every instruction on both AMD GPUs, and the FMA-family ops stay fused. | build | RX 9070 (RDNA4) | gfx1036 (RDNA2) | |---|---|---| | default | 6 differ | 6 differ | | `-Gis` | 9 differ (FMA family) | (RX 6800M: 8, @⁠luckyteagirl) | | **`precise` helpers below** | **0 differ** | **0 differ** | `valu_fuzz_backends_agree` from #2169 at `e792e6b` on `568e7db`: 341 instructions, 333 compared, 8 refused by both. `cargo test --workspace -- --test-threads=4` with the change (RX 9070): 1152 passed, 2 failed (seeds 722 / 1599, as on `main`), 48 ignored. The change: four small helpers whose result is `precise` (so `nsz` / reassociation cannot touch it), used by `v_mul_f16`, `v_pk_mul_f16`, `v_ldexp_f16` and `v_sin` / `v_cos` (f16 and f32): ```diff --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -3199,7 +3199,7 @@ impl Em { let curh = if hi { format!("({cur} >> 16)") } else { format!("({cur} & 0xFFFFu)") }; Some(match name { "v_pk_add_f16" => fr(format!("{} + {}", fh(0, hi), fh(1, hi))), - "v_pk_mul_f16" => fr(format!("{} * {}", fh(0, hi), fh(1, hi))), + "v_pk_mul_f16" => fr(format!("xcl_pmul({}, {})", fh(0, hi), fh(1, hi))), "v_pk_fma_f16" => fr(format!("mad({}, {}, {})", fh(0, hi), fh(1, hi), fh(2, hi))), "v_pk_fmac_f16" => fr(format!("mad({}, {}, f16tof32({curh}))", fh(0, hi), fh(1, hi))), "v_pk_min_f16" => fr(format!("min({}, {})", fh(0, hi), fh(1, hi))), @@ -3389,7 +3389,7 @@ impl Em { "v_add_f16" => fr(format!("{} + {}", fh(0), fh(1))), "v_sub_f16" => fr(format!("{} - {}", fh(0), fh(1))), "v_subrev_f16" => fr(format!("{} - {}", fh(1), fh(0))), - "v_mul_f16" => fr(format!("{} * {}", fh(0), fh(1))), + "v_mul_f16" => fr(format!("xcl_pmul({}, {})", fh(0), fh(1))), "v_min_f16" => fr(format!("min({}, {})", fh(0), fh(1))), "v_max_f16" => fr(format!("max({}, {})", fh(0), fh(1))), "v_fma_f16" => fr(format!("mad({}, {}, {})", fh(0), fh(1), fh(2))), @@ -3413,14 +3413,14 @@ impl Em { "v_fmac_f16" => fr(format!("mad({}, {}, f16tof32({curh}))", fh(0), fh(1))), "v_fmamk_f16" => fr(format!("mad({}, f16tof32({} & 0xFFFFu), {})", fh(0), u[1], fh(2))), "v_fmaak_f16" => fr(format!("mad({}, {}, f16tof32({} & 0xFFFFu))", fh(0), fh(1), u[2])), - "v_ldexp_f16" => fr(format!("ldexp({}, (float){})", fh(0), si(1))), + "v_ldexp_f16" => fr(format!("xcl_pldexp({}, (float){})", fh(0), si(1))), "v_rcp_f16" => fr(format!("rcp({})", fh(0))), "v_rsq_f16" => fr(format!("rsqrt({})", fh(0))), "v_sqrt_f16" => fr(format!("sqrt({})", fh(0))), "v_log_f16" => fr(format!("log2({})", fh(0))), "v_exp_f16" => fr(format!("exp2({})", fh(0))), - "v_sin_f16" => fr(format!("sin({} * 6.2831853f)", fh(0))), - "v_cos_f16" => fr(format!("cos({} * 6.2831853f)", fh(0))), + "v_sin_f16" => fr(format!("xcl_psin({})", fh(0))), + "v_cos_f16" => fr(format!("xcl_pcos({})", fh(0))), "v_fract_f16" => fr(format!("fract_f({})", fh(0))), "v_floor_f16" => fr(format!("floor({})", fh(0))), "v_ceil_f16" => fr(format!("ceil({})", fh(0))), @@ -3757,8 +3757,8 @@ impl Em { "v_sqrt_f32" => fr(format!("sqrt({})", fs(0))), "v_exp_f32" => fr(format!("exp2({})", fs(0))), "v_log_f32" => fr(format!("log2({})", fs(0))), - "v_sin_f32" => fr(format!("sin({} * 6.2831853f)", fs(0))), - "v_cos_f32" => fr(format!("cos({} * 6.2831853f)", fs(0))), + "v_sin_f32" => fr(format!("xcl_psin({})", fs(0))), + "v_cos_f32" => fr(format!("xcl_pcos({})", fs(0))), "v_fract_f32" => fr(format!("fract_f({})", fs(0))), "v_trunc_f32" => fr(format!("trunc({})", fs(0))), "v_floor_f32" => fr(format!("floor({})", fs(0))), @@ -5829,6 +5829,10 @@ void put_bits(inout uint4 r, uint off, uint w, uint v) { or_at4(r, i, v << s); if (s != 0u && s + w > 32u && i < 3u) or_at4(r, i + 1u, v >> (32u - s)); } +float xcl_pmul(float a, float b) { precise float r = a * b; return r; } +float xcl_pldexp(float a, float b) { precise float r = ldexp(a, b); return r; } +float xcl_psin(float a) { precise float r = sin(a * 6.2831853f); return r; } +float xcl_pcos(float a) { precise float r = cos(a * 6.2831853f); return r; } uint f16_rtz(float f) { uint h = f32tof16(f) & 0xFFFFu; return h - (uint)and(and(!isnan(f), (h & 0x7FFFu) != 0u), abs(f16tof32(h)) > abs(f)); } uint fmt_encode(uint x, uint info, uint c) { uint ty = (info >> 3) & 7u; uint w = (info >> (8u + 6u * c)) & 63u; float f = asfloat(x); ``` It touches `recomp/emit.rs`, so a PR needs a smoke run on a real title, which I cannot do here. Anyone with a title is welcome to take it, or I can open it once someone runs `scripts/smoke.ps1` on it. Not tested: NVIDIA (the RTX 3060 run above already had no default-build differences), and the shader-size or performance cost of `precise` on real shaders. AI use: Claude Code (Claude Opus 5.5) wrote the change, ran both fuzzer builds and the suite on this machine, and wrote this comment.
This discussion has been locked. Commenting is limited to contributors.
No description provided.