mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:15:52 +01:00
[PR #423] [CLOSED] SHADER-PK16-HALVES: the packed 16-bit shifts read their halves through the shared readers #474
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#474
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/423
Author: @fiestorra
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:carry/pk16-shared-halves📝 Commits (1)
3a53caardna2spirv: the packed 16-bit shifts read their halves with the shared half readers📊 Changes
3 files changed (+54 additions, -13 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
tests/test_u16_high_half.py(+38 -0)📝
tools/rdna2spirv.py(+15 -12)📄 Description
Claimed in the coordination issue as:
SHADER-PK16-HALVES(claim comment).Where this starts
The packed 16-bit shifts reading a half with a shift instead of a field extract at offset 16 landed as
a148559ba, which is what the old #4622 asked for; that change is onmainand is not re-opened here. This is the follow-up on top of it.What is left after
a148559bais that the three packed shifts still read their value halves with their own private copy of the code, while every other 16-bit half reader intools/rdna2spirv.pygoes throughGen.u16_half/Gen.i16_half:v_pk_lshlrev_b16/v_pk_lshrrev_b16/v_pk_ashrrev_i16read the high half withOpShiftRight{Logical,Arithmetic} %uint s1 16and the low half withOpBitField{S,U}Extract … 0 16, written inline.v_pk_ashrrev_i16the value is weighted as%uintand then shifted withOpShiftRightArithmetic, so the sign extension the op needs comes from a consumer choosing to read an arithmetic shift on an unsigned operand as arithmetic, instead of from the type of the operand. Everywhere else in the file a signed 16-bit half isas_intof the word, shifted as%int, and bitcast back when the result is unsigned.Both value halves now come from
Gen.u16_half/Gen.i16_half, and the signed op weights its half as%int(as_intof the source, sign-extended), shifts withOpShiftRightArithmetic %int, and only then bitcasts to%uintbefore the0xFFFFmask. The shift amount is unchanged:(s0 >> 16) & 15for a high half,OpBitFieldUExtract(s0, 0, 4)for a low one. Extracts at offset 0 elsewhere in the file are left as they were. The "16-bit high-half reads" row of the contract table now says both halves come from the shared readers and what the signed form weighs as%int, which is what the code does.This is a lowering and a consistency change, not a value change: the low 16 bits of the packed result are the same, which is why no semantic test changes its expected words. The reason to do it is that the offset-16 field extract is exactly the shape an AMD Windows driver 25.10.36 on a
gfx1036iGPU was measured reading with the offset taken mod 16 (5 of 2,000 wave32 programs oftools/valu_fuzz.py --family f16 --seed 1, measured by @Darkz0rz on 2026-11-22; the same 2,000 programs matched 2000/2000 on a secondgfx1036with driver 31.0.24002.92), and a private variant of a read the file already has one agreed shape for is where that kind of difference survives.Evidence on
ece4ba5b3Head
3a53caad8, one commit rebased ontoece4ba5b3:tools/rdna2spirv.py(27 insertions, 13 deletions),tests/test_u16_high_half.py(+38 lines), and one contract row indocs/design.md. The rebase was clean;docs/design.mdtook my row next to the ones this repository has since gained.py -3.13 -m pytest tests/test_u16_high_half.py tests/test_pk16_diff.py -q— cleanece4ba5b3:49 passed, 12 subtests passed in 15.22s. This branch:53 passed, 12 subtests passed in 4.40s. Four tests added, none changed.tools/rdna2spirv.pytaken fromece4ba5b3(git checkout refs/main -- tools/rdna2spirv.py), thenpytest tests/test_u16_high_half.py -q→2 failed, 35 passed. The two failures aretest_pk_shifts_read_the_half_they_shift_like_every_other_reader[v_pk_ashrrev_i16]andtest_pk_ashrrev_i16_shifts_the_value_as_signed, and both assert that the emitted reads carry the signed type. Restoring the file returns that single file to 37 passed.runtime/test/shaders/ps_ops4.asmandruntime/test/shaders/ps_ops6.asm(searched every.asmunderruntime/test/shadersforv_pk_(lshlrev|lshrrev|ashrrev)_b?16in both trees: the same two files). Translated throughtools/rdna2spirv.pyfrom the assembled listings on both sides:ps_ops46,820 → 6,812 bytes andps_ops65,524 → 5,636 bytes, and the tool reports1 translated, 1 pass spirv-valfor all four runs (spirv-as/spirv-valfrom Vulkan SDK 1.4.363.0).py -3.13 -I scripts/run_semantic_tests.py tests/semantic): this branch465 files, 6103 tests, 0 files failed in 354 s with 16 jobs, withllvm-mc(the onescripts/build_llvm_mc.ps1produced, LLVM 21.1.8) onPATHandspirv-as/spirv-valfrom Vulkan SDK 1.4.363.0 onPATH, andLLVM_MCunset. Nothing is red with my change in. Run withLLVM_MCset to a Windows path instead, the same tree reports1 files failed: test_image_cube_store_glc, which is that file's own helper mangling the path and has nothing to do with this branch — #419 fixes it.py -3.13 -I -m unittest discover -s tests -p "test_docs_*.py"):Ran 47 tests in 44.733s / OKon this branch andRan 47 tests in 45.178s / OKon cleanece4ba5b3. Same 47 tests, no failures either side.Tested on one desktop machine, Windows build 26300, CPython 3.13.14, MSVC 14.44.35207 (used only for the unrelated runtime build in the same worktree; nothing in this PR needs a built runtime). No GPU was used for anything measured here — the translator and its tests are CPU-side; the GPU-side value comparison of the two listings was done on 2026-11-23 on the previous base and is described above only as background. Written with an AI assistant.
Supersedes the branch carried in the private tracker as #4622's follow-up.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.