Skip to content

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

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

kotekompotek wants to merge 1 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.

…ITWISE

Add v_and_or_b32, v_xnor_b32, and v_bfi_b32 to VECTOR_BITWISE in tools/lane_masks.py so per-lane wave masks computed through them under partial EXEC receive all-lanes stores and keep mask status through v_readfirstlane_b32, while non-mask data inputs stay EXEC-gated.

Update the Whole-wave masks row in docs/design.md and add unit + semantic interpreter checks in tests/test_lane_masks.py and tests/semantic/test_lane_masks_vector_bitwise.py.

Verification (Windows 10 Pro x64, Python 3.12.6, CPU-only; no llvm-mc/spirv-val/WinSDK 10.0.26100):
- tests/test_lane_masks.py: ok
- tests/semantic/test_lane_masks_vector_bitwise.py: 4 tests OK (Wave32, Wave64 native, Wave64 emulated structural, data control)
- docs/line-endings/hygiene/startup checks and 83 pytest checks (3 skipped): OK
@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.

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