From: cp0613@linux.alibaba.com
To: ruanjinjie@huawei.com
Cc: akpm@linux-foundation.org, alex@ghiti.fr, aou@eecs.berkeley.edu,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
palmer@dabbelt.com, pjw@kernel.org
Subject: Re: [PATCH] arch/riscv: Add bitrev.h file to support rev8 and brev8
Date: Mon, 13 Apr 2026 20:28:08 +0800 [thread overview]
Message-ID: <20260413122817.122787-1-cp0613@linux.alibaba.com> (raw)
In-Reply-To: <150bfb90-ec49-7209-b841-2e48ca12b370@huawei.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 2271 bytes --]
On Sat, 11 Apr 2026 10:48:17 +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>.
>
> Actually, you can't simply use the default implementation from
> linux/bitrev.h. It includes asm/bitrev.h (the architecture-specific
> implementation), which would lead to compilation issues. Furthermore,
> when ZBKB is not supported, current implementation is identical to the
> default one.
Understood. So, have you considered renaming the function to `generic_xxx`,
like `generic___ffs` in bitops?
> > 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.
>
> I don't have access to RISC-V hardware at the moment, so I've only
> performed basic functional testing on QEMU, which completed without
> issues,could you please help run some benchmarks to verify the performance?
I don't currently have the hardware that supports the corresponding extension,
but I can test it using an FPGA environment when I have the opportunity (it
will take some time).
> Thanks,
> Jinjie
>
> >
> > Thanks,
> > Pei
Thanks,
Pei
[-- Attachment #2: Type: text/plain, Size: 161 bytes --]
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
prev parent reply other threads:[~2026-04-13 12:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 7:13 [PATCH] arch/riscv: Add bitrev.h file to support rev8 and brev8 Jinjie Ruan
2026-04-02 6:41 ` Jinjie Ruan
2026-04-10 11:36 ` cp0613
2026-04-11 2:48 ` Jinjie Ruan
2026-04-13 12:28 ` cp0613 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260413122817.122787-1-cp0613@linux.alibaba.com \
--to=cp0613@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=ruanjinjie@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox