Skip to content

test(semantic): value tests for v_floor/ceil/trunc/fract/rndne_f16 - #689

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Caasares:test-valu-f16-round
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Caasares:test-valu-f16-round

Conversation

@Caasares

Copy link
Copy Markdown
Contributor

Claimed in #374 as: a new TEST item, semantic value tests for 16-bit float rounding/fraction VALU ops (claim)

What and why

v_floor_f16, v_ceil_f16, v_trunc_f16, v_rndne_f16, and v_fract_f16 had no semantic value tests in tests/semantic/. This adds a standalone test suite tests/semantic/test_valu_f16_round.py comparing tools/rdna2spirv.py + tests/semantic/spirv_mini_interp.py against an independent IEEE-754 binary16 Python reference without modifying the translator or interpreter:

  • v_floor_f16, v_ceil_f16, v_trunc_f16, v_rndne_f16 (end-to-end execution in spirv_mini_interp.py):
    • Finite values, exact integers, .5 ties including binary16 large-integer ties (1022.5 -> 1022.0, 1023.5 -> 1024.0), signed zero (-0.0) preservation in (-1.0, -0.0], subnormals, +-inf, and NaNs across _e32, _e64, and bare mnemonics.
    • Untouched 16-bit half preservation and all op_sel:[src,dst] combinations ([0,0], [1,0], [0,1], [1,1]).
    • VOP3 source modifiers (neg, abs, -|...|) and output modifiers (mul:2, mul:4, div:2, clamp) applied before narrowing to f16.
    • Inline f16 constants (0.5, -0.5, -1.0), SGPR sources with op_sel, destination aliasing, EXEC masking, and a SPIR-V sabotage negative control (Floor -> Ceil).
  • v_fract_f16 (oracle + SPIR-V structural check):
    • tools/rdna2spirv.py lowers v_fract_f16 to GLSL.std.450 Fract, which tests/semantic/spirv_mini_interp.py does not yet implement (UnsupportedConstruct: GLSL.std.450 Fract). Tested via an independent IEEE-754 binary16 oracle and structural SPIR-V verification (UnpackHalf2x16, GLSL.std.450 Fract, FClamp).

No existing files were modified.

Tested

CPU only, no game data, on Windows 11 with Python 3.12.10 (llvm-mc, spirv-as, and spirv-val are not installed in this environment; semantic checks ran in spirv_mini_interp.py):

  • python -m compileall -q make_game.py tools tests — passed
  • python -I tests/semantic/test_valu_f16_round.py -v — Ran 10 tests in 2.670s, OK
  • python -m unittest discover -s tests/semantic -v — Ran 815 tests in 203.802s, OK

AI-assisted, as AGENTS.md asks contributors to say.

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. (Not applicable: tests only; no translator change.)

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

tests pass merged with main (815) ^_^ AI-assisted review (Claude Code).

@matheuskshn

Copy link
Copy Markdown
Contributor

Tested 149870e on Windows 11 / Python 3.12.14: all 10 tests in python -I tests/semantic/test_valu_f16_round.py passed against the base translator, including the deliberately altered SPIR-V control. This exercises the CPU path for source/output modifiers, op_sel, and preservation of the other half. AI-assisted, synthetic inputs.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 149870e on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass

  • pytest tests/semantic/test_valu_f16_round.py: 10 passed, 472 subtests
  • Code read: the references look right. round() is round-half-to-even, as v_rndne needs. ref_fract gives 0.75 for −0.25 and +0.0 for −0.0. Non-finite values pass through floor/ceil/trunc/rndne unchanged. Since spirv_mini_interp has no GLSL.std.450 Fract, using the oracle plus a structural check for v_fract_f16 is reasonable. Adding Fract to the interpreter would be a natural follow-up.

(AI-assisted review.)

@kapitche

Copy link
Copy Markdown
Contributor

For the v_fract_f16 gap: #494 (SHADER-45) adds GLSL.std.450 Fract to spirv_mini_interp.py (exact, rounded once to binary32). Once it lands, v_fract_f16 could run end to end here too. A small follow-up after both merge. (AI-assisted.)

@ItsNotRexed
ItsNotRexed merged commit d35045e into ItsNotRexed:main Nov 22, 2026
7 checks passed
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.

5 participants