diff options
author | Richard Henderson <rth@twiddle.net> | 2007-05-29 19:01:35 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-30 13:07:54 -0400 |
commit | 74fd1b687fbeba566ceb59cc1fdbc7a64c5e0c0b (patch) | |
tree | efc6ffd2080ec94bef934758f40c220d710adf28 | |
parent | f54496f55a729078e9eef90bf9e0783857a27db1 (diff) |
alpha: cleanup in bitops.h
Remove 2 functions private to the alpha implemetation,
in favor of similar functions in <linux/log2.h>.
Provide a more efficient version of the fls64 function
for pre-ev67 alphas.
Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/alpha/kernel/pci_iommu.c | 3 | ||||
-rw-r--r-- | arch/alpha/kernel/setup.c | 3 | ||||
-rw-r--r-- | arch/alpha/lib/Makefile | 3 | ||||
-rw-r--r-- | arch/alpha/lib/fls.c | 38 | ||||
-rw-r--r-- | include/asm-alpha/bitops.h | 50 |
5 files changed, 73 insertions, 24 deletions
diff --git a/arch/alpha/kernel/pci_iommu.c b/arch/alpha/kernel/pci_iommu.c index 6e7d1fe6e935..28c84e55feb9 100644 --- a/arch/alpha/kernel/pci_iommu.c +++ b/arch/alpha/kernel/pci_iommu.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/pci.h> | 7 | #include <linux/pci.h> |
8 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
9 | #include <linux/bootmem.h> | 9 | #include <linux/bootmem.h> |
10 | #include <linux/log2.h> | ||
10 | 11 | ||
11 | #include <asm/io.h> | 12 | #include <asm/io.h> |
12 | #include <asm/hwrpb.h> | 13 | #include <asm/hwrpb.h> |
@@ -53,7 +54,7 @@ size_for_memory(unsigned long max) | |||
53 | { | 54 | { |
54 | unsigned long mem = max_low_pfn << PAGE_SHIFT; | 55 | unsigned long mem = max_low_pfn << PAGE_SHIFT; |
55 | if (mem < max) | 56 | if (mem < max) |
56 | max = 1UL << ceil_log2(mem); | 57 | max = roundup_pow_of_two(mem); |
57 | return max; | 58 | return max; |
58 | } | 59 | } |
59 | 60 | ||
diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c index 915f26345c45..bd5e68cd61e8 100644 --- a/arch/alpha/kernel/setup.c +++ b/arch/alpha/kernel/setup.c | |||
@@ -43,6 +43,7 @@ | |||
43 | #include <linux/notifier.h> | 43 | #include <linux/notifier.h> |
44 | #include <asm/setup.h> | 44 | #include <asm/setup.h> |
45 | #include <asm/io.h> | 45 | #include <asm/io.h> |
46 | #include <linux/log2.h> | ||
46 | 47 | ||
47 | extern struct atomic_notifier_head panic_notifier_list; | 48 | extern struct atomic_notifier_head panic_notifier_list; |
48 | static int alpha_panic_event(struct notifier_block *, unsigned long, void *); | 49 | static int alpha_panic_event(struct notifier_block *, unsigned long, void *); |
@@ -1303,7 +1304,7 @@ external_cache_probe(int minsize, int width) | |||
1303 | long size = minsize, maxsize = MAX_BCACHE_SIZE * 2; | 1304 | long size = minsize, maxsize = MAX_BCACHE_SIZE * 2; |
1304 | 1305 | ||
1305 | if (maxsize > (max_low_pfn + 1) << PAGE_SHIFT) | 1306 | if (maxsize > (max_low_pfn + 1) << PAGE_SHIFT) |
1306 | maxsize = 1 << (floor_log2(max_low_pfn + 1) + PAGE_SHIFT); | 1307 | maxsize = 1 << (ilog2(max_low_pfn + 1) + PAGE_SHIFT); |
1307 | 1308 | ||
1308 | /* Get the first block cached. */ | 1309 | /* Get the first block cached. */ |
1309 | read_mem_block(__va(0), stride, size); | 1310 | read_mem_block(__va(0), stride, size); |
diff --git a/arch/alpha/lib/Makefile b/arch/alpha/lib/Makefile index ea098f3b629f..266f78e13076 100644 --- a/arch/alpha/lib/Makefile +++ b/arch/alpha/lib/Makefile | |||
@@ -37,7 +37,8 @@ lib-y = __divqu.o __remqu.o __divlu.o __remlu.o \ | |||
37 | $(ev6-y)clear_page.o \ | 37 | $(ev6-y)clear_page.o \ |
38 | $(ev6-y)copy_page.o \ | 38 | $(ev6-y)copy_page.o \ |
39 | fpreg.o \ | 39 | fpreg.o \ |
40 | callback_srm.o srm_puts.o srm_printk.o | 40 | callback_srm.o srm_puts.o srm_printk.o \ |
41 | fls.o | ||
41 | 42 | ||
42 | lib-$(CONFIG_SMP) += dec_and_lock.o | 43 | lib-$(CONFIG_SMP) += dec_and_lock.o |
43 | 44 | ||
diff --git a/arch/alpha/lib/fls.c b/arch/alpha/lib/fls.c new file mode 100644 index 000000000000..7ad84ea0acf8 --- /dev/null +++ b/arch/alpha/lib/fls.c | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * arch/alpha/lib/fls.c | ||
3 | */ | ||
4 | |||
5 | #include <linux/module.h> | ||
6 | #include <asm/bitops.h> | ||
7 | |||
8 | /* This is fls(x)-1, except zero is held to zero. This allows most | ||
9 | efficent input into extbl, plus it allows easy handling of fls(0)=0. */ | ||
10 | |||
11 | const unsigned char __flsm1_tab[256] = | ||
12 | { | ||
13 | 0, | ||
14 | 0, | ||
15 | 1, 1, | ||
16 | 2, 2, 2, 2, | ||
17 | 3, 3, 3, 3, 3, 3, 3, 3, | ||
18 | 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, | ||
19 | |||
20 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | ||
21 | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, | ||
22 | |||
23 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
24 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
25 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
26 | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
27 | |||
28 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
29 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
30 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
31 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
32 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
33 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
34 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
35 | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, | ||
36 | }; | ||
37 | |||
38 | EXPORT_SYMBOL(__flsm1_tab); | ||
diff --git a/include/asm-alpha/bitops.h b/include/asm-alpha/bitops.h index 4b6ef7f21b93..3a0cbeb03fa1 100644 --- a/include/asm-alpha/bitops.h +++ b/include/asm-alpha/bitops.h | |||
@@ -313,32 +313,29 @@ static inline int ffs(int word) | |||
313 | * fls: find last bit set. | 313 | * fls: find last bit set. |
314 | */ | 314 | */ |
315 | #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67) | 315 | #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67) |
316 | static inline int fls(int word) | 316 | static inline int fls64(unsigned long word) |
317 | { | 317 | { |
318 | return 64 - __kernel_ctlz(word & 0xffffffff); | 318 | return 64 - __kernel_ctlz(word); |
319 | } | 319 | } |
320 | #else | 320 | #else |
321 | #include <asm-generic/bitops/fls.h> | 321 | extern const unsigned char __flsm1_tab[256]; |
322 | #endif | ||
323 | #include <asm-generic/bitops/fls64.h> | ||
324 | 322 | ||
325 | /* Compute powers of two for the given integer. */ | 323 | static inline int fls64(unsigned long x) |
326 | static inline long floor_log2(unsigned long word) | ||
327 | { | 324 | { |
328 | #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67) | 325 | unsigned long t, a, r; |
329 | return 63 - __kernel_ctlz(word); | 326 | |
330 | #else | 327 | t = __kernel_cmpbge (x, 0x0101010101010101); |
331 | long bit; | 328 | a = __flsm1_tab[t]; |
332 | for (bit = -1; word ; bit++) | 329 | t = __kernel_extbl (x, a); |
333 | word >>= 1; | 330 | r = a*8 + __flsm1_tab[t] + (x != 0); |
334 | return bit; | 331 | |
335 | #endif | 332 | return r; |
336 | } | 333 | } |
334 | #endif | ||
337 | 335 | ||
338 | static inline long ceil_log2(unsigned long word) | 336 | static inline int fls(int x) |
339 | { | 337 | { |
340 | long bit = floor_log2(word); | 338 | return fls64((unsigned int) x); |
341 | return bit + (word > (1UL << bit)); | ||
342 | } | 339 | } |
343 | 340 | ||
344 | /* | 341 | /* |
@@ -353,9 +350,20 @@ static inline unsigned long hweight64(unsigned long w) | |||
353 | return __kernel_ctpop(w); | 350 | return __kernel_ctpop(w); |
354 | } | 351 | } |
355 | 352 | ||
356 | #define hweight32(x) (unsigned int) hweight64((x) & 0xfffffffful) | 353 | static inline unsigned int hweight32(unsigned int w) |
357 | #define hweight16(x) (unsigned int) hweight64((x) & 0xfffful) | 354 | { |
358 | #define hweight8(x) (unsigned int) hweight64((x) & 0xfful) | 355 | return hweight64(w); |
356 | } | ||
357 | |||
358 | static inline unsigned int hweight16(unsigned int w) | ||
359 | { | ||
360 | return hweight64(w & 0xffff); | ||
361 | } | ||
362 | |||
363 | static inline unsigned int hweight8(unsigned int w) | ||
364 | { | ||
365 | return hweight64(w & 0xff); | ||
366 | } | ||
359 | #else | 367 | #else |
360 | #include <asm-generic/bitops/hweight.h> | 368 | #include <asm-generic/bitops/hweight.h> |
361 | #endif | 369 | #endif |