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 .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
38 * Purpose : Find next 'zero' bit
39 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
41 ENTRY(_find_next_zero_bit_le)
45 beq 1b @ If new byte, goto old routine
46 ldrb r3, [r0, r2, lsr #3]
47 eor r3, r3, #0xff @ now looking for a 1 bit
48 movs r3, r3, lsr ip @ shift off unused bits
50 orr r2, r2, #7 @ if zero, then no bits here
51 add r2, r2, #1 @ align bit pointer
52 b 2b @ loop for next bit
55 * Purpose : Find a 'one' bit
56 * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
58 ENTRY(_find_first_bit_le)
62 1: ldrb r3, [r0, r2, lsr #3]
64 bne .found @ any now set - found zero bit
65 add r2, r2, #8 @ next bit pointer
66 2: cmp r2, r1 @ any more?
68 3: mov r0, r1 @ no free bits
72 * Purpose : Find next 'one' bit
73 * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
75 ENTRY(_find_next_bit_le)
79 beq 1b @ If new byte, goto old routine
80 ldrb r3, [r0, r2, lsr #3]
81 movs r3, r3, lsr ip @ shift off unused bits
83 orr r2, r2, #7 @ if zero, then no bits here
84 add r2, r2, #1 @ align bit pointer
85 b 2b @ loop for next bit
89 ENTRY(_find_first_zero_bit_be)
93 1: eor r3, r2, #0x18 @ big endian byte ordering
94 ldrb r3, [r0, r3, lsr #3]
95 eors r3, r3, #0xff @ invert bits
96 bne .found @ any now set - found zero bit
97 add r2, r2, #8 @ next bit pointer
98 2: cmp r2, r1 @ any more?
100 3: mov r0, r1 @ no free bits
103 ENTRY(_find_next_zero_bit_be)
107 beq 1b @ If new byte, goto old routine
108 eor r3, r2, #0x18 @ big endian byte ordering
109 ldrb r3, [r0, r3, lsr #3]
110 eor r3, r3, #0xff @ now looking for a 1 bit
111 movs r3, r3, lsr ip @ shift off unused bits
113 orr r2, r2, #7 @ if zero, then no bits here
114 add r2, r2, #1 @ align bit pointer
115 b 2b @ loop for next bit
117 ENTRY(_find_first_bit_be)
121 1: eor r3, r2, #0x18 @ big endian byte ordering
122 ldrb r3, [r0, r3, lsr #3]
124 bne .found @ any now set - found zero bit
125 add r2, r2, #8 @ next bit pointer
126 2: cmp r2, r1 @ any more?
128 3: mov r0, r1 @ no free bits
131 ENTRY(_find_next_bit_be)
135 beq 1b @ If new byte, goto old routine
136 eor r3, r2, #0x18 @ big endian byte ordering
137 ldrb r3, [r0, r3, lsr #3]
138 movs r3, r3, lsr ip @ shift off unused bits
140 orr r2, r2, #7 @ if zero, then no bits here
141 add r2, r2, #1 @ align bit pointer
142 b 2b @ loop for next bit
147 * One or more bits in the LSB of r3 are assumed to be set.
150 #if __LINUX_ARM_ARCH__ >= 5