gpu/recomp: validate s_round_mode and round non-fused intermediate products #120

Closed
github-bot wants to merge 1 commit from gh-pr/120/head into gh-pr/120/base
Owner

@⁠Lum7nt on GitHub · 2026-11-23 13:20 UTC · original
Lum7nt:recomp-fp-modes → main · +62 −2 · 2 files · 1 commits · closed without merging

Resolves #73

Summary of Changes

  1. s_round_mode validation & reporting (crates/xcl/src/gpu/recomp/emit.rs):

    • Removed s_round_mode from the unconditional NOOPS list.
    • Handled in sopp(): default rounding mode (Round to Nearest Even, SIMM16 == 0) is tracked in ignored and continues cleanly as a safe no-op.
    • Non-default directed rounding modes (SIMM16 != 0) are recorded in unsupported / unsupported_why (s_round_mode: non-default round mode 0x...), preventing silent miscompilations in titles that configure directed rounding.
  2. v_mad_f16 non-fused intermediate rounding (crates/xcl/src/gpu/recomp/emit.rs):

    • Lowered v_mad_f16 to mad_nf16(a, b, c) in the shader preamble with explicit f16 rounding on both the intermediate product and sum:
      float mad_nf16(float a, float b, float c) {
          precise float p = f16tof32(f32tof16(a * b));
          precise float r = f16tof32(f32tof16(p + c));
          return r;
      }
      
    • Guarantees that intermediate f16 products overflow/round according to half-precision semantics before addition.
  3. Unit & GPU Kernel Tests (crates/xcl/src/gpu/recomp/tests.rs):

    • Added s_round_mode_default_is_ignored_non_default_is_unsupported.
    • Added mad_nf_and_mad_nf16_non_fused_intermediate_rounding verifying the golden vector from #73.
    • All 353 library tests pass cleanly.
**@⁠Lum7nt** on GitHub · 2026-11-23 13:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/120) `Lum7nt:recomp-fp-modes` → `main` · +62 −2 · 2 files · 1 commits · closed without merging Resolves #73 ### Summary of Changes 1. **`s_round_mode` validation & reporting (`crates/xcl/src/gpu/recomp/emit.rs`)**: - Removed `s_round_mode` from the unconditional `NOOPS` list. - Handled in `sopp()`: default rounding mode (Round to Nearest Even, `SIMM16 == 0`) is tracked in `ignored` and continues cleanly as a safe no-op. - Non-default directed rounding modes (`SIMM16 != 0`) are recorded in `unsupported` / `unsupported_why` (`s_round_mode: non-default round mode 0x...`), preventing silent miscompilations in titles that configure directed rounding. 2. **`v_mad_f16` non-fused intermediate rounding (`crates/xcl/src/gpu/recomp/emit.rs`)**: - Lowered `v_mad_f16` to `mad_nf16(a, b, c)` in the shader preamble with explicit `f16` rounding on both the intermediate product and sum: ```hlsl float mad_nf16(float a, float b, float c) { precise float p = f16tof32(f32tof16(a * b)); precise float r = f16tof32(f32tof16(p + c)); return r; } ``` - Guarantees that intermediate f16 products overflow/round according to half-precision semantics before addition. 3. **Unit & GPU Kernel Tests (`crates/xcl/src/gpu/recomp/tests.rs`)**: - Added `s_round_mode_default_is_ignored_non_default_is_unsupported`. - Added `mad_nf_and_mad_nf16_non_fused_intermediate_rounding` verifying the golden vector from #73. - All 353 library tests pass cleanly.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:06 +00:00
github-bot closed this pull request 2026-11-26 04:11:06 +00:00
Author
Owner

@⁠Foniass on GitHub · 2026-11-23 13:25 UTC · original

Heads-up @⁠Lum7nt: #73 was already resolved by #91 (merged this morning, 088d682), and this PR conflicts with it.

  • Rounding modes: on current main, s_round_mode and the MODE writes of s_setreg* are no longer no-ops. The f16 rounding mode is tracked (dynamic_f16_rm / xcl_fp16_rm) and applied through f32_to_f16_rm. Recording every non-zero s_round_mode as unsupported would make those programs incomplete. Per #73, mode 0xC alone appears in 3 305 programs of the retail pack, and incomplete translations aren't used for pipelines.
  • v_mad_f16: V_MAD_F16 is in neither rdna2_spec.rs nor rdna2_xbox.rs; encode("V_MAD_F16", …) fails. So the v_mad_f16 lowering here, like the arm #91 added, can never be reached.
  • Related: #111 tracks what #91 still gets wrong. f16 add / sub / FMA under a directed mode are rounded twice (through f32); a fix for that is in progress.
**@⁠Foniass** on GitHub · 2026-11-23 13:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/120#issuecomment-7102521897) Heads-up @⁠Lum7nt: #73 was already resolved by #91 (merged this morning, 088d682), and this PR conflicts with it. - **Rounding modes:** on current `main`, `s_round_mode` and the MODE writes of `s_setreg*` are no longer no-ops. The f16 rounding mode is tracked (`dynamic_f16_rm` / `xcl_fp16_rm`) and applied through `f32_to_f16_rm`. Recording every non-zero `s_round_mode` as unsupported would make those programs incomplete. Per #73, mode `0xC` alone appears in 3 305 programs of the retail pack, and incomplete translations aren't used for pipelines. - **`v_mad_f16`:** `V_MAD_F16` is in neither `rdna2_spec.rs` nor `rdna2_xbox.rs`; `encode("V_MAD_F16", …)` fails. So the `v_mad_f16` lowering here, like the arm #91 added, can never be reached. - **Related:** #111 tracks what #91 still gets wrong. f16 add / sub / FMA under a directed mode are rounded twice (through f32); a fix for that is in progress.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 14:14 UTC · original

Thanks – closing: #73 was resolved by #91, and as @⁠Foniass explains above, recording every non-zero s_round_mode as unsupported would make the ~3 300 retail programs that set 0xC incomplete. The remaining f16 double-rounding is tracked in #111.

**@⁠ivall** on GitHub · 2026-11-23 14:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/120#issuecomment-7103690483) Thanks – closing: #73 was resolved by #91, and as @⁠Foniass explains above, recording every non-zero `s_round_mode` as unsupported would make the ~3 300 retail programs that set 0xC incomplete. The remaining f16 double-rounding is tracked in #111.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.