startup: lower v_cvt_pknorm_u16_f32 in gfx2hlsl #1808

Closed
tedin7 wants to merge 1 commit from upstream-pr/1815 into main
tedin7 commented 2026-11-24 19:07:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:07:06Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589332189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1815). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:07:06Z. --- 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.
upstream-sync closed this pull request 2026-11-24 20:00:45 +00:00
tedin7 commented 2026-11-24 20:01:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:14:56Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141819817 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1815#issuecomment-7141819817). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:14:56Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1808
No description provided.