"""All 16 binary32 vector compares, v_cmp_*_f32 and v_cmpx_*_f32, including the negated ones, on NaN, infinity and -0. RDNA2 ISA (VOPC), per lane, with unordered = either source is a NaN (quiet or signaling): F = 0, TRU = 1, O = ordered, U = unordered; LT, EQ, LE, GT, GE and LG (S0 < S1 or S0 > S1) are false when unordered, and -0 equals +0; NGE, NLG, NGT, NLE, NEQ, NLT are the logical negations of GE, LG, GT, LE, EQ, LT, so they are TRUE when unordered. v_cmp writes the result to VCC (e32) or an SGPR pair (e64) and v_cmpx writes EXEC; v_cmpx is checked by the lanes it leaves active. VOP3 abs and neg act on the sources before the compare (so -|NaN| is still a NaN). Expected values come from the Python predicates below, not from the translator. Each case translates a one-lane pixel shader with tools/rdna2spirv.py and runs it in tests/semantic/spirv_mini_interp.py. """ import itertools import math import os 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 spirv_mini_interp as si # noqa: E402 import support # noqa: E402 PREDS = { "f": lambda a, b: False, "tru": lambda a, b: True, "o": lambda a, b: not (math.isnan(a) or math.isnan(b)), "u": lambda a, b: math.isnan(a) or math.isnan(b), "lt": lambda a, b: a < b, "eq": lambda a, b: a == b, "le": lambda a, b: a <= b, "gt": lambda a, b: a > b, "ge": lambda a, b: a >= b, "lg": lambda a, b: a < b or a > b, "nlt": lambda a, b: not a < b, "neq": lambda a, b: not a == b, "nle": lambda a, b: not a <= b, "ngt": lambda a, b: not a > b, "nge": lambda a, b: not a >= b, "nlg": lambda a, b: not (a < b or a > b), } # Bit patterns: -inf, -1, -0, +0, +1, 1+ulp, +inf, quiet NaN (both signs), signaling NaN. VALUES = [0xFF800000, 0xBF800000, 0x80000000, 0x00000000, 0x3F800000, 0x3F800001, 0x7F800000, 0x7FC00000, 0xFFC00000, 0x7F800001] def f32(bits): return struct.unpack("