From 2b9f6d30f8ba5d693e87bc172bf577c6dd83dcfc Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 21 May 2020 18:09:53 -0400 Subject: [PATCH] pan/mdg: Avoid division in printing helpers Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/midgard/compiler.h | 1 + src/panfrost/midgard/midgard_print.c | 6 ++---- src/panfrost/midgard/mir.c | 13 +++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index f9cfcb09fc8..c26f82613f8 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -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 */ diff --git a/src/panfrost/midgard/midgard_print.c b/src/panfrost/midgard/midgard_print.c index b2cc8e27aa4..a5133f09e20 100644 --- a/src/panfrost/midgard/midgard_print.c +++ b/src/panfrost/midgard/midgard_print.c @@ -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("#"); diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c index b7e2917c465..ec6c099db67 100644 --- a/src/panfrost/midgard/mir.c +++ b/src/panfrost/midgard/mir.c @@ -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) { -- 2.30.2