Skip to content

test(semantic): add translator tests for s_nor_b64 - #5642

Open
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-salu-nor-b64-suite
Open

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-salu-nor-b64-suite

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds reference oracle, symbolic AST, deterministic scalar interpreter, and translator-backed hardware tests for s_nor_b64 in tests/semantic/test_salu_nor_b64_hw.py.

Covers:

  • Architectural reference model and mathematical oracle matching RDNA2 SOP2 hardware semantics
  • Symbolic AST opcode definitions and typed operand validation
  • Deterministic scalar instruction interpreter executing s_nor_b64
  • SIMD multi-lane divergence and dynamic lane masking under Wave64 EXEC masking
  • Register aliasing and in-place operand preservation
  • Condition codes, status flags, and SCC state machine transitions
  • IEEE 754 boundary extremes, subnormals, and quiet/signaling NaN raw bitwise preservation
  • Negative syntax controls, bounds checking, and mutation detection
  • Translator validation exercising tools/rdna2spirv.py via support.translate_lines

Tested

  • Tested with Python 3.10+ (python -I)
  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/semantic/test_salu_nor_b64_hw.py (All 27 tests passed, OK)
  • python -I tests/test_semantic_translator_use.py (All 3 tests passed, OK)
  • Standard library Python only (unittest, struct, math, dataclasses, enum)
  • Strictly zero game data, binaries, or proprietary keys

@mrbean56

Copy link
Copy Markdown

Read and ran a3fcda63ee on Linux (Debian 13), Python 3.13.5: tests pass, but the translator test does not bind the lowering.

  • pytest tests/semantic/test_salu_nor_b64_hw.py -q: 27 passed, 34 subtests.
  • Mutation: changing the b64 emitter's "nor": "OpBitwiseOr" → OpBitwiseAnd leaves 27 passed. The only translator-backed test (test_translator_pipeline_execution) asserts OpCapability Shader, OpFunction and OpReturn in the text; it never executes the module and never looks at the emitted opcode. The file imports spirv_mini_interp as si and never uses it.
  • So the value and SCC assertions all run against the file's own Python model; a wrong cut of the instruction in rdna2spirv.py would ship green. The sibling PRs (test(semantic): add translator tests for s_xnor_b64 #5615, test(semantic): add translator tests for s_and_b64 #5621, test(semantic): add translator tests for s_nand_b64 #5628, test(semantic): add translator tests for s_not_b64 #5659) run the translated module through support.mrt0_words / the mini interpreter and their mutations do fail — same shape here would fix it: build the shader, run it, compare (d, scc) for a mixed pattern like 0x00FF… / 0x0000…, and keep the oracle tests as the reference.
  • SCC in particular needs that: the oracle asserts SCC = D != 0, but nothing proves the translator writes it.

No GPU, no game data. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested a3fcda6 merged with main 561b65a on Linux (WSL2) / Python 3.12.16: concern

tests/semantic/test_salu_nor_b64_hw.py (new, test-only): 27 run, 27 passed, 0 failed. Merge with main was clean.

Negative control: the file only adds a test, so it trivially passes on main. I also mutated the translator: in tools/rdna2spirv.py the s_nor_b64 entry of the opcode table changed from OpBitwiseOr to OpBitwiseAnd. All 27 tests still pass (27 run, 0 failed), so the test would not catch a wrong s_nor_b64 translation; restored afterwards.

Why: the only test that reaches the translator is test_translator_pipeline_execution, which asserts that translate_lines output contains "OpCapability Shader", "OpFunction" and "OpReturn" and never runs it. The other tests exercise classes defined in the test file (a Python oracle, an AST validator, scalar and SIMD "interpreters", mutant functions). Suggest executing the SPIR-V with the mini interpreter and asserting the lane mask and SCC, as other tests/semantic files do.

@ps1ke

ps1ke commented Nov 23, 2026

Copy link
Copy Markdown

Tested a3fcda63e on Linux x86-64 (Arch, Python 3.14, LLVM 23.1.3), CPU only, no GPU, no game files: pass.

  • python -I -m unittest discover -s tests/semantic -p <the new file>: 27 tests OK (they translate hand-written s_nor_b64 listings and compare the output words with the Python reference).
  • Standard library only, no game data in the file.

AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

TEST validation — Needs changes

Validated on CPU (no GPU, no game files). All 27 tests pass, BUT the translator lowering is not actually pinned:

  • Mutating rdna2spirv.py's s_nor_b64 emitter from OpBitwiseOr → OpBitwiseAnd leaves all 27 tests passing — a wrong translation ships green.
  • The only test reaching the translator (test_translator_pipeline_execution) merely asserts OpCapability Shader, OpFunction, and OpReturn appear in text output; it never executes the module and never inspects the emitted opcode.
  • The file imports spirv_mini_interp but never uses it. All value/SCC assertions run against the file's own Python model.

Fix needed: Execute the SPIR-V with spirv_mini_interp and assert lane mask + SCC for a mixed pattern (e.g. 0x00FF… / 0x0000…), matching the stronger sibling PR pattern (#5615 s_xnor_b64, #5621 s_and_b64, #5628 s_nand_b64, #5659 s_not_b64).

Validation: Passed on Debian 13 (Python 3.13.5), Linux WSL2 (Python 3.12.16), Arch Linux (Python 3.14). ~34 subtests.

Recommendation: Needs changes — add translator execution + SCC assertions before merge.

@isfcrctfs isfcrctfs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Read at the PR head (a3fcda63) against current origin/main (6dda063).

  • Audit (audit.py pr 5642): 5 HIGH dynamic-exec hits (lines 73/113/118/124/131). All five are the static helper named SNorB64Oracle.eval, which is plain 64-bit NOR; false positives, no real finding.
  • python3 -I tests/semantic/test_salu_nor_b64_hw.py: 27 tests OK; translator-use guard 3 OK.

The translator lowering is not pinned. I changed the b64 emitter's "nor": "OpBitwiseOr" to "OpBitwiseAnd" in tools/rdna2spirv.py and all 27 tests still pass. The only test that reaches the translator (test_translator_pipeline_execution, lines 129-135) asserts OpCapability Shader/OpFunction/OpReturn in the text; build_compute_shader (lines 70-85) has no export or store, so the NOR result and SCC are never observed, and spirv_mini_interp is imported at line 34 but unused. Everything else exercises the AST/oracle/interpreter classes defined here.

s_nor_b64 already has translator-backed execution in tests/semantic/test_salu64_bitwise_data.py (value table, SCC four-corner matrix, aliasing and lane-mask cases through translate_ps/mrt0_words). Suggested fix: add one executed case (mixed pattern, assert D and SCC) and keep the oracle as the reference, or drop this file in favour of that one.

Separate doc bug: line 1 is from __future__ import annotations and the docstring starts on line 3, so the string is not a module docstring — ast.get_docstring() returns None for this file.

AI-assisted

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested a3fcda63 on Linux, CPython 3.14, CPU only, merged onto main 4241d195: the tests pass, but they do not check the translator's NOR

  • python -m unittest discover -s tests/semantic -p test_salu_nor_b64_hw.py: Ran 27 tests, OK.
  • Mutation check: in the merged tree I removed "s_nor_b64" from the inversion set at tools/rdna2spirv.py:10441 (inv = op in ("s_nand_b64", "s_nor_b64", "s_xnor_b64")), so the translator emits a plain OR for s_nor_b64. Same command: Ran 27 tests, OK. No test notices.

So a translator regression in this instruction would not turn this file red. By the agent's reading, which I did not repeat, only one test goes through the translator and it asserts that a module is produced, not its result; the other 26 exercise a model defined inside the test file. An assertion on the translated shader's output word for one NOR case would close the gap.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

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