summaryrefslogtreecommitdiff
path: root/include/linux/bitops.h
diff options
context:
space:
mode:
authorFabio Estevam <fabio.estevam@freescale.com>2015-11-05 12:43:38 -0200
committerTom Rini <trini@konsulko.com>2015-11-05 10:52:34 -0500
commitde4d2e9e7ce0f9fda76f07bafafefa10f01a9605 (patch)
treef467257112f0f644afb4b58c776612ad1dea1f8a /include/linux/bitops.h
parent61a177767cfcaa231b9e16d1d462a12ad472d777 (diff)
downloadu-boot-de4d2e9e7ce0f9fda76f07bafafefa10f01a9605.tar.gz
u-boot-de4d2e9e7ce0f9fda76f07bafafefa10f01a9605.tar.bz2
u-boot-de4d2e9e7ce0f9fda76f07bafafefa10f01a9605.zip
bitops: Add fls_long and __ffs64
Add fls_long and __ffs64 support to align with the kernel bitops implementation. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Diffstat (limited to 'include/linux/bitops.h')
-rw-r--r--include/linux/bitops.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 7b4011f0a3..1b2e4915a0 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -2,6 +2,7 @@
#define _LINUX_BITOPS_H
#include <asm/types.h>
+#include <linux/compiler.h>
#define BIT(nr) (1UL << (nr))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
@@ -139,6 +140,32 @@ static inline unsigned int generic_hweight8(unsigned int w)
# define fls generic_fls
#endif
+static inline unsigned fls_long(unsigned long l)
+{
+ if (sizeof(l) == 4)
+ return fls(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);
+}
+
/**
* __set_bit - Set a bit in memory
* @nr: the bit to set