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)
28 1: ldrb r3, [r0, r2, lsr #3]
29 eors r3, r3, #0xff @ invert bits
30 bne .L_found @ any now set - found zero bit
31 add r2, r2, #8 @ next bit pointer
32 2: cmp r2, r1 @ any more?
34 3: mov r0, r1 @ no free bits
36 ENDPROC(_find_first_zero_bit_le)
39 * Purpose : Find next 'zero' bit
40 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
42 ENTRY(_find_next_zero_bit_le)
46 beq 1b @ If new byte, goto old routine
47 ldrb r3, [r0, r2, lsr #3]
48 eor r3, r3, #0xff @ now looking for a 1 bit
49 movs r3, r3, lsr ip @ shift off unused bits
51 orr r2, r2, #7 @ if zero, then no bits here
52 add r2, r2, #1 @ align bit pointer
53 b 2b @ loop for next bit
54 ENDPROC(_find_next_zero_bit_le)
57 * Purpose : Find a 'one' bit
58 * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
60 ENTRY(_find_first_bit_le)
64 1: ldrb r3, [r0, r2, lsr #3]
66 bne .L_found @ any now set - found zero bit
67 add r2, r2, #8 @ next bit pointer
68 2: cmp r2, r1 @ any more?
70 3: mov r0, r1 @ no free bits
72 ENDPROC(_find_first_bit_le)
75 * Purpose : Find next 'one' bit
76 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
78 ENTRY(_find_next_bit_le)
82 beq 1b @ If new byte, goto old routine
83 ldrb r3, [r0, r2, lsr #3]
84 movs r3, r3, lsr ip @ shift off unused bits
86 orr r2, r2, #7 @ if zero, then no bits here
87 add r2, r2, #1 @ align bit pointer
88 b 2b @ loop for next bit
89 ENDPROC(_find_next_bit_le)
93 ENTRY(_find_first_zero_bit_be)
97 1: eor r3, r2, #0x18 @ big endian byte ordering
98 ldrb r3, [r0, r3, lsr #3]
99 eors r3, r3, #0xff @ invert bits
100 bne .L_found @ any now set - found zero bit
101 add r2, r2, #8 @ next bit pointer
102 2: cmp r2, r1 @ any more?
104 3: mov r0, r1 @ no free bits
106 ENDPROC(_find_first_zero_bit_be)
108 ENTRY(_find_next_zero_bit_be)
112 beq 1b @ If new byte, goto old routine
113 eor r3, r2, #0x18 @ big endian byte ordering
114 ldrb r3, [r0, r3, lsr #3]
115 eor r3, r3, #0xff @ now looking for a 1 bit
116 movs r3, r3, lsr ip @ shift off unused bits
118 orr r2, r2, #7 @ if zero, then no bits here
119 add r2, r2, #1 @ align bit pointer
120 b 2b @ loop for next bit
121 ENDPROC(_find_next_zero_bit_be)
123 ENTRY(_find_first_bit_be)
127 1: eor r3, r2, #0x18 @ big endian byte ordering
128 ldrb r3, [r0, r3, lsr #3]
130 bne .L_found @ any now set - found zero bit
131 add r2, r2, #8 @ next bit pointer
132 2: cmp r2, r1 @ any more?
134 3: mov r0, r1 @ no free bits
136 ENDPROC(_find_first_bit_be)
138 ENTRY(_find_next_bit_be)
142 beq 1b @ If new byte, goto old routine
143 eor r3, r2, #0x18 @ big endian byte ordering
144 ldrb r3, [r0, r3, lsr #3]
145 movs r3, r3, lsr ip @ shift off unused bits
147 orr r2, r2, #7 @ if zero, then no bits here
148 add r2, r2, #1 @ align bit pointer
149 b 2b @ loop for next bit
150 ENDPROC(_find_next_bit_be)
155 * One or more bits in the LSB of r3 are assumed to be set.
158 #if __LINUX_ARM_ARCH__ >= 5