public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Alexandre Ghiti <alex@ghiti.fr>
To: Ignacio Encinas <ignacio@iencinas.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>
Cc: "Eric Biggers" <ebiggers@kernel.org>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linux.dev,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Zhihang Shao" <zhihang.shao.iscas@gmail.com>,
	"Björn Töpel" <bjorn@kernel.org>,
	Linux-Arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] riscv: introduce asm/swab.h
Date: Wed, 23 Apr 2025 13:08:42 +0200	[thread overview]
Message-ID: <66a5aba9-2a32-4ef9-a839-a389b975757d@ghiti.fr> (raw)
In-Reply-To: <b3f8e641-9690-4792-974c-c895d2e4531a@iencinas.com>

Hi Ignacio,

On 04/04/2025 19:35, Ignacio Encinas wrote:
>
> On 4/4/25 7:58, Arnd Bergmann wrote:
>> On Thu, Apr 3, 2025, at 22:34, Ignacio Encinas wrote:
>>> +#define ARCH_SWAB(size) \
>>> +static __always_inline unsigned long __arch_swab##size(__u##size value) \
>>> +{									\
>>> +	unsigned long x = value;					\
>>> +									\
>>> +	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);				\
>>> +}
> Hello Arnd!
>
>> I think the fallback should really just use the __builtin_bswap
>> helpers instead of the ___constant_swab variants. The output
>> would be the same, but you can skip patch 1/2.
> I tried, but that change causes build errors:
>
> ```
> undefined reference to `__bswapsi2'
>
> [...]
>
> undefined reference to `__bswapdi2
> ```
>
> I tried working around those, but couldn't find a good solution. I'm a
> bit out of my depth here, but I "summarized" everything here [1]. Let me
> know if I'm missing something.
>
> [1] https://lore.kernel.org/linux-riscv/b3b59747-0484-4042-bdc4-c067688e3bfe@iencinas.com/

Note that I only encountered those issues in the purgatory.

So to me we have 3 solutions:

- either implementing both __bswapsi2 and __bswapdi2

- or linking against libgcc

- or merging patch 1.

Given the explanation in commit d67703a8a69e ("arm64: kill off the 
libgcc dependency"), I would not use libgcc.

The less intrusive solution (for us riscv) is merging patch 1.

But please let me know if I missed another solution or if I'm wrong.

Thanks,

Alex


>
>> I would also suggest dumbing down the macro a bit so you can
>> still find the definition with 'git grep __arch_swab64'. Ideally
>> just put the function body into a macro but leave the three
>> separate inline function definitions.
> Good point, thanks for bringing it up. Just to be sure, is this what you
> had in mind? (Give or take formatting + naming of variables)
>
> #define arch_swab(size, value) 						\
> ({                      						\
> 	unsigned long x = value;					\
> 									\
> 	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));			\
> 		x = x >> (BITS_PER_LONG - size);			\
> 	} else {                                                        \
> 		x = ___constant_swab##size(value);                      \
> 	}								\
> 	x;								\
> })
>
> static __always_inline unsigned long __arch_swab64(__u64 value) {
> 	return arch_swab(64, value);
> }
>
> Thanks!
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-04-23 11:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 20:34 [PATCH v3 0/2] Implement endianess swap macros for RISC-V Ignacio Encinas
2025-04-03 20:34 ` [PATCH v3 1/2] include/uapi/linux/swab.h: move default implementation for swab macros into asm-generic Ignacio Encinas
2025-04-04 15:31   ` kernel test robot
2025-04-03 20:34 ` [PATCH v3 2/2] riscv: introduce asm/swab.h Ignacio Encinas
2025-04-04  5:58   ` Arnd Bergmann
2025-04-04 15:54     ` Ben Dooks
2025-04-04 17:35     ` Ignacio Encinas
2025-04-23 11:08       ` Alexandre Ghiti [this message]
2025-04-24 17:27         ` Ignacio Encinas Rubio
2025-04-04 15:47   ` Ben Dooks
2025-04-04 17:53     ` Ignacio Encinas
2025-04-04 19:28     ` Eric Biggers
2025-04-04 15:55   ` Ben Dooks
2025-04-04 18:13     ` Ignacio Encinas
2025-04-04 15:56 ` [PATCH v3 0/2] Implement endianess swap macros for RISC-V Ben Dooks

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=66a5aba9-2a32-4ef9-a839-a389b975757d@ghiti.fr \
    --to=alex@ghiti.fr \
    --cc=arnd@arndb.de \
    --cc=bjorn@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=ignacio@iencinas.com \
    --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