Skip to content

Commit b9b60b3

Browse files
committed
x86: improve bitop code generation with clang
This uses the new ASM_INPUT_RM macro to avoid the bad code generation issue that clang has with more generic asm inputs. This ends up avoiding generating code like this: mov %r10,(%rsp) tzcnt (%rsp),%rcx which now becomes just tzcnt %r10,%rcx and in the process ends up also removing a few unnecessary stack frames when the only use was that pointless "asm uses memory location off stack". Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7453b94 commit b9b60b3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

arch/x86/include/asm/bitops.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static __always_inline unsigned long variable__ffs(unsigned long word)
250250
{
251251
asm("rep; bsf %1,%0"
252252
: "=r" (word)
253-
: "rm" (word));
253+
: ASM_INPUT_RM (word));
254254
return word;
255255
}
256256

@@ -297,7 +297,7 @@ static __always_inline unsigned long __fls(unsigned long word)
297297

298298
asm("bsr %1,%0"
299299
: "=r" (word)
300-
: "rm" (word));
300+
: ASM_INPUT_RM (word));
301301
return word;
302302
}
303303

@@ -320,7 +320,7 @@ static __always_inline int variable_ffs(int x)
320320
*/
321321
asm("bsfl %1,%0"
322322
: "=r" (r)
323-
: "rm" (x), "0" (-1));
323+
: ASM_INPUT_RM (x), "0" (-1));
324324
#elif defined(CONFIG_X86_CMOV)
325325
asm("bsfl %1,%0\n\t"
326326
"cmovzl %2,%0"
@@ -377,7 +377,7 @@ static __always_inline int fls(unsigned int x)
377377
*/
378378
asm("bsrl %1,%0"
379379
: "=r" (r)
380-
: "rm" (x), "0" (-1));
380+
: ASM_INPUT_RM (x), "0" (-1));
381381
#elif defined(CONFIG_X86_CMOV)
382382
asm("bsrl %1,%0\n\t"
383383
"cmovzl %2,%0"
@@ -416,7 +416,7 @@ static __always_inline int fls64(__u64 x)
416416
*/
417417
asm("bsrq %1,%q0"
418418
: "+r" (bitpos)
419-
: "rm" (x));
419+
: ASM_INPUT_RM (x));
420420
return bitpos + 1;
421421
}
422422
#else

0 commit comments

Comments
 (0)