aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlexander van Heukelum <heukelum@mailshack.com>2008-04-01 05:46:19 -0400
committerIngo Molnar <mingo@elte.hu>2008-04-26 13:21:16 -0400
commit77b9bd9c49442407804c37bcc82021a35277f83c (patch)
tree251900d95c6c9c5371542d5dda7d89cb31cd0801 /lib
parentd57594c203b1e7b54373080a797f0cbfa4aade68 (diff)
x86: generic versions of find_first_(zero_)bit, convert i386
Generic versions of __find_first_bit and __find_first_zero_bit are introduced as simplified versions of __find_next_bit and __find_next_zero_bit. Their compilation and use are guarded by a new config variable GENERIC_FIND_FIRST_BIT. The generic versions of find_first_bit and find_first_zero_bit are implemented in terms of the newly introduced __find_first_bit and __find_first_zero_bit. This patch does not remove the i386-specific implementation, but it does switch i386 to use the generic functions by setting GENERIC_FIND_FIRST_BIT=y for X86_32. Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile1
-rw-r--r--lib/find_next_bit.c58
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Makefile b/lib/Makefile
index bf8000fc7d48..2d7001b7f5a4 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o
29obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o 29obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
30lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o 30lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
31lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o 31lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
32lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
32lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o 33lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
33obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o 34obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
34obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o 35obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c
index ce94c4c92d10..d3f5784807b4 100644
--- a/lib/find_next_bit.c
+++ b/lib/find_next_bit.c
@@ -16,6 +16,7 @@
16 16
17#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) 17#define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
18 18
19#ifdef CONFIG_GENERIC_FIND_NEXT_BIT
19/* 20/*
20 * Find the next set bit in a memory region. 21 * Find the next set bit in a memory region.
21 */ 22 */
@@ -102,6 +103,63 @@ found_middle:
102 return result + ffz(tmp); 103 return result + ffz(tmp);
103} 104}
104EXPORT_SYMBOL(__find_next_zero_bit); 105EXPORT_SYMBOL(__find_next_zero_bit);
106#endif /* CONFIG_GENERIC_FIND_NEXT_BIT */
107
108#ifdef CONFIG_GENERIC_FIND_FIRST_BIT
109/*
110 * Find the first set bit in a memory region.
111 */
112unsigned long __find_first_bit(const unsigned long *addr,
113 unsigned long size)
114{
115 const unsigned long *p = addr;
116 unsigned long result = 0;
117 unsigned long tmp;
118
119 while (size & ~(BITS_PER_LONG-1)) {
120 if ((tmp = *(p++)))
121 goto found;
122 result += BITS_PER_LONG;
123 size -= BITS_PER_LONG;
124 }
125 if (!size)
126 return result;
127
128 tmp = (*p) & (~0UL >> (BITS_PER_LONG - size));
129 if (tmp == 0UL) /* Are any bits set? */
130 return result + size; /* Nope. */
131found:
132 return result + __ffs(tmp);
133}
134EXPORT_SYMBOL(__find_first_bit);
135
136/*
137 * Find the first cleared bit in a memory region.
138 */
139unsigned long __find_first_zero_bit(const unsigned long *addr,
140 unsigned long size)
141{
142 const unsigned long *p = addr;
143 unsigned long result = 0;
144 unsigned long tmp;
145
146 while (size & ~(BITS_PER_LONG-1)) {
147 if (~(tmp = *(p++)))
148 goto found;
149 result += BITS_PER_LONG;
150 size -= BITS_PER_LONG;
151 }
152 if (!size)
153 return result;
154
155 tmp = (*p) | (~0UL << size);
156 if (tmp == ~0UL) /* Are any bits zero? */
157 return result + size; /* Nope. */
158found:
159 return result + ffz(tmp);
160}
161EXPORT_SYMBOL(__find_first_zero_bit);
162#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
105 163
106#ifdef __BIG_ENDIAN 164#ifdef __BIG_ENDIAN
107 165