[CRIU] [PATCH] bitops: use a gcc builtin function instead of our __ffs

Andrei Vagin avagin at virtuozzo.com
Sun Jun 17 06:32:53 MSK 2018


Our __ffs implementation is straightforward and non-optimal,
__builtin_ffsl should be faster.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 include/common/asm-generic/bitops.h | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/include/common/asm-generic/bitops.h b/include/common/asm-generic/bitops.h
index cb449fbf8..e1a097511 100644
--- a/include/common/asm-generic/bitops.h
+++ b/include/common/asm-generic/bitops.h
@@ -57,17 +57,7 @@ static inline void clear_bit(int nr, volatile unsigned long *addr)
  */
 static inline unsigned long __ffs(unsigned long word)
 {
-	int p = 0;
-
-	for (; p < 8*sizeof(word); ++p) {
-		if (word & 1) {
-			break;
-		}
-
-		word >>= 1;
-	}
-
-	return p;
+	return __builtin_ffsl(word) - 1;
 }
 
 #define BITOP_WORD(nr)		((nr) / BITS_PER_LONG)
-- 
2.14.3



More information about the CRIU mailing list