summaryrefslogtreecommitdiffstats
path: root/arch/unicore32/lib/findbit.S
blob: 42f1282670d2ac97257eec61eae9dd9e6a78c492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * linux/arch/unicore32/lib/findbit.S
 *
 * Code specific to PKUnity SoC and UniCore ISA
 *
 * Copyright (C) 2001-2010 GUAN Xue-tao
 */
#include <linux/linkage.h>
#include <asm/assembler.h>
                .text

/*
 * Purpose  : Find a 'zero' bit
 * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
 */
ENTRY(find_first_zero_bit)
		cxor.a	r1, #0
		beq	3f
		mov	r2, #0
1:		ldb	r3, [r0+], r2 >> #3
		xor.a	r3, r3, #0xff		@ invert bits
		bne	.L_found		@ any now set - found zero bit
		add	r2, r2, #8		@ next bit pointer
2:		csub.a	r2, r1			@ any more?
		bub	1b
3:		mov	r0, r1			@ no free bits
		mov	pc, lr
ENDPROC(find_first_zero_bit)

/*
 * Purpose  : Find next 'zero' bit
 * Prototype: int find_next_zero_bit
 *		(void *addr, unsigned int maxbit, int offset)
 */
ENTRY(find_next_zero_bit)
		cxor.a	r1, #0
		beq	3b
		and.a	ip, r2, #7
		beq	1b			@ If new byte, goto old routine
		ldb	r3, [r0+], r2 >> #3
		xor	r3, r3, #0xff		@ now looking for a 1 bit
		mov.a	r3, r3 >> ip		@ shift off unused bits
		bne	.L_found
		or	r2, r2, #7		@ if zero, then no bits here
		add	r2, r2, #1		@ align bit pointer
		b	2b			@ loop for next bit
ENDPROC(find_next_zero_bit)

/*
 * Purpose  : Find a 'one' bit
 * Prototype: int find_first_bit
 *		(const unsigned long *addr, unsigned int maxbit);
 */
ENTRY(find_first_bit)
		cxor.a	r1, #0
		beq	3f
		mov	r2, #0
1:		ldb	r3, [r0+], r2 >> #3
		mov.a	r3, r3
		bne	.L_found		@ any now set - found zero bit
		add	r2, r2, #8		@ next bit pointer
2:		csub.a	r2, r1			@ any more?
		bub	1b
3:		mov	r0, r1			@ no free bits
		mov	pc, lr
ENDPROC(find_first_bit)

/*
 * Purpose  : Find next 'one' bit
 * Prototype: int find_next_zero_bit
 *		(void *addr, unsigned int maxbit, int offset)
 */
ENTRY(find_next_bit)
		cxor.a	r1, #0
		beq	3b
		and.a	ip, r2, #7
		beq	1b			@ If new byte, goto old routine
		ldb	r3, [r0+], r2 >> #3
		mov.a	r3, r3 >> ip		@ shift off unused bits
		bne	.L_found
		or	r2, r2, #7		@ if zero, then no bits here
		add	r2, r2, #1		@ align bit pointer
		b	2b			@ loop for next bit
ENDPROC(find_next_bit)

/*
 * One or more bits in the LSB of r3 are assumed to be set.
 */
.L_found:
		rsub	r1, r3, #0
		and	r3, r3, r1
		cntlz	r3, r3
		rsub	r3, r3, #31
		add	r0, r2, r3
		mov	pc, lr