Skip to content

tests/semantic: restore test_alu_u16_clamp.py, the u16 add/sub clamp check - #4108

Open
slint6614-dev wants to merge 1 commit into
ItsNotRexed:mainfrom
slint6614-dev:test/restore-u16-clamp
Open

slint6614-dev wants to merge 1 commit into
ItsNotRexed:mainfrom
slint6614-dev:test/restore-u16-clamp

Conversation

@slint6614-dev

@slint6614-dev slint6614-dev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new TEST item, #3918 (comment) (corrected from "delete" to "restore" in #3918 (comment))

Depends on: #4114 (conflict only: both remove adjacent lines from DEBT in tests/test_semantic_translator_use.py; whichever lands second needs a one-line rebase, which I will do).

What and why

docs/design.md (row "Integer clamp") cites tests/semantic/test_alu_u16_clamp.py as the CPU check of the VOP3 clamp on v_add_nc_u16 / v_sub_nc_u16 and the v_add/sub/subrev_u16 _e64 names: saturate to [0, 0xFFFF] and keep the high half of the destination.

@quackottu added that file in 523c32e as a 114-line translator test, together with the translator change. Three later commits (fb9743a, 1352258, 91b2c31) overwrote it with Python max(min(...)) helpers that never call the translator and name no instruction. The file then went into DEBT in tests/test_semantic_translator_use.py, and the documented rule had no test left.

This brings back 523c32e's file unchanged (git diff 523c32ed -- tests/semantic/test_alu_u16_clamp.py is empty) and removes it from DEBT.

Tested

Linux (WSL2), CPython 3.14.4, CPU only, no GPU, no game files, at aa2988cc:

  • python -m unittest discover -s tests/semantic -p test_alu_u16_clamp.py: 3/3 pass on today's main.
  • python -I tests/test_semantic_translator_use.py: pass. python -I tests/test_text_write_line_endings.py: pass. git diff --check: clean.

Mutation check of the clamp select in tools/rdna2spirv.py (~line 6842). The "other files" are the seven other test files that use these ops: test_valu_add_sub_nc_i16, test_ps_semantics, test_value_semantics, test_valu_int16, test_pk16_diff, test_wint_diff and test_isa_coverage, run CI-style and all green first.

Mutation main: current file main: 7 other files restored file
clamp ignored (result wraps) not caught not caught caught
sub saturates to 0xFFFF instead of 0 not caught not caught caught

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. (No new rule: the row already cites this file.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_013nWg6BssUf8MjNaKuMSkfc

…check

docs/design.md (Integer clamp) cites tests/semantic/test_alu_u16_clamp.py
as the CPU check of the VOP3 clamp on v_add_nc_u16 / v_sub_nc_u16 and the
v_add/sub/subrev_u16 e64 names: saturate to [0, 0xFFFF] and keep the high
half of the destination. 523c32e added it as a translator test together
with that translator change. fb9743a, 1352258 and 91b2c31 then
overwrote it with Python min/max helpers that never call the translator
and name no instruction, so the rule had no test left: on main, with the
clamp select in rdna2spirv.py removed (results wrap) or with sub
saturating high, this file and the seven other test files that use these
ops all still pass.

Bring back 523c32e's file unchanged (3/3 pass on main; both mutations
fail it) and drop it from DEBT in tests/test_semantic_translator_use.py.

Co-Authored-By: quackottu <224479491+quackottu@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nWg6BssUf8MjNaKuMSkfc
@tupacfan04

Copy link
Copy Markdown
Contributor

The restoration mechanics are right: the file is byte-identical to 523c32ed, it was overwritten in place rather than deleted, 3/3 tests pass, the neighbours and test_semantic_translator_use.py pass, and merge/compileall are clean. The coverage control is convincing (dropping the clamp select or saturating sub to 0xFFFF gives 188 failures).

But the restored file is not translator coverage: main's version imports rdna2spirv without ever calling translate, it is a pure max/min oracle, and on a deliberately broken translator it still passes 3/3 in 0.00 s. That is the pattern #2992 and the merged tests/test_semantic_translator_use.py exist to stop, so restoring it unchanged silently regresses that work (and the guard does not flag it because the import is referenced).

Since v_add_nc_u16/v_sub_nc_u16 are implemented, the file can be converted: a hand-written listing through support.translate_lines + spirv_mini_interp, asserting the same clamp values, as the neighbours do. If that is out of scope here, add it to the guard's DEBT table with this PR so the coverage gap is explicit rather than restored silently.

AI-assisted review, no game files, no GPU.

@slint6614-dev

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @tupacfan04. I think the second half describes the file this PR replaces (the current main version), not the one it restores. The restored file (523c32e, the head of this PR) does call the translator:

  • tests/semantic/test_alu_u16_clamp.py:79: spv = rdna2spirv.translate(_SRC_PATH), on a listing written at line 75;
  • :80: lo, hi = si.run_fragment(spv)["%out_mrt0"][:2], executed in spirv_mini_interp;
  • test_values and test_seeded go through that helper for each op/value/clamp case.

That's why it takes about 0.9 s here rather than 0.00 s, and why removing the clamp select fails it (your own 188-failure control, and the mutation table in the description). The "pure max/min oracle that passes 3/3 on a broken translator in 0.00 s" is the version on main today, which is what this PR removes.

So I'd keep the file as restored. It already is the translator-driven test you suggest converting to: it writes its own listing rather than using support.translate_lines, as files of that date did. Adding it back to DEBT would hide it from the guard, which is the opposite of what we want.

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

CPU verification: checked out pull/4108/head in an isolated worktree and ran pytest -q tests/semantic/test_alu_u16_clamp.py: 3 passed, 850 subtests passed.

The restoration is sound: the test exercises the real translator through the semantic-translator-use harness rather than a private model, and the u16 add/sub clamp cases are now driven from the interpreter's own operand decode. The companion change to tests/test_semantic_translator_use.py keeps the test in the generated list, so it will run in CI instead of being silently skipped again.

One note: 850 subtests from 3 tests is a wide sweep; if a future translator change breaks one case, the failure name should identify the operand set clearly enough to triage without rerunning under a debugger. The current parameterisation does that.

No game files, keys or GPU involved.

@memorypressure

Copy link
Copy Markdown

Restored u16 clamp test verified on Linux: the PR sits on current main (fast-forward), compileall is clean, and test_alu_u16_clamp.py passes under python -I and pytest — 3 test methods, 850 subtests, all real translations through rdna2spirv.translate plus the interpreter. Swapping the clamp saturation constants in the translator's u16 path fails 188 of those subtests, so the coverage is genuine, and the DEBT entry you drop here is indeed no longer needed: the guard's own test passes with the file importing rdna2spirv directly. Two small fixes for a follow-up: the temp .s write at line 75 should pin newline="\n" alongside encoding="utf-8" for Windows, and support.translate_listing already does the tempdir/DXBC setup this file repeats. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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