On 4/7/23 00:40, gaosong wrote:

在 2023/4/2 上午11:34, Richard Henderson 写道:
On 3/27/23 20:06, Song Gao wrote:
+#define DO_CLO_B(N)  (clz32((uint8_t)~N) - 24)
+#define DO_CLO_H(N)  (clz32((uint16_t)~N) - 16)

I think this is wrong.
It is wried,  the result is always right. :-\
and  (clz32(~N) - 24)  or (clz32((uint32_t)~N) - 24) is wrong.
You *want* the high bits to be set, so that they are ones, and included in the count, which you then subtract off.  You want the "real" count to start after the 24th leading 1.

Yes,
and  we use clz32(),   how about the following way?

#define DO_CLO_B(N)  (clz32( ~N & 0xff) -24)
#define DO_CLO_H(N)  (clz32( ~N & 0xffff) -16)

Ah yes, I see.  My mistake.  Either old or new formulation is fine.

Reviewed-by: Richard Henderson <richard.hender...@linaro.org>


r~

Reply via email to