[PATCH] Add generic_ffz for use for archs without an optimized version
authorJens Axboe <axboe@suse.de>
Wed, 9 Nov 2005 08:24:14 +0000 (09:24 +0100)
committerJens Axboe <axboe@suse.de>
Wed, 9 Nov 2005 08:24:14 +0000 (09:24 +0100)
arch-alpha.h
arch-s390.h
arch.h

index b1b1e8abbbc2e0ce1e3dd879d97ae5e792fb1f02..09293bd30fc52e5ac4488e7893594cc753ce6179 100644 (file)
@@ -13,5 +13,6 @@
 #endif
 
 #define nop    do { } while (0)
+#define ffz(v) generic_ffz((v))
 
 #endif
index 956dccf32a5c617943fa6b170dc4d8a449fb8d4a..b7048ad6a11b37a475271f44f9f5483bc5d3a80b 100644 (file)
@@ -13,5 +13,6 @@
 #endif
 
 #define nop    asm volatile ("diag 0,0,68" : : : "memory")
+#define ffz(v) generic_ffz((v))
 
 #endif
diff --git a/arch.h b/arch.h
index 44d09e966230f3f7f8ffb0428407f1a9b34a8581..4ea55bc1d05119b71ddb18b9cd5807d0313d06dd 100644 (file)
--- a/arch.h
+++ b/arch.h
@@ -10,6 +10,17 @@ enum {
        arch_alpha,
 };
 
+static inline unsigned long generic_ffz(unsigned long word)
+{
+       int i;
+
+       for (i = 0; i < sizeof(word) * 8; i++)
+               if ((word & (1UL << i)) == 0)
+                       return i;
+
+       return -1;
+}
+
 #if defined(__i386__)
 #include "arch-x86.h"
 #elif defined(__x86_64__)