From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [ltt-dev] [UST PATCH] Generic fls()
Date: Sun, 19 Sep 2010 23:56:29 -0400 [thread overview]
Message-ID: <20100920035629.GA10716@Krystal> (raw)
Merge identical x86 32/64 fls() code, move ppc code closer to other fls and
implement an architecture-agnostic fls() fallback. This last function is a
rewrite from the Linux generic fls() function. The code ends up being quite
similar because this function is trivial.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
include/ust/processor.h | 80 ++++++++++++++++++++++++++++++++----------------
1 file changed, 54 insertions(+), 26 deletions(-)
Index: ust/include/ust/processor.h
===================================================================
--- ust.orig/include/ust/processor.h
+++ ust/include/ust/processor.h
@@ -27,6 +27,60 @@ extern volatile __thread long *ust_reg_s
#define ____cacheline_aligned __attribute__((aligned(CACHE_LINE_SIZE)))
+#if defined(__i386) || defined(__x86_64)
+
+static inline int fls(unsigned int x)
+{
+ int r;
+ asm("bsrl %1,%0\n\t"
+ "cmovzl %2,%0"
+ : "=&r" (r) : "rm" (x), "rm" (-1));
+ return r + 1;
+}
+
+#elif defined(__PPC__)
+
+static inline int fls(unsigned int x)
+{
+ int lz;
+
+ asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
+ return 32 - lz;
+}
+
+#else
+
+static inline int fls(unsigned 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;
+}
+
+#endif
+
#ifdef __i386
struct registers {
@@ -43,15 +97,6 @@ struct registers {
long esp;
};
-static inline int fls(int x)
-{
- int r;
- asm("bsrl %1,%0\n\t"
- "cmovzl %2,%0"
- : "=&r" (r) : "rm" (x), "rm" (-1));
- return r + 1;
-}
-
#ifdef CONFIG_UST_GDB_INTEGRATION
/* save_registers - saves most of the processor's registers so
@@ -241,15 +286,6 @@ struct registers {
unsigned long rsp;
};
-static inline int fls(int x)
-{
- int r;
- asm("bsrl %1,%0\n\t"
- "cmovzl %2,%0"
- : "=&r" (r) : "rm" (x), "rm" (-1));
- return r + 1;
-}
-
#ifdef CONFIG_UST_GDB_INTEGRATION
#define save_registers(regsptr) \
@@ -432,14 +468,6 @@ static inline int fls(int x)
struct registers {
};
-static __inline__ int fls(unsigned int x)
-{
- int lz;
-
- asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
- return 32 - lz;
-}
-
#define ARCH_COPY_ADDR(dst) \
"lis " dst ",2b at h\n\t" /* load high bytes */ \
"ori " dst "," dst ",2b at l\n\t" /* load low bytes */
--
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com
reply other threads:[~2010-09-20 3:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20100920035629.GA10716@Krystal \
--to=mathieu.desnoyers@efficios.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