"""Carry-out subtracts of a register from itself: v_sub_co_u32 / v_subrev_co_u32 (and the _ci_ forms) vD, sdst, vX, vX. x - x is 0 with no borrow, so D = 0 - carry in and the borrow out is the carry in. The translator writes that out instead of OpISubBorrow %x %x: AMD's Windows driver (amdvlk64.dll 32.0.21037.1004 and 32.0.21045.29003, gfx1036) dies with an access violation creating a native wave64 compute pipeline in which the borrow of such an OpISubBorrow predicates the value of a subgroup shuffle (crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext, programs 1 and 181; docs/design.md, "Carry-out subtract of a register from itself"). Checked here, in wave32 and native wave64 (run in spirv_mini_interp): - D and the borrow mask for every lane, with and without a carry in, under a partial EXEC (an inactive lane keeps D and reads 0 in the mask), and the wave-wide count of the mask; - the clamp bit (D saturates to 0 on a borrow, the borrow is still reported); - no OpISubBorrow is emitted for the same-operand forms, and two different registers holding equal values still go through OpISubBorrow and give the same answers. With --wave64-emulate only the emitted form is checked (the last point). """ import gc import os import re 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)) TOOLS_DIR = os.environ.get("LEONIDA_TOOLS_DIR") or os.path.join(ROOT, "tools") sys.dont_write_bytecode = True if HERE not in sys.path: sys.path.insert(0, HERE) if TOOLS_DIR not in sys.path: sys.path.insert(0, TOOLS_DIR) import rdna2spirv # noqa: E402 import spirv_mini_interp as si # noqa: E402 STUB_DXBC = b"DXBC" + bytes(24) + struct.pack("