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