Skip to content

test(semantic): add reference oracle and semantic tests for buffer_atomic_sub_x2 - #3587

Closed
slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-buffer-atomic-sub-x2
Closed

slopgobblercobbler wants to merge 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-buffer-atomic-sub-x2

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What and why

Adds a bit-accurate reference mathematical oracle and comprehensive semantic validation suite for buffer_atomic_sub_x2 in tests/semantic/test_buffer_atomic_sub_x2.py.

Covers:

  • Reference mathematical oracle matching AMD RDNA2 ISA hardware specifications (64-bit untyped buffer atomic subtraction)
  • Symbolic AST opcode definitions and typed expressions
  • Deterministic scalar instruction interpreter and execution model
  • SIMD multi-lane divergence under Wave32 and Wave64 EXEC masking
  • Register aliasing hazards and in-place operand preservation
  • Condition codes, status flags, and carry/borrow bit generation
  • IEEE 754 boundary extremes, 64-bit integer wrapping, and raw bit patterns
  • Negative controls, syntax rejection, and mutation detection

Tested

  • python -m compileall -q tests (Clean, 0 errors)
  • python -I tests/semantic/test_buffer_atomic_sub_x2.py (All 44 tests pass)
  • Standard library Python only (python -I compatible, 0 external dependencies)
  • AI-assisted: yes

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.

@ray3242

ray3242 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

At 2324b95d, the new tests/semantic/test_buffer_atomic_sub_x2.py never calls the translator. Its checks run the file's own scalar/SIMD buffer interpreters (:308,401), not rdna2spirv's lowering. With every instruction lowering disabled in memory, the suite still passes:

import rdna2spirv; rdna2spirv.Gen._insn = lambda self, *a, **k: None   # then run the suite
44 passed; translator calls: 0                     (head and merge with main)
control, #3583's suite: 1 failed, 1 passed; translator calls: 34

So a regression in the translated buffer_atomic_sub_x2 would not fail this test. CONTRIBUTING asks that tests run the repository's code, not a model written inside the test. Translating a hand-written fixture with support.translate_lines and running it in spirv_mini_interp, as the other semantic suites do, would close the gap. The model can stay as the expected-value oracle.

AI-assisted (Devin); Linux, Python 3.12.16, no GPU or game files.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured on gfx1036 (RDNA2, driver 26.10.1, game MODE; integer op), through raw hw_oracle kernels, one lane, a raw V# over the output buffer, the qword seeded with a global store, then buffer_atomic_sub_x2 v[6:7], off, s[4:7], 0 offset:16 glc and a coherent read-back: every (M, D) pair of {0, 1, 0xffffffff, 1<<32, 2^63-1, 2^63, 2^64-2, 2^64-1, 0x123456789abcdef0}, 81 cases. The returned pair is the old qword and the qword afterwards is (M - D) mod 2^64 (borrow across the two dwords) in all 81. I compared the instruction's behaviour with the formula in this PR's header; the PR's test file and any translation were not part of this run. The script is local, not pushed. AI-assisted.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested 2324b95d on Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), AMD Radeon RX 9070 XT (AMD 26.11.2), Python 3.12.10: changes suggested.

run result
unittest discover -s tests/semantic -p test_buffer_atomic_sub_x2.py 44 OK

Review: I read the whole new file at the head and compared it with current main's tools/rdna2spirv.py and the sibling suite tests/semantic/test_buffer_atomics_x2.py. The formula in the header, (M - D) mod 2^64 with the old qword returned under glc, matches Vonsek's hardware measurement in this thread. But the file tests only its own Python model, never the translator. On main, the translator doesn't lower buffer_atomic_sub_x2 at all yet. So the 44 passing tests don't cover any repository code, and they could not fail on a translator regression.

  1. tests/semantic/test_buffer_atomic_sub_x2.py:37-44 imports only the standard library; there is no rdna2spirv or spirv_mini_interp import anywhere in the file. Every test drives the file's own ref_buffer_atomic_sub_x2 (:119) through ScalarBufferInterpreter (:308) or SIMDBufferWavefrontInterpreter (:401). ray3242 already reported this and showed it by running the suite with the translator stubbed out (0 translator calls). I confirmed it independently by reading the file. There is also a new point: on upstream/main, buffer_atomic in tools/rdna2spirv.py:2114-2118 sends only and/or/xor/swap_x2 to buffer_atomic_x2 and raises Unsupported for every other *_x2, sub_x2 included. So no lowering exists for this suite to run through yet. The lowering is proposed in rdna2spirv: global_atomic_add/sub_x2 and buffer_atomic_add/sub_x2 #3065 (open, currently conflicting). This model would be most useful as the expected-value oracle for a translate + spirv_mini_interp test on top of rdna2spirv: global_atomic_add/sub_x2 and buffer_atomic_add/sub_x2 #3065, written in the same style as test_buffer_atomics_x2.py.
  2. :969-1039 (TestBufferAtomicSubX2MutationDetection) never mutates the oracle. For example, test_mutation_oob_check_omission asserts that assertEqual(in_bounds, True) raises right after assertFalse(in_bounds), which is the same check twice. test_mutation_glc_returns_post_op_value and test_mutation_addition_instead_of_sub call hand-written mutant functions and assert that they differ from a constant, without ever calling ref_buffer_atomic_sub_x2. test_mutation_simd_exec_leak writes 0 itself and then asserts that the canary is gone. All four would pass unchanged if the oracle's - were turned into +, so they detect no mutation. Similarly, :284/:383 and test_condition_codes_zero_pos_neg_borrow (:744) test "condition codes" (zero/negative/positive/borrow) that a MUBUF atomic does not produce. Without glc, the code also computes them with old_val forced to 0 (:384). These tests check state that has no hardware or translator counterpart.

AI-assisted (Claude Code); I checked the results.

@sds-228 sds-228 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.

Code review of 2324b95: no issues found. The synthetic oracle covers atomic widths, masks and rejection cases without game files. Targeted suite: 44 tests OK; compileall and diff check clean.

AI-assisted (OpenCode).

@memorypressure

Copy link
Copy Markdown

Verified on Linux against current main: merges cleanly, compiles, and the new test_buffer_atomic_sub_x2.py passes its 44 tests standalone — but it imports nothing from the repo (stdlib only) and never runs tools/rdna2spirv.py, so tests/test_semantic_translator_use.py fails on the merged tree with "imports no rdna2spirv and no helper that does" where it is green on plain main. As written it cannot observe a translator regression by construction (its own docstring calls it a reference oracle / architectural model). Reworking it through support.translate_* and the SPIR-V interpreter, in the style of the translator-driven files in tests/semantic/, would make it both admissible and regression-sensitive. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@ItsNotRexed

Copy link
Copy Markdown
Owner

Closing: the tests never exercise the translator (they model the instruction in Python without calling tools/rdna2spirv.py), so tests/test_semantic_translator_use.py rejects them. Please translate a listing through support.translate_* and check its result instead.

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