<div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 12, 2019 at 11:51 AM Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This is set to True only for numeric conversion opcodes.<br>
---<br>
src/compiler/nir/nir.h | 3 ++<br>
src/compiler/nir/nir_opcodes.py | 73 +++++++++++++++++--------------<br>
src/compiler/nir/nir_opcodes_c.py | 1 +<br>
3 files changed, 44 insertions(+), 33 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index ff2c41faf27..2793662b1d9 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -926,6 +926,9 @@ typedef struct {<br>
nir_alu_type input_types[NIR_MAX_VEC_COMPONENTS];<br>
<br>
nir_op_algebraic_property algebraic_properties;<br>
+<br>
+ /* Whether this represents a numeric conversion opcode */<br>
+ bool is_conversion;<br>
} nir_op_info;<br>
<br>
extern const nir_op_info nir_op_infos[nir_num_opcodes];<br>
diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py<br>
index d32005846a6..dc4cd9ac63d 100644<br>
--- a/src/compiler/nir/nir_opcodes.py<br>
+++ b/src/compiler/nir/nir_opcodes.py<br>
@@ -33,12 +33,13 @@ class Opcode(object):<br>
NOTE: this must be kept in sync with nir_op_info<br>
"""<br>
def __init__(self, name, output_size, output_type, input_sizes,<br>
- input_types, algebraic_properties, const_expr):<br>
+ input_types, is_conversion, algebraic_properties, const_expr):<br>
"""Parameters:<br>
<br>
- name is the name of the opcode (prepend nir_op_ for the enum name)<br>
- all types are strings that get nir_type_ prepended to them<br>
- input_types is a list of types<br>
+ - is_conversion is true if this opcode represents a type conversion<br>
- algebraic_properties is a space-seperated string, where nir_op_is_ is<br>
prepended before each entry<br>
- const_expr is an expression or series of statements that computes the<br>
@@ -70,6 +71,7 @@ class Opcode(object):<br>
assert isinstance(input_sizes[0], int)<br>
assert isinstance(input_types, list)<br>
assert isinstance(input_types[0], str)<br>
+ assert isinstance(is_conversion, bool)<br>
assert isinstance(algebraic_properties, str)<br>
assert isinstance(const_expr, str)<br>
assert len(input_sizes) == len(input_types)<br>
@@ -84,6 +86,7 @@ class Opcode(object):<br>
self.output_type = output_type<br>
self.input_sizes = input_sizes<br>
self.input_types = input_types<br>
+ self.is_conversion = is_conversion<br>
self.algebraic_properties = algebraic_properties<br>
self.const_expr = const_expr<br>
<br>
@@ -138,21 +141,22 @@ associative = "associative "<br>
opcodes = {}<br>
<br>
def opcode(name, output_size, output_type, input_sizes, input_types,<br>
- algebraic_properties, const_expr):<br>
+ is_conversion, algebraic_properties, const_expr):<br>
assert name not in opcodes<br>
opcodes[name] = Opcode(name, output_size, output_type, input_sizes,<br>
- input_types, algebraic_properties, const_expr)<br>
+ input_types, is_conversion, algebraic_properties,<br>
+ const_expr)<br>
<br>
def unop_convert(name, out_type, in_type, const_expr):<br>
- opcode(name, 0, out_type, [0], [in_type], "", const_expr)<br>
+ opcode(name, 0, out_type, [0], [in_type], False, "", const_expr)<br>
<br>
def unop(name, ty, const_expr):<br>
- opcode(name, 0, ty, [0], [ty], "", const_expr)<br>
+ opcode(name, 0, ty, [0], [ty], False, "", const_expr)<br>
<br>
def unop_horiz(name, output_size, output_type, input_size, input_type,<br>
const_expr):<br>
- opcode(name, output_size, output_type, [input_size], [input_type], "",<br>
- const_expr)<br>
+ opcode(name, output_size, output_type, [input_size], [input_type],<br>
+ False, "", const_expr)<br>
<br>
def unop_reduce(name, output_size, output_type, input_type, prereduce_expr,<br>
reduce_expr, final_expr):<br>
@@ -173,6 +177,8 @@ def unop_reduce(name, output_size, output_type, input_type, prereduce_expr,<br>
unop_horiz(name + "4", output_size, output_type, 4, input_type,<br>
final(reduce_(reduce_(src0, src1), reduce_(src2, src3))))<br>
<br>
+def unop_numeric_convert(name, out_type, in_type, const_expr):<br>
+ opcode(name, 0, out_type, [0], [in_type], True, "", const_expr)<br>
<br>
# These two move instructions differ in what modifiers they support and what<br>
# the negate modifier means. Otherwise, they are identical.<br>
@@ -215,13 +221,13 @@ for src_t in [tint, tuint, tfloat, tbool]:<br>
if bit_size == 16 and dst_t == tfloat and src_t == tfloat:<br>
rnd_modes = ['_rtne', '_rtz', '']<br>
for rnd_mode in rnd_modes:<br>
- unop_convert("{0}2{1}{2}{3}".format(src_t[0], dst_t[0],<br>
- bit_size, rnd_mode),<br>
- dst_t + str(bit_size), src_t, "src0")<br>
+ unop_numeric_convert("{0}2{1}{2}{3}".format(src_t[0], dst_t[0],<br>
+ bit_size, rnd_mode),<br>
+ dst_t + str(bit_size), src_t, "src0")<br>
else:<br>
conv_expr = "src0 != 0" if dst_t == tbool else "src0"<br>
- unop_convert("{0}2{1}{2}".format(src_t[0], dst_t[0], bit_size),<br>
- dst_t + str(bit_size), src_t, conv_expr)<br>
+ unop_numeric_convert("{0}2{1}{2}".format(src_t[0], dst_t[0], bit_size),<br>
+ dst_t + str(bit_size), src_t, conv_expr)<br>
<br>
<br>
# Unary floating-point rounding operations.<br>
@@ -426,7 +432,8 @@ if (src0.z < 0 && absZ >= absX && absZ >= absY) dst.x = 5;<br>
<br>
<br>
def binop_convert(name, out_type, in_type, alg_props, const_expr):<br>
- opcode(name, 0, out_type, [0, 0], [in_type, in_type], alg_props, const_expr)<br>
+ opcode(name, 0, out_type, [0, 0], [in_type, in_type],<br>
+ False, alg_props, const_expr)<br>
<br>
def binop(name, ty, alg_props, const_expr):<br>
binop_convert(name, ty, ty, alg_props, const_expr)<br>
@@ -440,7 +447,7 @@ def binop_compare32(name, ty, alg_props, const_expr):<br>
def binop_horiz(name, out_size, out_type, src1_size, src1_type, src2_size,<br>
src2_type, const_expr):<br>
opcode(name, out_size, out_type, [src1_size, src2_size], [src1_type, src2_type],<br>
- "", const_expr)<br>
+ False, "", const_expr)<br>
<br>
def binop_reduce(name, output_size, output_type, src_type, prereduce_expr,<br>
reduce_expr, final_expr):<br>
@@ -455,13 +462,13 @@ def binop_reduce(name, output_size, output_type, src_type, prereduce_expr,<br>
src2 = prereduce("src0.z", "src1.z")<br>
src3 = prereduce("src0.w", "src1.w")<br>
opcode(name + "2", output_size, output_type,<br>
- [2, 2], [src_type, src_type], commutative,<br>
+ [2, 2], [src_type, src_type], False, commutative,<br>
final(reduce_(src0, src1)))<br>
opcode(name + "3", output_size, output_type,<br>
- [3, 3], [src_type, src_type], commutative,<br>
+ [3, 3], [src_type, src_type], False, commutative,<br>
final(reduce_(reduce_(src0, src1), src2)))<br>
opcode(name + "4", output_size, output_type,<br>
- [4, 4], [src_type, src_type], commutative,<br>
+ [4, 4], [src_type, src_type], False, commutative,<br>
final(reduce_(reduce_(src0, src1), reduce_(src2, src3))))<br>
<br>
binop("fadd", tfloat, commutative + associative, "src0 + src1")<br>
@@ -611,9 +618,9 @@ binop("seq", tfloat32, commutative, "(src0 == src1) ? 1.0f : 0.0f") # Set on Equ<br>
binop("sne", tfloat32, commutative, "(src0 != src1) ? 1.0f : 0.0f") # Set on Not Equal<br>
<br>
<br>
-opcode("ishl", 0, tint, [0, 0], [tint, tuint32], "", "src0 << src1")<br>
-opcode("ishr", 0, tint, [0, 0], [tint, tuint32], "", "src0 >> src1")<br>
-opcode("ushr", 0, tuint, [0, 0], [tuint, tuint32], "", "src0 >> src1")<br>
+opcode("ishl", 0, tint, [0, 0], [tint, tuint32], False, "", "src0 << src1")<br>
+opcode("ishr", 0, tint, [0, 0], [tint, tuint32], False, "", "src0 >> src1")<br>
+opcode("ushr", 0, tuint, [0, 0], [tuint, tuint32], False, "", "src0 >> src1")<br>
<br>
# bitwise logic operators<br>
#<br>
@@ -644,9 +651,9 @@ binop_reduce("fdot", 1, tfloat, tfloat, "{src0} * {src1}", "{src0} + {src1}",<br>
binop_reduce("fdot_replicated", 4, tfloat, tfloat,<br>
"{src0} * {src1}", "{src0} + {src1}", "{src}")<br>
<br>
-opcode("fdph", 1, tfloat, [3, 4], [tfloat, tfloat], "",<br>
+opcode("fdph", 1, tfloat, [3, 4], [tfloat, tfloat], False, "",<br>
"src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w")<br>
-opcode("fdph_replicated", 4, tfloat, [3, 4], [tfloat, tfloat], "",<br>
+opcode("fdph_replicated", 4, tfloat, [3, 4], [tfloat, tfloat], False, "",<br>
"src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w")<br>
<br>
binop("fmin", tfloat, "", "fminf(src0, src1)")<br>
@@ -723,7 +730,7 @@ else<br>
dst = ((1u << bits) - 1) << offset;<br>
""")<br>
<br>
-opcode("ldexp", 0, tfloat, [0, 0], [tfloat, tint32], "", """<br>
+opcode("ldexp", 0, tfloat, [0, 0], [tfloat, tint32], False, "", """<br>
dst = (bit_size == 64) ? ldexp(src0, src1) : ldexpf(src0, src1);<br>
/* flush denormals to zero. */<br>
if (!isnormal(dst))<br>
@@ -747,11 +754,11 @@ binop("extract_i16", tint, "", "(int16_t)(src0 >> (src1 * 16))")<br>
<br>
<br>
def triop(name, ty, const_expr):<br>
- opcode(name, 0, ty, [0, 0, 0], [ty, ty, ty], "", const_expr)<br>
+ opcode(name, 0, ty, [0, 0, 0], [ty, ty, ty], False, "", const_expr)<br>
def triop_horiz(name, output_size, src1_size, src2_size, src3_size, const_expr):<br>
opcode(name, output_size, tuint,<br>
[src1_size, src2_size, src3_size],<br>
- [tuint, tuint, tuint], "", const_expr)<br>
+ [tuint, tuint, tuint], False, "", const_expr)<br>
<br>
triop("ffma", tfloat, "src0 * src1 + src2")<br>
<br>
@@ -780,9 +787,9 @@ triop("imed3", tint, "MAX2(MIN2(MAX2(src0, src1), src2), MIN2(src0, src1))")<br>
triop("umed3", tuint, "MAX2(MIN2(MAX2(src0, src1), src2), MIN2(src0, src1))")<br>
<br>
opcode("bcsel", 0, tuint, [0, 0, 0],<br>
- [tbool1, tuint, tuint], "", "src0 ? src1 : src2")<br>
+ [tbool1, tuint, tuint], False, "", "src0 ? src1 : src2")<br>
opcode("b32csel", 0, tuint, [0, 0, 0],<br>
- [tbool32, tuint, tuint], "", "src0 ? src1 : src2")<br>
+ [tbool32, tuint, tuint], False, "", "src0 ? src1 : src2")<br>
<br>
# SM5 bfi assembly<br>
triop("bfi", tuint32, """<br>
@@ -801,7 +808,7 @@ if (mask == 0) {<br>
<br>
# SM5 ubfe/ibfe assembly<br>
opcode("ubfe", 0, tuint32,<br>
- [0, 0, 0], [tuint32, tint32, tint32], "", """<br>
+ [0, 0, 0], [tuint32, tint32, tint32], False, "", """<br>
unsigned base = src0;<br>
int offset = src1, bits = src2;<br>
if (bits == 0) {<br>
@@ -815,7 +822,7 @@ if (bits == 0) {<br>
}<br>
""")<br>
opcode("ibfe", 0, tint32,<br>
- [0, 0, 0], [tint32, tint32, tint32], "", """<br>
+ [0, 0, 0], [tint32, tint32, tint32], False, "", """<br>
int base = src0;<br>
int offset = src1, bits = src2;<br>
if (bits == 0) {<br>
@@ -831,7 +838,7 @@ if (bits == 0) {<br>
<br>
# GLSL bitfieldExtract()<br>
opcode("ubitfield_extract", 0, tuint32,<br>
- [0, 0, 0], [tuint32, tint32, tint32], "", """<br>
+ [0, 0, 0], [tuint32, tint32, tint32], False, "", """<br>
unsigned base = src0;<br>
int offset = src1, bits = src2;<br>
if (bits == 0) {<br>
@@ -843,7 +850,7 @@ if (bits == 0) {<br>
}<br>
""")<br>
opcode("ibitfield_extract", 0, tint32,<br>
- [0, 0, 0], [tint32, tint32, tint32], "", """<br>
+ [0, 0, 0], [tint32, tint32, tint32], False, "", """<br>
int base = src0;<br>
int offset = src1, bits = src2;<br>
if (bits == 0) {<br>
@@ -868,10 +875,10 @@ def quadop_horiz(name, output_size, src1_size, src2_size, src3_size,<br>
opcode(name, output_size, tuint,<br>
[src1_size, src2_size, src3_size, src4_size],<br>
[tuint, tuint, tuint, tuint],<br>
- "", const_expr)<br>
+ False, "", const_expr)<br>
<br>
opcode("bitfield_insert", 0, tuint32, [0, 0, 0, 0],<br>
- [tuint32, tuint32, tint32, tint32], "", """<br>
+ [tuint32, tuint32, tint32, tint32], False, "", """<br>
unsigned base = src0, insert = src1;<br>
int offset = src2, bits = src3;<br>
if (bits == 0) {<br>
diff --git a/src/compiler/nir/nir_opcodes_c.py b/src/compiler/nir/nir_opcodes_c.py<br>
index 017c8b7ea9a..96c71a1b2c5 100644<br>
--- a/src/compiler/nir/nir_opcodes_c.py<br>
+++ b/src/compiler/nir/nir_opcodes_c.py<br>
@@ -117,6 +117,7 @@ const nir_op_info nir_op_infos[nir_num_opcodes] = {<br>
.input_types = {<br>
${ ", ".join("nir_type_" + type for type in opcode.input_types) }<br>
},<br>
+ .is_conversion = ${"true" if opcode.is_conversion else "false"},<br>
.algebraic_properties =<br>
${ "0" if opcode.algebraic_properties == "" else " | ".join(<br>
"NIR_OP_IS_" + prop.upper() for prop in<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div>