[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250916134803.874580-4-hca@linux.ibm.com>
Date: Tue, 16 Sep 2025 15:48:02 +0200
From: Heiko Carstens <hca@...ux.ibm.com>
To: Nathan Chancellor <nathan@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Kees Cook <kees@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Juergen Christ <jchrist@...ux.ibm.com>
Cc: linux-kernel@...r.kernel.org, linux-s390@...r.kernel.org,
Sven Schnelle <svens@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>
Subject: [PATCH v2 3/4] s390/bitops: Use __assume() for __flogr() inline assembly return value
Use __assume() to tell compilers that the output operand of the __flogr()
inline assembly contains a value in the range of 0..64. This allows to
optimize the logical AND operation away.
This reduces the kernel image size by 2804 bytes (defconfig, gcc 15.2.0).
Suggested-by: Juergen Christ <jchrist@...ux.ibm.com>
Reviewed-by: Juergen Christ <jchrist@...ux.ibm.com>
Signed-off-by: Heiko Carstens <hca@...ux.ibm.com>
---
arch/s390/include/asm/bitops.h | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/arch/s390/include/asm/bitops.h b/arch/s390/include/asm/bitops.h
index a1dd72b16f54..5ff069fe9526 100644
--- a/arch/s390/include/asm/bitops.h
+++ b/arch/s390/include/asm/bitops.h
@@ -132,9 +132,10 @@ static inline bool test_bit_inv(unsigned long nr,
*/
static __always_inline unsigned char __flogr(unsigned long word)
{
- if (__builtin_constant_p(word)) {
- unsigned long bit = 0;
+ unsigned long bit;
+ if (__builtin_constant_p(word)) {
+ bit = 0;
if (!word)
return 64;
if (!(word & 0xffffffff00000000UL)) {
@@ -169,7 +170,14 @@ static __always_inline unsigned char __flogr(unsigned long word)
asm volatile(
" flogr %[rp],%[rp]\n"
: [rp] "+d" (rp.pair) : : "cc");
- return rp.even & 127;
+ bit = rp.even;
+ /*
+ * The result of the flogr instruction is a value in the range
+ * of 0..64. Let the compiler know that the AND operation can
+ * be optimized away.
+ */
+ __assume(bit <= 64);
+ return bit & 127;
}
}
--
2.48.1
Powered by blists - more mailing lists