[PATCH 07/22] risc-v: replace bitmap_weight with bitmap_empty in riscv_fill_hwcap()

Anup Patel anup at brainfault.org
Tue May 10 09:31:30 PDT 2022


On Tue, May 10, 2022 at 9:18 PM Yury Norov <yury.norov at gmail.com> wrote:
>
> bitmap_empty() is better than bitmap_weight() because it may return
> earlier, and improves on readability.
>
> CC: Albert Ou <aou at eecs.berkeley.edu>
> CC: Anup Patel <anup at brainfault.org>
> CC: Atish Patra <atishp at atishpatra.org>
> CC: Jisheng Zhang <jszhang at kernel.org>
> CC: Palmer Dabbelt <palmer at dabbelt.com>
> CC: Paul Walmsley <paul.walmsley at sifive.com>
> CC: Tsukasa OI <research_trasio at irq.a4lg.com>
> CC: linux-riscv at lists.infradead.org
> CC: linux-kernel at vger.kernel.org
> Signed-off-by: Yury Norov <yury.norov at gmail.com>

Looks good to me.

Reviewed-by: Anup Patel <anup at brainfault.org>

Regards,
Anup

> ---
>  arch/riscv/kernel/cpufeature.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> index 1b2d42d7f589..f0298d756f66 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -206,11 +206,10 @@ void __init riscv_fill_hwcap(void)
>                 else
>                         elf_hwcap = this_hwcap;
>
> -               if (bitmap_weight(riscv_isa, RISCV_ISA_EXT_MAX))
> -                       bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
> -               else
> +               if (bitmap_empty(riscv_isa, RISCV_ISA_EXT_MAX))
>                         bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
> -
> +               else
> +                       bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX);
>         }
>
>         /* We don't support systems with F but without D, so mask those out
> --
> 2.32.0
>



More information about the linux-riscv mailing list