1/* Copyright (C) 1998 Free Software Foundation, Inc.
2   This file is part of the GNU C Library.
3   Contributed by Philip Blundell <philb@gnu.org>
4
5   The GNU C Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public
16   License along with the GNU C Library; if not, see
17   <http://www.gnu.org/licenses/>.  */
18
19#include <features.h>
20#include <bits/arm_asm.h>
21#include <bits/arm_bx.h>
22
23.text
24.global memset
25.type memset,%function
26.align 4
27
28#if defined(THUMB1_ONLY)
29.thumb_func
30memset:
31	mov	ip, r0
32	cmp	r2, #8		@ at least 8 bytes to do?
33	bcc	2f
34
35	and	r1, r1, #0xFF
36	lsl	r3, r1, #8
37	orr	r1, r3
38	lsl	r3, r1, #16
39	orr	r1, r3
40
41	mov	r3, #3
421:	@ Fill up to the first word boundary
43	tst	r0, r3
44	beq	1f
45	strb	r1, [r0]
46	add	r0, r0, #1
47	sub	r2, r2, #1
48	b	1b
491:	@ Fill aligned words
50	str	r1, [r0]
51	add	r0, r0, #4
52	sub	r2, r2, #4
53	cmp	r2, #4
54	bcs	1b
55
562:	@ Fill the remaining bytes
57	cmp	r2, #0
58	beq	2f
591:
60	strb	r1, [r0]
61	add	r0, r0, #1
62	sub	r2, r2, #1
63	bne	1b
642:
65	mov	r0, ip
66	bx lr
67#else
68memset:
69	mov	a4, a1
70	cmp	a3, $8		@ at least 8 bytes to do?
71	blo	2f
72	and	a2, a2, #0xFF
73	orr	a2, a2, a2, lsl $8
74	orr	a2, a2, a2, lsl $16
751:
76	tst	a4, $3		@ aligned yet?
77#if defined(__thumb2__)
78	itt	ne
79	strbne	a2, [a4], $1
80	subne	a3, a3, $1
81#else
82	strneb	a2, [a4], $1
83	subne	a3, a3, $1
84#endif
85	bne	1b
86	mov	ip, a2
871:
88	cmp	a3, $8		@ 8 bytes still to do?
89	blo	2f
90	stmia	a4!, {a2, ip}
91	sub	a3, a3, $8
92	cmp	a3, $8		@ 8 bytes still to do?
93	blo	2f
94	stmia	a4!, {a2, ip}
95	sub	a3, a3, $8
96	cmp	a3, $8		@ 8 bytes still to do?
97	blo	2f
98	stmia	a4!, {a2, ip}
99	sub	a3, a3, $8
100	cmp	a3, $8		@ 8 bytes still to do?
101#if defined(__thumb2__)
102	itt	hs
103	stmiahs	a4!, {a2, ip}
104	subhs	a3, a3, $8
105#else
106	stmhsia	a4!, {a2, ip}
107	subhs	a3, a3, $8
108#endif
109	bhs	1b
1102:
111	movs	a3, a3		@ anything left?
112	IT(t, eq)
113	BXC(eq, lr)			@ nope
114#if defined (__thumb2__)
1151:
116	strb	a2, [a4], #1
117	subs	a3, a3, #1
118	bne	1b
119	bx	lr
120#else
121	rsb	a3, a3, $7
122	add	pc, pc, a3, lsl $2
123	mov	r0, r0
124	strb	a2, [a4], $1
125	strb	a2, [a4], $1
126	strb	a2, [a4], $1
127	strb	a2, [a4], $1
128	strb	a2, [a4], $1
129	strb	a2, [a4], $1
130	strb	a2, [a4], $1
131	BX(lr)
132#endif
133#endif
134
135.size memset,.-memset
136
137libc_hidden_def(memset)
138