1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/lib/findbit.S
5 * Copyright (C) 1995-2000 Russell King
7 * 16th March 2001 - John Ripley <jripley@sonicblue.com>
8 * Fixed so that "size" is an exclusive not an inclusive quantity.
9 * All users of these functions expect exclusive sizes, and may
10 * also call with zero size.
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
18 * Purpose : Find a 'zero' bit
19 * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
21 ENTRY(_find_first_zero_bit_le)
26 ARM( ldrb r3, [r0, r2, lsr #3] )
27 THUMB( lsr r3, r2, #3 )
28 THUMB( ldrb r3, [r0, r3] )
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 ARM( ldrb r3, [r0, r2, lsr #3] )
48 THUMB( lsr r3, r2, #3 )
49 THUMB( ldrb r3, [r0, r3] )
50 eor r3, r3, #0xff @ now looking for a 1 bit
51 movs r3, r3, lsr ip @ shift off unused bits
53 orr r2, r2, #7 @ if zero, then no bits here
54 add r2, r2, #1 @ align bit pointer
55 b 2b @ loop for next bit
56 ENDPROC(_find_next_zero_bit_le)
59 * Purpose : Find a 'one' bit
60 * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
62 ENTRY(_find_first_bit_le)
67 ARM( ldrb r3, [r0, r2, lsr #3] )
68 THUMB( lsr r3, r2, #3 )
69 THUMB( ldrb r3, [r0, r3] )
71 bne .L_found @ any now set - found zero bit
72 add r2, r2, #8 @ next bit pointer
73 2: cmp r2, r1 @ any more?
75 3: mov r0, r1 @ no free bits
77 ENDPROC(_find_first_bit_le)
80 * Purpose : Find next 'one' bit
81 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
83 ENTRY(_find_next_bit_le)
87 beq 1b @ If new byte, goto old routine
88 ARM( ldrb r3, [r0, r2, lsr #3] )
89 THUMB( lsr r3, r2, #3 )
90 THUMB( ldrb r3, [r0, r3] )
91 movs r3, r3, lsr ip @ shift off unused bits
93 orr r2, r2, #7 @ if zero, then no bits here
94 add r2, r2, #1 @ align bit pointer
95 b 2b @ loop for next bit
96 ENDPROC(_find_next_bit_le)
100 ENTRY(_find_first_zero_bit_be)
104 1: eor r3, r2, #0x18 @ big endian byte ordering
105 ARM( ldrb r3, [r0, r3, lsr #3] )
107 THUMB( ldrb r3, [r0, r3] )
108 eors r3, r3, #0xff @ invert bits
109 bne .L_found @ any now set - found zero bit
110 add r2, r2, #8 @ next bit pointer
111 2: cmp r2, r1 @ any more?
113 3: mov r0, r1 @ no free bits
115 ENDPROC(_find_first_zero_bit_be)
117 ENTRY(_find_next_zero_bit_be)
121 beq 1b @ If new byte, goto old routine
122 eor r3, r2, #0x18 @ big endian byte ordering
123 ARM( ldrb r3, [r0, r3, lsr #3] )
125 THUMB( ldrb r3, [r0, r3] )
126 eor r3, r3, #0xff @ now looking for a 1 bit
127 movs r3, r3, lsr ip @ shift off unused bits
129 orr r2, r2, #7 @ if zero, then no bits here
130 add r2, r2, #1 @ align bit pointer
131 b 2b @ loop for next bit
132 ENDPROC(_find_next_zero_bit_be)
134 ENTRY(_find_first_bit_be)
138 1: eor r3, r2, #0x18 @ big endian byte ordering
139 ARM( ldrb r3, [r0, r3, lsr #3] )
141 THUMB( ldrb r3, [r0, r3] )
143 bne .L_found @ any now set - found zero bit
144 add r2, r2, #8 @ next bit pointer
145 2: cmp r2, r1 @ any more?
147 3: mov r0, r1 @ no free bits
149 ENDPROC(_find_first_bit_be)
151 ENTRY(_find_next_bit_be)
155 beq 1b @ If new byte, goto old routine
156 eor r3, r2, #0x18 @ big endian byte ordering
157 ARM( ldrb r3, [r0, r3, lsr #3] )
159 THUMB( ldrb r3, [r0, r3] )
160 movs r3, r3, lsr ip @ shift off unused bits
162 orr r2, r2, #7 @ if zero, then no bits here
163 add r2, r2, #1 @ align bit pointer
164 b 2b @ loop for next bit
165 ENDPROC(_find_next_bit_be)
170 * One or more bits in the LSB of r3 are assumed to be set.
173 #if __LINUX_ARM_ARCH__ >= 5
190 cmp r1, r0 @ Clamp to maxbit