public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Ignacio Encinas Rubio <ignacio@iencinas.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: "Paul Walmsley" <paul.walmsley@sifive.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Arnd Bergmann" <arnd@arndb.de>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
	"Zhihang Shao" <zhihang.shao.iscas@gmail.com>,
	"Björn Töpel" <bjorn@kernel.org>,
	linux-arch@vger.kernel.org
Subject: Re: [PATCH v2 2/2] riscv: introduce asm/swab.h
Date: Fri, 21 Mar 2025 22:07:41 +0100	[thread overview]
Message-ID: <fd8e4380-eba3-4602-b925-d81c0afed6d8@iencinas.com> (raw)
In-Reply-To: <20250321033718.GA98513@sol.localdomain>



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!

      reply	other threads:[~2025-03-21 21:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 21:09 [PATCH v2 0/2] Implement endianness swap macros for RISC-V Ignacio Encinas
2025-03-19 21:09 ` [PATCH v2 1/2] include/uapi/linux/swab.h: move default implementation for swab macros into asm-generic Ignacio Encinas
2025-03-19 21:12   ` Arnd Bergmann
2025-03-19 21:37     ` Ignacio Encinas Rubio
2025-03-19 21:49       ` Arnd Bergmann
2025-03-20 22:36         ` Ignacio Encinas Rubio
2025-03-21 10:23           ` Arnd Bergmann
2025-03-21 18:38             ` Ignacio Encinas Rubio
2025-03-19 21:09 ` [PATCH v2 2/2] riscv: introduce asm/swab.h Ignacio Encinas
2025-03-21  3:37   ` Eric Biggers
2025-03-21 21:07     ` Ignacio Encinas Rubio [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=fd8e4380-eba3-4602-b925-d81c0afed6d8@iencinas.com \
    --to=ignacio@iencinas.com \
    --cc=alex@ghiti.fr \
    --cc=arnd@arndb.de \
    --cc=bjorn@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=skhan@linuxfoundation.org \
    --cc=zhihang.shao.iscas@gmail.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