rdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8) #338

Open
github-bot wants to merge 1 commit from github-bot/gh-338 into main AGit
Owner

@⁠NolanCotter on GitHub · 2026-11-24 03:24 UTC · original
NolanCotter:shader-satpk-u8 → main · +143 −3 · 7 files · 1 commits · open

Claimed in #14 as SHADER-SATPK-U8.

Summary

  • tools/rdna2spirv.py: new rule for v_sat_pk_u8_i16 (VOP1 0x62 / VOP3 0x1E2). Each signed i16 half of SRC0 is sign-extended, OpSClamped to [0, 255] and packed into the low 16 bits of VDST; the high half is preserved (GFX9+ partial 16-bit write — LLVM models the def as VOP1Inst_t16, Mesa ACO instr_is_16bit, same class as v_cvt_f16_f32). Source neg/abs, clamp, omod and op_sel raise Unsupported; _sdwa whitelists src0_sel/dst_sel/dst_unused; _dpp goes through non_dpp_mods; _e32 refuses all modifiers.
  • tests/semantic/fixtures/sat_pk_u8_i16.asm + tests/semantic/test_alu_sat_pk_u8_i16.py: hand-written listing, runs the emitted SPIR-V through spirv_mini_interp against a plain-Python reference — lane edge values (-0x8000/-1/0/255/256/0x7FFF), SGPR, literal and inline-constant sources, _sdwa source/destination selects, and refused modifiers.
  • docs/design.md: contract-table row naming the confirmation (AMD machine-readable ISA semantics; LLVM/ACO partial-write reference; CPU-checked test; not GPU-verified).
  • docs/fssm_crosscheck.md: removed from the unhandled-xbsc list.
  • tests/test_translate.py, tests/test_f16_op_sel.py: the still-unsupported canary is repointed from v_sat_pk_u8_i16 to v_mullit_f32 (still unhandled on this base).

Heads-up for reviewers: PR #265's _FULL32_V16_PREFIXES lists v_sat_pk as a full-32-bit write for its wave64-halves liveness fix; this op writes only the low 16 bits and preserves the high half, so whichever of the two lands second should drop that prefix (noted as a finding: in #14).

Test plan

  • python -m unittest discover -s tests/semantic -p test_alu_sat_pk_u8_i16.py — 5 tests pass
  • python -m pytest tests/test_f16_op_sel.py — passes
  • python -I scripts/run_semantic_tests.py tests/semantic — 444 files / 5894 tests; the only 4 failures (test_float_nan_fract, test_image_atomics_guard, test_image_store_d16, test_int32_to_f64) reproduce identically on clean main (the last is a spirv-opt SIGSEGV in the test environment)
  • python -I scripts/check_no_game_data.py on both new files — clean

AI-assisted (Devin). No game files, no GPU, nothing online; semantics confirmed against AMD's ISA spec and the LLVM/ACO tables, not hardware. GPUs tested: none.

Generated with Devin

**@⁠NolanCotter** on GitHub · 2026-11-24 03:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/338) `NolanCotter:shader-satpk-u8` → `main` · +143 −3 · 7 files · 1 commits · open Claimed in #14 as SHADER-SATPK-U8. ## Summary - `tools/rdna2spirv.py`: new rule for `v_sat_pk_u8_i16` (VOP1 0x62 / VOP3 0x1E2). Each signed i16 half of SRC0 is sign-extended, `OpSClamp`ed to [0, 255] and packed into the low 16 bits of VDST; the high half is preserved (GFX9+ partial 16-bit write — LLVM models the def as `VOP1Inst_t16`, Mesa ACO `instr_is_16bit`, same class as `v_cvt_f16_f32`). Source `neg`/`abs`, `clamp`, `omod` and `op_sel` raise `Unsupported`; `_sdwa` whitelists `src0_sel`/`dst_sel`/`dst_unused`; `_dpp` goes through `non_dpp_mods`; `_e32` refuses all modifiers. - `tests/semantic/fixtures/sat_pk_u8_i16.asm` + `tests/semantic/test_alu_sat_pk_u8_i16.py`: hand-written listing, runs the emitted SPIR-V through `spirv_mini_interp` against a plain-Python reference — lane edge values (-0x8000/-1/0/255/256/0x7FFF), SGPR, literal and inline-constant sources, `_sdwa` source/destination selects, and refused modifiers. - `docs/design.md`: contract-table row naming the confirmation (AMD machine-readable ISA semantics; LLVM/ACO partial-write reference; CPU-checked test; not GPU-verified). - `docs/fssm_crosscheck.md`: removed from the unhandled-xbsc list. - `tests/test_translate.py`, `tests/test_f16_op_sel.py`: the still-unsupported canary is repointed from `v_sat_pk_u8_i16` to `v_mullit_f32` (still unhandled on this base). Heads-up for reviewers: PR #265's `_FULL32_V16_PREFIXES` lists `v_sat_pk` as a full-32-bit write for its wave64-halves liveness fix; this op writes only the low 16 bits and preserves the high half, so whichever of the two lands second should drop that prefix (noted as a `finding:` in #14). #### Test plan - [x] `python -m unittest discover -s tests/semantic -p test_alu_sat_pk_u8_i16.py` — 5 tests pass - [x] `python -m pytest tests/test_f16_op_sel.py` — passes - [x] `python -I scripts/run_semantic_tests.py tests/semantic` — 444 files / 5894 tests; the only 4 failures (`test_float_nan_fract`, `test_image_atomics_guard`, `test_image_store_d16`, `test_int32_to_f64`) reproduce identically on clean `main` (the last is a `spirv-opt` SIGSEGV in the test environment) - [x] `python -I scripts/check_no_game_data.py` on both new files — clean AI-assisted (Devin). No game files, no GPU, nothing online; semantics confirmed against AMD's ISA spec and the LLVM/ACO tables, not hardware. GPUs tested: none. Generated with [Devin](https://devin.ai)
The VOP1/VOP3 op saturates each signed i16 half of SRC0 to unsigned
8-bit and packs the pair into the low 16 bits of VDST, preserving the
high half (GFX9+ partial write; LLVM VOP1Inst_t16, Mesa ACO
instr_is_16bit). Neg/abs/clamp/omod are refused; _sdwa restricts to the
documented source/destination selects; _e32 rejects all modifiers.

Adds a hand-written fixture and a semantic test driving the SPIR-V
through spirv_mini_interp against a plain-Python reference (lane edge
values, SGPR/literal sources, sdwa selects, refused modifiers), the
docs/design.md contract row, and drops the op from the
fssm_crosscheck unhandled list. The two tests that used the mnemonic
as the still-unsupported canary now use v_mullit_f32.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:54:14 +00:00
Author
Owner

@⁠Sangonapou on GitHub · 2026-11-24 05:06 UTC · original

Tested 6446e3ce on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, regression check

Runtime built at this head with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026); llvm-mc 23.1.6 (conda-forge), SPIRV-Tools 2026.4, Vulkan SDK 1.4.363.0. No game files. This PR adds no GPU fixture, so this checks the translator change on the GPU suite.

  • Full run_gpu_tests.py: 257 shaders, 257 translated, 257 pass spirv-val; native 197/248 passed, 49 skipped; LEONIDA_W64_EMULATE=1 229/248 passed, 17 skipped, the same counts as main ece4ba5b. The only failures, cs_imgload_tfe and cs_imgload_d16_tfe, fail identically on main ece4ba5b on this card (main: native 197/248, emulated 229/248), the same pair as #31 / #336.
  • CPU: tests/semantic/test_alu_sat_pk_u8_i16.py 5 OK (unittest discover). tests/test_f16_op_sel.py and tests/test_translate.py need pytest, which is not installed here, so they were not run.
**@⁠Sangonapou** on GitHub · 2026-11-24 05:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7122623729) Tested 6446e3ce on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, regression check Runtime built at this head with `scripts\build_runtime.ps1` (MSVC 19.51, VS Build Tools 2026); `llvm-mc` 23.1.6 (conda-forge), SPIRV-Tools 2026.4, Vulkan SDK 1.4.363.0. No game files. This PR adds no GPU fixture, so this checks the translator change on the GPU suite. - Full `run_gpu_tests.py`: 257 shaders, 257 translated, 257 pass spirv-val; native 197/248 passed, 49 skipped; `LEONIDA_W64_EMULATE=1` 229/248 passed, 17 skipped, the same counts as `main` `ece4ba5b`. The only failures, `cs_imgload_tfe` and `cs_imgload_d16_tfe`, fail identically on `main` `ece4ba5b` on this card (main: native 197/248, emulated 229/248), the same pair as #31 / #336. - CPU: `tests/semantic/test_alu_sat_pk_u8_i16.py` 5 OK (`unittest discover`). `tests/test_f16_op_sel.py` and `tests/test_translate.py` need pytest, which is not installed here, so they were not run.
Author
Owner

@⁠milk4sale on GitHub · 2026-11-24 06:39 UTC · original

Follow-up for the wave64_halves side of this op is in #508 (SHADER-SATPK-HALVES, Depends on: #338). It takes v_sat_pk out of _FULL32_V16_PREFIXES so the halves analysis keeps the high half this PR's write_lo16 keeps. #508 was stacked on this head plus main, because #265 is not in this branch's base.

One note on the references. The row and the test docstring cite Mesa ACO instr_is_16bit for the GFX10 high-half keep, but instr_is_16bit returns false for v_sat_pk_u8_i16 before GFX11. The op is only in get_gfx11_true16_mask, which can_use_opsel reads for GFX11+ (aco_ir.cpp, Mesa 99abc485). LLVM's zeroesHigh16BitsOfDest does not list it either. So on RDNA2 the keep rests on the analogy with v_cvt_f16_f32 until someone measures it on RDNA2 hardware. It might be worth saying that in the row rather than citing ACO for it.

**@⁠milk4sale** on GitHub · 2026-11-24 06:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7124150986) Follow-up for the `wave64_halves` side of this op is in #508 (SHADER-SATPK-HALVES, `Depends on: #338`). It takes `v_sat_pk` out of `_FULL32_V16_PREFIXES` so the halves analysis keeps the high half this PR's `write_lo16` keeps. #508 was stacked on this head plus `main`, because #265 is not in this branch's base. One note on the references. The row and the test docstring cite Mesa ACO `instr_is_16bit` for the GFX10 high-half keep, but `instr_is_16bit` returns false for `v_sat_pk_u8_i16` before GFX11. The op is only in `get_gfx11_true16_mask`, which `can_use_opsel` reads for GFX11+ (`aco_ir.cpp`, Mesa `99abc485`). LLVM's `zeroesHigh16BitsOfDest` does not list it either. So on RDNA2 the keep rests on the analogy with `v_cvt_f16_f32` until someone measures it on RDNA2 hardware. It might be worth saying that in the row rather than citing ACO for it.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-24 18:22 UTC · original

Checked 6446e3c merged into current main (3aa9754): it still merges cleanly. On Linux, Python 3.13, no GPU: tests/semantic/test_alu_sat_pk_u8_i16.py 5/5 pass, and tests/test_f16_op_sel.py + tests/test_translate.py pass under pytest (40 passed, the rest skipped without llvm-mc). I recomputed the fixture's four words by hand from the ISA definition (each i16 half saturated to [0, 255], packed into D[15:0], D[31:16] kept): cafeff00 dead00ff 00008000 abcdffff, matching.

+1 to @⁠milk4sale's note on the ACO citation: on current Mesa main, v_sat_pk_u8_i16 is in neither instr_is_16bit nor can_use_opsel, only in get_gfx11_true16_mask.

One small test gap: the fixture's _e64 case writes v5, whose high half is already 0x0000, so it cannot tell a kept high half from a zeroed one for the VOP3 encoding. Seeding v5 with e.g. 0x12340000 (expected 0x12348000) would check the VOP3 form the same way as the VOP1 ones, and would be the case to run when someone measures the high-half rule on RDNA2.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-24 18:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7140551718) Checked 6446e3c merged into current `main` (3aa9754): it still merges cleanly. On Linux, Python 3.13, no GPU: `tests/semantic/test_alu_sat_pk_u8_i16.py` 5/5 pass, and `tests/test_f16_op_sel.py` + `tests/test_translate.py` pass under pytest (40 passed, the rest skipped without llvm-mc). I recomputed the fixture's four words by hand from the ISA definition (each i16 half saturated to [0, 255], packed into D[15:0], D[31:16] kept): `cafeff00 dead00ff 00008000 abcdffff`, matching. +1 to @⁠milk4sale's note on the ACO citation: on current Mesa `main`, `v_sat_pk_u8_i16` is in neither `instr_is_16bit` nor `can_use_opsel`, only in `get_gfx11_true16_mask`. One small test gap: the fixture's `_e64` case writes `v5`, whose high half is already `0x0000`, so it cannot tell a kept high half from a zeroed one for the VOP3 encoding. Seeding `v5` with e.g. `0x12340000` (expected `0x12348000`) would check the VOP3 form the same way as the VOP1 ones, and would be the case to run when someone measures the high-half rule on RDNA2. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/338/head:github-bot/gh-338'
git switch 'github-bot/gh-338'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-338'
git switch 'github-bot/gh-338'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-338'
git switch 'github-bot/gh-338'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-338'
git switch 'main'
git merge --squash 'github-bot/gh-338'
git switch 'main'
git merge --ff-only 'github-bot/gh-338'
git switch 'main'
git merge 'github-bot/gh-338'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.