import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / arm / lib / findbit.S
1 /*
2  *  linux/arch/arm/lib/findbit.S
3  *
4  *  Copyright (C) 1995-2000 Russell King
5  *
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.
9  */
10 #include <linux/linkage.h>
11 #include <asm/assembler.h>
12                 .text
13
14 /*
15  * Purpose  : Find a 'zero' bit
16  * Prototype: int find_first_zero_bit(void *addr, int maxbit);
17  */
18 ENTRY(find_first_zero_bit)
19                 mov     r2, #0
20 .bytelp:        ldrb    r3, [r0, r2, lsr #3]
21                 eors    r3, r3, #0xff           @ invert bits
22                 bne     .found                  @ any now set - found zero bit
23                 add     r2, r2, #8              @ next bit pointer
24                 cmp     r2, r1                  @ any more?
25                 bcc     .bytelp
26                 add     r0, r1, #1              @ no free bits
27                 RETINSTR(mov,pc,lr)
28
29 /*
30  * Purpose  : Find next 'zero' bit
31  * Prototype: int find_next_zero_bit(void *addr, int maxbit, int offset)
32  */
33 ENTRY(find_next_zero_bit)
34                 ands    ip, r2, #7
35                 beq     .bytelp                 @ If new byte, goto old routine
36                 ldrb    r3, [r0, r2, lsr#3]
37                 eor     r3, r3, #0xff           @ now looking for a 1 bit
38                 movs    r3, r3, lsr ip          @ shift off unused bits
39                 orreq   r2, r2, #7              @ if zero, then no bits here
40                 addeq   r2, r2, #1              @ align bit pointer
41                 beq     .bytelp                 @ loop for next bit
42
43 /*
44  * One or more bits in the LSB of r3 are assumed to be set.
45  */
46 .found:         tst     r3, #0x0f
47                 addeq   r2, r2, #4
48                 movne   r3, r3, lsl #4
49                 tst     r3, #0x30
50                 addeq   r2, r2, #2
51                 movne   r3, r3, lsl #2
52                 tst     r3, #0x40
53                 addeq   r2, r2, #1
54                 mov     r0, r2
55                 RETINSTR(mov,pc,lr)
56