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
55def_fn	strcmp
56	.cfi_sections .debug_frame
57	.cfi_startproc
58	mov	r2, r0
59	push	{r4, r5, r6, lr}
60	orrs	r2, r1
61	lsls	r2, r2, #30
62	bne	6f
63	ldr	r5, =0x01010101
64	lsls	r6, r5, #7
651:
66	ldmia	r0!, {r2}
67	ldmia	r1!, {r3}
68	subs	r4, r2, r5
69	bics	r4, r2
70	ands	r4, r6
71	beq	3f
72
73#ifdef __ARM_BIG_ENDIAN
74	Byte_Test #24, 4f
75	Byte_Test #16, 4f
76	Byte_Test #8, 4f
77
78	b       7f
793:
80	cmp     r2, r3
81	beq     1b
82	cmp     r2, r3
83#else
84	uxtb    r0, r2
85	uxtb    r1, r3
86	DoSub   #24, 2f
87
88	uxth    r0, r2
89	uxth    r1, r3
90	DoSub   #16, 2f
91
92	lsls    r0, r2, #8
93	lsls    r1, r3, #8
94	lsrs    r0, r0, #8
95	lsrs    r1, r1, #8
96	DoSub   #8, 2f
97
98	lsrs    r0, r2, #24
99	lsrs    r1, r3, #24
100	subs    r0, r0, r1
1012:
102	pop     {r4, r5, r6, pc}
103
1043:
105	cmp     r2, r3
106	beq     1b
107	rev     r0, r2
108	rev     r1, r3
109	cmp     r0, r1
110#endif
111
112	bls	5f
113	movs	r0, #1
1144:
115	pop	{r4, r5, r6, pc}
1165:
117	movs	r0, #0
118	mvns	r0, r0
119	pop	{r4, r5, r6, pc}
1206:
121	ldrb	r2, [r0, #0]
122	ldrb	r3, [r1, #0]
123	adds	r0, #1
124	adds	r1, #1
125	cmp	r2, #0
126	beq	7f
127	cmp	r2, r3
128	bne	7f
129	ldrb	r2, [r0, #0]
130	ldrb	r3, [r1, #0]
131	adds	r0, #1
132	adds	r1, #1
133	cmp	r2, #0
134	beq	7f
135	cmp	r2, r3
136	beq	6b
1377:
138	subs	r0, r2, r3
139	pop	{r4, r5, r6, pc}
140	.cfi_endproc
141	.size	strcmp, . - strcmp
142