From 7e09ff63c9a4e5fdbf24182ed2ad8b1ccaecd397 Mon Sep 17 00:00:00 2001 From: x2Tweek Date: Mon, 23 Nov 2026 14:55:16 +0100 Subject: [PATCH] tests/semantic: add v_cvt_f32_ubyte2 translator coverage Add a semantic regression test for RDNA2 v_cvt_f32_ubyte2 (extract byte 2 of a u32 source, zero-extend, convert unsigned int to float) translated via tools/rdna2spirv.py and executed through spirv_mini_interp.py, compared against a hand-computed reference. Covers VGPR/SGPR/inline-literal sources, destination aliasing, all four v_cvt_f32_ubyte{N} forms, and random operands. This instruction is implemented in the translator (rdna2spirv.py:2418-2425) but has no semantic test on upstream/main. Standard library only: no GPU, no game data. AI-assisted. Co-Authored-By: Claude Code --- tests/semantic/test_alu_cvt_f32_ubyte2.py | 123 ++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 tests/semantic/test_alu_cvt_f32_ubyte2.py diff --git a/tests/semantic/test_alu_cvt_f32_ubyte2.py b/tests/semantic/test_alu_cvt_f32_ubyte2.py new file mode 100644 index 0000000000..49a6ed36ba --- /dev/null +++ b/tests/semantic/test_alu_cvt_f32_ubyte2.py @@ -0,0 +1,123 @@ +"""v_cvt_f32_ubyte2 (RDNA2 VOP3) through tools/rdna2spirv.py. + +v_cvt_f32_ubyte2 D.f32 = (float)((S0.u32 >> 16) & 0xFF): it extracts byte 2 (bits [16:23]) +of the source register, zero-extends it to 32 bits, and converts unsigned int to float. +The plain (non-SDWA, non-_e64) form encodes the byte index in the opcode name (0..3). + +Every case is a synthetic one-lane pixel shader translated by the translator and executed +by tests/semantic/spirv_mini_interp.py, compared against a hand-computed reference. +Standard library only: no GPU, no game data. +""" +import os +import random +import struct +import sys +import unittest + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.dont_write_bytecode = True +sys.path.insert(0, HERE) +import support # noqa: E402 +import rdna2spirv # noqa: E402 + +M32 = 0xFFFFFFFF + + +def ref_cvt_f32_ubyte2(src): + """Reference for v_cvt_f32_ubyte2: float((src >> 16) & 0xFF).""" + return float((src >> 16) & 0xFF) + + +def run_cvt_f32_ubyte2(src, form="v", dst="v0"): + """v_cvt_f32_ubyte2 on one lane. Source form: v (VGPR), s (SGPR), i (inline literal).""" + setup, srcs = [], [] + if form == "v": + setup.append(f"v_mov_b32 v1, {src & M32:#x}") + srcs.append("v1") + elif form == "s": + setup.append(f"s_mov_b32 s1, {src & M32:#x}") + srcs.append("s1") + else: + srcs.append(f"{src & M32:#x}") + lines = setup + [ + f"v_cvt_f32_ubyte2 {dst}, {', '.join(srcs)}", + f"exp mrt0 {dst}, {dst}, {dst}, {dst} done vm", + "s_endpgm", + ] + out = support.mrt0_words(support.translate_lines("ps_cvt_f32_ubyte2", lines)) + return struct.unpack("