Re: [PATCH v3 2/2] riscv: introduce asm/swab.h

From: Ben Dooks
Date: Fri Apr 04 2025 - 11:54:54 EST


On 04/04/2025 06: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); \
+}

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 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.

I thought we explicitly disabled the builtin from gc... I tried doing
this and just ended up with undefined calls from these sites.,

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html