lkml.org 
[lkml]   [2026]   [Apr]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] arch/riscv: Add bitrev.h file to support rev8 and brev8
Date
On Wed, 11 Mar 2026 15:13:44 +0800, ruanjinjie@huawei.com wrote:

> +#include <linux/types.h>
> +#include <asm/cpufeature-macros.h>
> +#include <asm/hwcap.h>
> +
> +extern u8 const byte_rev_table[256];
> +static __always_inline __attribute_const__ u32 __arch_bitrev32(u32 x)
> +{
> + if (IS_ENABLED(CONFIG_RISCV_ISA_ZBKB) &&
> + riscv_has_extension_likely(RISCV_ISA_EXT_ZBKB)) {
> + unsigned long result = x;
> +
> + asm volatile(
> + ".option push\n"
> + ".option arch,+zbkb\n"
> + "rev8 %0, %0\n"
> + "brev8 %0, %0\n"
> + ".option pop"
> + : "+r" (result)
> + );
> +
> + if (__riscv_xlen == 64)
> + return (u32)(result >> 32);
> +
> + return (u32)result;
> + }
> +
> + return (u32)byte_rev_table[x & 0xff] << 24 |
> + (u32)byte_rev_table[(x >> 8) & 0xff] << 16 |
> + (u32)byte_rev_table[(x >> 16) & 0xff] << 8 |
> + (u32)byte_rev_table[x >> 24];
> +}

Hi Jinjie,

Thanks for your patch. I have two suggestions.
1. When ZBKB is not supported, is it simpler to directly use the generic
implementation __bitrev32 in <linux/bitrev.h>.
2. Could you please provide a benchmark test case to illustrate the
performance comparison with and without this extension (refer to
test_bitops.c) and also provide the results by bloat-o-meter.

Thanks,
Pei

\
 
 \ /
  Last update: 2026-04-10 13:41    [W:0.106 / U:1.915 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog