summaryrefslogtreecommitdiffstats
path: root/arch/ppc/include
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-05-02 10:09:22 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-05-02 10:09:22 +0200
commit272704fcf364f17e80d5a445f2c42e65d2e4d23a (patch)
tree9840fb6815d99f658d53db43f4c199ae9032e777 /arch/ppc/include
parentd5d96ca6c31f503d1286773a40620e0fdd1e5da4 (diff)
downloadbarebox-272704fcf364f17e80d5a445f2c42e65d2e4d23a.tar.gz
barebox-272704fcf364f17e80d5a445f2c42e65d2e4d23a.tar.xz
ppc: Add fls, fls64, __ilog2_u64 and ffs64 bitops
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/ppc/include')
-rw-r--r--arch/ppc/include/asm/bitops.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/arch/ppc/include/asm/bitops.h b/arch/ppc/include/asm/bitops.h
index 8048232325..3b31d5420e 100644
--- a/arch/ppc/include/asm/bitops.h
+++ b/arch/ppc/include/asm/bitops.h
@@ -166,6 +166,48 @@ extern __inline__ int ffz(unsigned int x)
return __ilog2(x & -x);
}
+/*
+ * fls: find last (most-significant) bit set.
+ * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
+ */
+static inline int fls(unsigned int x)
+{
+ int lz;
+
+ asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
+ return 32 - lz;
+}
+
+/*
+ * fls64 - find last set bit in a 64-bit word
+ * @x: the word to search
+ *
+ * This is defined in a similar way as the libc and compiler builtin
+ * ffsll, but returns the position of the most significant set bit.
+ *
+ * fls64(value) returns 0 if value is 0 or the position of the last
+ * set bit if value is nonzero. The last (most significant) bit is
+ * at position 64.
+ */
+
+static inline int fls64(__u64 x)
+{
+ __u32 h = x >> 32;
+ if (h)
+ return fls(h) + 32;
+ return fls(x);
+}
+
+static inline int __ilog2_u64(u64 n)
+{
+ return fls64(n) - 1;
+}
+
+static inline int ffs64(u64 x)
+{
+ return __ilog2_u64(x & -x) + 1ull;
+}
+
#ifdef __KERNEL__
/*