bitops: Add __ffs64 bitop
authorSteven Whitehouse <swhiteho@redhat.com>
Thu, 23 Apr 2009 07:48:15 +0000 (08:48 +0100)
committerSteven Whitehouse <swhiteho@redhat.com>
Thu, 23 Apr 2009 09:06:35 +0000 (10:06 +0100)
Finds the first set bit in a 64 bit word. This is required in order
to fix a bug in GFS2, but I think it should be a generic function
in case of future users.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Reviewed-by: Christoph Lameter <cl@linux.com>
Reviewed-by: Willy Tarreau <w@1wt.eu>
include/linux/bitops.h

index 6182913..c05a29c 100644 (file)
@@ -112,6 +112,25 @@ static inline unsigned fls_long(unsigned long l)
        return fls64(l);
 }
 
+/**
+ * __ffs64 - find first set bit in a 64 bit word
+ * @word: The 64 bit word
+ *
+ * On 64 bit arches this is a synomyn for __ffs
+ * The result is not defined if no bits are set, so check that @word
+ * is non-zero before calling this.
+ */
+static inline unsigned long __ffs64(u64 word)
+{
+#if BITS_PER_LONG == 32
+       if (((u32)word) == 0UL)
+               return __ffs((u32)(word >> 32)) + 32;
+#elif BITS_PER_LONG != 64
+#error BITS_PER_LONG not 32 or 64
+#endif
+       return __ffs((unsigned long)word);
+}
+
 #ifdef __KERNEL__
 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT