shader: accept a literal source in gfx2hlsl v_pk_mul_f16 #3490

Manually merged
github merged 1 commit from github-bot/gh-3488 into gh-pr/3488/base 2026-11-30 08:50:59 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-29 17:31 UTC · original
Leyukaka:shader-gfx2hlsl-pk-mul-literal → main · +22 −4 · 3 files · 1 commits · merged 2026-11-30 08:45 UTC

Refs #2022 (item claimed there). Replaces the earlier attempt in the closed draft #2930.

What changes

tools/startup/gfx2hlsl.py: v_pk_mul_f16 now accepts a 32-bit hex literal (0x plus 1 to 8 hex digits) as a source operand. Nothing else in the lowering changes: the literal is emitted as a full 32-bit word (gfx2hlsl.py:2698) and each half is picked by op_sel / op_sel_hi exactly as for a VGPR (gfx2hlsl.py:10132), then goes through the existing f16tof32 and rounding path.

Still refused, each with a test:

  • SGPR source (s20), bare inline 0, inline floats (2.0)
  • literal as destination
  • 9-digit hex (0x100000000)
  • clamp, neg_lo / neg_hi, negated source (-v0)
  • literal source on v_pk_add_f16 and v_pk_fma_f16

Why

In one long local run of the application with only the Python path active, one compute program using a literal source for this instruction accounted for about 847,000 dispatches, none translated.

Tests

tests/startup_gfx2hlsl_f16_alu_check.py:

  • v_pk_mul_f16 v3, v0, 0x4000 moves from the refusal list to a positive case (v0 = (3, 3) gives 0x00004600: the high lane uses the literal's high half, 0).
  • Two synthetic gfx1013 VOP3P encodings, decoded by the in-tree decoder, with literal 0xc4003e00 (+1.5 low, -4 high) and v0 = 0x42003c01 (1+2^-10 low, 3 high):
    • literal as src0, default selectors: 0xca003e02. The low product is halfway between 0x3e01 and 0x3e02 and rounds to even.
    • literal as src1 with its two selectors swapped (op_sel:[0,1] op_sel_hi:[1,0]): 0x4480c401.
  • Five new refusal controls (SGPR, bare 0, 9-digit hex, literal destination, literal with clamp).

Expected values were worked out by hand.

tests/startup_gfx2hlsl_pk_minmax_check.py drops mul from its "literal is not a single VGPR" refusal loop, because that refusal is now wrong for mul. The add and fma entries stay.

Passing: startup_gfx2hlsl_f16_alu_check, startup_gfx2hlsl_pk_minmax_check, startup_gfx2hlsl_compute_check (no arguments), startup_gfx2hlsl_pack_b32_f16_check, startup_gfx2hlsl_fma_mix_check, startup_gfx2hlsl_refusals_check.

Mutations, each reverted afterwards:

mutation result
swap the literal's halves f16_alu_check fails on the 3 literal cases
also accept an SGPR in the new guard f16_alu_check fails on refuses v_pk_mul_f16 v3, s20, v0

Not covered

  • startup_gfx2hlsl_compute_check in binary mode needs llvm-mc and was not run.
  • The literal's half selection was checked against the in-tree decoder output, not against the ISA document.
**@⁠Leyukaka** on GitHub · 2026-11-29 17:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3488) `Leyukaka:shader-gfx2hlsl-pk-mul-literal` → `main` · +22 −4 · 3 files · 1 commits · merged 2026-11-30 08:45 UTC Refs #2022 (item claimed there). Replaces the earlier attempt in the closed draft #2930. ## What changes `tools/startup/gfx2hlsl.py`: `v_pk_mul_f16` now accepts a 32-bit hex literal (`0x` plus 1 to 8 hex digits) as a source operand. Nothing else in the lowering changes: the literal is emitted as a full 32-bit word (`gfx2hlsl.py:2698`) and each half is picked by `op_sel` / `op_sel_hi` exactly as for a VGPR (`gfx2hlsl.py:10132`), then goes through the existing `f16tof32` and rounding path. Still refused, each with a test: - SGPR source (`s20`), bare inline `0`, inline floats (`2.0`) - literal as destination - 9-digit hex (`0x100000000`) - `clamp`, `neg_lo` / `neg_hi`, negated source (`-v0`) - literal source on `v_pk_add_f16` and `v_pk_fma_f16` ## Why In one long local run of the application with only the Python path active, one compute program using a literal source for this instruction accounted for about 847,000 dispatches, none translated. ## Tests `tests/startup_gfx2hlsl_f16_alu_check.py`: - `v_pk_mul_f16 v3, v0, 0x4000` moves from the refusal list to a positive case (`v0` = (3, 3) gives `0x00004600`: the high lane uses the literal's high half, 0). - Two synthetic gfx1013 VOP3P encodings, decoded by the in-tree decoder, with literal `0xc4003e00` (+1.5 low, -4 high) and `v0 = 0x42003c01` (1+2^-10 low, 3 high): - literal as src0, default selectors: `0xca003e02`. The low product is halfway between `0x3e01` and `0x3e02` and rounds to even. - literal as src1 with its two selectors swapped (`op_sel:[0,1] op_sel_hi:[1,0]`): `0x4480c401`. - Five new refusal controls (SGPR, bare `0`, 9-digit hex, literal destination, literal with `clamp`). Expected values were worked out by hand. `tests/startup_gfx2hlsl_pk_minmax_check.py` drops `mul` from its "literal is not a single VGPR" refusal loop, because that refusal is now wrong for `mul`. The `add` and `fma` entries stay. Passing: `startup_gfx2hlsl_f16_alu_check`, `startup_gfx2hlsl_pk_minmax_check`, `startup_gfx2hlsl_compute_check` (no arguments), `startup_gfx2hlsl_pack_b32_f16_check`, `startup_gfx2hlsl_fma_mix_check`, `startup_gfx2hlsl_refusals_check`. Mutations, each reverted afterwards: | mutation | result | |---|---| | swap the literal's halves | `f16_alu_check` fails on the 3 literal cases | | also accept an SGPR in the new guard | `f16_alu_check` fails on `refuses v_pk_mul_f16 v3, s20, v0` | ## Not covered - `startup_gfx2hlsl_compute_check` in `binary` mode needs `llvm-mc` and was not run. - The literal's half selection was checked against the in-tree decoder output, not against the ISA document.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 17:33:40 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 08:16 UTC · original · approved these changes

Reviewed e9014c09 by reading the diff; not built or run. I also disassembled the two synthetic words with llvm-mc 15 (-mcpu=gfx1013).

Verdict: approve. The literal uses the lowering v_pk_min/max_f16 already use for hex words, and LLVM agrees with the test encodings. No MUST.

  • LLVM decodes the test words as the comments say. 0xcc104003 0x180200ff gives v_pk_mul_f16 v3, 0xc4003e00, v0, and 0xcc105003 0x0801ff00 gives v_pk_mul_f16 v3, v0, 0xc4003e00 op_sel:[0,1] op_sel_hi:[1,0]. Assembling v_pk_mul_f16 v3, v0, 0xc4003e00 keeps the full 32-bit literal word. So LLVM also models the VOP3P literal as one 32-bit value whose halves op_sel/op_sel_hi pick, as packed_half does (gfx2hlsl.py:10132-10137). That partly covers the "not checked against the ISA document" item; hardware is still unverified.
  • The guard (gfx2hlsl.py:10117) runs after the select_bits branch, so min/max are unchanged. i excludes the destination. Add and fma still refuse, as the kept pk_minmax loop shows.
  • NIT: the text case v_pk_mul_f16 v3, v0, 0x4000 is a form the disassembler never prints. LLVM encodes 0x4000 there as the inline constant 2.0 (0xe9), not as a literal. It tests the parser only; the two decoded words are the cases that match real code.

Tests: f16_alu_check now covers both literal positions, the round-to-even half, and five new refusals. The mutations show it catches swapped halves and an SGPR that slips through. CI did not run it: startup_gfx2hlsl_f16_alu (CMakeLists.txt:3886) is not in the pr preset's list, and the Linux Python job does not include it. Only pk_minmax_check ran there (passed). The local run in the body is the only run of f16_alu_check at this head.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 08:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3488#pullrequestreview-6108766466) · **approved these changes** Reviewed `e9014c09` by reading the diff; not built or run. I also disassembled the two synthetic words with llvm-mc 15 (`-mcpu=gfx1013`). **Verdict: approve.** The literal uses the lowering `v_pk_min/max_f16` already use for hex words, and LLVM agrees with the test encodings. No MUST. - LLVM decodes the test words as the comments say. `0xcc104003 0x180200ff` gives `v_pk_mul_f16 v3, 0xc4003e00, v0`, and `0xcc105003 0x0801ff00` gives `v_pk_mul_f16 v3, v0, 0xc4003e00 op_sel:[0,1] op_sel_hi:[1,0]`. Assembling `v_pk_mul_f16 v3, v0, 0xc4003e00` keeps the full 32-bit literal word. So LLVM also models the VOP3P literal as one 32-bit value whose halves `op_sel`/`op_sel_hi` pick, as `packed_half` does (`gfx2hlsl.py:10132`-`10137`). That partly covers the "not checked against the ISA document" item; hardware is still unverified. - The guard (`gfx2hlsl.py:10117`) runs after the `select_bits` branch, so min/max are unchanged. `i` excludes the destination. Add and fma still refuse, as the kept `pk_minmax` loop shows. - **NIT:** the text case `v_pk_mul_f16 v3, v0, 0x4000` is a form the disassembler never prints. LLVM encodes `0x4000` there as the inline constant `2.0` (`0xe9`), not as a literal. It tests the parser only; the two decoded words are the cases that match real code. Tests: `f16_alu_check` now covers both literal positions, the round-to-even half, and five new refusals. The mutations show it catches swapped halves and an SGPR that slips through. CI did not run it: `startup_gfx2hlsl_f16_alu` (`CMakeLists.txt:3886`) is not in the `pr` preset's list, and the Linux Python job does not include it. Only `pk_minmax_check` ran there (passed). The local run in the body is the only run of `f16_alu_check` at this head.
github-bot changed target branch from main to gh-pr/3488/base 2026-11-30 08:50:58 +00:00
github manually merged commit e9014c0960 into gh-pr/3488/base 2026-11-30 08:50:59 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.