Skip to content

Commit 7916160

Browse files
hcahcaAlexander Gordeev
authored andcommitted
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@linux.ibm.com> Reviewed-by: Juergen Christ <jchrist@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent f72e2cf commit 7916160

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

arch/s390/include/asm/bitops.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ static inline bool test_bit_inv(unsigned long nr,
132132
*/
133133
static __always_inline unsigned char __flogr(unsigned long word)
134134
{
135-
if (__builtin_constant_p(word)) {
136-
unsigned long bit = 0;
135+
unsigned long bit;
137136

137+
if (__builtin_constant_p(word)) {
138+
bit = 0;
138139
if (!word)
139140
return 64;
140141
if (!(word & 0xffffffff00000000UL)) {
@@ -169,7 +170,14 @@ static __always_inline unsigned char __flogr(unsigned long word)
169170
asm volatile(
170171
" flogr %[rp],%[rp]\n"
171172
: [rp] "+d" (rp.pair) : : "cc");
172-
return rp.even & 127;
173+
bit = rp.even;
174+
/*
175+
* The result of the flogr instruction is a value in the range
176+
* of 0..64. Let the compiler know that the AND operation can
177+
* be optimized away.
178+
*/
179+
__assume(bit <= 64);
180+
return bit & 127;
173181
}
174182
}
175183

0 commit comments

Comments
 (0)