Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: jason.wessel@windriver.com (Jason Wessel)
Subject: [ltt-dev] [PATCH 2/4] add a definition for fls() for ARM, taken from the linux kernel
Date: Tue, 22 Feb 2011 15:48:32 -0600	[thread overview]
Message-ID: <1298411314-25405-3-git-send-email-jason.wessel@windriver.com> (raw)
In-Reply-To: <1298411314-25405-2-git-send-email-jason.wessel@windriver.com>

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





  reply	other threads:[~2011-02-22 21:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-22 21:48 [ltt-dev] [PATCH 0/4] Embedded UST support for ARM and busybox Jason Wessel
2011-02-22 21:48 ` [ltt-dev] [PATCH 1/4] add ARM specific support for UST Jason Wessel
2011-02-22 21:48   ` Jason Wessel [this message]
2011-02-22 21:48     ` [ltt-dev] [PATCH 3/4] usttrace: Use /bin/sh instead of /bin/bash for busybox compatibility Jason Wessel
2011-02-22 21:48       ` [ltt-dev] [PATCH 4/4] usttrace: use short signal names " Jason Wessel
2011-02-22 22:21     ` [ltt-dev] [PATCH 2/4] add a definition for fls() for ARM, taken from the linux kernel Mathieu Desnoyers
2011-02-22 22:31       ` Mathieu Desnoyers
2011-02-22 22:24 ` [ltt-dev] [PATCH 0/4] Embedded UST support for ARM and busybox Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1298411314-25405-3-git-send-email-jason.wessel@windriver.com \
    --to=jason.wessel@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox