aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2005-11-01 01:28:10 -0500
committerPaul Mackerras <paulus@samba.org>2005-11-01 05:49:02 -0500
commita0e60b2033b30a6bb8479629001cf98e58e4079a (patch)
tree6386eeca340a25c4ae1876f2f9663f94628c8cc3 /arch/powerpc
parent031ef0a72aa8f7ee63ae9f307c1bcff92b3ccc2c (diff)
[PATCH] powerpc: Merge bitops.h
Here's a revised version. This re-introduces the set_bits() function from ppc64, which I removed because I thought it was unused (it exists on no other arch). In fact it is used in the powermac interrupt code (but not on pSeries). - We use LARXL/STCXL macros to generate the right (32 or 64 bit) instructions, similar to LDL/STL from ppc_asm.h, used in fpu.S - ppc32 previously used a full "sync" barrier at the end of test_and_*_bit(), whereas ppc64 used an "isync". The merged version uses "isync", since I believe that's sufficient. - The ppc64 versions of then minix_*() bitmap functions have changed semantics. Previously on ppc64, these functions were big-endian (that is bit 0 was the LSB in the first 64-bit, big-endian word). On ppc32 (and x86, for that matter, they were little-endian. As far as I can tell, the big-endian usage was simply wrong - I guess no-one ever tried to use minixfs on ppc64. - On ppc32 find_next_bit() and find_next_zero_bit() are no longer inline (they were already out-of-line on ppc64). - For ppc64, sched_find_first_bit() has moved from mmu_context.h to the merged bitops. What it was doing in mmu_context.h in the first place, I have no idea. - The fls() function is now implemented using the cntlzw instruction on ppc64, instead of generic_fls(), as it already was on ppc32. - For ARCH=ppc, this patch requires adding arch/powerpc/lib to the arch/ppc/Makefile. This in turn requires some changes to arch/powerpc/lib/Makefile which didn't correctly handle ARCH=ppc. Built and running on G5. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/kernel/ppc_ksyms.c9
-rw-r--r--arch/powerpc/lib/Makefile9
-rw-r--r--arch/powerpc/lib/bitops.c150
3 files changed, 155 insertions, 13 deletions
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 8bc540337ba0..47d6f7e2ea9f 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -81,15 +81,6 @@ EXPORT_SYMBOL(_prep_type);
81EXPORT_SYMBOL(ucSystemType); 81EXPORT_SYMBOL(ucSystemType);
82#endif 82#endif
83 83
84#if !defined(__INLINE_BITOPS)
85EXPORT_SYMBOL(set_bit);
86EXPORT_SYMBOL(clear_bit);
87EXPORT_SYMBOL(change_bit);
88EXPORT_SYMBOL(test_and_set_bit);
89EXPORT_SYMBOL(test_and_clear_bit);
90EXPORT_SYMBOL(test_and_change_bit);
91#endif /* __INLINE_BITOPS */
92
93EXPORT_SYMBOL(strcpy); 84EXPORT_SYMBOL(strcpy);
94EXPORT_SYMBOL(strncpy); 85EXPORT_SYMBOL(strncpy);
95EXPORT_SYMBOL(strcat); 86EXPORT_SYMBOL(strcat);
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index dfb33915ad61..34f5c2e074c9 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -3,13 +3,14 @@
3# 3#
4 4
5ifeq ($(CONFIG_PPC_MERGE),y) 5ifeq ($(CONFIG_PPC_MERGE),y)
6obj-y := string.o 6obj-y := string.o strcase.o
7obj-$(CONFIG_PPC32) += div64.o copy_32.o checksum_32.o
7endif 8endif
8 9
9obj-y += strcase.o 10obj-y += bitops.o
10obj-$(CONFIG_PPC32) += div64.o copy_32.o checksum_32.o
11obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \ 11obj-$(CONFIG_PPC64) += checksum_64.o copypage_64.o copyuser_64.o \
12 memcpy_64.o usercopy_64.o mem_64.o string.o 12 memcpy_64.o usercopy_64.o mem_64.o string.o \
13 strcase.o
13obj-$(CONFIG_PPC_ISERIES) += e2a.o 14obj-$(CONFIG_PPC_ISERIES) += e2a.o
14obj-$(CONFIG_XMON) += sstep.o 15obj-$(CONFIG_XMON) += sstep.o
15 16
diff --git a/arch/powerpc/lib/bitops.c b/arch/powerpc/lib/bitops.c
new file mode 100644
index 000000000000..b67ce3004ebf
--- /dev/null
+++ b/arch/powerpc/lib/bitops.c
@@ -0,0 +1,150 @@
1#include <linux/types.h>
2#include <linux/module.h>
3#include <asm/byteorder.h>
4#include <asm/bitops.h>
5
6/**
7 * find_next_bit - find the next set bit in a memory region
8 * @addr: The address to base the search on
9 * @offset: The bitnumber to start searching at
10 * @size: The maximum size to search
11 */
12unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
13 unsigned long offset)
14{
15 const unsigned long *p = addr + BITOP_WORD(offset);
16 unsigned long result = offset & ~(BITS_PER_LONG-1);
17 unsigned long tmp;
18
19 if (offset >= size)
20 return size;
21 size -= result;
22 offset %= BITS_PER_LONG;
23 if (offset) {
24 tmp = *(p++);
25 tmp &= (~0UL << offset);
26 if (size < BITS_PER_LONG)
27 goto found_first;
28 if (tmp)
29 goto found_middle;
30 size -= BITS_PER_LONG;
31 result += BITS_PER_LONG;
32 }
33 while (size & ~(BITS_PER_LONG-1)) {
34 if ((tmp = *(p++)))
35 goto found_middle;
36 result += BITS_PER_LONG;
37 size -= BITS_PER_LONG;
38 }
39 if (!size)
40 return result;
41 tmp = *p;
42
43found_first:
44 tmp &= (~0UL >> (64 - size));
45 if (tmp == 0UL) /* Are any bits set? */
46 return result + size; /* Nope. */
47found_middle:
48 return result + __ffs(tmp);
49}
50EXPORT_SYMBOL(find_next_bit);
51
52/*
53 * This implementation of find_{first,next}_zero_bit was stolen from
54 * Linus' asm-alpha/bitops.h.
55 */
56unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
57 unsigned long offset)
58{
59 const unsigned long *p = addr + BITOP_WORD(offset);
60 unsigned long result = offset & ~(BITS_PER_LONG-1);
61 unsigned long tmp;
62
63 if (offset >= size)
64 return size;
65 size -= result;
66 offset %= BITS_PER_LONG;
67 if (offset) {
68 tmp = *(p++);
69 tmp |= ~0UL >> (BITS_PER_LONG - offset);
70 if (size < BITS_PER_LONG)
71 goto found_first;
72 if (~tmp)
73 goto found_middle;
74 size -= BITS_PER_LONG;
75 result += BITS_PER_LONG;
76 }
77 while (size & ~(BITS_PER_LONG-1)) {
78 if (~(tmp = *(p++)))
79 goto found_middle;
80 result += BITS_PER_LONG;
81 size -= BITS_PER_LONG;
82 }
83 if (!size)
84 return result;
85 tmp = *p;
86
87found_first:
88 tmp |= ~0UL << size;
89 if (tmp == ~0UL) /* Are any bits zero? */
90 return result + size; /* Nope. */
91found_middle:
92 return result + ffz(tmp);
93}
94EXPORT_SYMBOL(find_next_zero_bit);
95
96static inline unsigned int ext2_ilog2(unsigned int x)
97{
98 int lz;
99
100 asm("cntlzw %0,%1": "=r"(lz):"r"(x));
101 return 31 - lz;
102}
103
104static inline unsigned int ext2_ffz(unsigned int x)
105{
106 u32 rc;
107 if ((x = ~x) == 0)
108 return 32;
109 rc = ext2_ilog2(x & -x);
110 return rc;
111}
112
113unsigned long find_next_zero_le_bit(const unsigned long *addr,
114 unsigned long size, unsigned long offset)
115{
116 const unsigned int *p = ((const unsigned int *)addr) + (offset >> 5);
117 unsigned int result = offset & ~31;
118 unsigned int tmp;
119
120 if (offset >= size)
121 return size;
122 size -= result;
123 offset &= 31;
124 if (offset) {
125 tmp = cpu_to_le32p(p++);
126 tmp |= ~0U >> (32 - offset); /* bug or feature ? */
127 if (size < 32)
128 goto found_first;
129 if (tmp != ~0)
130 goto found_middle;
131 size -= 32;
132 result += 32;
133 }
134 while (size >= 32) {
135 if ((tmp = cpu_to_le32p(p++)) != ~0)
136 goto found_middle;
137 result += 32;
138 size -= 32;
139 }
140 if (!size)
141 return result;
142 tmp = cpu_to_le32p(p);
143found_first:
144 tmp |= ~0 << size;
145 if (tmp == ~0) /* Are any bits zero? */
146 return result + size; /* Nope. */
147found_middle:
148 return result + ext2_ffz(tmp);
149}
150EXPORT_SYMBOL(find_next_zero_le_bit);