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

Merged
NolanCotter merged 1 commit from upstream-pr/338 into main 2026-11-28 11:51:16 +00:00
NolanCotter commented 2026-11-24 03:24:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by NolanCotter on 2026-11-24T03:24:44Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465493639 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/338). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T03:24:44Z. --- 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)
Sangonapou commented 2026-11-24 05:06:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Sangonapou on 2026-11-24T05:06:04Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7122623729 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7122623729). Originally posted by [Sangonapou](https://github.com/Sangonapou) on 2026-11-24T05:06:04Z. --- 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.
milk4sale commented 2026-11-24 06:39:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by milk4sale on 2026-11-24T06:39:03Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124150986 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7124150986). Originally posted by [milk4sale](https://github.com/milk4sale) on 2026-11-24T06:39:03Z. --- 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.
tiguan26 commented 2026-11-24 18:22:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-24T18:22:21Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140551718 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/338#issuecomment-7140551718). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-24T18:22:21Z. --- 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).
sodove commented 2026-11-28 10:45:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:45:21Z.


#338 | head 6446e3ce76483c5c3ba2b539258ab5d80482369e | python3 -m unittest discover -s tests/semantic -p test_alu_sat_pk_u8_i16.py -v, python3 -m pytest -q -rA tests/test_f16_op_sel.py, python3 -m pytest -q -rA tests/test_translate.py | red: 759 run, 1 failure, 4 errors | green: 769 passed | Red → green

The new packed saturation opcode failed on main. All three merged files passed, including the full PR-modified test_translate.py file.

Captured 17 distinct complete SPIR-V module(s) emitted while rerunning test_alu_sat_pk_u8_i16.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.

Test file Main + PR tests PR + main
tests/semantic/test_alu_sat_pk_u8_i16.py 5 run, 4 errors 5 passed
tests/test_f16_op_sel.py 40 passed 40 passed
tests/test_translate.py 714 run, 1 failure 724 passed

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238100987 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/338#issuecomment-7238100987). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:45:21Z. --- #338 | head `6446e3ce76483c5c3ba2b539258ab5d80482369e` | `python3 -m unittest discover -s tests/semantic -p test_alu_sat_pk_u8_i16.py -v`, `python3 -m pytest -q -rA tests/test_f16_op_sel.py`, `python3 -m pytest -q -rA tests/test_translate.py` | red: 759 run, 1 failure, 4 errors | green: 769 passed | **Red → green** The new packed saturation opcode failed on main. All three merged files passed, including the full PR-modified test_translate.py file. Captured 17 distinct complete SPIR-V module(s) emitted while rerunning test_alu_sat_pk_u8_i16.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand. | Test file | Main + PR tests | PR + main | |---|---|---| | `tests/semantic/test_alu_sat_pk_u8_i16.py` | 5 run, 4 errors | 5 passed | | `tests/test_f16_op_sel.py` | 40 passed | 40 passed | | `tests/test_translate.py` | 714 run, 1 failure | 724 passed | Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
DadaCap commented 2026-11-28 11:51:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:51:18Z.


Merged, thank you @NolanCotter! This translator PR (rdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238826547 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/338#issuecomment-7238826547). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:51:18Z. --- Merged, thank you @NolanCotter! This translator PR (rdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
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
ProjectLeonida/mandy!338
No description provided.