summaryrefslogtreecommitdiffstats
path: root/arch/csky/abiv2/strlen.S
blob: bcdd70764d086441eeb80414e37f99e4d4781eb6 (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 */
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.

#include <linux/linkage.h>
#include "sysdep.h"

ENTRY(strlen)
	/* Check if the start addr is aligned.  */
	mov	r3, r0
	andi	r1, r0, 3
	movi	r2, 4
	movi	r0, 0
	bnez	r1, .L_start_not_aligned

	LABLE_ALIGN
.L_start_addr_aligned:
	/* Check if all the bytes in the word are not zero.  */
	ldw	r1, (r3)
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 4)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 8)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 12)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 16)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 20)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 24)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	ldw	r1, (r3, 28)
	addi	r0, 4
	tstnbz	r1
	bf	.L_string_tail

	addi	r0, 4
	addi	r3, 32
	br	.L_start_addr_aligned

.L_string_tail:
# ifdef __CSKYBE__
	xtrb0	r3, r1
	bez	r3, .L_return
	addi	r0, 1
	xtrb1	r3, r1
	bez	r3, .L_return
	addi	r0, 1
	xtrb2	r3, r1
	bez	r3, .L_return
	addi	r0, 1
# else
	xtrb3	r3, r1
	bez	r3, .L_return
	addi	r0, 1
	xtrb2	r3, r1
	bez	r3, .L_return
	addi	r0, 1
	xtrb1	r3, r1
	bez	r3, .L_return
	addi	r0, 1
# endif	/* !__CSKYBE__ */

.L_return:
	rts

.L_start_not_aligned:
	sub	r2, r2, r1
.L_start_not_aligned_loop:
	ldb	r1, (r3)
	PRE_BNEZAD (r2)
	addi	r3, 1
	bez	r1, .L_return
	addi	r0, 1
	BNEZAD (r2, .L_start_not_aligned_loop)
	br	.L_start_addr_aligned
ENDPROC(strlen)