xref: /linux/arch/csky/abiv2/strcmp.S (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1*c5af58b7SGuo Ren/* SPDX-License-Identifier: GPL-2.0 */
2*c5af58b7SGuo Ren// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3*c5af58b7SGuo Ren
4*c5af58b7SGuo Ren#include <linux/linkage.h>
5*c5af58b7SGuo Ren#include "sysdep.h"
6*c5af58b7SGuo Ren
7*c5af58b7SGuo RenENTRY(strcmp)
8*c5af58b7SGuo Ren	mov	a3, a0
9*c5af58b7SGuo Ren	/* Check if the s1 addr is aligned.  */
10*c5af58b7SGuo Ren	xor	a2, a3, a1
11*c5af58b7SGuo Ren	andi	a2, 0x3
12*c5af58b7SGuo Ren	bnez	a2, 7f
13*c5af58b7SGuo Ren	andi	t1, a0, 0x3
14*c5af58b7SGuo Ren	bnez	t1, 5f
15*c5af58b7SGuo Ren
16*c5af58b7SGuo Ren1:
17*c5af58b7SGuo Ren	/* If aligned, load word each time.  */
18*c5af58b7SGuo Ren	ldw	t0, (a3, 0)
19*c5af58b7SGuo Ren	ldw	t1, (a1, 0)
20*c5af58b7SGuo Ren	/* If s1[i] != s2[i], goto 2f.  */
21*c5af58b7SGuo Ren	cmpne   t0, t1
22*c5af58b7SGuo Ren	bt      2f
23*c5af58b7SGuo Ren	/* If s1[i] == s2[i], check if s1 or s2 is at the end.  */
24*c5af58b7SGuo Ren	tstnbz	t0
25*c5af58b7SGuo Ren	/* If at the end, goto 3f (finish comparing).  */
26*c5af58b7SGuo Ren	bf	3f
27*c5af58b7SGuo Ren
28*c5af58b7SGuo Ren	ldw	t0, (a3, 4)
29*c5af58b7SGuo Ren	ldw	t1, (a1, 4)
30*c5af58b7SGuo Ren	cmpne	t0, t1
31*c5af58b7SGuo Ren	bt	2f
32*c5af58b7SGuo Ren	tstnbz	t0
33*c5af58b7SGuo Ren	bf	3f
34*c5af58b7SGuo Ren
35*c5af58b7SGuo Ren	ldw	t0, (a3, 8)
36*c5af58b7SGuo Ren	ldw	t1, (a1, 8)
37*c5af58b7SGuo Ren	cmpne	t0, t1
38*c5af58b7SGuo Ren	bt	2f
39*c5af58b7SGuo Ren	tstnbz	t0
40*c5af58b7SGuo Ren	bf	3f
41*c5af58b7SGuo Ren
42*c5af58b7SGuo Ren	ldw	t0, (a3, 12)
43*c5af58b7SGuo Ren	ldw	t1, (a1, 12)
44*c5af58b7SGuo Ren	cmpne	t0, t1
45*c5af58b7SGuo Ren	bt	2f
46*c5af58b7SGuo Ren	tstnbz	t0
47*c5af58b7SGuo Ren	bf	3f
48*c5af58b7SGuo Ren
49*c5af58b7SGuo Ren	ldw	t0, (a3, 16)
50*c5af58b7SGuo Ren	ldw	t1, (a1, 16)
51*c5af58b7SGuo Ren	cmpne	t0, t1
52*c5af58b7SGuo Ren	bt	2f
53*c5af58b7SGuo Ren	tstnbz	t0
54*c5af58b7SGuo Ren	bf	3f
55*c5af58b7SGuo Ren
56*c5af58b7SGuo Ren	ldw	t0, (a3, 20)
57*c5af58b7SGuo Ren	ldw	t1, (a1, 20)
58*c5af58b7SGuo Ren	cmpne	t0, t1
59*c5af58b7SGuo Ren	bt	2f
60*c5af58b7SGuo Ren	tstnbz	t0
61*c5af58b7SGuo Ren	bf	3f
62*c5af58b7SGuo Ren
63*c5af58b7SGuo Ren	ldw	t0, (a3, 24)
64*c5af58b7SGuo Ren	ldw	t1, (a1, 24)
65*c5af58b7SGuo Ren	cmpne	t0, t1
66*c5af58b7SGuo Ren	bt	2f
67*c5af58b7SGuo Ren	tstnbz	t0
68*c5af58b7SGuo Ren	bf	3f
69*c5af58b7SGuo Ren
70*c5af58b7SGuo Ren	ldw	t0, (a3, 28)
71*c5af58b7SGuo Ren	ldw	t1, (a1, 28)
72*c5af58b7SGuo Ren	cmpne	t0, t1
73*c5af58b7SGuo Ren	bt	2f
74*c5af58b7SGuo Ren	tstnbz	t0
75*c5af58b7SGuo Ren	bf	3f
76*c5af58b7SGuo Ren
77*c5af58b7SGuo Ren	addi	a3, 32
78*c5af58b7SGuo Ren	addi	a1, 32
79*c5af58b7SGuo Ren
80*c5af58b7SGuo Ren	br	1b
81*c5af58b7SGuo Ren
82*c5af58b7SGuo Ren# ifdef __CSKYBE__
83*c5af58b7SGuo Ren	/* d[i] != s[i] in word, so we check byte 0.  */
84*c5af58b7SGuo Ren2:
85*c5af58b7SGuo Ren	xtrb0   a0, t0
86*c5af58b7SGuo Ren	xtrb0   a2, t1
87*c5af58b7SGuo Ren	subu    a0, a2
88*c5af58b7SGuo Ren	bez     a2, 4f
89*c5af58b7SGuo Ren	bnez    a0, 4f
90*c5af58b7SGuo Ren
91*c5af58b7SGuo Ren	/* check byte 1 */
92*c5af58b7SGuo Ren	xtrb1   a0, t0
93*c5af58b7SGuo Ren	xtrb1   a2, t1
94*c5af58b7SGuo Ren	subu    a0, a2
95*c5af58b7SGuo Ren	bez     a2, 4f
96*c5af58b7SGuo Ren	bnez    a0, 4f
97*c5af58b7SGuo Ren
98*c5af58b7SGuo Ren	/* check byte 2 */
99*c5af58b7SGuo Ren	xtrb2   a0, t0
100*c5af58b7SGuo Ren	xtrb2   a2, t1
101*c5af58b7SGuo Ren	subu    a0, a2
102*c5af58b7SGuo Ren	bez     a2, 4f
103*c5af58b7SGuo Ren	bnez    a0, 4f
104*c5af58b7SGuo Ren
105*c5af58b7SGuo Ren	/* check byte 3 */
106*c5af58b7SGuo Ren	xtrb3   a0, t0
107*c5af58b7SGuo Ren	xtrb3   a2, t1
108*c5af58b7SGuo Ren	subu    a0, a2
109*c5af58b7SGuo Ren# else
110*c5af58b7SGuo Ren	/* s1[i] != s2[i] in word, so we check byte 3.  */
111*c5af58b7SGuo Ren2:
112*c5af58b7SGuo Ren	xtrb3	a0, t0
113*c5af58b7SGuo Ren	xtrb3	a2, t1
114*c5af58b7SGuo Ren	subu    a0, a2
115*c5af58b7SGuo Ren	bez     a2, 4f
116*c5af58b7SGuo Ren	bnez    a0, 4f
117*c5af58b7SGuo Ren
118*c5af58b7SGuo Ren	/* check byte 2 */
119*c5af58b7SGuo Ren	xtrb2	a0, t0
120*c5af58b7SGuo Ren	xtrb2	a2, t1
121*c5af58b7SGuo Ren	subu    a0, a2
122*c5af58b7SGuo Ren	bez     a2, 4f
123*c5af58b7SGuo Ren	bnez    a0, 4f
124*c5af58b7SGuo Ren
125*c5af58b7SGuo Ren	/* check byte 1 */
126*c5af58b7SGuo Ren	xtrb1	a0, t0
127*c5af58b7SGuo Ren	xtrb1	a2, t1
128*c5af58b7SGuo Ren	subu	a0, a2
129*c5af58b7SGuo Ren	bez	a2, 4f
130*c5af58b7SGuo Ren	bnez    a0, 4f
131*c5af58b7SGuo Ren
132*c5af58b7SGuo Ren	/* check byte 0 */
133*c5af58b7SGuo Ren	xtrb0	a0, t0
134*c5af58b7SGuo Ren	xtrb0	a2, t1
135*c5af58b7SGuo Ren	subu	a0, a2
136*c5af58b7SGuo Ren
137*c5af58b7SGuo Ren# endif /* !__CSKYBE__ */
138*c5af58b7SGuo Ren	jmp     lr
139*c5af58b7SGuo Ren3:
140*c5af58b7SGuo Ren	movi	a0, 0
141*c5af58b7SGuo Ren4:
142*c5af58b7SGuo Ren	jmp     lr
143*c5af58b7SGuo Ren
144*c5af58b7SGuo Ren	/* Compare when s1 or s2 is not aligned.  */
145*c5af58b7SGuo Ren5:
146*c5af58b7SGuo Ren	subi    t1, 4
147*c5af58b7SGuo Ren6:
148*c5af58b7SGuo Ren	ldb	a0, (a3, 0)
149*c5af58b7SGuo Ren	ldb	a2, (a1, 0)
150*c5af58b7SGuo Ren	subu	a0, a2
151*c5af58b7SGuo Ren	bez	a2, 4b
152*c5af58b7SGuo Ren	bnez	a0, 4b
153*c5af58b7SGuo Ren	addi    t1, 1
154*c5af58b7SGuo Ren	addi	a1, 1
155*c5af58b7SGuo Ren	addi	a3, 1
156*c5af58b7SGuo Ren	bnez	t1, 6b
157*c5af58b7SGuo Ren	br	1b
158*c5af58b7SGuo Ren
159*c5af58b7SGuo Ren7:
160*c5af58b7SGuo Ren	ldb	a0, (a3, 0)
161*c5af58b7SGuo Ren	addi	a3, 1
162*c5af58b7SGuo Ren	ldb	a2, (a1, 0)
163*c5af58b7SGuo Ren	addi	a1, 1
164*c5af58b7SGuo Ren	subu    a0, a2
165*c5af58b7SGuo Ren	bnez    a0, 4b
166*c5af58b7SGuo Ren	bnez	a2, 7b
167*c5af58b7SGuo Ren	jmp	r15
168*c5af58b7SGuo RenENDPROC(strcmp)
169