qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH v2 30/44] target/loongarch: Implement vclo vclz


From: Richard Henderson
Subject: Re: [RFC PATCH v2 30/44] target/loongarch: Implement vclo vclz
Date: Fri, 7 Apr 2023 09:46:00 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0

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.henderson@linaro.org>


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]