Skip to content

lane_masks: track v_and_or_b32, v_xnor_b32, and v_bfi_b32 in VECTOR_BITWISE - #4367

Closed
kotekompotek wants to merge 0 commit into
ItsNotRexed:mainfrom
kotekompotek:contribution/lane-masks-vector-bitwise-ops
Closed

kotekompotek wants to merge 0 commit into
ItsNotRexed:mainfrom
kotekompotek:contribution/lane-masks-vector-bitwise-ops

Conversation

@kotekompotek

Copy link
Copy Markdown

Claimed in the coordination issue as: #4257 (comment)

What and why

AI-assisted contribution (CPU-verified locally on Windows 10 Pro / Python 3.12.6; synthetic shaders only, no game data).

Adds "v_and_or_b32", "v_xnor_b32", and "v_bfi_b32" to VECTOR_BITWISE in tools/lane_masks.py. All three instructions compute per-lane 32-bit bitwise combinations (and rdna2spirv.py already models all three without operand modifiers changing mask bit meaning). Because they were absent from VECTOR_BITWISE, building a per-lane wave mask with them left write_all_lanes = False (leaving inactive lanes holding stale values) and broke downstream v_readfirstlane_b32 whole-wave mask reconstruction.

Checked open PRs and #2885 (now merged on main) plus #3225: this change only adds these three opcodes to VECTOR_BITWISE plus dedicated unit/semantic tests and docs/design.md, and is rebased cleanly on main.

Tested

CPU-only (Windows 10 Pro x64, Python 3.12.6; no llvm-mc, spirv-as/spirv-val, Windows SDK 10.0.26100, or GPU runtime build available locally):

  • Pre-fix reproduction: tests/test_lane_masks.py failed (AssertionError on v_and_or_b32), and tests/semantic/test_lane_masks_vector_bitwise.py failed on 3 of 4 tests (Wave32: 32 != 18, Wave64Native: 64 != 34, Wave64Emulated: 0 != 6; non-mask EXEC control passed).
  • Post-rebase & post-fix (3637cd86 on 03b09a08):
    • python -I tests/test_lane_masks.py -> ok
    • python -I tests/semantic/test_lane_masks_vector_bitwise.py -v -> Ran 4 tests in 1.437s OK (Wave32 & Wave64 native execution via spirv_mini_interp.py, --wave64-emulate SPIR-V structural check, non-mask EXEC control)
    • python -m pytest tests/test_wave64_halves_fixtures.py tests/test_salu_diff.py tests/test_crosslane_fuzz.py -q -> 85 passed, 3 skipped in 26.41s (llvm-mc/spirv-val skips)
    • tests/test_docs_design_rows.py (2 OK), test_docs_repo_paths.py (2 OK), test_docs_links.py (6 OK), test_docs_list_items.py (2 OK), test_text_write_line_endings.py (3 OK), test_resource_hygiene.py (2 OK), compileall, git diff --check -> all passed.

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.

@justr4mzi

Copy link
Copy Markdown
Contributor

Tested 3637cd86 on Windows 11 (25H2 26200.9974, Python 3.14.0, SPIRV-Tools v2026.4 from Vulkan SDK 1.4.363.0, native llvm-mc 21.1.8): pass.

  • python -I tests/test_lane_masks.py -v: ok (py_compile on tools/lane_masks.py, tests/test_lane_masks.py, and tests/semantic/test_lane_masks_vector_bitwise.py exit 0).
  • python -I tests/semantic/test_lane_masks_vector_bitwise.py -v: 4/4 OK (0.639 s; 4/4 via unittest discover as well).
  • Negative control against main (f847748c via LEONIDA_TOOLS_DIR): 3 failed, 1 passed (exact expected failures on Wave32 32 != 18, Wave64 native 64 != 34, Wave64 emulated mask_writes 0 != 6, while non-mask data control stayed ok).
  • spirv-as + spirv-val --target-env vulkan1.2 (v2026.4) on all 4 translated test shaders (wave32 mask_writes=3, wave64 native mask_writes=6, wave64 --wave64-emulate mask_writes=6, ctrl32 mask_writes=0): all 4 assemble and pass validation (rc=0).
  • Docs & contract suites: test_docs_design_rows.py (2/2), test_docs_repo_paths.py (2/2), test_docs_cli_flags.py (3/3), test_design_contract_rows.py (4/4) all OK.

No game data. AI-assisted (Gemini, Antigravity).

@SphyserX

Copy link
Copy Markdown

Tested 3637cd8 on Arch Linux (in a VM), CPython 3.14: pass.

@mrbean56

Copy link
Copy Markdown

Tested 3637cd8631 on Linux (Debian 13), Python 3.13.5: pass.

  • pytest tests/test_lane_masks.py -q: 9 passed. pytest tests/semantic/test_lane_masks_vector_bitwise.py -q: 4 passed.
  • I checked why the three ops are safe at the mask bit level: lane_masks.py only classifies a VALU write when every source is a mask or a constant 0/-1 (if None not in kinds), and all three are per-bit functions (and_or = (a&b)|c, xnor = ~(a^b), bfi = (a&b)|(~a&c)), so mask/constant inputs can only give 0/~0 per lane; modified forms and SDWA/DPP are still excluded.

No GPU, no game data. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 3637cd86 on Windows 11: tests/test_lane_masks.py -> ok; tests/semantic/test_lane_masks_vector_bitwise.py -> 4 tests, OK; git diff --check clean.

lane_masks now tracks v_and_or_b32, v_xnor_b32 and v_bfi_b32 as vector bitwise mask producers, and the new cases plus the existing mask tests pass. No blocking issue.

@lines9686-rgb

Copy link
Copy Markdown
Contributor

Tested b90ef06 on Windows 11 (26200), Python 3.12: pass. tests/semantic/test_lane_masks_vector_bitwise.py and tests/test_lane_masks.py OK on this branch; against the base's code (3faac55) the first fails 3 and the second stops at AssertionError: v_and_or_b32, so the new VECTOR_BITWISE entries are what they check. Merges cleanly with main; compileall OK. No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested b90ef06 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.

  • tests/test_lane_masks.py OK; tests/semantic/test_lane_masks_vector_bitwise.py 4 tests OK; all 10 tests/test_docs_*.py OK.
  • Related semantic files also pass: test_lane_mask*.py (43), test_salu_lane_mask.py (15, 1 skipped), test_wave64_*.py (198), test_scalar_bcnt.py (35).
  • Negative control: with main's tools/lane_masks.py, test_lane_masks.py fails (AssertionError on v_and_or_b32 in test_v_and_or_xnor_bfi_track_vector_masks) and the semantic file fails 3 of 4 tests.
  • FYI unrelated: tests/semantic/test_loop_ballot_barrier.py fails here (3 failures, 2 errors) identically with main's lane_masks.py, so it is not caused by this PR.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
@kotekompotek
kotekompotek force-pushed the contribution/lane-masks-vector-bitwise-ops branch from b90ef06 to dde82f2 Compare November 23, 2026 17:40
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.

7 participants