diff options
author | Jason Ekstrand <[email protected]> | 2018-11-07 13:43:40 -0600 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-12-05 15:03:07 -0600 |
commit | dca6cd9ce65100896976e913bf72c2c68ea4e1a7 (patch) | |
tree | 069181199b9b4f00d8c44f1ae507412c28ccc81f /src/compiler/nir/nir_opcodes.py | |
parent | be98b1db3899121f2d0cea009ef6430b13589032 (diff) |
nir: Make boolean conversions sized just like the others
Instead of a single i2b and b2i, we now have i2b32 and b2iN where N is
one if 8, 16, 32, or 64. This leads to having a few more opcodes but
now everything is consistent and booleans aren't a weird special case
anymore.
Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_opcodes.py')
-rw-r--r-- | src/compiler/nir/nir_opcodes.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index 00720708305..55b2ff0f678 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -90,6 +90,7 @@ class Opcode(object): # helper variables for strings tfloat = "float" tint = "int" +tbool = "bool" tbool32 = "bool32" tuint = "uint" tuint16 = "uint16" @@ -117,6 +118,8 @@ def type_size(type_): def type_sizes(type_): if type_has_size(type_): return [type_size(type_)] + elif type_ == 'bool': + return [32] elif type_ == 'float': return [16, 32, 64] else: @@ -196,11 +199,15 @@ unop("fexp2", tfloat, "exp2f(src0)") unop("flog2", tfloat, "log2f(src0)") # 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] +for src_t in [tint, tuint, tfloat, tbool]: + if src_t == tbool: + dst_types = [tfloat, tint] + elif src_t == tint: + dst_types = [tfloat, tint, tbool] + elif src_t == tuint: + dst_types = [tfloat, tuint] elif src_t == tfloat: - dst_types = [tint, tuint, tfloat] + dst_types = [tint, tuint, tfloat, tbool] for dst_t in dst_types: for bit_size in type_sizes(dst_t): @@ -211,15 +218,9 @@ for src_t in [tint, tuint, tfloat]: bit_size, rnd_mode), dst_t + str(bit_size), src_t, "src0") else: + conv_expr = "src0 != 0" if dst_t == tbool else "src0" 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", tbool32, tfloat, "src0 != 0.0") -unop_convert("i2b", tbool32, tint, "src0 != 0") -unop_convert("b2f", tfloat, tbool32, "src0 ? 1.0 : 0.0") -unop_convert("b2i", tint, tbool32, "src0 ? 1 : 0") + dst_t + str(bit_size), src_t, conv_expr) # Unary floating-point rounding operations. |