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>
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");