1/*
2 * Copyright (c) 2015 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#include "arm_asm.h"
30
31	.thumb
32	.syntax unified
33	.global memset
34	.type	memset, %function
35	.p2align 1
36memset:
37	.fnstart
38	.cfi_sections .debug_frame
39	.cfi_startproc
40	prologue 4 6 push_ip=HAVE_PAC_LEAF
41
42	lsls	r3, r0, #30
43	beq	10f
44	subs	r4, r2, #1
45	cmp	r2, #0
46	beq	9f
47	lsls	r5, r1, #24
48	lsrs	r5, r5, #24
49	movs	r3, r0
50	movs	r6, #3
51	b	2f
521:
53	subs	r2, r4, #1
54	cmp	r4, #0
55	beq	9f
56	movs	r4, r2
572:
58	adds	r3, r3, #1
59	subs	r2, r3, #1
60	strb	r5, [r2]
61	tst	r3, r6
62	bne	1b
633:
64	cmp	r4, #3
65	bls	7f
66	movs	r5, #255
67	ands	r5, r1
68	lsls	r2, r5, #8
69	orrs	r5, r2
70	lsls	r2, r5, #16
71	orrs	r5, r2
72	cmp	r4, #15
73	bls	5f
74	movs	r6, r4
75	subs	r6, r6, #16
76	lsrs	r6, r6, #4
77	adds	r6, r6, #1
78	lsls	r6, r6, #4
79	movs	r2, r3
80	adds	r3, r3, r6
814:
82	str	r5, [r2]
83	str	r5, [r2, #4]
84	str	r5, [r2, #8]
85	str	r5, [r2, #12]
86	adds	r2, r2, #16
87	cmp	r3, r2
88	bne	4b
89	movs	r2, #15
90	ands	r4, r2
91	cmp	r4, #3
92	bls	7f
935:
94	subs	r6, r4, #4
95	lsrs	r6, r6, #2
96	adds	r6, r6, #1
97	lsls	r6, r6, #2
98	movs	r2, r3
99	adds	r3, r3, r6
1006:
101	stmia	r2!, {r5}
102	cmp	r3, r2
103	bne	6b
104	movs	r2, #3
105	ands	r4, r2
1067:
107	cmp	r4, #0
108	beq	9f
109	lsls	r1, r1, #24
110	lsrs	r1, r1, #24
111	adds	r4, r3, r4
1128:
113	strb	r1, [r3]
114	adds	r3, r3, #1
115	cmp	r4, r3
116	bne	8b
1179:
118	.cfi_remember_state
119	epilogue 4 6 push_ip=HAVE_PAC_LEAF
120	.cfi_restore_state
12110:
122	movs	r3, r0
123	movs	r4, r2
124	b	3b
125	.cfi_endproc
126	.cantunwind
127	.fnend
128	.size memset, . - memset
129