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 <picolibc.h>
30
31#include "arm_asm.h"
32
33	.thumb
34	.syntax unified
35	.global memset
36	.type	memset, %function
37	.p2align 1
38memset:
39	.fnstart
40	.cfi_sections .debug_frame
41	.cfi_startproc
42	prologue 4 6 push_ip=HAVE_PAC_LEAF
43	lsls	r4, r0, #30
44	beq	10f
45	subs	r4, r2, #1
46	cmp	r2, #0
47	beq	9f
48	uxtb	r5, r1
49	mov	r3, r0
50	b	2f
511:
52	subs	r2, r4, #1
53	cbz	r4, 9f
54	mov	r4, r2
552:
56	strb	r5, [r3], #1
57	lsls	r2, r3, #30
58	bne	1b
593:
60	cmp	r4, #3
61	bls	7f
62	uxtb	r5, r1
63	orr	r5, r5, r5, lsl #8
64	cmp	r4, #15
65	orr	r5, r5, r5, lsl #16
66	bls	5f
67	mov	r6, r4
68	add	r2, r3, #16
694:
70	subs	r6, r6, #16
71	cmp	r6, #15
72	str	r5, [r2, #-16]
73	str	r5, [r2, #-12]
74	str	r5, [r2, #-8]
75	str	r5, [r2, #-4]
76	add	r2, r2, #16
77	bhi	4b
78	sub	r2, r4, #16
79	bic	r2, r2, #15
80	and	r4, r4, #15
81	adds	r2, r2, #16
82	cmp	r4, #3
83	add	r3, r3, r2
84	bls	7f
855:
86	mov	r6, r3
87	mov	r2, r4
886:
89	subs	r2, r2, #4
90	cmp	r2, #3
91	str	r5, [r6], #4
92	bhi	6b
93	subs	r2, r4, #4
94	bic	r2, r2, #3
95	adds	r2, r2, #4
96	add	r3, r3, r2
97	and	r4, r4, #3
987:
99	cbz	r4, 9f
100	uxtb	r1, r1
101	add	r4, r4, r3
1028:
103	strb	r1, [r3], #1
104	cmp	r3, r4
105	bne	8b
1069:
107	.cfi_remember_state
108	epilogue 4 6 push_ip=HAVE_PAC_LEAF
109	.cfi_restore_state
11010:
111	mov	r4, r2
112	mov	r3, r0
113	b	3b
114	.cfi_endproc
115	.cantunwind
116	.fnend
117	.size memset, . - memset
118
119#if defined(__linux__) && defined(__ELF__)
120.section .note.GNU-stack,"",%progbits
121#endif
122