pan/mdg: Avoid division in printing helpers
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 21 May 2020 22:09:53 +0000 (18:09 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Thu, 21 May 2020 22:29:53 +0000 (18:29 -0400)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5154>

src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_print.c
src/panfrost/midgard/mir.c

index f9cfcb09fc8b91320257b55e4a975dcf15ccaccc..c26f82613f8aa3c41e0bf27d7fa50612ea0d4f33 100644 (file)
@@ -498,6 +498,7 @@ uint16_t mir_bytemask(midgard_instruction *ins);
 uint16_t mir_round_bytemask_up(uint16_t mask, unsigned bits);
 void mir_set_bytemask(midgard_instruction *ins, uint16_t bytemask);
 signed mir_upper_override(midgard_instruction *ins, unsigned inst_size);
+unsigned mir_components_for_type(nir_alu_type T);
 
 /* MIR printing */
 
index b2cc8e27aa4f0dc70da2dc3d3512856055089293..a5133f09e20c003a789d7d608be59544226c4273 100644 (file)
@@ -73,8 +73,7 @@ mir_print_mask(unsigned mask)
 static void
 mir_print_swizzle(unsigned *swizzle, nir_alu_type T)
 {
-        unsigned sz = nir_alu_type_get_type_size(T);
-        unsigned comps = 128 / sz;
+        unsigned comps = mir_components_for_type(T);
 
         printf(".");
 
@@ -230,7 +229,6 @@ mir_print_constant_component(FILE *fp, const midgard_constants *consts, unsigned
 static void
 mir_print_embedded_constant(midgard_instruction *ins, unsigned src_idx)
 {
-        unsigned type_size = nir_alu_type_get_type_size(ins->dest_type);
         midgard_vector_alu_src src;
 
         assert(src_idx <= 1);
@@ -242,7 +240,7 @@ mir_print_embedded_constant(midgard_instruction *ins, unsigned src_idx)
         unsigned *swizzle = ins->swizzle[src_idx];
         unsigned comp_mask = effective_writemask(&ins->alu, ins->mask);
         unsigned num_comp = util_bitcount(comp_mask);
-        unsigned max_comp = 64 / type_size;
+        unsigned max_comp = mir_components_for_type(ins->dest_type) >> 1;
         bool first = true;
 
         printf("#");
index b7e2917c4651f4d59929905b1ac41a0806e79f71..ec6c099db67c724220764f571ad7d65709569015 100644 (file)
@@ -145,6 +145,19 @@ mir_nontrivial_outmod(midgard_instruction *ins)
                 return mod != midgard_outmod_none;
 }
 
+/* 128 / sz = exp2(log2(128 / sz))
+ *          = exp2(log2(128) - log2(sz))
+ *          = exp2(7 - log2(sz))
+ *          = 1 << (7 - log2(sz))
+ */
+
+unsigned
+mir_components_for_type(nir_alu_type T)
+{
+        unsigned sz = nir_alu_type_get_type_size(T);
+        return 1 << (7 - util_logbase2(sz));
+}
+
 uint16_t
 mir_from_bytemask(uint16_t bytemask, unsigned bits)
 {