1/*
2 * Copyright (c) 2014 ARM Ltd
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. The name of the company may not be used to endorse or promote
14 *    products derived from this software without specific prior written
15 *    permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/* Implementation of strcmp for ARMv6m.  This version is only used in
30   ARMv6-M when we want an efficient implementation.  Otherwize if the
31   code size is preferred, strcmp-armv4t.S will be used.  */
32
33	.thumb_func
34	.syntax unified
35	.arch	armv6-m
36
37	.macro DoSub n, label
38	subs	r0, r0, r1
39#ifdef __ARM_BIG_ENDIAN
40	lsrs	r1, r4, \n
41#else
42	lsls	r1, r4, \n
43#endif
44	orrs	r1, r0
45	bne	\label
46	.endm
47
48	.macro Byte_Test n, label
49	lsrs	r0, r2, \n
50	lsrs	r1, r3, \n
51	DoSub	\n, \label
52	.endm
53
54	.text
55	.p2align	0
56	.global	strcmp
57	.type	strcmp, %function
58strcmp:
59	.cfi_startproc
60	mov	r2, r0
61	push	{r4, r5, r6, lr}
62	orrs	r2, r1
63	lsls	r2, r2, #30
64	bne	6f
65	ldr	r5, =0x01010101
66	lsls	r6, r5, #7
671:
68	ldmia	r0!, {r2}
69	ldmia	r1!, {r3}
70	subs	r4, r2, r5
71	bics	r4, r2
72	ands	r4, r6
73	beq	3f
74
75#ifdef __ARM_BIG_ENDIAN
76	Byte_Test #24, 4f
77	Byte_Test #16, 4f
78	Byte_Test #8, 4f
79
80	b       7f
813:
82	cmp     r2, r3
83	beq     1b
84	cmp     r2, r3
85#else
86	uxtb    r0, r2
87	uxtb    r1, r3
88	DoSub   #24, 2f
89
90	uxth    r0, r2
91	uxth    r1, r3
92	DoSub   #16, 2f
93
94	lsls    r0, r2, #8
95	lsls    r1, r3, #8
96	lsrs    r0, r0, #8
97	lsrs    r1, r1, #8
98	DoSub   #8, 2f
99
100	lsrs    r0, r2, #24
101	lsrs    r1, r3, #24
102	subs    r0, r0, r1
1032:
104	pop     {r4, r5, r6, pc}
105
1063:
107	cmp     r2, r3
108	beq     1b
109	rev     r0, r2
110	rev     r1, r3
111	cmp     r0, r1
112#endif
113
114	bls	5f
115	movs	r0, #1
1164:
117	pop	{r4, r5, r6, pc}
1185:
119	movs	r0, #0
120	mvns	r0, r0
121	pop	{r4, r5, r6, pc}
1226:
123	ldrb	r2, [r0, #0]
124	ldrb	r3, [r1, #0]
125	adds	r0, #1
126	adds	r1, #1
127	cmp	r2, #0
128	beq	7f
129	cmp	r2, r3
130	bne	7f
131	ldrb	r2, [r0, #0]
132	ldrb	r3, [r1, #0]
133	adds	r0, #1
134	adds	r1, #1
135	cmp	r2, #0
136	beq	7f
137	cmp	r2, r3
138	beq	6b
1397:
140	subs	r0, r2, r3
141	pop	{r4, r5, r6, pc}
142	.cfi_endproc
143	.size	strcmp, . - strcmp
144