nir: extract out convert_to_bitsize() helper
authorRob Clark <robdclark@chromium.org>
Wed, 3 Jun 2020 19:09:59 +0000 (12:09 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 3 Jun 2020 21:24:13 +0000 (21:24 +0000)
Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5318>

src/compiler/nir/nir_builder.h
src/compiler/nir/nir_lower_bit_size.c

index 6c4b2da6f5c56f6f3817aebd132e31a505298ce1..de84bc85784cf83e696b96416ab32eae7f0c7a60 100644 (file)
@@ -1384,4 +1384,19 @@ nir_scoped_memory_barrier(nir_builder *b,
    nir_scoped_barrier(b, NIR_SCOPE_NONE, scope, semantics, modes);
 }
 
+static inline nir_ssa_def *
+nir_convert_to_bit_size(nir_builder *b,
+                    nir_ssa_def *src,
+                    nir_alu_type type,
+                    unsigned bit_size)
+{
+   nir_alu_type base_type = nir_alu_type_get_base_type(type);
+   nir_alu_type dst_type = (nir_alu_type)(bit_size | base_type);
+
+   nir_op opcode =
+      nir_type_conversion_op(type, dst_type, nir_rounding_mode_undef);
+
+   return nir_build_alu(b, opcode, src, NULL, NULL, NULL);
+}
+
 #endif /* NIR_BUILDER_H */
index 100ac4864a5896fe36aec0afc058d6ea1c0cd2bd..fbab2677756190829fc124515600424249eae7d4 100644 (file)
  * a bit-size that is supported natively and then converts the result back to
  * the original bit-size.
  */
-static nir_ssa_def *
-convert_to_bit_size(nir_builder *bld,
-                    nir_ssa_def *src,
-                    nir_alu_type type,
-                    unsigned bit_size)
-{
-   nir_alu_type base_type = nir_alu_type_get_base_type(type);
-   nir_alu_type lowered_type = bit_size | base_type;
-
-   nir_op opcode =
-      nir_type_conversion_op(type, lowered_type, nir_rounding_mode_undef);
-
-   return nir_build_alu(bld, opcode, src, NULL, NULL, NULL);
-}
 
 static void
 lower_instr(nir_builder *bld, nir_alu_instr *alu, unsigned bit_size)
@@ -59,7 +45,7 @@ lower_instr(nir_builder *bld, nir_alu_instr *alu, unsigned bit_size)
 
       nir_alu_type type = nir_op_infos[op].input_types[i];
       if (nir_alu_type_get_type_size(type) == 0)
-         src = convert_to_bit_size(bld, src, type, bit_size);
+         src = nir_convert_to_bit_size(bld, src, type, bit_size);
 
       if (i == 1 && (op == nir_op_ishl || op == nir_op_ishr || op == nir_op_ushr)) {
          assert(util_is_power_of_two_nonzero(dst_bit_size));
@@ -85,7 +71,7 @@ lower_instr(nir_builder *bld, nir_alu_instr *alu, unsigned bit_size)
 
    /* Convert result back to the original bit-size */
    nir_alu_type type = nir_op_infos[op].output_type;
-   nir_ssa_def *dst = convert_to_bit_size(bld, lowered_dst, type, dst_bit_size);
+   nir_ssa_def *dst = nir_convert_to_bit_size(bld, lowered_dst, type, dst_bit_size);
    nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, nir_src_for_ssa(dst));
 }