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>
21 * Purpose : Find a 'zero' bit
22 * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
24 ENTRY(_find_first_zero_bit_le)
29 ARM( ldrb r3, [r0, r2, lsr #3] )
30 THUMB( lsr r3, r2, #3 )
31 THUMB( ldrb r3, [r0, r3] )
32 eors r3, r3, #0xff @ invert bits
33 bne .L_found @ any now set - found zero bit
34 add r2, r2, #8 @ next bit pointer
35 2: cmp r2, r1 @ any more?
37 3: mov r0, r1 @ no free bits
39 ENDPROC(_find_first_zero_bit_le)
42 * Purpose : Find next 'zero' bit
43 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
45 ENTRY(_find_next_zero_bit_le)
49 beq 1b @ If new byte, goto old routine
50 ARM( ldrb r3, [r0, r2, lsr #3] )
51 THUMB( lsr r3, r2, #3 )
52 THUMB( ldrb r3, [r0, r3] )
53 eor r3, r3, #0xff @ now looking for a 1 bit
54 movs r3, r3, lsr ip @ shift off unused bits
56 orr r2, r2, #7 @ if zero, then no bits here
57 add r2, r2, #1 @ align bit pointer
58 b 2b @ loop for next bit
59 ENDPROC(_find_next_zero_bit_le)
62 * Purpose : Find a 'one' bit
63 * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
65 ENTRY(_find_first_bit_le)
70 ARM( ldrb r3, [r0, r2, lsr #3] )
71 THUMB( lsr r3, r2, #3 )
72 THUMB( ldrb r3, [r0, r3] )
74 bne .L_found @ any now set - found zero bit
75 add r2, r2, #8 @ next bit pointer
76 2: cmp r2, r1 @ any more?
78 3: mov r0, r1 @ no free bits
80 ENDPROC(_find_first_bit_le)
83 * Purpose : Find next 'one' bit
84 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
86 ENTRY(_find_next_bit_le)
90 beq 1b @ If new byte, goto old routine
91 ARM( ldrb r3, [r0, r2, lsr #3] )
92 THUMB( lsr r3, r2, #3 )
93 THUMB( ldrb r3, [r0, r3] )
94 movs r3, r3, lsr ip @ shift off unused bits
96 orr r2, r2, #7 @ if zero, then no bits here
97 add r2, r2, #1 @ align bit pointer
98 b 2b @ loop for next bit
99 ENDPROC(_find_next_bit_le)
103 ENTRY(_find_first_zero_bit_be)
107 1: eor r3, r2, #0x18 @ big endian byte ordering
108 ARM( ldrb r3, [r0, r3, lsr #3] )
110 THUMB( ldrb r3, [r0, r3] )
111 eors r3, r3, #0xff @ invert bits
112 bne .L_found @ any now set - found zero bit
113 add r2, r2, #8 @ next bit pointer
114 2: cmp r2, r1 @ any more?
116 3: mov r0, r1 @ no free bits
118 ENDPROC(_find_first_zero_bit_be)
120 ENTRY(_find_next_zero_bit_be)
124 beq 1b @ If new byte, goto old routine
125 eor r3, r2, #0x18 @ big endian byte ordering
126 ARM( ldrb r3, [r0, r3, lsr #3] )
128 THUMB( ldrb r3, [r0, r3] )
129 eor r3, r3, #0xff @ now looking for a 1 bit
130 movs r3, r3, lsr ip @ shift off unused bits
132 orr r2, r2, #7 @ if zero, then no bits here
133 add r2, r2, #1 @ align bit pointer
134 b 2b @ loop for next bit
135 ENDPROC(_find_next_zero_bit_be)
137 ENTRY(_find_first_bit_be)
141 1: eor r3, r2, #0x18 @ big endian byte ordering
142 ARM( ldrb r3, [r0, r3, lsr #3] )
144 THUMB( ldrb r3, [r0, r3] )
146 bne .L_found @ any now set - found zero bit
147 add r2, r2, #8 @ next bit pointer
148 2: cmp r2, r1 @ any more?
150 3: mov r0, r1 @ no free bits
152 ENDPROC(_find_first_bit_be)
154 ENTRY(_find_next_bit_be)
158 beq 1b @ If new byte, goto old routine
159 eor r3, r2, #0x18 @ big endian byte ordering
160 ARM( ldrb r3, [r0, r3, lsr #3] )
162 THUMB( ldrb r3, [r0, r3] )
163 movs r3, r3, lsr ip @ shift off unused bits
165 orr r2, r2, #7 @ if zero, then no bits here
166 add r2, r2, #1 @ align bit pointer
167 b 2b @ loop for next bit
168 ENDPROC(_find_next_bit_be)
173 * One or more bits in the LSB of r3 are assumed to be set.
176 #if __LINUX_ARM_ARCH__ >= 5