From: Stephen Hemminger <shemminger@osdl.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] fls in asm for i386
Date: Fri, 2 Dec 2005 16:22:40 -0800 [thread overview]
Message-ID: <20051202162240.746c436e@localhost.localdomain> (raw)
There is a single instruction on i386 to find largest set bit;
so it makes sense to use it (like we use bfs for ffs()).
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- orig/include/asm-i386/bitops.h
+++ new/include/asm-i386/bitops.h
@@ -367,12 +367,6 @@ static inline unsigned long ffz(unsigned
return word;
}
-/*
- * fls: find last bit set.
- */
-
-#define fls(x) generic_fls(x)
-
#ifdef __KERNEL__
/*
@@ -414,6 +408,23 @@ static inline int ffs(int x)
}
/**
+ * fls - find last bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs.
+ */
+static inline int fls(int x)
+{
+ int r;
+
+ __asm__("bsrl %1,%0\n\t"
+ "jnz 1f\n\t"
+ "movl $-1,%0\n"
+ "1:" : "=r" (r) : "rm" (x));
+ return r+1;
+}
+
+/**
* hweightN - returns the hamming weight of a N-bit word
* @x: the word to weigh
*
next reply other threads:[~2005-12-03 0:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-03 0:22 Stephen Hemminger [this message]
2005-12-03 0:24 ` [PATCH] fls in asm for x86_64 Stephen Hemminger
2005-12-03 1:44 ` Andi Kleen
2005-12-05 13:46 ` [PATCH] fls in asm for i386 Pádraig Brady
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=20051202162240.746c436e@localhost.localdomain \
--to=shemminger@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.