Re: [PATCH 1/3] riscv: word-at-a-time: improve find_zero() for !RISCV_ISA_ZBB

From: Nam Cao

Date: Thu Sep 03 2026 - 07:26:18 EST


Jisheng Zhang <jszhang@xxxxxxxxxx> writes:

> On Thu, Aug 20, 2026 at 10:31:49AM +0200, Nam Cao wrote:
>> Jisheng Zhang <jszhang@xxxxxxxxxx> writes:
>> > +#if !(defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB))
>> > +#include <asm-generic/word-at-a-time.h>
>> > +#else
>>
>> Instead of this #if, would it be better to do
>>
>> static inline unsigned long find_zero(unsigned long mask)
>> {
>> if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) &&
>> riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
>> return !mask ? 0 : ((__fls(mask) + 1) >> 3);
>>
>> return count_masked_bytes(mask);
>> }
>>
>> and let compiler's dead code elimination does its job?
>
> This is impossible because the generic word-at-a-time.h implements
> the generic find_zero() itself, so there will be compile error.

Don't include word-at-a-time.h then? It compiles fine for me (obviously
count_masked_bytes() from PATCH 2/3 needs to be added first).

Nam