bitops: use a gcc builtin function instead of our __ffs

Submitted by Andrey Vagin on June 17, 2018, 3:32 a.m.

Details

Message ID 20180617033253.5906-1-avagin@virtuozzo.com
State Accepted
Series "bitops: use a gcc builtin function instead of our __ffs"
Commit 03598ea5aee4824b4ec16301742a165a29dd6f06
Headers show

Commit Message

Andrey Vagin June 17, 2018, 3:32 a.m.
Our __ffs implementation is straightforward and non-optimal,
__builtin_ffsl should be faster.

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

Patch hide | download patch | download mbox

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)