|
From: | Richard Henderson |
Subject: | Re: [PATCH 15/30] tcg/loongarch: Implement clz/ctz ops |
Date: | Mon, 20 Sep 2021 09:10:49 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 |
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 <richard.henderson@linaro.org> r~
[Prev in Thread] | Current Thread | [Next in Thread] |