startup: lower v_cvt_pknorm_u16_f32 in gfx2hlsl #1815

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

@⁠tedin7 on GitHub · 2026-11-24 19:07 UTC · original
tedin7:x2w-frontier-gfx-pknorm16 → main · +190 −0 · 4 files · 1 commits · closed without merging

Part of #870 (no Fixes). Draft.

What

Lowers v_cvt_pknorm_u16_f32 in tools/startup/gfx2hlsl.py. It was refused as unsupported, which stops the pair behind #1710.

The instruction is VOP3 only (opcode 0x369, no e32 form). Per the public RDNA ISA description:

  • bits 15:0 = round-to-nearest-even(clamp(S0, 0, 1) * 65535)
  • bits 31:16 = the same for S1
  • a NaN reads 0

Lowering: uint(round(saturate(a) * 65535.0)) | (uint(round(saturate(b) * 65535.0)) << 16).

Source neg and abs reach the operands. Any output modifier (clamp, mul, div) or op_sel is refused, because it would change the packed words. This matches the refusal style of #1755 and #1778 without depending on them. No other open PR implements this instruction.

Change

  • One op_v_cvt_pknorm_u16_f32 method (the dispatch finds it by name, so no table row). Placed away from the hunks of #1755.
  • tests/startup_gfx2hlsl_pknorm_u16_check.py on the shared lane runner, registered in CMakeLists.txt and .github/workflows/windows.yml.

Test

  • Reference from the ISA text: 0, 1, -0.5, 1.5, 0.5, 1.5 and 2.5 over 65535 (ties), 0.25, 0.5, NaN, -0.0, +Inf, -Inf, on both halves, in different lanes so a swapped pair cannot pass.
  • The translated lane text is also evaluated in Python (binary32 product, HLSL saturate and round) and compared with the reference on all 8 sets.
  • Encoding: reassembled with llvm-mc, words recorded (checked with llvm-mc-19 for gfx1010 and gfx1030, same 0x369 VOP3 word; CI uses llvm-mc-15 in binary mode).
  • The draw mode (WARP and GPU, DXC only) is registered but was not run here.

The reference rounds the binary32 product. For 1.5/65535 that product is exactly 1.5 and ties to 2, while the exact value of the nearest binary32 input is just under 1.5. No hardware run of this instruction was available, so the draw mode is what confirms it.

Commands executed locally

  • python3 -B tests/startup_gfx2hlsl_pknorm_u16_check.py and ... binary llvm-mc-19: ok
  • llvm-mc-19 -mcpu=gfx1010 and gfx1030 encodings of the instruction, plain, with neg/abs and with clamp
  • Five real mutations of the handler, each fails the check: floor instead of round, no upper clamp, halves swapped, modifier refusal removed; and the three mutated-text controls inside the check (rounding, clamp, order of the halves)
  • The existing cvt_alu, op_refusals, bit_alu and vcvt_omod checks still pass
  • git diff --check, tests/docs_links_check.py, tests/bidi_controls_check.py: pass
  • git merge-tree against origin/main, #1796, #1798, #1778, #1755, #1750: no conflicts. #1783 and #1747 conflict with main already (same counts as without this branch).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 19:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1815) `tedin7:x2w-frontier-gfx-pknorm16` → `main` · +190 −0 · 4 files · 1 commits · closed without merging Part of #870 (no `Fixes`). Draft. ## What Lowers `v_cvt_pknorm_u16_f32` in `tools/startup/gfx2hlsl.py`. It was refused as unsupported, which stops the pair behind #1710. The instruction is VOP3 only (opcode 0x369, no e32 form). Per the public RDNA ISA description: - bits 15:0 = round-to-nearest-even(clamp(S0, 0, 1) * 65535) - bits 31:16 = the same for S1 - a NaN reads 0 Lowering: `uint(round(saturate(a) * 65535.0)) | (uint(round(saturate(b) * 65535.0)) << 16)`. Source neg and abs reach the operands. Any output modifier (clamp, mul, div) or op_sel is refused, because it would change the packed words. This matches the refusal style of #1755 and #1778 without depending on them. No other open PR implements this instruction. ## Change - One `op_v_cvt_pknorm_u16_f32` method (the dispatch finds it by name, so no table row). Placed away from the hunks of #1755. - `tests/startup_gfx2hlsl_pknorm_u16_check.py` on the shared lane runner, registered in `CMakeLists.txt` and `.github/workflows/windows.yml`. ## Test - Reference from the ISA text: 0, 1, -0.5, 1.5, 0.5, 1.5 and 2.5 over 65535 (ties), 0.25, 0.5, NaN, -0.0, +Inf, -Inf, on both halves, in different lanes so a swapped pair cannot pass. - The translated lane text is also evaluated in Python (binary32 product, HLSL saturate and round) and compared with the reference on all 8 sets. - Encoding: reassembled with `llvm-mc`, words recorded (checked with llvm-mc-19 for gfx1010 and gfx1030, same 0x369 VOP3 word; CI uses llvm-mc-15 in binary mode). - The draw mode (WARP and GPU, DXC only) is registered but was not run here. The reference rounds the binary32 product. For 1.5/65535 that product is exactly 1.5 and ties to 2, while the exact value of the nearest binary32 input is just under 1.5. No hardware run of this instruction was available, so the draw mode is what confirms it. ## Commands executed locally - `python3 -B tests/startup_gfx2hlsl_pknorm_u16_check.py` and `... binary llvm-mc-19`: ok - `llvm-mc-19 -mcpu=gfx1010` and `gfx1030` encodings of the instruction, plain, with neg/abs and with clamp - Five real mutations of the handler, each fails the check: floor instead of round, no upper clamp, halves swapped, modifier refusal removed; and the three mutated-text controls inside the check (rounding, clamp, order of the halves) - The existing cvt_alu, op_refusals, bit_alu and vcvt_omod checks still pass - `git diff --check`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: pass - `git merge-tree` against `origin/main`, #1796, #1798, #1778, #1755, #1750: no conflicts. #1783 and #1747 conflict with main already (same counts as without this branch). AI-assisted; commands listed were executed locally.
VOP3 only. Each half is clamp(S, 0, 1) * 65535 rounded to nearest even, a NaN reads 0. Output modifiers and op_sel are refused. Refs #870.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:35:02 +00:00
github-bot closed this pull request 2026-11-26 23:35:02 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:14 UTC · original

Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

**@⁠tedin7** on GitHub · 2026-11-24 19:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1815#issuecomment-7141819817) Closing this draft for now to help keep the open PR queue manageable; the branch stays preserved on the fork so it can be reopened once the queue clears.

Pull request closed

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