Skip to content

startup: lower v_cvt_pknorm_u16_f32 in gfx2hlsl - #1815

Closed
tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-frontier-gfx-pknorm16
Closed

tedin7 wants to merge 1 commit into
R0Y00:mainfrom
tedin7:x2w-frontier-gfx-pknorm16

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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

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

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 R0Y00#870.
@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

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.

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.

1 participant