Skip to content

Recompiler: f16 add / sub / fma rounded once under a directed mode (#… - #128

Open
gbuyssens wants to merge 1 commit into
xcl-dev:mainfrom
gbuyssens:pr/f16-directed-rounding
Open

gbuyssens wants to merge 1 commit into
xcl-dev:mainfrom
gbuyssens:pr/f16-directed-rounding

Conversation

@gbuyssens

Copy link
Copy Markdown
Contributor

…111)

Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak, the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24 needs 25 bits) the first rounding could land exactly on a binary16 value and the directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console gives 1 + 2^-10).

  • PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops, so the other programs' HLSL is unchanged): f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16 rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm / fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in f32), fma_mix_f16_rm from a double TwoSum (f32 sources). OMOD and CLAMP apply to the result and its error before the rounding.
  • v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm and mad_nf_f16 go.
  • is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil / trunc / rndne / fract, min / max, frexp_mant) no longer make s_round_mode unsupported.
  • GPU tests: the helpers lane by lane, and the ISA forms under the four modes (the f16 add / FMA under a directed rounding mode are rounded twice (through f32) #111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on a binary16 midpoint, OMOD and CLAMP).

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Holding this one: its own GPU test fails on an RX 9070 (RDNA4), in the PR as it is (without merging anything else): lane 0 mode 0x4: v_sub_f16 – left 813710337 (0x30804001), right 15361 (0x3C01) (gpu_f16_add_and_fma_round_once_under_directed_modes, tests.rs:5791). Note both halves are off, the high half too. Which GPU did you run it on? (#111 stays open; @gefydev offered to take it as well.)

@gbuyssens
gbuyssens force-pushed the pr/f16-directed-rounding branch from 1c4f1e2 to 34dbc3b Compare November 23, 2026 14:21
@Foniass

Foniass commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested on an NVIDIA RTX 5070 Ti (32-lane waves, driver 621.14), merged onto origin/main (95bda11, fast-forward).

NVIDIA and denormals: this is fine. With DXC's default -denorm any this GPU does flush f32 results below the normal range (precise 2⁻⁷⁰ × 2⁻⁷⁰ → 0). But the f32 TwoSum here only handles multiples of 2⁻⁴⁸ (2⁻⁴⁹ after OMOD ×0.5), so the flush never reaches it, and f32↔f64 conversions keep denormals. Over 21 M random f16 add vectors × 4 modes, the GPU matches an exact CPU reference (big-integer value, rounded once), apart from the sign of zero (see 5).

Verified on the GPU

  1. Regression under RNE: a result just below 65536 rounds to 65504 instead of inf. In f32_to_f16_rm_sticky the overflow branch's tie case compares with 0x47800000 (65536). An f32 result of exactly 65536 with a negative error is really in (65520, 65536) and must round to inf under RNE. main gives 0x7C00 for all of these:

    instruction inputs PR correct (= main)
    v_fma_f16 0x5C00 × 0x5C00 + 0x8001 (256·256 − 2⁻²⁴) 0x7BFF 0x7C00
    v_fmac_f16 same 0x7BFF 0x7C00
    v_pk_fma_f16 same, both halves 0x7BFF7BFF 0x7C007C00
    v_add_f16 OMOD ×2 0x7800 + 0x8001 0x7BFF 0x7C00
    v_fma_mixlo_f16 1.0f × 65536.0f + (−2⁻³⁰) 0x7BFF 0x7C00
    • Where it applies: programs that change the mode while running under RNE, which is also the state before their first s_round_mode. A random run found 674 add+OMOD, 76 fma and 7 514 fma_mix cases, all of this kind, negative values included.
    • Suggested fix: in that branch, if (rm == 0u) return sign | 0x7C00u;. The probe at 0x477FF000 takes the normal path, so it never reaches this branch.
  2. v_fract_f64 is listed as exact, but it isn't. RDNA2 defines it as x − floor(x), which rounds for negative x.

    • Example: fract(0xBFD0000000000001) under RTZ gives 0x3FE8000000000000; RTZ is 0x3FE7FFFFFFFFFFFF.
    • main reported s_round_mode 0xC + v_fract_f64 as unsupported; with this PR it translates and computes in RNE. The retail pack doesn't hit it, but v_fract_f64 should probably leave the exact list.
  3. gpu_s_round_mode_controls_f16_rounding_across_modes fails here (lane 17): v_fma_mixlo_f16(−0.0, 1.0, +0.0) under RNE gives 0x0000, and the test expects 0x8000. The PR is right: by IEEE fma(−0, 1, +0) is +0. The test reuses the conversion table, which expects −0. main probably passed because DXC simplified mad(x, 1, 0) to x. With lane 17's v22 / v25 expected as 0x0000, it passes. If it passes on AMD, that may mean the precise +0 is being dropped there.

Also present on main (not regressions)

  1. fma_mix_f16_rm, f32 range limits: the product is exact in a double, but its f32 rounding can overflow or underflow.
    • 2¹⁰⁰f × 2¹⁰⁰f under RTZ gives 0x7C00 instead of 0x7BFF (84 862 random cases).
    • When the f32 result is 0, if (ax == 0u) return sign; drops the error: 2⁻¹⁰⁰f × 2⁻¹⁰⁰f under +inf gives 0x0000 instead of 0x0001 (59 211 cases). The f32-denormal case (2⁻⁷⁰ × 2⁻⁷⁰ under +inf → 0x0001) is fixed by this PR.
  2. Zero sign under −inf: exact cancellation gives +0 where IEEE gives −0 (v_add_f16 0x3C00 + 0xBC00).

Other checks

  • HLSL of other programs: for the 21 922 retail programs that don't use the new rounding, the HLSL is identical except that f32_to_f16_rm / mad_nf_f16 leave the shared prelude. Behaviour is the same, but the text changes, so every program's DXIL cache entry is rebuilt once.
  • Test counts: with XCL_SAMPLE_RPF, main gives 517 passed / 0 failed in the lib tests, and this PR 517 passed / 1 failed (3 above). Every other test binary has the same counts, and XCL_SPLIT_WAVE64=1 gives the same result. The PR's new GPU tests run on this card; they are not skipped.

gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
…vall#111)

Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak,
the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to
binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24
needs 25 bits) the first rounding could land exactly on a binary16 value and the
directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console
gives 1 + 2^-10).

- PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself
  is unchanged, so no other program's HLSL or DXIL cache entry changes):
  f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16
  rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm /
  fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in
  f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is
  brought to 2^17 / 2^-40 first – the mode alone decides there). OMOD and CLAMP apply to
  the result and its error before the rounding. An exactly zero sum takes IEEE's sign
  (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode).
- v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes.
- is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil /
  trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported
  (v_fract_f64 = x - floor(x) rounds for a negative x and stays).
- GPU tests: the helpers lane by lane (the ivall#128 review's cases: 65536 - 2^-24 under RNE
  overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the
  four modes (the ivall#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on
  a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes:
  fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
@gbuyssens
gbuyssens force-pushed the pr/f16-directed-rounding branch from 34dbc3b to 19fc146 Compare November 23, 2026 14:52
gbuyssens added a commit to gbuyssens/xcl that referenced this pull request Nov 23, 2026
…vall#111)

Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak,
the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to
binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24
needs 25 bits) the first rounding could land exactly on a binary16 value and the
directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console
gives 1 + 2^-10).

- PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself
  is unchanged, so no other program's HLSL or DXIL cache entry changes):
  f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16
  rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm /
  fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in
  f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is
  brought to 2^17 / 2^-40 first – the mode alone decides there). OMOD and CLAMP apply to
  the result and its error before the rounding. An exactly zero sum takes IEEE's sign
  (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode).
- v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes.
- is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil /
  trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported
  (v_fract_f64 = x - floor(x) rounds for a negative x and stays).
- GPU tests: the helpers lane by lane (the ivall#128 review's cases: 65536 - 2^-24 under RNE
  overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the
  four modes (the ivall#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on
  a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes:
  fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
@gbuyssens
gbuyssens force-pushed the pr/f16-directed-rounding branch from 19fc146 to 49ee291 Compare November 23, 2026 15:38
@tronLives111

Copy link
Copy Markdown

A follow-up case for #111: default round-to-nearest-even can also double-round a fused half-precision multiply-add. On 49ee291, emit.rs still uses mad followed by f32tof16 when the shader never writes a non-default MODE[3:2] (see lines 456, 534, and 2854). That looks like pre-existing behavior outside this PR’s directed-mode fix.

I checked these binary16 bit patterns using native AArch64 half-precision FMADD and, separately, binary32 fmaf followed by a binary16 conversion on Apple Silicon. All nonzero inputs are normal.

a b c Single-round f16 f32 then f16
0x6A00 0x3C01 0x8400 0x6A01 0x6A02
0x6A00 0x3C03 0x0400 0x6A05 0x6A04

The exact sums sit just below and above their respective half-precision midpoints. The binary32 intermediate lands exactly on each midpoint, so ties-to-even picks the wrong neighbor. With c = 0, both paths agree on the even neighbor in each case. A v_fma_f16 fixture with no s_round_mode would exercise the default emitter path. CPU arithmetic and source inspection only, no XCL GPU run or game data. AI-assisted review.

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Not merged yet: with this PR on current main, gpu_s_round_mode_controls_f16_rounding_across_modes fails on an RX 9070 (RDNA4): lane 18 (0x7f800000) v_fma_mixlo_f16 RTZ: left 31743, right 31744 - an infinite f32 input under RTZ comes out as 0x7BFF instead of 0x7C00 (infinity stays infinity in every mode). Could you look at the fma path for an infinite input (the TwoSum error is NaN there) and rebase on main?

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The RX 9070 failure reproduces on NVIDIA Turing through vkd3d-proton / dxil-spirv (lane 18 (0x7f800000) v_fma_mixlo_f16 RTZ, left 31743, right 31744), so it's the HLSL, not RDNA4. The test is right: an infinite operand is an exact infinity in every mode. The clamp @RemingtonWilcox pointed at in fma_mix_f16_rm is the cause. Clamping only finite sums fixes it here (false for ±inf and NaN; HLSL has no isinf on a double):

if (sa > 131072.0 && sa <= 1.7976931348623157e308) s = select(s < 0.0, -131072.0, 131072.0);

Tested

Not tested

  • AMD.
  • Foniass's RNE case near 65536 and tronLives111's default-mode double rounding; both are separate from this line.

🤖 Claude Opus 5.5

@srcamarda

Copy link
Copy Markdown
Contributor

AMD run, as asked: RDNA3 Radeon RX 7800 XT, driver 32.0.32029.2010, Windows 11 26300, native 64-lane waves, DXC 1.8.2502.11, debug build. 49ee291 merged onto main 60565c4 (clean merge).

f16 filter cargo test -p xcl --lib XCL_SPLIT_WAVE64=1
as merged 12 passed, 1 failed 611 passed, 1 failed 611 passed, 1 failed
+ @Kalmarv's line 13 passed, 0 failed 612 passed, 0 failed 612 passed, 0 failed
  • The one failure as merged is the RX 9070's: gpu_s_round_mode_controls_f16_rounding_across_modes, lane 18 (0x7f800000) v_fma_mixlo_f16 RTZ, left 31743, right 31744. So it shows on RDNA3 as on RDNA4 and Turing. Clamping only finite sums in fma_mix_f16_rm fixes it here as well (same line as Kalmarv's, with a comment; diff below).
  • The original RDNA4 failure does not reproduce here: gpu_f16_add_and_fma_round_once_under_directed_modes (lane 0 mode 0x4: v_sub_f16) passes on the RX 7800 XT, as it does on Turing.
  • Lane 17 (fma(-0, 1, +0) → +0) passes here, so AMD keeps the precise +0.
  • Foniass's points 1 (RNE overflow near 65536) and 2 (v_fract_f64 off the exact list) are in 49ee291 already.
-    if (sa > 131072.0) s = select(s < 0.0, -131072.0, 131072.0);
+    // (finite sums only: an infinite operand gives an exact infinity in every mode; HLSL has no
+    // isinf on a double, and a NaN fails both compares)
+    if (sa > 131072.0 && sa <= 1.7976931348623157e308) s = select(s < 0.0, -131072.0, 131072.0);

Not covered: RDNA4 with the line (whether the RX 9070's v_sub_f16 failure is still there on the current head), and the open points that predate this PR (@tronLives111's default-mode double rounding of fused f16 multiply-adds, and Foniass's 4 and 5).

@WarmMilkCodes

Copy link
Copy Markdown
Contributor

Tested #128 49ee291 merged onto main 9ab7d76 on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): fail – one test on main now fails

cargo test --workspace --no-fail-fast -- --test-threads=4: main 651 passed / 0 failed; this 651 passed / 1 failed:

gpu::recomp::tests::gpu_s_round_mode_controls_f16_rounding_across_modes
assertion `left == right` failed: lane 18 (0x7f800000) v_fma_mixlo_f16 RTZ
  left: 31743
 right: 31744

That test came to main with 93072dc ("handle s_round_mode/s_setreg*"), after this branch's base (129 commits behind), so it won't show on the branch itself. Lane 18 is +inf: under RTZ, v_fma_mixlo_f16 now gives 0x7BFF (max finite) instead of 0x7C00 (+inf), which the test's table expects for +inf in every mode. Looks like the directed-mode path for the fma_mix forms clamps overflow to the largest finite value without letting an infinite input through – RTZ should only clamp finite results that overflow. Probably not GPU-specific; it should reproduce anywhere after a rebase.

@PHeitor1

Copy link
Copy Markdown

Tested 49ee291 merged onto main 9ab7d76 on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*. Baseline main 9ab7d76: 651 passed, 0 failed, 40 ignored.

Fail, same as on RDNA2 above (so not GPU-specific): 651 passed, 1 failed ? gpu_s_round_mode_controls_f16_rounding_across_modes, lane 18 (0x7f800000) v_fma_mixlo_f16 RTZ: 31743 (0x7BFF) vs 31744 (0x7C00).

Cause: in fma_mix_f16_rm an infinite sum reaches the out-of-range clamp (if (sa > 131072.0) s = ?131072.0) and becomes a finite overflow, which RTZ rounds to 65504. A guard before the clamp fixes it:

    // an infinite or NaN source gives an infinite or NaN sum, which is not an overflow: no mode
    // turns it into a finite value (the f32 sources are checked: HLSL's isinf takes a float, and
    // a finite double sum such as 2^200 would test as infinite)
    if (any(isinf(float3(a, b, c))) || any(isnan(float3(a, b, c)))) return f16_result_rm((float)s, 0.0f, 1.0f, clamp, rm);

Note the check is on the f32 sources: my first try, isinf(s) on the double, broke this PR's own fma_mix_f16_rm(2^100, 2^100, 0, false, 3u) case (expects 0x7BFF) because HLSL's isinf converts the double 2^200 to a float first.

With the guard on the same merge: cargo test -p xcl --lib f16: 13 passed, 0 failed; whole suite 652 passed, 0 failed, 40 ignored. GPU skips: the same 2 as on main (no wave64).

Not tested: AMD with the guard; no game.

Run and written with Claude Code (Claude Opus 5.5).

@ic3bear-ai

Copy link
Copy Markdown

A note for this PR from #111 (the details and numbers are there): on an RTX 3070 the default mode is wrong for these instructions too, so this PR may want to cover it as well.

  • Without a dynamic mode, to_f16_expr emits the legacy f32tof16, which truncates on that GPU: about 30 % of random v_add/sub_f16 and v_pk_add_f16 results are one ulp off, and the fma forms too.
  • For fma, RNE double rounding through f32 is also wrong in rare tie cases, so the fma fix is needed in the default mode, not only the directed ones.

What fixed both locally: round-to-odd in binary32 (TwoSum, then the sticky lowest bit), then f32_to_f16_rm, one helper for every mode. I haven't checked it against the infinite-input RTZ case this PR is held on.

I'd rather not open a PR that conflicts with this one. The exact-reference test is in #111, if it helps.

Comment written with Claude Code (Claude Opus 5.5); I checked the results.

…cl-dev#111)

Under s_round_mode MODE[3:2] != RNE the f16 add, sub, fma (also fmac / fmamk / fmaak,
the packed forms and v_fma_mix*_f16) computed in f32 with RNE and then converted to
binary16 in the requested mode: when the exact result does not fit f32 (1.0 + 2^-24
needs 25 bits) the first rounding could land exactly on a binary16 value and the
directed rounding had nothing left to do (1.0 + 2^-24 under +inf gave 1.0; the console
gives 1 + 2^-10).

- PRELUDE_F16_RM (only in programs that change MODE[3:2] and have f16 ops; PRELUDE itself
  is unchanged, so no other program's HLSL or DXIL cache entry changes):
  f32_to_f16_rm_sticky folds the sign of the f32 result's rounding error into the binary16
  rounding – on a binary16 value or midpoint it decides the direction; add_f16_rm /
  fma_f16_rm get that error from a TwoSum (the product of two binary16 values is exact in
  f32), fma_mix_f16_rm from a double TwoSum (f32 sources; a double beyond f32's range is
  brought to 2^17 / 2^-40 first – the mode alone decides there). An infinite or NaN source gives inf / NaN
  under every mode (the review's lane 18: +inf under RTZ was taken for a finite overflow and
  gave 65504). OMOD and CLAMP apply to
  the result and its error before the rounding. An exactly zero sum takes IEEE's sign
  (x + -x is +0, -0 under -inf; the f32 sum's RNE zero ignored the mode).
- v_mad_f16 does not exist on RDNA2 (not in the ISA tables): its arm goes.
- is_f64_rounded_op: exact f64 ops (conversions from f32 / i32 / u32, floor / ceil /
  trunc / rndne, min / max, frexp_mant) no longer make s_round_mode unsupported
  (v_fract_f64 = x - floor(x) rounds for a negative x and stays).
- GPU tests: the helpers lane by lane (the xcl-dev#128 review's cases: 65536 - 2^-24 under RNE
  overflows, mix results beyond f32's range, the zero's sign), and the ISA forms under the
  four modes (the xcl-dev#111 cases, the overflow and subnormal edges, a fma whose f32 sum ties on
  a binary16 midpoint, OMOD and CLAMP). gpu_s_round_mode_controls_f16_rounding_across_modes:
  fma(-0, 1, +0) is +0 (DXC's mad(x, 1, 0) folded to x before).
@gbuyssens
gbuyssens force-pushed the pr/f16-directed-rounding branch from 49ee291 to 2bc03fa Compare November 24, 2026 17:35
@vladbondarenko97

Copy link
Copy Markdown
Contributor

A data point for this PR from NVIDIA, where the default (round-to-nearest-even) case is wrong on main today, not only directed modes: on an RTX 3080 Ti (wave32, Windows 11, DXC 1.9.2602.17), the HLSL path's f16 add/sub/fma/fmac/ldexp and v_pk_add_f16/v_pk_fma_f16 results go through to_f16_expr → f32tof16, which rounds toward zero on this driver. Examples from GPU tests against Rust-computed RDNA2 results: v_add_f16(0x3C01, 2^-11) (a tie) gives 0x3C01, expected 0x3C02; v_pk_add_f16 high half lane 0 gives 0xbfff, expected 0xc000; v_ldexp_f16 into denormals lane 15 gives 0x207, expected 0x208. v_mul_f16 / v_pk_mul_f16 are right (they use f32_to_f16_rm). AMD drivers likely round to nearest already, so an RDNA4 run may not show this. The test programs are on vladbondarenko97/xcl recomp/f16-tests (1a08c39); I have not run this PR's head yet.

AI use: Claude Code (Claude Opus 5.5) wrote and ran the GPU tests and this note.

@joeypercia

Copy link
Copy Markdown

#842 fixes this default-mode case: to_f16_expr rounds to nearest even with f32_to_f16_rm(e, 0u), the helper the multiplies already use, so add/sub/fma/ldexp and the packed ops round to nearest even. On AMD it isn't different: the RDNA2 iGPU of a 7800X3D truncates the same way on main (#842's Tested has both GPUs). #842 also covers v_interp_p2_f16 and v_fma_mixlo/mixhi_f16.

AI use: Claude Code (Claude Opus 5.5) drafted this note.

@malzaharhub-ctrl

Copy link
Copy Markdown

Independent AMD GPU validation — RX 7900 XTX

Tested PR #128 at commit 2bc03fa2767727ca2a52c9a8d53c475c1fd7a346.

Hardware and environment

  • Windows 11 Pro, build 26300
  • AMD Ryzen 7 5800X
  • AMD Radeon RX 7900 XTX, 24 GB
  • AMD driver 32.0.32029.2010 (18 November 2026)
  • Rust 1.100.0
  • DXC / DXIL 1.9.2602.17

Targeted f16 GPU tests

Both tests passed with XCL_REQUIRE_GPU=wave64:

  • gpu_s_round_mode_controls_f16_rounding_across_modes: 1 passed.
  • gpu_f16_add_and_fma_round_once_under_directed_modes: 1 passed.

F16-filtered library tests

cargo test --locked -p xcl --lib f16 -- --test-threads=1 --nocapture

Result: 13 passed, 0 failed.

Note: this name filter also includes four UTF-16-related tests.

Full GPU recompiler test group

cargo test --locked -p xcl --lib gpu::recomp -- --test-threads=1 --show-output

Result:

  • 193 passed
  • 0 failed
  • 18 ignored
  • Runtime: 20.54 seconds

Run with XCL_REQUIRE_GPU=wave64.

Full workspace validation

Ran scripts/test.ps1.

Result: exit code 0.

One optional GPU test was skipped because the adapter does not support heap windows.

The repository working tree remained clean. No source changes were made.

I have not tested any game files.

AI assistance disclosure: ChatGPT assisted with interpreting test results and drafting this report. I independently executed the commands and tests on my hardware and verified the results.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
The HLSL path converted the f32 result of v_add / sub / subrev / fma /
fmac / fmamk / fmaak / ldexp_f16 and v_pk_add / pk_fma / pk_fmac_f16 with
f32tof16, which rounds toward zero on NVIDIA (RDNA2's default is nearest
even). Only v_mul_f16 / v_pk_mul_f16 used f32_to_f16_rm. Measured on an
RTX 3080 Ti: v_add_f16(0x3C01, 2^-11) gave 0x3C01 (want 0x3C02),
v_pk_add_f16 hi lane 0xbfff (want 0xc000), v_ldexp_f16 into the
denormals 0x207 (want 0x208).

add / sub / ldexp are exact enough in binary32 (2p+2 bits), so they go
through the same rounded conversion as v_mul_f16. fma needs one rounding:
fma_rto computes the exact product, the TwoSum error of the sum, and
rounds the f32 result to odd, so the later binary16 rounding sees the
exact value's side of every tie (fma(0x3C01, 0x0FFE, 0x3C01) is 0x3C01;
an RNE f32 sum gives 0x3C02).

v_cvt_f16_u16 / i16 (xcl-dev#515), the directed modes (xcl-dev#128) and
v_fma_mix*_f16 are not touched.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hri58aiQKmMwqS6K8CHq2s
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 2bc03fa2 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 2bc03fa2767727ca2a52c9a8d53c475c1fd7a346
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14813 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@JJAutoCompare

Copy link
Copy Markdown

Tested

I ran both checked-in f16 rounding fixtures from a clean checkout of 2bc03fa2767727ca2a52c9a8d53c475c1fd7a346. Afterward GitHub still showed PR #128 open at that exact head.

Intel Arc A770 (driver 32.0.101.9175), AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 26200.9974, Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), and loaded DXC/DXIL 1.9.2609.5. Cargo test profile was unoptimized with debug info disabled.

$env:CARGO_TARGET_DIR='L:/XclTooling/pr1512-tiling-edges-fddfa267/target'
$env:CARGO_BUILD_JOBS='2'
$env:CARGO_INCREMENTAL='0'
$env:CARGO_PROFILE_DEV_DEBUG='0'
$env:CARGO_PROFILE_TEST_DEBUG='0'
$env:TEMP='L:/XclTooling/pr128/run-2bc03fa-20261125-035429-077/temp'
$env:TMP=$env:TEMP
$env:XCL_ADAPTER='A770'
$env:XCL_DXC_DIR="$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64"
& 'C:/Users/ljensen/.cargo/bin/cargo.exe' test --locked -p xcl --lib --no-run --message-format=json

# Executable reported by Cargo. The Arc lock covered only execution.
# The lock wrapper ran in a PowerShell process launched with -NoProfile -ExecutionPolicy RemoteSigned.
$testExe='L:/XclTooling/pr1512-tiling-edges-fddfa267/target\debug\build\xcl/77aca8ccb20e299f\out\xcl-77aca8ccb20e299f.exe'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    & $testExe gpu::recomp::tests::gpu_f16_rounding_helpers_fold_the_sticky_bit --exact --nocapture --test-threads=1
    & $testExe gpu::recomp::tests::gpu_f16_add_and_fma_round_once_under_directed_modes --exact --nocapture --test-threads=1
}
  • The prebuild exited 0. The two GPU invocations each reported 0 passed, 1 failed, 0 ignored, 0 skipped, with 748 filtered out per invocation and exit code 101. No SKIPPED lines were emitted.
  • Both fixtures compiled HLSL to cs_6_6 with DXC and then failed at CreateComputePipelineState with The parameter is incorrect. (0x80070057). The helper failed creating the pipeline for its first probe kernel (tests.rs:6979), and the instruction fixture failed creating the pipeline for its kernel (tests.rs:7061). No GPU dispatch or result comparisons completed.
  • The helper fixture defines 49 comparisons (21 round-to-nearest-even, 10 toward +∞, 6 toward −∞, and 12 toward zero). The instruction fixture defines 228 32-bit result comparisons (57 per mode across the same four modes, including the packed outputs and OMOD/CLAMP checks). Executed comparisons: 0 of 49 and 0 of 228. GPU rounding-mode coverage: none.

Not tested

The cause of the D3D12 pipeline rejection, other adapters or DXC versions, direct DXIL, a main baseline, the full workspace suite, and retail-title smoke runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the fixtures, checked the exact head and assertion counts, and wrote this report.

ivall added a commit that referenced this pull request Nov 25, 2026
Every other method of the newer command list sits two slots after the older one, so #129 is the
older #127, not #126. A retail title's own calls through its list agree with the slots before it:
#126 takes a value and a pointer (RSSetShadingRate), #127 one resource (RSSetShadingRateImage), #128
one pointer. Nothing handles either slot yet; #2092's DispatchMesh is at #127.
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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.