"""An SDWA source under sext() is sign-extended with shifts, not OpBitFieldSExtract, and the conversion is unsigned. ``v_cvt_f32_u32_sdwa v4, sext(v1) src0_sel:BYTE_2`` sign-extends the selected field to 32 bits and converts that 32-bit pattern as unsigned: a negative field gives a value near 2**32, not a small negative number. A translated OpBitFieldSExtract feeding OpConvertUToF came back converted as signed on an NVIDIA driver (RTX 4050 Laptop, driver 621.01: ``v1 = 0x4fbdc08a`` gave -67.0 where the model has 0x4f800000), in 7 of 400 programs of ``tools/sdwa_diff.py --ops v_cvt_f32_u32`` judged by ``tools/vk_model_fuzz.py``. Two shifts give the same bits and the same 400 programs then match. The CPU interpreter cannot show the driver bug, so this test pins the two things it can: the SPIR-V has no OpBitFieldSExtract for an SDWA source, and every selector gives the value the model gives. python -I tests/semantic/test_sdwa_sext_source.py """ import os import struct import sys import tempfile import unittest import warnings HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) sys.dont_write_bytecode = True sys.path.insert(0, os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools")) sys.path.insert(0, HERE) import rdna2spirv # noqa: E402 import spirv_mini_interp as si # noqa: E402 STUB_DXBC = b"DXBC" + bytes(24) + struct.pack("> off) & ((1 << width) - 1) if field >> (width - 1): field -= 1 << width return field & 0xFFFFFFFF def unsigned_to_f32_bits(word): return struct.unpack("