Skip to content

pknorm_probe: v_cvt_pknorm_* give 0 for NaN on RDNA2, but round the exact product once (SHADER-339) - #2028

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
boraswim:shader-339-pknorm-nan
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
boraswim:shader-339-pknorm-nan

Conversation

@boraswim

@boraswim boraswim commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-339 (#1902 (comment))

Depends on: #2067 (conflict only). #2067 removes the duplicate v_cvt_pknorm_* row in docs/design.md, and this PR edits both copies the same way. Whichever merges second keeps one row, with this PR's text.

What and why

docs/design.md said v_cvt_pknorm_i16_f32 / v_cvt_pknorm_u16_f32 give 0 for a NaN, as v_cvt_i32_f32 does, but that this was not measured on hardware. This PR measures it on RDNA2.

tools/pknorm_probe.py (new, standard library only) runs both ops two ways:

  • through the translator on the CPU interpreter;
  • with --oracle hw, natively through tools/hw_oracle, in wave32 and wave64, under five MODEs: the game's (IEEE 0, DX10_CLAMP 1, f32 denormals flushed), then IEEE 1, DX10_CLAMP 0, both, and f32 denormals kept.

Each NaN pattern is tested in S0 and in S1: quiet, quiet with a payload, signalling, both signs.

NaN: measured, the translator is right. Every NaN half gives 0, 74 of 74, in all ten runs.

Rounding: a new difference, not fixed here.

  • The hardware rounds the exact product x · 32767 (or 65535) once, to nearest even.
  • The translator rounds the f32 OpFMul product and then RoundEven.
  • They differ by one where the f32 product lands exactly on k + 0.5. The probe's near-tie inputs show it in both directions: 28 of 28 hardware words equal single rounding, and 0 of 28 equal the translator. For example, 0x38400180 (exact product 1.5 - 1.4e-9) gives 1 on the hardware and 2 from the translator; 0x3c004101 (256.5 + 1.5e-5) gives 257 and 256.
  • The other 34 of 34 words are equal.

Changes:

  • docs/design.md: the pknorm row now records the measurement and the rounding difference. The row appears twice; both copies are updated the same way, and merging them is PROC-75.
  • docs/shader_validation.md: a new section, "v_cvt_pknorm_* NaN and rounding on RDNA2", with the results table.

I'll post the rounding fix as a finding: on the board.

Tested

  • GPU: AMD Radeon iGPU of a Ryzen 5 7600X (RDNA2, gfx1036), AMD Windows driver 32.0.21045.29003, Windows 11. HIP backend of the hardware oracle, AMD clang from rocm-sdk-core 10.0.0. main 4eb6155d.
  • python -I tools/pknorm_probe.py --oracle hw: exit 1, as expected, because of the rounding difference. In all ten runs: NaN halves giving 0, 74 of 74; near ties equal to single rounding, 28 of 28 (translator 0 of 28); other words, 34 of 34.
  • tests/test_pknorm_probe.py (new): four near-tie words derived by hand with exact arithmetic, case coverage, and the translator side's double rounding and NaN zero. OK with python -I and pytest.
  • tests/semantic/test_alu_cvt_pknorm_f32.py: OK.
  • Tests that read the docs: test_fma_mix_probe, test_mode_round, test_values, test_valu_fuzz and others: OK. test_docs_design_rows fails 3 times, the same on main without this change (duplicate rows; PROC-75).

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change; the existing row records the measurement.)

…xact product once (SHADER-339)

tools/pknorm_probe.py runs v_cvt_pknorm_i16_f32 / v_cvt_pknorm_u16_f32 through the translator on the CPU interpreter
and, with --oracle hw, natively through tools/hw_oracle in wave32 and wave64 under five MODEs. On an RDNA2 iGPU
(gfx1036) every NaN half (74 of 74: quiet, signalling, both signs, payloads, in S0 and S1) gives 0, as the translator
assumes, whatever IEEE, DX10_CLAMP and the f32 denormal mode are.

The rounding does not match: the hardware rounds the exact product x * 32767 (or 65535) once, while the translator
rounds the f32 OpFMul product and then RoundEven, one off on 28 of 28 near-tie inputs in both directions. Recorded in
docs/design.md and docs/shader_validation.md; the translator is not changed here. tests/test_pknorm_probe.py checks
four near-tie words against a hand derivation and the translator side's double rounding and NaN zero.
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.

2 participants