diff options
Diffstat (limited to 'arch/arm/include/asm/bitops.h')
-rw-r--r-- | arch/arm/include/asm/bitops.h | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/arch/arm/include/asm/bitops.h b/arch/arm/include/asm/bitops.h index 2750d9b486..b02c454d04 100644 --- a/arch/arm/include/asm/bitops.h +++ b/arch/arm/include/asm/bitops.h | |||
@@ -15,6 +15,8 @@ | |||
15 | #ifndef __ASM_ARM_BITOPS_H | 15 | #ifndef __ASM_ARM_BITOPS_H |
16 | #define __ASM_ARM_BITOPS_H | 16 | #define __ASM_ARM_BITOPS_H |
17 | 17 | ||
18 | #include <asm-generic/bitops/__ffs.h> | ||
19 | |||
18 | #ifdef __KERNEL__ | 20 | #ifdef __KERNEL__ |
19 | 21 | ||
20 | #include <asm/proc-armv/system.h> | 22 | #include <asm/proc-armv/system.h> |
@@ -108,50 +110,34 @@ static inline int __ilog2(unsigned int x) | |||
108 | return generic_fls(x) - 1; | 110 | return generic_fls(x) - 1; |
109 | } | 111 | } |
110 | 112 | ||
111 | /* | 113 | #define ffz(x) __ffs(~(x)) |
112 | * ffz = Find First Zero in word. Undefined if no zero exists, | ||
113 | * so code should check against ~0UL first.. | ||
114 | */ | ||
115 | static inline unsigned long ffz(unsigned long word) | ||
116 | { | ||
117 | int k; | ||
118 | |||
119 | word = ~word; | ||
120 | k = 31; | ||
121 | if (word & 0x0000ffff) { k -= 16; word <<= 16; } | ||
122 | if (word & 0x00ff0000) { k -= 8; word <<= 8; } | ||
123 | if (word & 0x0f000000) { k -= 4; word <<= 4; } | ||
124 | if (word & 0x30000000) { k -= 2; word <<= 2; } | ||
125 | if (word & 0x40000000) { k -= 1; } | ||
126 | return k; | ||
127 | } | ||
128 | 114 | ||
129 | static inline int find_next_zero_bit(void *addr, int size, int offset) | 115 | static inline int find_next_zero_bit(void *addr, int size, int offset) |
130 | { | 116 | { |
131 | unsigned long *p = ((unsigned long *)addr) + (offset >> 5); | 117 | unsigned long *p = ((unsigned long *)addr) + (offset / BITS_PER_LONG); |
132 | unsigned long result = offset & ~31UL; | 118 | unsigned long result = offset & ~(BITS_PER_LONG - 1); |
133 | unsigned long tmp; | 119 | unsigned long tmp; |
134 | 120 | ||
135 | if (offset >= size) | 121 | if (offset >= size) |
136 | return size; | 122 | return size; |
137 | size -= result; | 123 | size -= result; |
138 | offset &= 31UL; | 124 | offset &= (BITS_PER_LONG - 1); |
139 | if (offset) { | 125 | if (offset) { |
140 | tmp = *(p++); | 126 | tmp = *(p++); |
141 | tmp |= ~0UL >> (32-offset); | 127 | tmp |= ~0UL >> (BITS_PER_LONG - offset); |
142 | if (size < 32) | 128 | if (size < BITS_PER_LONG) |
143 | goto found_first; | 129 | goto found_first; |
144 | if (~tmp) | 130 | if (~tmp) |
145 | goto found_middle; | 131 | goto found_middle; |
146 | size -= 32; | 132 | size -= BITS_PER_LONG; |
147 | result += 32; | 133 | result += BITS_PER_LONG; |
148 | } | 134 | } |
149 | while (size & ~31UL) { | 135 | while (size & ~(BITS_PER_LONG - 1)) { |
150 | tmp = *(p++); | 136 | tmp = *(p++); |
151 | if (~tmp) | 137 | if (~tmp) |
152 | goto found_middle; | 138 | goto found_middle; |
153 | result += 32; | 139 | result += BITS_PER_LONG; |
154 | size -= 32; | 140 | size -= BITS_PER_LONG; |
155 | } | 141 | } |
156 | if (!size) | 142 | if (!size) |
157 | return result; | 143 | return result; |
@@ -191,7 +177,6 @@ found_middle: | |||
191 | #endif /* __KERNEL__ */ | 177 | #endif /* __KERNEL__ */ |
192 | 178 | ||
193 | #include <asm-generic/bitops/__fls.h> | 179 | #include <asm-generic/bitops/__fls.h> |
194 | #include <asm-generic/bitops/__ffs.h> | ||
195 | #include <asm-generic/bitops/fls.h> | 180 | #include <asm-generic/bitops/fls.h> |
196 | #include <asm-generic/bitops/fls64.h> | 181 | #include <asm-generic/bitops/fls64.h> |
197 | 182 | ||