From: Rusty Russell <rusty@rustcorp.com.au>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>, Mike Travis <travis@sgi.com>
Subject: [PATCH 5/6] bitmap: find_last_bit()
Date: Mon, 1 Dec 2008 18:48:31 +1030 [thread overview]
Message-ID: <200812011848.31552.rusty@rustcorp.com.au> (raw)
Impact: New API
As the name suggests. For the moment everyone uses the generic one.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
include/linux/bitops.h | 13 ++++++++++++-
lib/Kconfig | 4 ++++
lib/Makefile | 1 +
lib/find_next_bit.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+), 1 deletion(-)
diff -r 22df8a8dec81 include/linux/bitops.h
--- a/include/linux/bitops.h Sat Oct 18 04:46:13 2008 +1100
+++ b/include/linux/bitops.h Tue Oct 21 17:06:35 2008 +1100
@@ -134,8 +134,19 @@ extern unsigned long find_first_bit(cons
*/
extern unsigned long find_first_zero_bit(const unsigned long *addr,
unsigned long size);
+#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
-#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
+#ifdef CONFIG_GENERIC_FIND_LAST_BIT
+/**
+ * find_last_bit - find the last set bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit number of the first set bit, or size.
+ */
+extern unsigned long find_last_bit(const unsigned long *addr,
+ unsigned long size);
+#endif /* CONFIG_GENERIC_FIND_LAST_BIT */
#ifdef CONFIG_GENERIC_FIND_NEXT_BIT
diff -r 22df8a8dec81 lib/Kconfig
--- a/lib/Kconfig Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/Kconfig Tue Oct 21 17:06:35 2008 +1100
@@ -12,6 +12,10 @@ config GENERIC_FIND_FIRST_BIT
config GENERIC_FIND_NEXT_BIT
bool
+
+config GENERIC_FIND_LAST_BIT
+ bool
+ default y
config CRC_CCITT
tristate "CRC-CCITT functions"
diff -r 22df8a8dec81 lib/Makefile
--- a/lib/Makefile Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/Makefile Tue Oct 21 17:06:35 2008 +1100
@@ -37,6 +37,7 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) +=
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
+lib-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_next_bit.o
obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
obj-$(CONFIG_PLIST) += plist.o
diff -r 22df8a8dec81 lib/find_next_bit.c
--- a/lib/find_next_bit.c Sat Oct 18 04:46:13 2008 +1100
+++ b/lib/find_next_bit.c Tue Oct 21 17:06:35 2008 +1100
@@ -159,6 +159,37 @@ EXPORT_SYMBOL(find_first_zero_bit);
EXPORT_SYMBOL(find_first_zero_bit);
#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
+#ifdef CONFIG_GENERIC_FIND_LAST_BIT
+unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
+{
+ unsigned long words;
+ unsigned long tmp;
+
+ /* Start at final word. */
+ words = size / BITS_PER_LONG;
+
+ /* Partial final word? */
+ if (size & (BITS_PER_LONG-1)) {
+ tmp = (addr[words] & (~0UL >> (BITS_PER_LONG
+ - (size & (BITS_PER_LONG-1)))));
+ if (tmp)
+ goto found;
+ }
+
+ while (words) {
+ tmp = addr[--words];
+ if (tmp) {
+found:
+ return words * BITS_PER_LONG + __fls(tmp);
+ }
+ }
+
+ /* Not found */
+ return size;
+}
+EXPORT_SYMBOL(find_last_bit);
+#endif /* CONFIG_GENERIC_FIND_LAST_BIT */
+
#ifdef __BIG_ENDIAN
/* include/linux/byteorder does not support "unsigned long" type */
next reply other threads:[~2008-12-01 8:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-01 8:18 Rusty Russell [this message]
2009-02-16 12:58 ` [PATCH] bitmap: Cleanup find_last_bit Benny Halevy
2009-02-16 23:10 ` Rusty Russell
2009-02-17 4:44 ` Benny Halevy
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=200812011848.31552.rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=travis@sgi.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