From ad06e0592aa5c1b92ea113b6151c55a2b7d208ab Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 27 Jan 2021 12:31:45 -0500 Subject: [PATCH] pan/bi: Implement ufind_msb Lowered to #(sz - 1) - clz(x), taking advantage of the machine's 8-bit and 16-bit variants of clz and the widening on the second argument of ISUB to implement neatly in two instructions. Note that in NIR, ufind_msb can take any integer type but always output i32. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index ac99a7c9a5f..51f77b7b394 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -1525,6 +1525,18 @@ bi_emit_alu(bi_builder *b, nir_alu_instr *instr) bi_bitrev_i32_to(b, dst, s0); break; + case nir_op_ufind_msb: { + bi_index clz = bi_clz(b, src_sz, s0, false); + + if (sz == 8) + clz = bi_byte(clz, 0); + else if (sz == 16) + clz = bi_half(clz, false); + + bi_isub_u32_to(b, dst, bi_imm_u32(src_sz - 1), clz, false); + break; + } + default: fprintf(stderr, "Unhandled ALU op %s\n", nir_op_infos[instr->op].name); unreachable("Unknown ALU op");