shader: lower the binary16 rounding ops in pixel_aot #881

Manually merged
github merged 1 commit from gh-pr/881/head into gh-pr/881/base 2026-11-26 22:25:26 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-23 15:28 UTC · original
JB2WIN:shader/f16-round → main · +565 −3 · 5 files · 1 commits · merged 2026-11-23 15:43 UTC

Change

This is the second binary16 slice from #839. It follows the same rules as #854. tools/pixel_aot.py now lowers v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16 in the e32 and _e64 encodings.

  • Semantics: LLVM 15.0.7 VOP1Instructions.td L449-452 maps these four ops to ffloor, fceil, ftrunc and frint. frint rounds to nearest even under the default rounding mode.
  • Lowering: the operand goes through widen16, then the binary32 floor/ceil/trunc/round, then narrow16. HLSL round is DXIL Round_ne. The narrowing is exact because the rounded value of a finite half is itself a representable half.
  • Rules carried over from #854:
    • the operand must be proven finite;
    • the binary16 denormal entry profile must be explicit;
    • the result is computed at translation time as well, so chains stay provable;
    • the result is a half16 low half, read only by the audited readers;
    • clamp, omod and modifiers are refused.
  • Changed expectations: v_ceil_f16_e32 and v_rndne_f16_e32 sat in the rounding-mode neighbour list. They were only refused there because the entry profile was unknown, not because the form was unsupported. They are replaced by v_fract_f16_e32 and v_rcp_f16_e32, which are still unsupported.
  • Still out of scope: v_fract_f16, because of its clamp near 1, plus min/max and the transcendental ops.

Refs #839. AI-assisted (Claude Code).

Verification

Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at fc89b9e.

  • Draw draw-f16-round (pixel_aot_f16_round_{hardware,warp}): results are read back as integers and compared with an independent reference. The cases cover:
    • ±0, and negative inputs that round to -0: trunc(-0.5), ceil(-0.3) and rndne(-0.4);
    • rndne halfway values at 0.5, 1.5, 2.5 and -2.5, and at ±1022.5 and ±1023.5, where the ulp is 0.5;
    • values from 1024 up, where the ulp is 1 or 2, including 2047, 2048, 2050 and 4094;
    • ±65504 and ± subnormals.
  • Reference: checked offline over every finite binary16 value for all four ops against Python struct/math/round, including the sign of zero.
  • Mutations: each was detected on both adapters:
    • floor and ceil swapped;
    • trunc replaced by floor on negative inputs;
    • rndne replaced by round-half-away;
    • the sign of a -0 result lost;
    • the source read from its high half.
  • Dev-time check (not committed): with the new branch disabled, the new controls fail inside check_f16_round_controls.
  • Commands:
    • ctest --preset dev --no-tests=error -R "^pixel_aot_f16_round_": 2/2 passed, 22.8 s on the RTX 3080.
    • Full ctest --preset dev --no-tests=error -j4: 453/453 passed. The only skips are capability skips.
    • The LLVM 15 binary round trip passes, with byte pins for the e32/e64 encodings. It runs locally through a clang -cc1as shim standing in for llvm-mc.
    • The controls, form_coverage_check.py (8 forms in both TSVs, 7 neighbours uncovered), rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py all pass.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-23 15:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/881) `JB2WIN:shader/f16-round` → `main` · +565 −3 · 5 files · 1 commits · merged 2026-11-23 15:43 UTC ## Change This is the second binary16 slice from #839. It follows the same rules as #854. `tools/pixel_aot.py` now lowers `v_floor_f16`, `v_ceil_f16`, `v_trunc_f16` and `v_rndne_f16` in the e32 and `_e64` encodings. - **Semantics:** LLVM 15.0.7 [`VOP1Instructions.td` L449-452](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/VOP1Instructions.td#L449-L452) maps these four ops to `ffloor`, `fceil`, `ftrunc` and `frint`. `frint` rounds to nearest even under the default rounding mode. - **Lowering:** the operand goes through `widen16`, then the binary32 `floor`/`ceil`/`trunc`/`round`, then `narrow16`. HLSL `round` is DXIL `Round_ne`. The narrowing is exact because the rounded value of a finite half is itself a representable half. - **Rules carried over from #854:** - the operand must be proven finite; - the binary16 denormal entry profile must be explicit; - the result is computed at translation time as well, so chains stay provable; - the result is a `half16` low half, read only by the audited readers; - `clamp`, omod and modifiers are refused. - **Changed expectations:** `v_ceil_f16_e32` and `v_rndne_f16_e32` sat in the rounding-mode neighbour list. They were only refused there because the entry profile was unknown, not because the form was unsupported. They are replaced by `v_fract_f16_e32` and `v_rcp_f16_e32`, which are still unsupported. - **Still out of scope:** `v_fract_f16`, because of its clamp near 1, plus `min`/`max` and the transcendental ops. Refs #839. AI-assisted (Claude Code). ## Verification Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at `fc89b9e`. - **Draw `draw-f16-round`** (`pixel_aot_f16_round_{hardware,warp}`): results are read back as integers and compared with an independent reference. The cases cover: - ±0, and negative inputs that round to -0: `trunc(-0.5)`, `ceil(-0.3)` and `rndne(-0.4)`; - `rndne` halfway values at 0.5, 1.5, 2.5 and -2.5, and at ±1022.5 and ±1023.5, where the ulp is 0.5; - values from 1024 up, where the ulp is 1 or 2, including 2047, 2048, 2050 and 4094; - ±65504 and ± subnormals. - **Reference:** checked offline over every finite binary16 value for all four ops against Python `struct`/`math`/`round`, including the sign of zero. - **Mutations:** each was detected on both adapters: - `floor` and `ceil` swapped; - `trunc` replaced by `floor` on negative inputs; - `rndne` replaced by round-half-away; - the sign of a -0 result lost; - the source read from its high half. - **Dev-time check (not committed):** with the new branch disabled, the new controls fail inside `check_f16_round_controls`. - **Commands:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_f16_round_"`: 2/2 passed, 22.8 s on the RTX 3080. - Full `ctest --preset dev --no-tests=error -j4`: 453/453 passed. The only skips are capability skips. - The LLVM 15 binary round trip passes, with byte pins for the e32/e64 encodings. It runs locally through a `clang -cc1as` shim standing in for `llvm-mc`. - The controls, `form_coverage_check.py` (8 forms in both TSVs, 7 neighbours uncovered), `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` all pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_floor_f16, v_ceil_f16, v_trunc_f16 and v_rndne_f16 (e32 and e64)
under the #854 rules: the operand must be proven finite, the binary16
denormal entry profile must be explicit, and the half16 result is read
only by the audited readers. LLVM 15 maps them to ffloor, fceil, ftrunc
and frint; widen16, the binary32 rounding op and narrow16 are exact
because the rounded value of a finite half is representable. clamp,
omod and modifiers are refused. Adds controls, LLVM 15 binary fixtures,
form coverage and a draw with five mutations (pixel_aot_f16_round_*).

Refs #839

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:25:25 +00:00
github manually merged commit 8872308d42 into gh-pr/881/base 2026-11-26 22:25:26 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.