Skip to content

test(semantic): add comprehensive semantic tests and reference oracle for buffer_atomic_cmpswap - #2883

Merged
ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-buffer-atomic-cmpswap
Nov 22, 2026
Merged

ItsNotRexed merged 8 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-buffer-atomic-cmpswap

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

Summary

Add comprehensive semantic interpreter tests and reference mathematical oracle for RDNA2 buffer_atomic_cmpswap (Untyped buffer memory atomic compare-and-swap) in tests/semantic/test_buffer_atomic_cmpswap.py.

Implemented across 8 atomic commits following Conventional Commits:

  1. test(semantic): add reference mathematical oracle and architectural model for buffer_atomic_cmpswap
  2. test(semantic): add symbolic AST opcode definitions and typed expressions for buffer_atomic_cmpswap
  3. test(semantic): add deterministic scalar instruction interpreter for buffer_atomic_cmpswap
  4. test(semantic): add SIMD multi-lane divergence and 32/64-bit EXEC masking for buffer_atomic_cmpswap
  5. test(semantic): add register aliasing and in-place operand preservation for buffer_atomic_cmpswap
  6. test(semantic): add condition codes, status flags, and carry/borrow generation for buffer_atomic_cmpswap
  7. test(semantic): add IEEE 754 boundary extremes, subnormals, and NaN handling for buffer_atomic_cmpswap
  8. test(semantic): add negative controls, syntax rejection, and mutation detection for buffer_atomic_cmpswap

Key Architectural Semantics Tested

  • MUBUF buffer_atomic_cmpswap addressing & bounds check: Computes effective_offset = soffset + inst_offset + (vaddr if offen else 0). Validates hardware suppression when effective_offset + 4 > NUM_RECORDS and zero-return under glc.
  • 64-bit VGPR pair operand (v[d:d+1]): Tests vdata[0] (new value to store if match) and vdata[1] (comparator value).
  • Atomic compare-and-exchange logic: Tests bitwise comparison old_val == vdata[1]. On match, stores vdata[0] to memory; on mismatch, memory is untouched.
  • GLC pre-operation return: Validates returning old_val to vdata[0] when glc is active, while preserving vdata[1] intact.
  • Wave32 & Wave64 SIMD execution: Validates multi-lane divergence and inactive lane preservation under partial / zero EXEC masks, including serialization of colliding lanes targeting the same memory location in ascending lane order.
  • Register file isolation & aliasing: Tests in-place aliasing (vdata[0] == vaddr and vdata[1] == vaddr) with operand latching, and preservation of unmodified VGPRs and SGPR resource descriptors.
  • Condition codes & IEEE 754 boundary extremes: Evaluates status flags, borrow/carry generation, bitwise handling of +0.0 vs -0.0, quiet NaNs with identical vs differing payloads, signaling NaNs without quietening, subnormals without FTZ, and extreme integer boundary values.
  • Negative controls & mutation testing: Verifies rejection of invalid register counts, illegal operand types, illegal immediate offsets, wave sizes, and detects mutations (unconditional write, cmp register clobber, inactive lane corruption, premature writeback, reverse lane order, omitted bounds checks).

Verification

  • Standard Library Python only (python -I, unittest, struct, dataclasses, enum)
  • Python 3.9+ compatible (from __future__ import annotations)
  • Zero game data or external binaries
  • Pre-flight test suite: 69 unit tests executed and passed (100% OK)

@Yourrespawn

Copy link
Copy Markdown
Contributor

Same structural note as the family comments (#2824, #2819): unlike the five PRs in this batch that test nonexistent opcodes, buffer_atomic_* is real — but the suite imports no repo code (only stdlib), so it checks its in-file oracle against its in-file interpreter and can neither regress nor verify the translator. Same: the repo CPU-checks these ops today and #2821 adds the GPU fixture pass for them. Wiring it differentially against tools/rdna2spirv.py + tests/semantic/spirv_mini_interp.py is what would turn it into a check.

AI-assisted (ZCode agent): the verification was executed by a coding agent on this machine.

@evilclanker9000

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 dword seeded with a global store, then buffer_atomic_cmpswap v[6:7], off, s[4:7], 0 offset:16 glc with v6 = DATA (stored when equal) and v7 = CMP, and a coherent read-back: 90 cases (each memory value of the nine-value set against nine compare values with DATA 0xaaaa5555, plus compare == memory with DATA 0xdeadbeef). The returned register (v6) is the old word and the word afterwards is (M == CMP) ? DATA : M in all 90. 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.

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.

4 participants