[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fd8e4380-eba3-4602-b925-d81c0afed6d8@iencinas.com>
Date: Fri, 21 Mar 2025 22:07:41 +0100
From: Ignacio Encinas Rubio <ignacio@...cinas.com>
To: Eric Biggers <ebiggers@...nel.org>
Cc: Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>, Alexandre Ghiti <alex@...ti.fr>,
Arnd Bergmann <arnd@...db.de>, linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-kernel-mentees@...ts.linux.dev,
skhan@...uxfoundation.org, Zhihang Shao <zhihang.shao.iscas@...il.com>,
Björn Töpel <bjorn@...nel.org>,
linux-arch@...r.kernel.org
Subject: Re: [PATCH v2 2/2] riscv: introduce asm/swab.h
On 21/3/25 4:37, Eric Biggers wrote:
> On Wed, Mar 19, 2025 at 10:09:46PM +0100, Ignacio Encinas wrote:
>> +#define ARCH_SWAB(size) \
>> +static __always_inline unsigned long __arch_swab##size(__u##size value) \
>> +{ \
>> + unsigned long x = value; \
>> + \
>> + asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, \
>> + RISCV_ISA_EXT_ZBB, 1) \
>> + :::: legacy); \
>
> Is there a reason to use this instead of
> riscv_has_extension_likely(RISCV_ISA_EXT_ZBB) which seems to do the same thing,
> including using a static branch?
I just followed what's already in arch/riscv/include/asm/bitops.h
However, I changed it to
if(riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)) {
asm volatile (".option push\n"
".option arch,+zbb\n"
"rev8 %0, %1\n"
".option pop\n"
: "=r" (x) : "r" (x));
return x >> (BITS_PER_LONG - size);
}
return ___constant_swab##size(value);
and it seems gcc generates the exact same code. I tested it with
arch/riscv/lib/csum.c (which uses swab32) and both versions generate the
exact same object file.
This certainly looks easier to read. If there are no complaints I'll
send a v3 using a plain if with riscv_has_extension_likely.
Thanks for pointing it out!
Powered by blists - more mailing lists