Skip to content

test(semantic): add translator-backed tests for v_pk_max_i16 - #5652

Open
slopgobblercobbler wants to merge 9 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-pk-max-i16-suite
Open

slopgobblercobbler wants to merge 9 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-pk-max-i16-suite

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds hardware-semantic translator-backed tests and reference mathematical oracle for RDNA2 VALU packed signed 16-bit integer maximum v_pk_max_i16 in tests/semantic/test_valu_pk_max_i16_hw.py.

The 8-commit progression covers:

  1. Reference mathematical oracle (ref_pk_max_i16): element-wise signed two's complement 16-bit integer maximum across low and high halves.
  2. Symbolic AST opcode definitions (V_PK_MAX_I16) and 32-bit packed operand validation.
  3. Deterministic scalar instruction interpreter with VGPR register state simulation.
  4. SIMD multi-lane divergence and per-lane varying packed signed comparisons.
  5. Register aliasing and in-place operand preservation across overlap topologies.
  6. Condition codes, status flags, and carry/borrow neutrality preservation.
  7. IEEE 754 half-precision float bit pattern interpretation and boundary checkerboard masks.
  8. Negative controls, syntax rejection, mutation detection, and end-to-end SPIR-V translator emission (support.translate_lines emitting SMax and verified via support.mrt0_words).

Tested

  • py -3.10 -m compileall -q tests (Clean, 0 errors)
  • py -3.10 -I tests/semantic/test_valu_pk_max_i16_hw.py (All test suites passed, OK)
  • py -3.10 -I tests/test_semantic_translator_use.py (Passes translator use guard, OK)
  • Standard library Python only (unittest, struct, dataclasses, enum)
  • Strictly zero game data, binaries, or proprietary keys

@mrbean56

Copy link
Copy Markdown

Tested 22a24f226b on Linux (Debian 13), Python 3.13.5: pass, mutation caught.

No GPU, no game data. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 22a24f2 merged with main 561b65a on Linux (WSL2) / Python 3.12.16 (-I, unittest discover -s tests/semantic -p test_valu_pk_max_i16_hw.py): pass

24 run, 24 passed, 0 failed. Test-only PR, so the tests also pass on main's translator (they pin existing v_pk_max_i16 behaviour). Mutation control: forcing signed = False in the packed 16-bit integer lowering of tools/rdna2spirv.py (line 6656, so max_i16 extracts unsigned) gives 2 failures; restored and it passes. Only 6 lines of the file reference the translator, so most of the 24 tests check Python reference code in the file; the 2 mutation failures show the translator-facing ones do bite.

… signed boundary cases

Address maintainer feedback from mrbean56 on PR ItsNotRexed#5652:

- Add translator-backed execution coverage (run_translated_pk_max_i16) across reference oracle cases, AST instruction validation, scalar interpreter, SIMD divergence, register aliasing, and condition codes.
- Add test_oracle_signed_vs_unsigned_discriminators with multiple execution assertions exercising signed extreme values (0x8000 vs 0x0000, 0xFFFF vs 0x0000, 0x8000 vs 0xFFFF, mixed half patterns).
- Add translated tests for op_sel / op_sel_hi modifiers and SGPR/literal operands.
- Under min/max flip mutation, 21 of 27 tests fail (up from 2); under signed=False mutation, 17 of 27 tests fail (up from 2).
- Verify with python -I (27/27 passed) and test_semantic_translator_use.py.
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Updated in cee6761 to address maintainer feedback regarding signed comparison rows and packed min/max selection sensitivity:

  • Expanded support.translate_lines execution coverage (run_translated_pk_max_i16) across all oracle cases, AST instruction validation, scalar interpreter, SIMD divergence, and register aliasing (vdst == src0, vdst == src1, all identical).
  • Added test_oracle_signed_vs_unsigned_discriminators with multiple execution assertions covering signed extreme values: 0x8000 (-32768) vs 0x0000 (0), 0xFFFF (-1) vs 0x0000 (0), 0x8000 vs 0xFFFF, and mixed-sign half combinations.
  • Added translated execution coverage for op_sel / op_sel_hi modifiers and SGPR/literal constant operands.
  • Verified mutation controls: under min/max flip mutation (SMax -> SMin), 21 of 27 tests fail (up from 2); under signed = False mutation, 17 of 27 tests fail (up from 2).
  • Verified with python -I tests/semantic/test_valu_pk_max_i16_hw.py (27/27 passed) and python -I tests/test_semantic_translator_use.py.

@larpinguser larpinguser 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.

Summary

Adds a 690-line semantic test suite for RDNA2 v_pk_max_i16: an exact signed-packed-max oracle, AST construction, scalar/SIMD lane models, register aliasing, condition codes, and bit-pattern edge cases including -32768, mixed signs, and signed-vs-unsigned discriminators. Translator-backed checks drive rdna2spirv.py through support.translate_lines/mrt0_words, including op_sel and op_sel_hi variants, comparing results to the oracle.

Why merge

Locks down packed 16-bit signed maximum semantics end-to-end, catching translator regressions on a subtle instruction.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary

Adds a 690-line semantic test suite for RDNA2 v_pk_max_i16: an exact signed-packed-max oracle, AST construction, scalar/SIMD lane models, register aliasing, condition codes, and bit-pattern edge cases including -32768, mixed signs, and signed-vs-unsigned discriminators. Translator-backed checks drive rdna2spirv.py through support.translate_lines/mrt0_words, including op_sel and op_sel_hi variants, comparing results to the oracle.

Why merge

Locks down packed 16-bit signed maximum semantics end-to-end, catching translator regressions on a subtle instruction.

Verdict: Approve

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