2 * linux/arch/arm/lib/findbit.S
4 * Copyright (C) 1995-2000 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * 16th March 2001 - John Ripley <jripley@sonicblue.com>
11 * Fixed so that "size" is an exclusive not an inclusive quantity.
12 * All users of these functions expect exclusive sizes, and may
13 * also call with zero size.
16 #include <linux/linkage.h>
17 #include <asm/assembler.h>
18 #include <asm/export.h>
22 * Purpose : Find a 'zero' bit
23 * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
25 ENTRY(_find_first_zero_bit_le)
30 ARM( ldrb r3, [r0, r2, lsr #3] )
31 THUMB( lsr r3, r2, #3 )
32 THUMB( ldrb r3, [r0, r3] )
33 eors r3, r3, #0xff @ invert bits
34 bne .L_found @ any now set - found zero bit
35 add r2, r2, #8 @ next bit pointer
36 2: cmp r2, r1 @ any more?
38 3: mov r0, r1 @ no free bits
40 ENDPROC(_find_first_zero_bit_le)
41 EXPORT_SYMBOL(_find_first_zero_bit_le)
44 * Purpose : Find next 'zero' bit
45 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
47 ENTRY(_find_next_zero_bit_le)
51 beq 1b @ If new byte, goto old routine
52 ARM( ldrb r3, [r0, r2, lsr #3] )
53 THUMB( lsr r3, r2, #3 )
54 THUMB( ldrb r3, [r0, r3] )
55 eor r3, r3, #0xff @ now looking for a 1 bit
56 movs r3, r3, lsr ip @ shift off unused bits
58 orr r2, r2, #7 @ if zero, then no bits here
59 add r2, r2, #1 @ align bit pointer
60 b 2b @ loop for next bit
61 ENDPROC(_find_next_zero_bit_le)
62 EXPORT_SYMBOL(_find_next_zero_bit_le)
65 * Purpose : Find a 'one' bit
66 * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
68 ENTRY(_find_first_bit_le)
73 ARM( ldrb r3, [r0, r2, lsr #3] )
74 THUMB( lsr r3, r2, #3 )
75 THUMB( ldrb r3, [r0, r3] )
77 bne .L_found @ any now set - found zero bit
78 add r2, r2, #8 @ next bit pointer
79 2: cmp r2, r1 @ any more?
81 3: mov r0, r1 @ no free bits
83 ENDPROC(_find_first_bit_le)
84 EXPORT_SYMBOL(_find_first_bit_le)
87 * Purpose : Find next 'one' bit
88 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
90 ENTRY(_find_next_bit_le)
94 beq 1b @ If new byte, goto old routine
95 ARM( ldrb r3, [r0, r2, lsr #3] )
96 THUMB( lsr r3, r2, #3 )
97 THUMB( ldrb r3, [r0, r3] )
98 movs r3, r3, lsr ip @ shift off unused bits
100 orr r2, r2, #7 @ if zero, then no bits here
101 add r2, r2, #1 @ align bit pointer
102 b 2b @ loop for next bit
103 ENDPROC(_find_next_bit_le)
104 EXPORT_SYMBOL(_find_next_bit_le)
108 ENTRY(_find_first_zero_bit_be)
112 1: eor r3, r2, #0x18 @ big endian byte ordering
113 ARM( ldrb r3, [r0, r3, lsr #3] )
115 THUMB( ldrb r3, [r0, r3] )
116 eors r3, r3, #0xff @ invert bits
117 bne .L_found @ any now set - found zero bit
118 add r2, r2, #8 @ next bit pointer
119 2: cmp r2, r1 @ any more?
121 3: mov r0, r1 @ no free bits
123 ENDPROC(_find_first_zero_bit_be)
124 EXPORT_SYMBOL(_find_first_zero_bit_be)
126 ENTRY(_find_next_zero_bit_be)
130 beq 1b @ If new byte, goto old routine
131 eor r3, r2, #0x18 @ big endian byte ordering
132 ARM( ldrb r3, [r0, r3, lsr #3] )
134 THUMB( ldrb r3, [r0, r3] )
135 eor r3, r3, #0xff @ now looking for a 1 bit
136 movs r3, r3, lsr ip @ shift off unused bits
138 orr r2, r2, #7 @ if zero, then no bits here
139 add r2, r2, #1 @ align bit pointer
140 b 2b @ loop for next bit
141 ENDPROC(_find_next_zero_bit_be)
142 EXPORT_SYMBOL(_find_next_zero_bit_be)
144 ENTRY(_find_first_bit_be)
148 1: eor r3, r2, #0x18 @ big endian byte ordering
149 ARM( ldrb r3, [r0, r3, lsr #3] )
151 THUMB( ldrb r3, [r0, r3] )
153 bne .L_found @ any now set - found zero bit
154 add r2, r2, #8 @ next bit pointer
155 2: cmp r2, r1 @ any more?
157 3: mov r0, r1 @ no free bits
159 ENDPROC(_find_first_bit_be)
160 EXPORT_SYMBOL(_find_first_bit_be)
162 ENTRY(_find_next_bit_be)
166 beq 1b @ If new byte, goto old routine
167 eor r3, r2, #0x18 @ big endian byte ordering
168 ARM( ldrb r3, [r0, r3, lsr #3] )
170 THUMB( ldrb r3, [r0, r3] )
171 movs r3, r3, lsr ip @ shift off unused bits
173 orr r2, r2, #7 @ if zero, then no bits here
174 add r2, r2, #1 @ align bit pointer
175 b 2b @ loop for next bit
176 ENDPROC(_find_next_bit_be)
177 EXPORT_SYMBOL(_find_next_bit_be)
182 * One or more bits in the LSB of r3 are assumed to be set.
185 #if __LINUX_ARM_ARCH__ >= 5
202 cmp r1, r0 @ Clamp to maxbit