Skip to content

tools: vint_diff.py, a differential fuzzer for 32-bit integer VALU in every encoding and source kind - #2371

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:fuzz/vint-diff
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:fuzz/vint-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-VINT-DIFF (claim)

What and why

tools/shader_diff.py checks the common integer VALU opcodes with VGPR sources in their e32 form. Nothing generates the VOP3-only integer opcodes a compiler emits all the time (v_add3_u32, v_lshl_add_u32, v_perm_b32, v_min3/max3/med3, ...), the e64 forms of the VOP1/VOP2 ones, or SGPR, float-inline and literal sources in the positions each encoding allows. tools/vint_diff.py covers that, in the style of tools/salu_diff.py (stdlib only, python -I, --programs/--seed/--max-ops/--ops/--list-ops/--self-test, shrinking on mismatch, skips counted with reasons, exit 0/1/2/77):

  • A separate reference for 55 opcodes: 24 VOP1/VOP2 (generated as e32 and e64) and 31 VOP3-only, including v_alignbit/alignbyte, v_perm_b32 (all selector kinds), v_bfe_u32/i32 (the field stops at bit 31), the 24-bit and 16-bit multiplies (op_sel on v_mad_u32_u16/v_mad_i32_i16), v_bcnt, v_bfm, v_ffbh/ffbl, v_cvt_pk_u16_u32/v_cvt_pk_i16_i32, plus VOPC e64 into s20/s21/vcc_lo followed by v_cndmask_b32_e64.
  • Sources: VGPRs, seeded SGPRs, integer inline constants, float inline constants (their f32 bits) and literals. An e32 VOP2 has a VGPR in src1 and a literal only in src0; a VOP3 form has at most one literal and two scalar values (the GFX10 constant bus). A literal in a 16-bit source of v_mad_*_u16/i16 has 16 bits, because the assembler rejects a wider one.
  • One lane: the translated SPIR-V runs in tests/semantic/spirv_mini_interp.py. Everything that depends on other lanes is in tools/wint_diff.py (tools: wint_diff.py, a whole-wave differential fuzzer for integer VALU under random EXEC #2336).
  • --oracle hw runs the same programs through tools/hw_oracle (one lane of a wave32 dispatch).
  • The one known divergence, a compare's mask read as VALU data (Translator: a lane mask read as data gives the wave's bits (SHADER-21 part 1, #210) #293), is left out by default and comes back with --known. The docstring lists what is modelled, what is not generated and that form.

tests/test_vint_diff.py (18 tests): hand-worked reference values (the VOP3-only ops, saturating packs, v_bfe past bit 31, v_perm selectors, 24/16-bit multiplies with op_sel, find-first-bit, constant sources, compare + select, the 16-bit literal rule), the translator on a list of hand cases, a short seeded run, generator checks (every op in every form, the encoding and constant-bus rules, known form only with --known), canaries (a faked wrong word is caught, shrinking keeps the guilty instruction) and the exit codes including 77. docs/shader_validation.md gets a short section.

Tested

Windows 11, Python 3.

  • python -I tools/vint_diff.py: --programs 4000 --seed 1 and --programs 2000 --seed 2 --max-ops 10 --no-literals, plus 500 at seed 1 while building: 0 mismatch, 0 skipped.
  • --known --programs 1000 --seed 1: 10 mismatches, all a compare's mask read as data (shrunk: v_cmp_t_i32_e64 s21, ... then v_mul_lo_u32 v5, 35, s21 gives 0x23 on the hardware model, 0xffffffdd translated).
  • Hardware, --oracle hw on the AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, gfx1036, driver 26.10.1, HIP oracle), known form included: --programs 500 with seeds 1 and 2 (--max-ops 10), and --oracle translator,hw --programs 500 --seed 3 on v_perm_b32, v_bfe_*, v_mad_*_u16/i16, v_alignbyte_b32, v_ffbh_i32, v_cvt_pk_i16_i32, v_mul_hi_i32_i24 and compares: 0 mismatch. A first run had 9 of 300 programs rejected by the assembler (32-bit literals in 16-bit sources); that led to the 16-bit literal rule, and a hand probe on the GPU measured how such a literal and a float constant read under op_sel. The NVIDIA RTX 5080 has no part here (CPU tool; the hardware oracle needs AMD).
  • Negative control: changing the constant-shift v_alignbit_b32 path in tools/rdna2spirv.py (inv_val = 32 - m_val -> 31 - m_val) fails test_hand_cases_match_the_translator (reference 0x03ffffff, translated 0x01ffffff) and test_short_seeded_run_matches, and gives 6 mismatches in 300 programs. Reverted.
  • python -I tests/test_vint_diff.py (about 5 s) OK, python -m compileall -q tools tests OK, tests/test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py, test_tool_startup.py, test_tool_stdout_encoding.py OK.
  • No new translator divergence came out of these runs.

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

AI-assisted.

… every encoding and source kind

A separate ISA model for 55 integer opcodes (VOP1/VOP2 as e32 and e64, VOP3-only ops, VOPC e64 + v_cndmask) with VGPR, SGPR, inline, float-inline and literal sources within the encoding and 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 mask read as data (ItsNotRexed#293) only with --known.

AI-assisted.
@TurboSosiska304

Copy link
Copy Markdown

Ran it on Linux / Python 3.14.10 (the description says Windows, Python 3), commit 4b6e54b — different interpreter and platform, and fresh seeds:

run result
tests/test_vint_diff.py 18 tests OK
--self-test match / hand values / unsupported-form skip: all True
--programs 5000 --seed 20261122 5000 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 800 --seed 3 795 pass, 5 mismatch — all one class: v_cmp_t_i32_e64 vcc_lo, ... with the mask read back as VALU data, i.e. #293, the divergence the --known flag documents. Same rate as your 10/1000.

No new translator divergence, and no Python 3.14 problem: 9,000 generated programs plus the negative-control machinery ran without an error or a skip. --max-ops 10 and --no-literals behave as advertised.

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