Skip to content

tools: pk16_diff.py, a differential fuzzer for packed and 16-bit integer VALU - #2431

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:fuzz/pk16-diff
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:fuzz/pk16-diff

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-TOOL-PK16 (claim)

What and why

tools/pk16_diff.py, a differential fuzzer for packed and 16-bit integer VALU, in the shape of salu_diff.py / #2336 / #2371 (standard library, python -I, seeded, shrinking, counted skips, exit codes 0/1/2/77). valu_fuzz.py --family f16 covers the 16-bit shifts, v_add/sub_nc_u16, v_mul_lo_u16 and 16-bit min/max with VGPR sources. Nothing generated the rest:

  • packed integer ops: v_pk_add/sub_u16/i16, v_pk_mul_lo_u16, v_pk_min/max_u16/i16, v_pk_mad_u16/i16, the packed shifts, with op_sel, op_sel_hi and clamp;
  • 16-bit VOP3 ops: v_add/sub_nc_u16/i16, v_mul_lo_u16, v_min/max_*16, the shifts, v_min3/max3/med3_u16/i16, v_mad_u16/i16, with op_sel on every source and on the destination half, the kept other half, and clamp;
  • sources: VGPRs, SGPRs, integer and float inline constants, literals, within the GFX10 constant-bus limits.

The reference is its own model from the ISA pseudocode (no code shared with the translator, cpu_ref.py or the other fuzzers), one lane, four exported words compared bit for bit with rdna2spirv run in tests/semantic/spirv_mini_interp.py. --oracle hw runs the same programs natively through tools/hw_oracle.

Known divergences are left out by default and come back with --known: a constant whose high half a packed add/sub/mul/min/max/mad reads. On main the translator rejects that (counted skip). #2224 removes the rejection.

Not covered: neg_lo/neg_hi on integer packed ops, DPP/SDWA, v_mad_u32_u16 (in #2371), v_dot* (#2229). The programs carry no encoding bytes, so encoding-dependent rules such as SHADER-208 (a literal's 12-byte VOP3 encoding) are out of reach. The VOP2-named 16-bit ops only have a VOP3 encoding on GFX10, so the generator writes them with _e64: without encoding bytes the translator reads a bare v_max_u16 as the VOP2 write that zeroes the high half. Game listings carry the bytes, so this does not affect them.

tests/test_pk16_diff.py: hand-worked reference values (halves under op_sel/op_sel_hi, clamp vs wrap, shift masks, kept halves, constants split like registers), generator rules (every op and modifier, constant bus, 16-bit literals, known forms off by default), the self-test canaries, a short seeded translator run (80 programs, 0 skips), twelve hand cases against the translator, a wrong-translation check, shrinking, exit codes, and exit 77 without the oracle tools. Plus a docs/shader_validation.md section.

Tested

Windows 11, Python 3.12.

  • Hardware: AMD Radeon RDNA2 iGPU (gfx1036, Ryzen 9 9950X3D, driver 26.10.1), --oracle hw (the --known forms included): seeds 1, 2, 3 and 6, 500 programs each (with and without literals, up to 8 ops), plus 300 programs with --oracle translator,hw (seed 5): 2,300 of 2,300 match the model. Before this, a probe measured that a constant in a 16-bit VOP3 op is its 32-bit value split into halves (1.0 is 0x0000/0x3f80, -16 is 0xfff0/0xffff, a 16-bit literal's high half is 0).
  • Translator: 3,000 programs (seed 11, up to 8 ops) and 1,000 without literals (seed 13, up to 10 ops): all match, 0 skipped. With --known (seed 12, 1,000): 615 match, 385 skipped (high half of a constant, rdna2spirv: a constant operand of the packed 16-bit integer ops is its 32-bit value (measured on RDNA2) #2224), 0 mismatch.
  • Negative control: changing the v_add/sub_nc_i16 clamp bound in rdna2spirv.py from 0x7FFF to 0x7FFE gives 300 programs: 284 pass, 16 mismatch with --ops v_add_nc_i16,v_sub_nc_i16, shrunk to one v_sub_nc_i16 ... clamp (reverted).
  • python -I tests/test_pk16_diff.py: 15 tests OK. tests/test_docs_repo_paths.py, test_docs_links.py, test_docs_list_items.py: OK.

No translator change. AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule.)

…ger VALU

A separate ISA model for the v_pk_* integer ops (op_sel, op_sel_hi, clamp) and the 16-bit VOP3 integer ops (op_sel on sources and the destination half, the kept other half, clamp), with VGPR, SGPR, inline-constant and literal sources within the constant-bus rules, compared one lane at a time with rdna2spirv run in tests/semantic/spirv_mini_interp.py, optionally with the hardware through tools/hw_oracle. A constant whose high half a packed op reads (ItsNotRexed#2224) only with --known.

AI-assisted.
@TurboSosiska304

Copy link
Copy Markdown

Ran it on Linux / Python 3.14.10 (description: Windows, Python 3.12), commit 91fb9d6, with fresh seeds and your seed 12 for a cross-check:

run result
tests/test_pk16_diff.py 15 tests OK
--self-test match / hand values / unsupported-form skip: all True
--programs 3000 --seed 20261122 3000 pass, 0 mismatch, 0 skipped
--programs 2000 --seed 7 --max-ops 10 2000 pass, 0 mismatch, 0 skipped
--programs 2000 --seed 7 --no-literals 2000 pass, 0 mismatch, 0 skipped
--known --programs 1000 --seed 12 615 pass, 0 mismatch, 385 skipped — identical to your numbers, every skip v_pk_* "high half of a constant" (#2224)

So the generator is reproducible across platform and Python version on the same seed, and 7,000 fresh programs found no divergence. No Python 3.14 issue.

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.

3 participants