Skip to content

test(semantic): add translator tests for v_bfi_b32 - #5580

Open
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-bfi-b32-suite
Open

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-bfi-b32-suite

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds reference oracle, symbolic AST, interpreter, SIMD, and translator-backed semantic regression tests for v_bfi_b32 in tests/semantic/test_valu_bfi_b32_hw.py.

Covers:

  • Pure reference mathematical oracle matching RDNA2 hardware semantics: (src0 & src1) | (~src0 & src2)
  • Symbolic AST opcode representation and operand typing
  • Deterministic scalar instruction interpreter execution
  • SIMD multi-lane divergence under Wave32 / Wave64 EXEC masking
  • Register aliasing and in-place operand preservation
  • Condition code generation and flag isolation (SCC / VCC preservation)
  • Bitfield boundary extremes, contiguous masks, single-bit and byte insertions
  • Negative controls and syntax rejection
  • Full translation through tools/rdna2spirv.py via support.translate_lines and execution through support.mrt0_words

Tested

  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/semantic/test_valu_bfi_b32_hw.py -v (27 tests passed, OK)
  • python -I tests/test_semantic_translator_use.py (3 tests passed, OK)
  • Standard library Python only (unittest, struct, math)
  • Strictly zero game data, binaries, or proprietary keys

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested aade79bd8f7766306fea36ef7507f420aae06072 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

On a Linux RTX 5090 at aade79bd, a synthetic compute shader checked which byte v_bfi_b32 inserts from field 0xaabbccdd into base 0x11223344. Mask 0x00ff0000 produced 0x11bb3344; mask 0x000000ff produced 0x112233dd. All 27 PR tests passed.

I then removed only the right shift that aligns the source field before OpBitFieldInsert in a temporary translator copy. Both shaders validated, but the shifted-mask GPU result became 0x11dd3344: it inserted the low byte instead of the selected byte. The low-mask control still passed. Of the 27 PR tests, test_translator_sgpr_inputs alone failed, confirming it detects this alignment regression.

AI-assisted verification.

@memorypressure

Copy link
Copy Markdown

Verified against main 561b65a (clean merge): all 27 tests pass (re-run), the translator-use guard is green, and v_bfi_b32 is a real mnemonic (rdna2_isa_tables.py:1118, 0x14a); test_alu_bfi/test_bfi_known_mask/test_alu_bitfield_rev stay green. Three things to fix: the two drive-by edits to tools/rdna2spirv.py (bin(mask).count("1") replacing int.bit_count, which stays correct on the required 3.11+ but diverges from five other files using bit_count, and an unneeded future-import in a test-only PR — please drop or justify); test_scc_and_vcc_unmodified assigns scc_after = scc_before before comparing, so it can never fail; and test_mutation_detection compares a locally-defined mutant. Also worth knowing before merge: v_bfi_b32 is already covered by main's test_alu_bfi.py (23) and test_bfi_known_mask.py (3) — extending those may serve better than a parallel file. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested aade79bd, merged onto main 561b65a8. Setup: Apple M4, macOS 27.2, MoltenVK 1.4.2, AppleClang, Python 3.15.2 / 3.12.16.

  • The PR's tests: its 27 tests and test_semantic_translator_use pass on both Pythons. Full tests/semantic on 3.15: 6,177 tests OK. main runs 6,150 tests, all OK. The difference is the 27 new tests, and neither tree has a failure.

  • The tools/rdna2spirv.py hunk changes nothing. It adds from __future__ import annotations and swaps mask.bit_count() for bin(mask).count("1").

    • int.bit_count() is in Python 3.10, and the repo asks for 3.11+ (README: 3.12+). Six other tools on main already call it, and 47 already have the __future__ import.
    • Corpus shard 0/64 of my local disassembly: 415 translated and 415 spirv-val-valid on both main and the PR; all 403 written modules are byte-identical, 253 of them with OpBitFieldInsert.
    • 4,864 of 25,734 listings use v_bfi_b32.
    • I'd drop the hunk so the PR is test-only.
  • What the new file adds over main's tests. Four translator mutations of the v_bfi_b32 rule:

    Mutation New file Already caught on main by
    General path ANDs the mask with S2 instead of S1 6 fail test_alu_bfi.py (2 fail)
    Contiguous field one bit narrower in OpBitFieldInsert 2 fail test_bfi_known_mask.py (1 fail)
    mask == 0xFFFFFFFF shortcut returns S2 1 fail test_bfi_known_mask.py (1 fail)
    Alignment shift dropped (tylerstraub's mutation) 1 fail test_bfi_known_mask.py (2 fail)

    The file pins the rule, but for these four it detects nothing main's tests miss.

  • GPU: the translated output doesn't change. ps_vint_logic3, a GPU fixture that uses v_bfi_b32, passes on the M4 as on main. Full suite with main's build: 165/232 passed, 59 skipped, the same per test as main.

Verdict: pass, no regression. I'd drop the rdna2spirv.py hunk.

AI-assisted.

@milas6669

Copy link
Copy Markdown

Tested aade79bd on Windows 11 (10.0.26200), CPython 3.13, no GPU, no game data: pass.

python -I -m unittest discover -s tests/semantic -p "test_valu_bfi_b32_hw.py"  -> OK
python -I tests/test_semantic_translator_use.py                              -> OK (3 tests)

The test is translator-backed (support.translate_lines + spirv_mini_interp.run_workgroup), so it is not the model-only pattern the translator-use guard exists to stop.

Two things about the tools/rdna2spirv.py hunk, since all three of your sibling PRs touch that file:

  1. test(semantic): add translator tests for ds_bpermute_b32 #5715, test(semantic): add translator tests for v_sad_u8 #5694 and test(semantic): add translator tests for v_bfi_b32 #5580 each add the same from __future__ import annotations line to the same file, so whichever lands second conflicts on an identical line. On the repo's floor (python -I, 3.12+) the import is not needed: X | Y annotations already work there. Dropping it from all three removes the conflict entirely.
  2. width = bin(mask).count("1") replacing width = mask.bit_count() is equivalent for every int I can construct (bit_count counts the bits of the absolute value, and bin() of a negative gives the same ones), but it is the slower spelling and int.bit_count() has existed since 3.10. If the rewrite is only there for the same older-Python reason as the future import, it can go back to mask.bit_count().

Neither changes what the tests prove; this is about keeping three PRs from fighting over one line.

AI-assisted.

@milas6669

Copy link
Copy Markdown

Cross-PR hazard from the tools/rdna2spirv.py hunk (reproduced; the same family @cynbun reported on #5715 for #5715 + #5694, which a reviewer of this PR would not see there).

This PR adds from __future__ import annotations at line 1 of tools/rdna2spirv.py, above the module docstring. #5715 adds the same line in the same place and #5694 adds it below the docstring. With throwaway merges of the PR heads (git checkout -b try <head-a>; git merge <head-b>; python -I -c "import sys; sys.path.insert(0,'tools'); import rdna2spirv"), on Windows 11, Python 3.14:

merge git import rdna2spirv
#5715 + #5580 (this PR) merges cleanly, no conflict SyntaxError: from future imports must occur at the beginning of the file
#5694 + #5715 (@cynbun's case) merges cleanly same SyntaxError
#5694 + #5580 CONFLICT (so at least git warns) not tested
each PR alone n/a imports fine

So the second of #5715 / #5580 to land breaks every translator run with no merge conflict to warn anyone. Dropping the tools/rdna2spirv.py change from all three PRs avoids it (the project requires Python 3.11+, so the import is not needed, and the bin(mask).count("1") edit @memorypressure flagged is unrelated to the new test); that is the authors' and maintainers' call.

Not tested: merging all three at once beyond the pairs above, and #5694's own head beyond the import.

AI-assisted. No game data.

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.

5 participants