diff options
author | Akinobu Mita <mita@miraclelinux.com> | 2006-03-26 04:39:40 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-26 11:57:14 -0500 |
commit | 2d78d4beb64eb07d50665432867971c481192ebf (patch) | |
tree | d007f5721ba96abff820f76db77f11ae578722f8 | |
parent | d59288b75797fd982546aee7ba24a495dee128dd (diff) |
[PATCH] bitops: sparc64: use generic bitops
- remove __{,test_and_}{set,clear,change}_bit() and test_bit()
- remove ffz()
- remove __ffs()
- remove generic_fls()
- remove generic_fls64()
- remove sched_find_first_bit()
- remove ffs()
- unless defined(ULTRA_HAS_POPULATION_COUNT)
- remove generic_hweight{64,32,16,8}()
- remove find_{next,first}{,_zero}_bit()
- remove ext2_{set,clear,test,find_first_zero,find_next_zero}_bit()
- remove minix_{test,set,test_and_clear,test,find_first_zero}_bit()
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | arch/sparc64/Kconfig | 8 | ||||
-rw-r--r-- | arch/sparc64/kernel/sparc64_ksyms.c | 5 | ||||
-rw-r--r-- | arch/sparc64/lib/Makefile | 2 | ||||
-rw-r--r-- | arch/sparc64/lib/find_bit.c | 127 | ||||
-rw-r--r-- | include/asm-sparc64/bitops.h | 219 |
5 files changed, 22 insertions, 339 deletions
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig index 267afddf63cf..d1e2fc566486 100644 --- a/arch/sparc64/Kconfig +++ b/arch/sparc64/Kconfig | |||
@@ -162,6 +162,14 @@ config RWSEM_XCHGADD_ALGORITHM | |||
162 | bool | 162 | bool |
163 | default y | 163 | default y |
164 | 164 | ||
165 | config GENERIC_FIND_NEXT_BIT | ||
166 | bool | ||
167 | default y | ||
168 | |||
169 | config GENERIC_HWEIGHT | ||
170 | bool | ||
171 | default y if !ULTRA_HAS_POPULATION_COUNT | ||
172 | |||
165 | config GENERIC_CALIBRATE_DELAY | 173 | config GENERIC_CALIBRATE_DELAY |
166 | bool | 174 | bool |
167 | default y | 175 | default y |
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c index 9914a17651b4..c7fbbcfce824 100644 --- a/arch/sparc64/kernel/sparc64_ksyms.c +++ b/arch/sparc64/kernel/sparc64_ksyms.c | |||
@@ -175,11 +175,6 @@ EXPORT_SYMBOL(set_bit); | |||
175 | EXPORT_SYMBOL(clear_bit); | 175 | EXPORT_SYMBOL(clear_bit); |
176 | EXPORT_SYMBOL(change_bit); | 176 | EXPORT_SYMBOL(change_bit); |
177 | 177 | ||
178 | /* Bit searching */ | ||
179 | EXPORT_SYMBOL(find_next_bit); | ||
180 | EXPORT_SYMBOL(find_next_zero_bit); | ||
181 | EXPORT_SYMBOL(find_next_zero_le_bit); | ||
182 | |||
183 | EXPORT_SYMBOL(ivector_table); | 178 | EXPORT_SYMBOL(ivector_table); |
184 | EXPORT_SYMBOL(enable_irq); | 179 | EXPORT_SYMBOL(enable_irq); |
185 | EXPORT_SYMBOL(disable_irq); | 180 | EXPORT_SYMBOL(disable_irq); |
diff --git a/arch/sparc64/lib/Makefile b/arch/sparc64/lib/Makefile index 8812ded19f01..4a725d8985f1 100644 --- a/arch/sparc64/lib/Makefile +++ b/arch/sparc64/lib/Makefile | |||
@@ -14,6 +14,6 @@ lib-y := PeeCeeI.o copy_page.o clear_page.o strlen.o strncmp.o \ | |||
14 | NGmemcpy.o NGcopy_from_user.o NGcopy_to_user.o NGpatch.o \ | 14 | NGmemcpy.o NGcopy_from_user.o NGcopy_to_user.o NGpatch.o \ |
15 | NGpage.o NGbzero.o \ | 15 | NGpage.o NGbzero.o \ |
16 | copy_in_user.o user_fixup.o memmove.o \ | 16 | copy_in_user.o user_fixup.o memmove.o \ |
17 | mcount.o ipcsum.o rwsem.o xor.o find_bit.o delay.o | 17 | mcount.o ipcsum.o rwsem.o xor.o delay.o |
18 | 18 | ||
19 | obj-y += iomap.o | 19 | obj-y += iomap.o |
diff --git a/arch/sparc64/lib/find_bit.c b/arch/sparc64/lib/find_bit.c deleted file mode 100644 index 6059557067b4..000000000000 --- a/arch/sparc64/lib/find_bit.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | #include <linux/bitops.h> | ||
2 | |||
3 | /** | ||
4 | * find_next_bit - find the next set bit in a memory region | ||
5 | * @addr: The address to base the search on | ||
6 | * @offset: The bitnumber to start searching at | ||
7 | * @size: The maximum size to search | ||
8 | */ | ||
9 | unsigned long find_next_bit(const unsigned long *addr, unsigned long size, | ||
10 | unsigned long offset) | ||
11 | { | ||
12 | const unsigned long *p = addr + (offset >> 6); | ||
13 | unsigned long result = offset & ~63UL; | ||
14 | unsigned long tmp; | ||
15 | |||
16 | if (offset >= size) | ||
17 | return size; | ||
18 | size -= result; | ||
19 | offset &= 63UL; | ||
20 | if (offset) { | ||
21 | tmp = *(p++); | ||
22 | tmp &= (~0UL << offset); | ||
23 | if (size < 64) | ||
24 | goto found_first; | ||
25 | if (tmp) | ||
26 | goto found_middle; | ||
27 | size -= 64; | ||
28 | result += 64; | ||
29 | } | ||
30 | while (size & ~63UL) { | ||
31 | if ((tmp = *(p++))) | ||
32 | goto found_middle; | ||
33 | result += 64; | ||
34 | size -= 64; | ||
35 | } | ||
36 | if (!size) | ||
37 | return result; | ||
38 | tmp = *p; | ||
39 | |||
40 | found_first: | ||
41 | tmp &= (~0UL >> (64 - size)); | ||
42 | if (tmp == 0UL) /* Are any bits set? */ | ||
43 | return result + size; /* Nope. */ | ||
44 | found_middle: | ||
45 | return result + __ffs(tmp); | ||
46 | } | ||
47 | |||
48 | /* find_next_zero_bit() finds the first zero bit in a bit string of length | ||
49 | * 'size' bits, starting the search at bit 'offset'. This is largely based | ||
50 | * on Linus's ALPHA routines, which are pretty portable BTW. | ||
51 | */ | ||
52 | |||
53 | unsigned long find_next_zero_bit(const unsigned long *addr, | ||
54 | unsigned long size, unsigned long offset) | ||
55 | { | ||
56 | const unsigned long *p = addr + (offset >> 6); | ||
57 | unsigned long result = offset & ~63UL; | ||
58 | unsigned long tmp; | ||
59 | |||
60 | if (offset >= size) | ||
61 | return size; | ||
62 | size -= result; | ||
63 | offset &= 63UL; | ||
64 | if (offset) { | ||
65 | tmp = *(p++); | ||
66 | tmp |= ~0UL >> (64-offset); | ||
67 | if (size < 64) | ||
68 | goto found_first; | ||
69 | if (~tmp) | ||
70 | goto found_middle; | ||
71 | size -= 64; | ||
72 | result += 64; | ||
73 | } | ||
74 | while (size & ~63UL) { | ||
75 | if (~(tmp = *(p++))) | ||
76 | goto found_middle; | ||
77 | result += 64; | ||
78 | size -= 64; | ||
79 | } | ||
80 | if (!size) | ||
81 | return result; | ||
82 | tmp = *p; | ||
83 | |||
84 | found_first: | ||
85 | tmp |= ~0UL << size; | ||
86 | if (tmp == ~0UL) /* Are any bits zero? */ | ||
87 | return result + size; /* Nope. */ | ||
88 | found_middle: | ||
89 | return result + ffz(tmp); | ||
90 | } | ||
91 | |||
92 | unsigned long find_next_zero_le_bit(unsigned long *addr, unsigned long size, unsigned long offset) | ||
93 | { | ||
94 | unsigned long *p = addr + (offset >> 6); | ||
95 | unsigned long result = offset & ~63UL; | ||
96 | unsigned long tmp; | ||
97 | |||
98 | if (offset >= size) | ||
99 | return size; | ||
100 | size -= result; | ||
101 | offset &= 63UL; | ||
102 | if(offset) { | ||
103 | tmp = __swab64p(p++); | ||
104 | tmp |= (~0UL >> (64-offset)); | ||
105 | if(size < 64) | ||
106 | goto found_first; | ||
107 | if(~tmp) | ||
108 | goto found_middle; | ||
109 | size -= 64; | ||
110 | result += 64; | ||
111 | } | ||
112 | while(size & ~63) { | ||
113 | if(~(tmp = __swab64p(p++))) | ||
114 | goto found_middle; | ||
115 | result += 64; | ||
116 | size -= 64; | ||
117 | } | ||
118 | if(!size) | ||
119 | return result; | ||
120 | tmp = __swab64p(p); | ||
121 | found_first: | ||
122 | tmp |= (~0UL << size); | ||
123 | if (tmp == ~0UL) /* Are any bits zero? */ | ||
124 | return result + size; /* Nope. */ | ||
125 | found_middle: | ||
126 | return result + ffz(tmp); | ||
127 | } | ||
diff --git a/include/asm-sparc64/bitops.h b/include/asm-sparc64/bitops.h index 2361f8736498..71944b0f09de 100644 --- a/include/asm-sparc64/bitops.h +++ b/include/asm-sparc64/bitops.h | |||
@@ -18,58 +18,7 @@ extern void set_bit(unsigned long nr, volatile unsigned long *addr); | |||
18 | extern void clear_bit(unsigned long nr, volatile unsigned long *addr); | 18 | extern void clear_bit(unsigned long nr, volatile unsigned long *addr); |
19 | extern void change_bit(unsigned long nr, volatile unsigned long *addr); | 19 | extern void change_bit(unsigned long nr, volatile unsigned long *addr); |
20 | 20 | ||
21 | /* "non-atomic" versions... */ | 21 | #include <asm-generic/bitops/non-atomic.h> |
22 | |||
23 | static inline void __set_bit(int nr, volatile unsigned long *addr) | ||
24 | { | ||
25 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
26 | |||
27 | *m |= (1UL << (nr & 63)); | ||
28 | } | ||
29 | |||
30 | static inline void __clear_bit(int nr, volatile unsigned long *addr) | ||
31 | { | ||
32 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
33 | |||
34 | *m &= ~(1UL << (nr & 63)); | ||
35 | } | ||
36 | |||
37 | static inline void __change_bit(int nr, volatile unsigned long *addr) | ||
38 | { | ||
39 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
40 | |||
41 | *m ^= (1UL << (nr & 63)); | ||
42 | } | ||
43 | |||
44 | static inline int __test_and_set_bit(int nr, volatile unsigned long *addr) | ||
45 | { | ||
46 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
47 | unsigned long old = *m; | ||
48 | unsigned long mask = (1UL << (nr & 63)); | ||
49 | |||
50 | *m = (old | mask); | ||
51 | return ((old & mask) != 0); | ||
52 | } | ||
53 | |||
54 | static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr) | ||
55 | { | ||
56 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
57 | unsigned long old = *m; | ||
58 | unsigned long mask = (1UL << (nr & 63)); | ||
59 | |||
60 | *m = (old & ~mask); | ||
61 | return ((old & mask) != 0); | ||
62 | } | ||
63 | |||
64 | static inline int __test_and_change_bit(int nr, volatile unsigned long *addr) | ||
65 | { | ||
66 | unsigned long *m = ((unsigned long *)addr) + (nr >> 6); | ||
67 | unsigned long old = *m; | ||
68 | unsigned long mask = (1UL << (nr & 63)); | ||
69 | |||
70 | *m = (old ^ mask); | ||
71 | return ((old & mask) != 0); | ||
72 | } | ||
73 | 22 | ||
74 | #ifdef CONFIG_SMP | 23 | #ifdef CONFIG_SMP |
75 | #define smp_mb__before_clear_bit() membar_storeload_loadload() | 24 | #define smp_mb__before_clear_bit() membar_storeload_loadload() |
@@ -79,78 +28,15 @@ static inline int __test_and_change_bit(int nr, volatile unsigned long *addr) | |||
79 | #define smp_mb__after_clear_bit() barrier() | 28 | #define smp_mb__after_clear_bit() barrier() |
80 | #endif | 29 | #endif |
81 | 30 | ||
82 | static inline int test_bit(int nr, __const__ volatile unsigned long *addr) | 31 | #include <asm-generic/bitops/ffz.h> |
83 | { | 32 | #include <asm-generic/bitops/__ffs.h> |
84 | return (1UL & (addr[nr >> 6] >> (nr & 63))) != 0UL; | 33 | #include <asm-generic/bitops/fls.h> |
85 | } | 34 | #include <asm-generic/bitops/fls64.h> |
86 | |||
87 | /* The easy/cheese version for now. */ | ||
88 | static inline unsigned long ffz(unsigned long word) | ||
89 | { | ||
90 | unsigned long result; | ||
91 | |||
92 | result = 0; | ||
93 | while(word & 1) { | ||
94 | result++; | ||
95 | word >>= 1; | ||
96 | } | ||
97 | return result; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * __ffs - find first bit in word. | ||
102 | * @word: The word to search | ||
103 | * | ||
104 | * Undefined if no bit exists, so code should check against 0 first. | ||
105 | */ | ||
106 | static inline unsigned long __ffs(unsigned long word) | ||
107 | { | ||
108 | unsigned long result = 0; | ||
109 | |||
110 | while (!(word & 1UL)) { | ||
111 | result++; | ||
112 | word >>= 1; | ||
113 | } | ||
114 | return result; | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * fls: find last bit set. | ||
119 | */ | ||
120 | |||
121 | #define fls(x) generic_fls(x) | ||
122 | #define fls64(x) generic_fls64(x) | ||
123 | 35 | ||
124 | #ifdef __KERNEL__ | 36 | #ifdef __KERNEL__ |
125 | 37 | ||
126 | /* | 38 | #include <asm-generic/bitops/sched.h> |
127 | * Every architecture must define this function. It's the fastest | 39 | #include <asm-generic/bitops/ffs.h> |
128 | * way of searching a 140-bit bitmap where the first 100 bits are | ||
129 | * unlikely to be set. It's guaranteed that at least one of the 140 | ||
130 | * bits is cleared. | ||
131 | */ | ||
132 | static inline int sched_find_first_bit(unsigned long *b) | ||
133 | { | ||
134 | if (unlikely(b[0])) | ||
135 | return __ffs(b[0]); | ||
136 | if (unlikely(((unsigned int)b[1]))) | ||
137 | return __ffs(b[1]) + 64; | ||
138 | if (b[1] >> 32) | ||
139 | return __ffs(b[1] >> 32) + 96; | ||
140 | return __ffs(b[2]) + 128; | ||
141 | } | ||
142 | |||
143 | /* | ||
144 | * ffs: find first bit set. This is defined the same way as | ||
145 | * the libc and compiler builtin ffs routines, therefore | ||
146 | * differs in spirit from the above ffz (man ffs). | ||
147 | */ | ||
148 | static inline int ffs(int x) | ||
149 | { | ||
150 | if (!x) | ||
151 | return 0; | ||
152 | return __ffs((unsigned long)x) + 1; | ||
153 | } | ||
154 | 40 | ||
155 | /* | 41 | /* |
156 | * hweightN: returns the hamming weight (i.e. the number | 42 | * hweightN: returns the hamming weight (i.e. the number |
@@ -193,102 +79,23 @@ static inline unsigned int hweight8(unsigned int w) | |||
193 | 79 | ||
194 | #else | 80 | #else |
195 | 81 | ||
196 | #define hweight64(x) generic_hweight64(x) | 82 | #include <asm-generic/bitops/hweight.h> |
197 | #define hweight32(x) generic_hweight32(x) | ||
198 | #define hweight16(x) generic_hweight16(x) | ||
199 | #define hweight8(x) generic_hweight8(x) | ||
200 | 83 | ||
201 | #endif | 84 | #endif |
202 | #endif /* __KERNEL__ */ | 85 | #endif /* __KERNEL__ */ |
203 | 86 | ||
204 | /** | 87 | #include <asm-generic/bitops/find.h> |
205 | * find_next_bit - find the next set bit in a memory region | ||
206 | * @addr: The address to base the search on | ||
207 | * @offset: The bitnumber to start searching at | ||
208 | * @size: The maximum size to search | ||
209 | */ | ||
210 | extern unsigned long find_next_bit(const unsigned long *, unsigned long, | ||
211 | unsigned long); | ||
212 | |||
213 | /** | ||
214 | * find_first_bit - find the first set bit in a memory region | ||
215 | * @addr: The address to start the search at | ||
216 | * @size: The maximum size to search | ||
217 | * | ||
218 | * Returns the bit-number of the first set bit, not the number of the byte | ||
219 | * containing a bit. | ||
220 | */ | ||
221 | #define find_first_bit(addr, size) \ | ||
222 | find_next_bit((addr), (size), 0) | ||
223 | |||
224 | /* find_next_zero_bit() finds the first zero bit in a bit string of length | ||
225 | * 'size' bits, starting the search at bit 'offset'. This is largely based | ||
226 | * on Linus's ALPHA routines, which are pretty portable BTW. | ||
227 | */ | ||
228 | |||
229 | extern unsigned long find_next_zero_bit(const unsigned long *, | ||
230 | unsigned long, unsigned long); | ||
231 | |||
232 | #define find_first_zero_bit(addr, size) \ | ||
233 | find_next_zero_bit((addr), (size), 0) | ||
234 | |||
235 | #define test_and_set_le_bit(nr,addr) \ | ||
236 | test_and_set_bit((nr) ^ 0x38, (addr)) | ||
237 | #define test_and_clear_le_bit(nr,addr) \ | ||
238 | test_and_clear_bit((nr) ^ 0x38, (addr)) | ||
239 | |||
240 | static inline int test_le_bit(int nr, __const__ unsigned long * addr) | ||
241 | { | ||
242 | int mask; | ||
243 | __const__ unsigned char *ADDR = (__const__ unsigned char *) addr; | ||
244 | |||
245 | ADDR += nr >> 3; | ||
246 | mask = 1 << (nr & 0x07); | ||
247 | return ((mask & *ADDR) != 0); | ||
248 | } | ||
249 | |||
250 | #define find_first_zero_le_bit(addr, size) \ | ||
251 | find_next_zero_le_bit((addr), (size), 0) | ||
252 | |||
253 | extern unsigned long find_next_zero_le_bit(unsigned long *, unsigned long, unsigned long); | ||
254 | 88 | ||
255 | #ifdef __KERNEL__ | 89 | #ifdef __KERNEL__ |
256 | 90 | ||
257 | #define __set_le_bit(nr, addr) \ | 91 | #include <asm-generic/bitops/ext2-non-atomic.h> |
258 | __set_bit((nr) ^ 0x38, (addr)) | ||
259 | #define __clear_le_bit(nr, addr) \ | ||
260 | __clear_bit((nr) ^ 0x38, (addr)) | ||
261 | #define __test_and_clear_le_bit(nr, addr) \ | ||
262 | __test_and_clear_bit((nr) ^ 0x38, (addr)) | ||
263 | #define __test_and_set_le_bit(nr, addr) \ | ||
264 | __test_and_set_bit((nr) ^ 0x38, (addr)) | ||
265 | 92 | ||
266 | #define ext2_set_bit(nr,addr) \ | ||
267 | __test_and_set_le_bit((nr),(unsigned long *)(addr)) | ||
268 | #define ext2_set_bit_atomic(lock,nr,addr) \ | 93 | #define ext2_set_bit_atomic(lock,nr,addr) \ |
269 | test_and_set_le_bit((nr),(unsigned long *)(addr)) | 94 | test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr)) |
270 | #define ext2_clear_bit(nr,addr) \ | ||
271 | __test_and_clear_le_bit((nr),(unsigned long *)(addr)) | ||
272 | #define ext2_clear_bit_atomic(lock,nr,addr) \ | 95 | #define ext2_clear_bit_atomic(lock,nr,addr) \ |
273 | test_and_clear_le_bit((nr),(unsigned long *)(addr)) | 96 | test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr)) |
274 | #define ext2_test_bit(nr,addr) \ | ||
275 | test_le_bit((nr),(unsigned long *)(addr)) | ||
276 | #define ext2_find_first_zero_bit(addr, size) \ | ||
277 | find_first_zero_le_bit((unsigned long *)(addr), (size)) | ||
278 | #define ext2_find_next_zero_bit(addr, size, off) \ | ||
279 | find_next_zero_le_bit((unsigned long *)(addr), (size), (off)) | ||
280 | 97 | ||
281 | /* Bitmap functions for the minix filesystem. */ | 98 | #include <asm-generic/bitops/minix.h> |
282 | #define minix_test_and_set_bit(nr,addr) \ | ||
283 | __test_and_set_bit((nr),(unsigned long *)(addr)) | ||
284 | #define minix_set_bit(nr,addr) \ | ||
285 | __set_bit((nr),(unsigned long *)(addr)) | ||
286 | #define minix_test_and_clear_bit(nr,addr) \ | ||
287 | __test_and_clear_bit((nr),(unsigned long *)(addr)) | ||
288 | #define minix_test_bit(nr,addr) \ | ||
289 | test_bit((nr),(unsigned long *)(addr)) | ||
290 | #define minix_find_first_zero_bit(addr,size) \ | ||
291 | find_first_zero_bit((unsigned long *)(addr),(size)) | ||
292 | 99 | ||
293 | #endif /* __KERNEL__ */ | 100 | #endif /* __KERNEL__ */ |
294 | 101 | ||