1bbbf1280Sopenharmony_ci/*
2bbbf1280Sopenharmony_ci * strcmp for ARMv6-M (optimized for performance, not size)
3bbbf1280Sopenharmony_ci *
4bbbf1280Sopenharmony_ci * Copyright (c) 2014-2020, Arm Limited.
5bbbf1280Sopenharmony_ci * SPDX-License-Identifier: MIT
6bbbf1280Sopenharmony_ci */
7bbbf1280Sopenharmony_ci
8bbbf1280Sopenharmony_ci#if __ARM_ARCH == 6 && __ARM_ARCH_6M__ >= 1
9bbbf1280Sopenharmony_ci
10bbbf1280Sopenharmony_ci	.thumb_func
11bbbf1280Sopenharmony_ci	.syntax unified
12bbbf1280Sopenharmony_ci	.arch	armv6-m
13bbbf1280Sopenharmony_ci
14bbbf1280Sopenharmony_ci	.macro DoSub n, label
15bbbf1280Sopenharmony_ci	subs	r0, r0, r1
16bbbf1280Sopenharmony_ci#ifdef __ARM_BIG_ENDIAN
17bbbf1280Sopenharmony_ci	lsrs	r1, r4, \n
18bbbf1280Sopenharmony_ci#else
19bbbf1280Sopenharmony_ci	lsls	r1, r4, \n
20bbbf1280Sopenharmony_ci#endif
21bbbf1280Sopenharmony_ci	orrs	r1, r0
22bbbf1280Sopenharmony_ci	bne	\label
23bbbf1280Sopenharmony_ci	.endm
24bbbf1280Sopenharmony_ci
25bbbf1280Sopenharmony_ci	.macro Byte_Test n, label
26bbbf1280Sopenharmony_ci	lsrs	r0, r2, \n
27bbbf1280Sopenharmony_ci	lsrs	r1, r3, \n
28bbbf1280Sopenharmony_ci	DoSub	\n, \label
29bbbf1280Sopenharmony_ci	.endm
30bbbf1280Sopenharmony_ci
31bbbf1280Sopenharmony_ciENTRY_ALIGN (__strcmp_armv6m, 4)
32bbbf1280Sopenharmony_ci	mov	r2, r0
33bbbf1280Sopenharmony_ci	push	{r4, r5, r6, lr}
34bbbf1280Sopenharmony_ci	orrs	r2, r1
35bbbf1280Sopenharmony_ci	lsls	r2, r2, #30
36bbbf1280Sopenharmony_ci	bne	6f
37bbbf1280Sopenharmony_ci	ldr	r5, =0x01010101
38bbbf1280Sopenharmony_ci	lsls	r6, r5, #7
39bbbf1280Sopenharmony_ci1:
40bbbf1280Sopenharmony_ci	ldmia	r0!, {r2}
41bbbf1280Sopenharmony_ci	ldmia	r1!, {r3}
42bbbf1280Sopenharmony_ci	subs	r4, r2, r5
43bbbf1280Sopenharmony_ci	bics	r4, r2
44bbbf1280Sopenharmony_ci	ands	r4, r6
45bbbf1280Sopenharmony_ci	beq	3f
46bbbf1280Sopenharmony_ci
47bbbf1280Sopenharmony_ci#ifdef __ARM_BIG_ENDIAN
48bbbf1280Sopenharmony_ci	Byte_Test #24, 4f
49bbbf1280Sopenharmony_ci	Byte_Test #16, 4f
50bbbf1280Sopenharmony_ci	Byte_Test #8, 4f
51bbbf1280Sopenharmony_ci
52bbbf1280Sopenharmony_ci	b       7f
53bbbf1280Sopenharmony_ci3:
54bbbf1280Sopenharmony_ci	cmp     r2, r3
55bbbf1280Sopenharmony_ci	beq     1b
56bbbf1280Sopenharmony_ci	cmp     r2, r3
57bbbf1280Sopenharmony_ci#else
58bbbf1280Sopenharmony_ci	uxtb    r0, r2
59bbbf1280Sopenharmony_ci	uxtb    r1, r3
60bbbf1280Sopenharmony_ci	DoSub   #24, 2f
61bbbf1280Sopenharmony_ci
62bbbf1280Sopenharmony_ci	uxth    r0, r2
63bbbf1280Sopenharmony_ci	uxth    r1, r3
64bbbf1280Sopenharmony_ci	DoSub   #16, 2f
65bbbf1280Sopenharmony_ci
66bbbf1280Sopenharmony_ci	lsls    r0, r2, #8
67bbbf1280Sopenharmony_ci	lsls    r1, r3, #8
68bbbf1280Sopenharmony_ci	lsrs    r0, r0, #8
69bbbf1280Sopenharmony_ci	lsrs    r1, r1, #8
70bbbf1280Sopenharmony_ci	DoSub   #8, 2f
71bbbf1280Sopenharmony_ci
72bbbf1280Sopenharmony_ci	lsrs    r0, r2, #24
73bbbf1280Sopenharmony_ci	lsrs    r1, r3, #24
74bbbf1280Sopenharmony_ci	subs    r0, r0, r1
75bbbf1280Sopenharmony_ci2:
76bbbf1280Sopenharmony_ci	pop     {r4, r5, r6, pc}
77bbbf1280Sopenharmony_ci
78bbbf1280Sopenharmony_ci3:
79bbbf1280Sopenharmony_ci	cmp     r2, r3
80bbbf1280Sopenharmony_ci	beq     1b
81bbbf1280Sopenharmony_ci	rev     r0, r2
82bbbf1280Sopenharmony_ci	rev     r1, r3
83bbbf1280Sopenharmony_ci	cmp     r0, r1
84bbbf1280Sopenharmony_ci#endif
85bbbf1280Sopenharmony_ci
86bbbf1280Sopenharmony_ci	bls	5f
87bbbf1280Sopenharmony_ci	movs	r0, #1
88bbbf1280Sopenharmony_ci4:
89bbbf1280Sopenharmony_ci	pop	{r4, r5, r6, pc}
90bbbf1280Sopenharmony_ci5:
91bbbf1280Sopenharmony_ci	movs	r0, #0
92bbbf1280Sopenharmony_ci	mvns	r0, r0
93bbbf1280Sopenharmony_ci	pop	{r4, r5, r6, pc}
94bbbf1280Sopenharmony_ci6:
95bbbf1280Sopenharmony_ci	ldrb	r2, [r0, #0]
96bbbf1280Sopenharmony_ci	ldrb	r3, [r1, #0]
97bbbf1280Sopenharmony_ci	adds	r0, #1
98bbbf1280Sopenharmony_ci	adds	r1, #1
99bbbf1280Sopenharmony_ci	cmp	r2, #0
100bbbf1280Sopenharmony_ci	beq	7f
101bbbf1280Sopenharmony_ci	cmp	r2, r3
102bbbf1280Sopenharmony_ci	bne	7f
103bbbf1280Sopenharmony_ci	ldrb	r2, [r0, #0]
104bbbf1280Sopenharmony_ci	ldrb	r3, [r1, #0]
105bbbf1280Sopenharmony_ci	adds	r0, #1
106bbbf1280Sopenharmony_ci	adds	r1, #1
107bbbf1280Sopenharmony_ci	cmp	r2, #0
108bbbf1280Sopenharmony_ci	beq	7f
109bbbf1280Sopenharmony_ci	cmp	r2, r3
110bbbf1280Sopenharmony_ci	beq	6b
111bbbf1280Sopenharmony_ci7:
112bbbf1280Sopenharmony_ci	subs	r0, r2, r3
113bbbf1280Sopenharmony_ci	pop	{r4, r5, r6, pc}
114bbbf1280Sopenharmony_ci
115bbbf1280Sopenharmony_ciEND (__strcmp_armv6m)
116bbbf1280Sopenharmony_ci
117bbbf1280Sopenharmony_ci#endif /* __ARM_ARCH == 6 && __ARM_ARCH_6M__ >= 1  */
118