[ltt-dev] [PATCH 2/4] add a definition for fls() for ARM, taken from the linux kernel

Jason Wessel jason.wessel at windriver.com
Tue Feb 22 16:48:32 EST 2011


Insert the definition from the linux kernel along with the copyright
attribution for the fls() operation for ARM.

Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
---
 include/ust/processor.h |   53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/include/ust/processor.h b/include/ust/processor.h
index 01aa290..70e244b 100644
--- a/include/ust/processor.h
+++ b/include/ust/processor.h
@@ -454,6 +454,59 @@ static __inline__ int fls(unsigned int x)
 struct registers {
 };
 
+/* constant_fls() and fls() were take directly from the linux kernel
+ * sources in 2.6.37 from the file arch/arm/include/asm/bitops.h
+ * which had the following copyright.
+ *
+ * Copyright 1995, Russell King.
+ * Various bits and pieces copyrights include:
+ *  Linus Torvalds (test_bit).
+ * Big endian support: Copyright 2001, Nicolas Pitre
+ *  reworked by rmk.
+ */
+
+static inline int constant_fls(int x)
+{
+	int r = 32;
+
+	if (!x)
+		return 0;
+	if (!(x & 0xffff0000u)) {
+		x <<= 16;
+		r -= 16;
+	}
+	if (!(x & 0xff000000u)) {
+		x <<= 8;
+		r -= 8;
+	}
+	if (!(x & 0xf0000000u)) {
+		x <<= 4;
+		r -= 4;
+	}
+	if (!(x & 0xc0000000u)) {
+		x <<= 2;
+		r -= 2;
+	}
+	if (!(x & 0x80000000u)) {
+		x <<= 1;
+		r -= 1;
+	}
+	return r;
+}
+
+static __inline__ int fls(unsigned int x)
+{
+        int ret;
+
+        if (__builtin_constant_p(x))
+               return constant_fls(x);
+
+        asm("clz\t%0, %1" : "=r" (ret) : "r" (x) : "cc");
+        ret = 32 - ret;
+        return ret;
+}
+/*------- end of source taken from linux kernel headers -------*/
+
 #define ARCH_COPY_ADDR(dst) "ldr "dst", =2b\n\t" \
 "b 55f\n\t" \
 ".ltorg\n\t" \
-- 
1.6.6.2





More information about the lttng-dev mailing list