From e85b6c4ab130670916ef83f32891f8c1023e4a4f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 21 May 2020 18:16:15 -0400 Subject: [PATCH] pan/mdg: Eliminate remaining divisions from compiler Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/midgard/midgard_schedule.c | 5 +++-- src/panfrost/midgard/mir.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/panfrost/midgard/midgard_schedule.c b/src/panfrost/midgard/midgard_schedule.c index a365cfaf09e..59fa830f68b 100644 --- a/src/panfrost/midgard/midgard_schedule.c +++ b/src/panfrost/midgard/midgard_schedule.c @@ -355,7 +355,8 @@ mir_adjust_constant(midgard_instruction *ins, unsigned src, bool upper) { unsigned type_size = nir_alu_type_get_type_size(ins->src_types[src]) / 8; - unsigned max_comp = 16 / type_size; + unsigned type_shift = util_logbase2(type_size); + unsigned max_comp = mir_components_for_type(ins->src_types[src]); unsigned comp_mask = mir_from_bytemask(mir_round_bytemask_up( mir_bytemask_of_read_components_index(ins, src), type_size * 8), @@ -413,7 +414,7 @@ mir_adjust_constant(midgard_instruction *ins, unsigned src, memcpy(&bundle_constants[i], constantp, type_size); *bundle_constant_mask |= type_mask << best_place; - comp_mapping[comp] = best_place / type_size; + comp_mapping[comp] = best_place >> type_shift; } return true; diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c index ec6c099db67..0bb87c8fe00 100644 --- a/src/panfrost/midgard/mir.c +++ b/src/panfrost/midgard/mir.c @@ -151,11 +151,17 @@ mir_nontrivial_outmod(midgard_instruction *ins) * = 1 << (7 - log2(sz)) */ +static unsigned +mir_components_for_bits(unsigned bits) +{ + return 1 << (7 - util_logbase2(bits)); +} + unsigned mir_components_for_type(nir_alu_type T) { unsigned sz = nir_alu_type_get_type_size(T); - return 1 << (7 - util_logbase2(sz)); + return mir_components_for_bits(sz); } uint16_t @@ -184,7 +190,7 @@ mir_round_bytemask_up(uint16_t mask, unsigned bits) { unsigned bytes = bits / 8; unsigned maxmask = mask_of(bytes); - unsigned channels = 16 / bytes; + unsigned channels = mir_components_for_bits(bits); for (unsigned c = 0; c < channels; ++c) { unsigned submask = maxmask << (c * bytes); @@ -229,7 +235,7 @@ mir_upper_override(midgard_instruction *ins, unsigned inst_size) * (16/bytes), which simplifies to 8/bytes = 8 / (bits / 8) = 64 / bits * */ - unsigned threshold = 64 / type_size; + unsigned threshold = mir_components_for_bits(type_size) >> 1; /* How many components did we shift over? */ unsigned zeroes = __builtin_ctz(ins->mask); -- 2.30.2