X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fnir%2Fnir_opcodes.py;h=278562b2bd1172dd4f2581e483fd874591245a5a;hb=5ef5944848527c214a460cd746fcc467991c80c7;hp=15066c2b580c760193ac7e78f9ca83a033fd070e;hpb=38b719d6244e831effe93a5d10e932aad2100984;p=mesa.git diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 15066c2b580..278562b2bd1 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python # # Copyright (C) 2014 Connor Abbott # @@ -95,6 +94,7 @@ tuint = "uint" tfloat32 = "float32" tint32 = "int32" tuint32 = "uint32" +tint64 = "int64" tuint64 = "uint64" tfloat64 = "float64" @@ -156,7 +156,7 @@ unop("fsign", tfloat, ("bit_size == 64 ? " + "((src0 == 0.0f) ? 0.0f : ((src0 > 0.0f) ? 1.0f : -1.0f))")) unop("isign", tint, "(src0 == 0) ? 0 : ((src0 > 0) ? 1 : -1)") unop("iabs", tint, "(src0 < 0) ? -src0 : src0") -unop("fabs", tfloat, "bit_size == 64 ? fabs(src0) : fabsf(src0)") +unop("fabs", tfloat, "fabs(src0)") unop("fsat", tfloat, ("bit_size == 64 ? " + "((src0 > 1.0) ? 1.0 : ((src0 <= 0.0) ? 0.0 : src0)) : " + "((src0 > 1.0f) ? 1.0f : ((src0 <= 0.0f) ? 0.0f : src0))")) @@ -165,25 +165,37 @@ unop("frsq", tfloat, "bit_size == 64 ? 1.0 / sqrt(src0) : 1.0f / sqrtf(src0)") unop("fsqrt", tfloat, "bit_size == 64 ? sqrt(src0) : sqrtf(src0)") unop("fexp2", tfloat, "exp2f(src0)") unop("flog2", tfloat, "log2f(src0)") -unop_convert("f2i", tint32, tfloat32, "src0") # Float-to-integer conversion. -unop_convert("f2u", tuint32, tfloat32, "src0") # Float-to-unsigned conversion -unop_convert("d2i", tint32, tfloat64, "src0") # Double-to-integer conversion. -unop_convert("d2u", tuint32, tfloat64, "src0") # Double-to-unsigned conversion. -unop_convert("i2f", tfloat32, tint32, "src0") # Integer-to-float conversion. -unop_convert("i2d", tfloat64, tint32, "src0") # Integer-to-double conversion. -# Float-to-boolean conversion -unop_convert("f2b", tbool, tfloat32, "src0 != 0.0f") -unop_convert("d2b", tbool, tfloat64, "src0 != 0.0") -# Boolean-to-float conversion -unop_convert("b2f", tfloat32, tbool, "src0 ? 1.0f : 0.0f") -# Int-to-boolean conversion -unop_convert("i2b", tbool, tint32, "src0 != 0") -unop_convert("b2i", tint32, tbool, "src0 ? 1 : 0") # Boolean-to-int conversion -unop_convert("u2f", tfloat32, tuint32, "src0") # Unsigned-to-float conversion. -unop_convert("u2d", tfloat64, tuint32, "src0") # Unsigned-to-double conversion. -# double-to-float conversion -unop_convert("d2f", tfloat32, tfloat64, "src0") # Double to single precision -unop_convert("f2d", tfloat64, tfloat32, "src0") # Single to double precision + +# Generate all of the numeric conversion opcodes +for src_t in [tint, tuint, tfloat]: + if src_t in (tint, tuint): + dst_types = [tfloat, src_t] + elif src_t == tfloat: + dst_types = [tint, tuint, tfloat] + + for dst_t in dst_types: + if dst_t == tfloat: + bit_sizes = [16, 32, 64] + else: + bit_sizes = [8, 16, 32, 64] + for bit_size in bit_sizes: + if bit_size == 16 and dst_t == tfloat and src_t == tfloat: + rnd_modes = ['rtne', 'rtz', 'undef'] + for rnd_mode in rnd_modes: + unop_convert("{0}2{1}{2}_{3}".format(src_t[0], dst_t[0], + bit_size, rnd_mode), + dst_t + str(bit_size), src_t, "src0") + else: + unop_convert("{0}2{1}{2}".format(src_t[0], dst_t[0], bit_size), + dst_t + str(bit_size), src_t, "src0") + +# We'll hand-code the to/from bool conversion opcodes. Because bool doesn't +# have multiple bit-sizes, we can always infer the size from the other type. +unop_convert("f2b", tbool, tfloat, "src0 != 0.0") +unop_convert("i2b", tbool, tint, "src0 != 0") +unop_convert("b2f", tfloat, tbool, "src0 ? 1.0 : 0.0") +unop_convert("b2i", tint, tbool, "src0 ? 1 : 0") + # Unary floating-point rounding operations. @@ -257,7 +269,7 @@ unpack_4x8("unorm") unpack_2x16("half") unop_horiz("pack_uvec2_to_uint", 1, tuint32, 2, tuint32, """ -dst.x = (src0.x & 0xffff) | (src0.y >> 16); +dst.x = (src0.x & 0xffff) | (src0.y << 16); """) unop_horiz("pack_uvec4_to_uint", 1, tuint32, 4, tuint32, """ @@ -267,10 +279,10 @@ dst.x = (src0.x << 0) | (src0.w << 24); """) -unop_horiz("pack_double_2x32", 1, tuint64, 2, tuint32, +unop_horiz("pack_64_2x32", 1, tuint64, 2, tuint32, "dst.x = src0.x | ((uint64_t)src0.y << 32);") -unop_horiz("unpack_double_2x32", 2, tuint32, 1, tuint64, +unop_horiz("unpack_64_2x32", 2, tuint32, 1, tuint64, "dst.x = src0.x; dst.y = src0.x >> 32;") # Lowered floating point unpacking operations. @@ -281,8 +293,8 @@ unop_horiz("unpack_half_2x16_split_x", 1, tfloat32, 1, tuint32, unop_horiz("unpack_half_2x16_split_y", 1, tfloat32, 1, tuint32, "unpack_half_1x16((uint16_t)(src0.x >> 16))") -unop_convert("unpack_double_2x32_split_x", tuint32, tuint64, "src0") -unop_convert("unpack_double_2x32_split_y", tuint32, tuint64, "src0 >> 32") +unop_convert("unpack_64_2x32_split_x", tuint32, tuint64, "src0") +unop_convert("unpack_64_2x32_split_y", tuint32, tuint64, "src0 >> 32") # Bit operations, part of ARB_gpu_shader5. @@ -303,7 +315,7 @@ for (unsigned bit = 0; bit < 32; bit++) { unop_convert("ufind_msb", tint32, tuint32, """ dst = -1; -for (int bit = 31; bit > 0; bit--) { +for (int bit = 31; bit >= 0; bit--) { if ((src0 >> bit) & 1) { dst = bit; break; @@ -462,14 +474,14 @@ binop_reduce("fany_nequal", 1, tfloat32, tfloat32, "{src0} != {src1}", # and false respectively binop("slt", tfloat32, "", "(src0 < src1) ? 1.0f : 0.0f") # Set on Less Than -binop("sge", tfloat32, "", "(src0 >= src1) ? 1.0f : 0.0f") # Set on Greater or Equal +binop("sge", tfloat, "", "(src0 >= src1) ? 1.0f : 0.0f") # Set on Greater or Equal binop("seq", tfloat32, commutative, "(src0 == src1) ? 1.0f : 0.0f") # Set on Equal binop("sne", tfloat32, commutative, "(src0 != src1) ? 1.0f : 0.0f") # Set on Not Equal -binop("ishl", tint, "", "src0 << src1") -binop("ishr", tint, "", "src0 >> src1") -binop("ushr", tuint, "", "src0 >> src1") +opcode("ishl", 0, tint, [0, 0], [tint, tuint32], "", "src0 << src1") +opcode("ishr", 0, tint, [0, 0], [tint, tuint32], "", "src0 >> src1") +opcode("ushr", 0, tuint, [0, 0], [tuint, tuint32], "", "src0 >> src1") # bitwise logic operators # @@ -562,7 +574,7 @@ binop("fpow", tfloat, "", "bit_size == 64 ? powf(src0, src1) : pow(src0, src1)") binop_horiz("pack_half_2x16_split", 1, tuint32, 1, tfloat32, 1, tfloat32, "pack_half_1x16(src0.x) | (pack_half_1x16(src1.x) << 16)") -binop_convert("pack_double_2x32_split", tuint64, tuint32, "", +binop_convert("pack_64_2x32_split", tuint64, tuint32, "", "src0 | ((uint64_t)src1 << 32)") # bfm implements the behavior of the first operation of the SM5 "bfi" assembly @@ -712,12 +724,12 @@ opcode("bitfield_insert", 0, tuint32, [0, 0, 0, 0], unsigned base = src0, insert = src1; int offset = src2, bits = src3; if (bits == 0) { - dst = 0; + dst = base; } else if (offset < 0 || bits < 0 || bits + offset > 32) { dst = 0; } else { unsigned mask = ((1ull << bits) - 1) << offset; - dst = (base & ~mask) | ((insert << bits) & mask); + dst = (base & ~mask) | ((insert << offset) & mask); } """)