1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/unicore32/lib/findbit.S
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
9 #include <linux/linkage.h>
10 #include <asm/assembler.h>
14 * Purpose : Find a 'zero' bit
15 * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
17 ENTRY(find_first_zero_bit)
21 1: ldb r3, [r0+], r2 >> #3
22 xor.a r3, r3, #0xff @ invert bits
23 bne .L_found @ any now set - found zero bit
24 add r2, r2, #8 @ next bit pointer
25 2: csub.a r2, r1 @ any more?
27 3: mov r0, r1 @ no free bits
29 ENDPROC(find_first_zero_bit)
32 * Purpose : Find next 'zero' bit
33 * Prototype: int find_next_zero_bit
34 * (void *addr, unsigned int maxbit, int offset)
36 ENTRY(find_next_zero_bit)
40 beq 1b @ If new byte, goto old routine
41 ldb r3, [r0+], r2 >> #3
42 xor r3, r3, #0xff @ now looking for a 1 bit
43 mov.a r3, r3 >> ip @ shift off unused bits
45 or r2, r2, #7 @ if zero, then no bits here
46 add r2, r2, #1 @ align bit pointer
47 b 2b @ loop for next bit
48 ENDPROC(find_next_zero_bit)
51 * Purpose : Find a 'one' bit
52 * Prototype: int find_first_bit
53 * (const unsigned long *addr, unsigned int maxbit);
59 1: ldb r3, [r0+], r2 >> #3
61 bne .L_found @ any now set - found zero bit
62 add r2, r2, #8 @ next bit pointer
63 2: csub.a r2, r1 @ any more?
65 3: mov r0, r1 @ no free bits
67 ENDPROC(find_first_bit)
70 * Purpose : Find next 'one' bit
71 * Prototype: int find_next_zero_bit
72 * (void *addr, unsigned int maxbit, int offset)
78 beq 1b @ If new byte, goto old routine
79 ldb r3, [r0+], r2 >> #3
80 mov.a r3, r3 >> ip @ shift off unused bits
82 or r2, r2, #7 @ if zero, then no bits here
83 add r2, r2, #1 @ align bit pointer
84 b 2b @ loop for next bit
85 ENDPROC(find_next_bit)
88 * One or more bits in the LSB of r3 are assumed to be set.