pan/bi: Implement ufind_msb
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 27 Jan 2021 17:31:45 +0000 (12:31 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 12 Feb 2021 21:44:31 +0000 (16:44 -0500)
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 <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8774>

src/panfrost/bifrost/bifrost_compile.c

index ac99a7c9a5f7a088bd544a4a9f6b7c603a6775d5..51f77b7b39463da2472e488809b70e595f20c56b 100644 (file)
@@ -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");