Skip to content

test(semantic): VALU transcendental instructions bundle (sin, cos, exp, log, rcp, rsq, sqrt) - #5884

Open
slopgobblercobbler wants to merge 29 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-transcendentals-bundle
Open

slopgobblercobbler wants to merge 29 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-valu-transcendentals-bundle

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

Summary

This PR implements Bundle 1 (VALU Transcendental Suite) in tests/semantic/test_valu_transcendentals_bundle.py, staging 28 atomic commits across 7 fundamental RDNA2 floating-point transcendental instructions:

  • v_sin_f32: Sine with input in turns ($1.0 \text{ turn} = 2\pi \text{ rad}$), range-reduced to $[-0.5, 0.5]$, exact zero at odd half turns ($|x - \text{round}(x)| = 0.5$), signed zero preservation.
  • v_cos_f32: Cosine with input in turns, range-reduced, exact zero at odd quarter turns ($|x - \text{round}(x)| = 0.25$).
  • v_exp_f32: Base-2 exponential ($2^x$), powers of two, infinite and negative-infinite limits.
  • v_log_f32: Base-2 logarithm ($\log_2(x)$), powers of two, pole at $x=0$, NaN on negative arguments.
  • v_rcp_f32: Single-precision reciprocal ($1.0 / x$), division by zero limits ($\pm\infty$), signed zeros.
  • v_rsq_f32: Reciprocal square root ($1.0 / \sqrt{x}$), zero pole ($+\infty$), negative NaN rejection.
  • v_sqrt_f32: Single-precision square root ($\sqrt{x}$), exact squares, negative NaN rejection, $-0.0 \to -0.0$.

Progression (28 Atomic Commits, 4 per Opcode)

For each of the 7 opcodes:

  1. test(semantic): add reference mathematical oracle for <opcode>
  2. test(semantic): add AST definitions and scalar interpreter for <opcode>
  3. test(semantic): add SIMD divergence and IEEE 754 handling for <opcode>
  4. test(semantic): add translator integration tests for <opcode>

Verification

  • python -m compileall -q tests passes with zero errors.
  • python -I tests/semantic/test_valu_transcendentals_bundle.py passes all test suites.
  • python -I tests/test_semantic_translator_use.py confirms translator execution for all 7 opcodes via support.translate_lines(...) and support.mrt0_words(...).
  • Pure Python standard library only (unittest, struct, math, dataclasses, enum).
  • Zero game data, keys, or decryption workarounds.

@kapitche

Copy link
Copy Markdown
Contributor

Tested ad4f28c merged with main 561b65a on Linux (WSL2) / Python 3.12.16: pass

test_valu_transcendentals_bundle.py (the only changed file): 44 tests run, 44 passed, 0 failed, 0 skipped (-I -m unittest discover -s tests/semantic -p test_valu_transcendentals_bundle.py). tests/test_semantic_translator_use.py also passes (3/3) on the merge.

Negative control: the PR changes only a test file, so there is no fix to revert. The tests translate hand-written lines through the unmodified tools/rdna2spirv.py and run the result in spirv_mini_interp, so they pass on current main as expected (they add coverage, not a fix). Not run: Windows, no GPU.

@BeegSchmooze

Copy link
Copy Markdown

Mutation check of the current head, Windows 11, Python 3.13. The file passes as submitted. Every mutation is caught:

  • The F1 table: v_rsq_f32 → Sqrt, v_sqrt_f32 → InverseSqrt, v_exp_f32 → Log2, v_log_f32 → Exp2.
  • v_sin_f32/v_cos_f32: the turns-to-radians 2π factor dropped (turn_angle), Sin ↔ Cos swapped, and the exact-zero fix-up (trig_exact_zero) skipped.

Nothing to flag. (These ops sit in a lookup table and a helper rather than an if op branch, so I made these mutations by hand; tools/semantic_mutants.py in #6548 needs --function turn_angle or --lines to reach them.)

AI-assisted (Claude Code). No game files.

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.

3 participants