On 9/20/21 1:04 AM, WANG Xuerui wrote:
+static void tcg_out_clzctz(TCGContext *s, LoongArchInsn opc,
+ TCGReg a0, TCGReg a1, TCGReg a2)
+{
+ /* all clz/ctz insns belong to DJ-format */
+ tcg_out32(s, encode_dj_insn(opc, TCG_REG_TMP0, a1));
+ /* a0 = a1 ? REG_TMP0 : a2 */
+ tcg_out_opc_maskeqz(s, TCG_REG_TMP0, TCG_REG_TMP0, a1);
+ tcg_out_opc_masknez(s, a0, a2, a1);
+ tcg_out_opc_or(s, a0, TCG_REG_TMP0, a0);
+}
From Song Gao's translation, I believe that ctz(0) == 32 or 64, depending on the
operation width. This is in fact the most common result, so it's worth specializing. See
tcg/i386/tcg-target.c.inc, tcg_out_clz, have_lzcnt.
But what's here looks ok.
Reviewed-by: Richard Henderson <[email protected]>
r~