xref: /linux/arch/arc/lib/strcmp-archs.S (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
4 */
5
6#include <linux/linkage.h>
7
8ENTRY_CFI(strcmp)
9	or	r2, r0, r1
10	bmsk_s	r2, r2, 1
11	brne	r2, 0, @.Lcharloop
12
13;;; s1 and s2 are word aligned
14	ld.ab	r2, [r0, 4]
15
16	mov_s	r12, 0x01010101
17	ror	r11, r12
18	.align  4
19.LwordLoop:
20	ld.ab	r3, [r1, 4]
21	;; Detect NULL char in str1
22	sub	r4, r2, r12
23	ld.ab	r5, [r0, 4]
24	bic	r4, r4, r2
25	and	r4, r4, r11
26	brne.d.nt	r4, 0, .LfoundNULL
27	;; Check if the read locations are the same
28	cmp	r2, r3
29	beq.d	.LwordLoop
30	mov.eq	r2, r5
31
32	;; A match is found, spot it out
33#ifdef __LITTLE_ENDIAN__
34	swape	r3, r3
35	mov_s	r0, 1
36	swape	r2, r2
37#else
38	mov_s	r0, 1
39#endif
40	cmp_s	r2, r3
41	j_s.d	[blink]
42	bset.lo	r0, r0, 31
43
44	.align 4
45.LfoundNULL:
46#ifdef __BIG_ENDIAN__
47	swape	r4, r4
48	swape	r2, r2
49	swape	r3, r3
50#endif
51	;; Find null byte
52	ffs	r0, r4
53	bmsk	r2, r2, r0
54	bmsk	r3, r3, r0
55	swape	r2, r2
56	swape	r3, r3
57	;; make the return value
58	sub.f	r0, r2, r3
59	mov.hi	r0, 1
60	j_s.d	[blink]
61	bset.lo	r0, r0, 31
62
63	.align 4
64.Lcharloop:
65	ldb.ab	r2, [r0, 1]
66	ldb.ab	r3, [r1, 1]
67	nop
68	breq	r2, 0, .Lcmpend
69	breq	r2, r3, .Lcharloop
70
71	.align 4
72.Lcmpend:
73	j_s.d	[blink]
74	sub	r0, r2, r3
75END_CFI(strcmp)
76