memset.S revision 1.3 1 1.3 matt /* $NetBSD: memset.S,v 1.3 2013/01/28 06:23:44 matt Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright 2003 Wasabi Systems, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * Written by Steve C. Woodford for Wasabi Systems, Inc.
8 1.1 christos *
9 1.1 christos * Redistribution and use in source and binary forms, with or without
10 1.1 christos * modification, are permitted provided that the following conditions
11 1.1 christos * are met:
12 1.1 christos * 1. Redistributions of source code must retain the above copyright
13 1.1 christos * notice, this list of conditions and the following disclaimer.
14 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 christos * notice, this list of conditions and the following disclaimer in the
16 1.1 christos * documentation and/or other materials provided with the distribution.
17 1.1 christos * 3. All advertising materials mentioning features or use of this software
18 1.1 christos * must display the following acknowledgement:
19 1.1 christos * This product includes software developed for the NetBSD Project by
20 1.1 christos * Wasabi Systems, Inc.
21 1.1 christos * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 christos * or promote products derived from this software without specific prior
23 1.1 christos * written permission.
24 1.1 christos *
25 1.1 christos * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
36 1.1 christos */
37 1.1 christos /*
38 1.1 christos * Copyright (c) 1995 Mark Brinicombe.
39 1.1 christos * All rights reserved.
40 1.1 christos *
41 1.1 christos * Redistribution and use in source and binary forms, with or without
42 1.1 christos * modification, are permitted provided that the following conditions
43 1.1 christos * are met:
44 1.1 christos * 1. Redistributions of source code must retain the above copyright
45 1.1 christos * notice, this list of conditions and the following disclaimer.
46 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
47 1.1 christos * notice, this list of conditions and the following disclaimer in the
48 1.1 christos * documentation and/or other materials provided with the distribution.
49 1.1 christos * 3. All advertising materials mentioning features or use of this software
50 1.1 christos * must display the following acknowledgement:
51 1.1 christos * This product includes software developed by Mark Brinicombe.
52 1.1 christos * 4. The name of the company nor the name of the author may be used to
53 1.1 christos * endorse or promote products derived from this software without specific
54 1.1 christos * prior written permission.
55 1.1 christos *
56 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
57 1.1 christos * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
58 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
59 1.1 christos * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
60 1.1 christos * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
61 1.1 christos * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
62 1.1 christos * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 1.1 christos * SUCH DAMAGE.
67 1.1 christos */
68 1.1 christos
69 1.1 christos #include <machine/asm.h>
70 1.1 christos
71 1.3 matt #if defined(__ARM_EABI__) && !defined(BZER0)
72 1.3 matt STRONG_ALIAS(__aeabi_memset, memset)
73 1.3 matt #endif
74 1.3 matt
75 1.1 christos /*
76 1.1 christos * memset: Sets a block of memory to the specified value
77 1.1 christos *
78 1.1 christos * On entry:
79 1.1 christos * r0 - dest address
80 1.1 christos * r1 - byte to write
81 1.1 christos * r2 - number of bytes to write
82 1.1 christos *
83 1.1 christos * On exit:
84 1.1 christos * r0 - dest address
85 1.1 christos */
86 1.1 christos #ifdef _BZERO
87 1.1 christos /* LINTSTUB: Func: void bzero(void *, size_t) */
88 1.1 christos ENTRY(bzero)
89 1.1 christos mov r3, #0x00
90 1.1 christos #else
91 1.1 christos /* LINTSTUB: Func: void *memset(void *, int, size_t) */
92 1.1 christos ENTRY(memset)
93 1.1 christos and r3, r1, #0xff /* We deal with bytes */
94 1.1 christos mov r1, r2
95 1.1 christos #endif
96 1.1 christos cmp r1, #0x04 /* Do we have less than 4 bytes */
97 1.1 christos mov ip, r0
98 1.1 christos blt .Lmemset_lessthanfour
99 1.1 christos
100 1.1 christos /* Ok first we will word align the address */
101 1.1 christos ands r2, ip, #0x03 /* Get the bottom two bits */
102 1.1 christos bne .Lmemset_wordunaligned /* The address is not word aligned */
103 1.1 christos
104 1.1 christos /* We are now word aligned */
105 1.1 christos .Lmemset_wordaligned:
106 1.1 christos #ifndef _BZERO
107 1.1 christos orr r3, r3, r3, lsl #8 /* Extend value to 16-bits */
108 1.1 christos #endif
109 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
110 1.1 christos tst ip, #0x04 /* Quad-align for Xscale */
111 1.1 christos #else
112 1.1 christos cmp r1, #0x10
113 1.1 christos #endif
114 1.1 christos #ifndef _BZERO
115 1.1 christos orr r3, r3, r3, lsl #16 /* Extend value to 32-bits */
116 1.1 christos #endif
117 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
118 1.1 christos subne r1, r1, #0x04 /* Quad-align if necessary */
119 1.1 christos strne r3, [ip], #0x04
120 1.1 christos cmp r1, #0x10
121 1.1 christos #endif
122 1.1 christos blt .Lmemset_loop4 /* If less than 16 then use words */
123 1.1 christos mov r2, r3 /* Duplicate data */
124 1.1 christos cmp r1, #0x80 /* If < 128 then skip the big loop */
125 1.1 christos blt .Lmemset_loop32
126 1.1 christos
127 1.1 christos /* Do 128 bytes at a time */
128 1.1 christos .Lmemset_loop128:
129 1.1 christos subs r1, r1, #0x80
130 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
131 1.1 christos strged r2, [ip], #0x08
132 1.1 christos strged r2, [ip], #0x08
133 1.1 christos strged r2, [ip], #0x08
134 1.1 christos strged r2, [ip], #0x08
135 1.1 christos strged r2, [ip], #0x08
136 1.1 christos strged r2, [ip], #0x08
137 1.1 christos strged r2, [ip], #0x08
138 1.1 christos strged r2, [ip], #0x08
139 1.1 christos strged r2, [ip], #0x08
140 1.1 christos strged r2, [ip], #0x08
141 1.1 christos strged r2, [ip], #0x08
142 1.1 christos strged r2, [ip], #0x08
143 1.1 christos strged r2, [ip], #0x08
144 1.1 christos strged r2, [ip], #0x08
145 1.1 christos strged r2, [ip], #0x08
146 1.1 christos strged r2, [ip], #0x08
147 1.1 christos #else
148 1.1 christos stmgeia ip!, {r2-r3}
149 1.1 christos stmgeia ip!, {r2-r3}
150 1.1 christos stmgeia ip!, {r2-r3}
151 1.1 christos stmgeia ip!, {r2-r3}
152 1.1 christos stmgeia ip!, {r2-r3}
153 1.1 christos stmgeia ip!, {r2-r3}
154 1.1 christos stmgeia ip!, {r2-r3}
155 1.1 christos stmgeia ip!, {r2-r3}
156 1.1 christos stmgeia ip!, {r2-r3}
157 1.1 christos stmgeia ip!, {r2-r3}
158 1.1 christos stmgeia ip!, {r2-r3}
159 1.1 christos stmgeia ip!, {r2-r3}
160 1.1 christos stmgeia ip!, {r2-r3}
161 1.1 christos stmgeia ip!, {r2-r3}
162 1.1 christos stmgeia ip!, {r2-r3}
163 1.1 christos stmgeia ip!, {r2-r3}
164 1.1 christos #endif
165 1.1 christos bgt .Lmemset_loop128
166 1.1 christos RETc(eq) /* Zero length so just exit */
167 1.1 christos
168 1.1 christos add r1, r1, #0x80 /* Adjust for extra sub */
169 1.1 christos
170 1.1 christos /* Do 32 bytes at a time */
171 1.1 christos .Lmemset_loop32:
172 1.1 christos subs r1, r1, #0x20
173 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
174 1.1 christos strged r2, [ip], #0x08
175 1.1 christos strged r2, [ip], #0x08
176 1.1 christos strged r2, [ip], #0x08
177 1.1 christos strged r2, [ip], #0x08
178 1.1 christos #else
179 1.1 christos stmgeia ip!, {r2-r3}
180 1.1 christos stmgeia ip!, {r2-r3}
181 1.1 christos stmgeia ip!, {r2-r3}
182 1.1 christos stmgeia ip!, {r2-r3}
183 1.1 christos #endif
184 1.1 christos bgt .Lmemset_loop32
185 1.1 christos RETc(eq) /* Zero length so just exit */
186 1.1 christos
187 1.1 christos adds r1, r1, #0x10 /* Partially adjust for extra sub */
188 1.1 christos
189 1.1 christos /* Deal with 16 bytes or more */
190 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
191 1.1 christos strged r2, [ip], #0x08
192 1.1 christos strged r2, [ip], #0x08
193 1.1 christos #else
194 1.1 christos stmgeia ip!, {r2-r3}
195 1.1 christos stmgeia ip!, {r2-r3}
196 1.1 christos #endif
197 1.1 christos RETc(eq) /* Zero length so just exit */
198 1.1 christos
199 1.1 christos addlt r1, r1, #0x10 /* Possibly adjust for extra sub */
200 1.1 christos
201 1.1 christos /* We have at least 4 bytes so copy as words */
202 1.1 christos .Lmemset_loop4:
203 1.1 christos subs r1, r1, #0x04
204 1.1 christos strge r3, [ip], #0x04
205 1.1 christos bgt .Lmemset_loop4
206 1.1 christos RETc(eq) /* Zero length so just exit */
207 1.1 christos
208 1.2 matt #ifdef _ARM_ARCH_DWORD_OK
209 1.1 christos /* Compensate for 64-bit alignment check */
210 1.1 christos adds r1, r1, #0x04
211 1.1 christos RETc(eq)
212 1.1 christos cmp r1, #2
213 1.1 christos #else
214 1.1 christos cmp r1, #-2
215 1.1 christos #endif
216 1.1 christos
217 1.1 christos strb r3, [ip], #0x01 /* Set 1 byte */
218 1.1 christos strgeb r3, [ip], #0x01 /* Set another byte */
219 1.1 christos strgtb r3, [ip] /* and a third */
220 1.1 christos RET /* Exit */
221 1.1 christos
222 1.1 christos .Lmemset_wordunaligned:
223 1.1 christos rsb r2, r2, #0x004
224 1.1 christos strb r3, [ip], #0x01 /* Set 1 byte */
225 1.1 christos cmp r2, #0x02
226 1.1 christos strgeb r3, [ip], #0x01 /* Set another byte */
227 1.1 christos sub r1, r1, r2
228 1.1 christos strgtb r3, [ip], #0x01 /* and a third */
229 1.1 christos cmp r1, #0x04 /* More than 4 bytes left? */
230 1.1 christos bge .Lmemset_wordaligned /* Yup */
231 1.1 christos
232 1.1 christos .Lmemset_lessthanfour:
233 1.1 christos cmp r1, #0x00
234 1.1 christos RETc(eq) /* Zero length so exit */
235 1.1 christos strb r3, [ip], #0x01 /* Set 1 byte */
236 1.1 christos cmp r1, #0x02
237 1.1 christos strgeb r3, [ip], #0x01 /* Set another byte */
238 1.1 christos strgtb r3, [ip] /* and a third */
239 1.1 christos RET /* Exit */
240