1 /* $NetBSD: memset.S,v 1.2 2008/02/16 17:37:13 apb Exp $ */
4 * Copyright (c) 2002 SHIMIZU Ryo. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <machine/asm.h>
31 #if defined(LIBC_SCCS) && !defined(lint)
32 RCSID("$NetBSD: memset.S,v 1.2 2008/02/16 17:37:13 apb Exp $")
53 mov REG_DST,REG_DST0 /* for return value */
55 /* small amount to fill ? */
57 cmp/hs REG_TMP1,REG_LEN /* if (len >= 28) goto large; */
59 mov #12,REG_TMP1 /* if (len >= 12) goto small; */
60 cmp/hs REG_TMP1,REG_LEN
65 /* very little fill (0 ~ 11 bytes) */
72 cmp/eq REG_DST,REG_LEN
73 1: mov.b REG_C,@-REG_LEN
75 cmp/eq REG_DST,REG_LEN
78 cmp/eq REG_DST,REG_LEN
81 cmp/eq REG_DST,REG_LEN
84 cmp/eq REG_DST,REG_LEN
101 mova 1f,r0 /* 1f must be 4bytes aligned! */
102 add #16,REG_TMP1 /* REG_TMP1 = dst+16; */
108 mov.b r0,@(15,REG_TMP1)
109 mov.b r0,@(14,REG_TMP1)
110 mov.b r0,@(13,REG_TMP1)
111 mov.b r0,@(12,REG_TMP1)
112 mov.b r0,@(11,REG_TMP1)
113 mov.b r0,@(10,REG_TMP1)
114 mov.b r0,@(9,REG_TMP1)
115 mov.b r0,@(8,REG_TMP1)
116 mov.b r0,@(7,REG_TMP1)
117 mov.b r0,@(6,REG_TMP1)
118 mov.b r0,@(5,REG_TMP1)
119 mov.b r0,@(4,REG_TMP1)
120 mov.b r0,@(3,REG_TMP1)
121 mov.b r0,@(2,REG_TMP1)
122 mov.b r0,@(1,REG_TMP1)
124 mov.b r0,@(15,REG_DST)
125 mov.b r0,@(14,REG_DST)
126 mov.b r0,@(13,REG_DST)
127 mov.b r0,@(12,REG_DST)
128 mov.b r0,@(11,REG_DST)
129 mov.b r0,@(10,REG_DST)
130 mov.b r0,@(9,REG_DST)
131 mov.b r0,@(8,REG_DST)
132 mov.b r0,@(7,REG_DST)
133 mov.b r0,@(6,REG_DST)
134 mov.b r0,@(5,REG_DST)
135 mov.b r0,@(4,REG_DST)
136 mov.b r0,@(3,REG_DST)
137 mov.b r0,@(2,REG_DST)
138 mov.b r0,@(1,REG_DST)
149 /* 2 bytes aligned small fill */
152 extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */
153 shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */
154 or REG_TMP1,REG_C /* REG_C = ????xxxx */
158 tst #1,r0 /* len is aligned? */
161 mov.b REG_C,@(r0,REG_DST) /* fill last a byte */
165 mova 1f,r0 /* 1f must be 4bytes aligned! */
171 mov.w r0,@(30,REG_DST)
172 mov.w r0,@(28,REG_DST)
173 mov.w r0,@(26,REG_DST)
174 mov.w r0,@(24,REG_DST)
175 mov.w r0,@(22,REG_DST)
176 mov.w r0,@(20,REG_DST)
177 mov.w r0,@(18,REG_DST)
178 mov.w r0,@(16,REG_DST)
179 mov.w r0,@(14,REG_DST)
180 mov.w r0,@(12,REG_DST)
181 mov.w r0,@(10,REG_DST)
182 mov.w r0,@(8,REG_DST)
183 mov.w r0,@(6,REG_DST)
184 mov.w r0,@(4,REG_DST)
185 mov.w r0,@(2,REG_DST)
202 extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */
203 shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */
204 or REG_C,REG_TMP1 /* REG_C = ????xx00, REG_TMP1 = ????xxxx */
205 swap.w REG_TMP1,REG_C /* REG_C = xxxx????, REG_TMP1 = ????xxxx */
206 xtrct REG_TMP1,REG_C /* REG_C = xxxxxxxx */
213 add REG_LEN,REG_PTR /* REG_PTR = dst + len; */
218 /* fill 32*n bytes */
220 cmp/hi REG_LEN,REG_TMP1
223 1: sub REG_TMP1,REG_PTR
226 mov.l REG_C,@(4,REG_PTR)
227 cmp/hi REG_LEN,REG_TMP1
228 mov.l REG_C,@(8,REG_PTR)
229 mov.l REG_C,@(12,REG_PTR)
230 mov.l REG_C,@(16,REG_PTR)
231 mov.l REG_C,@(20,REG_PTR)
232 mov.l REG_C,@(24,REG_PTR)
234 mov.l REG_C,@(28,REG_PTR)
237 /* fill left 4*n bytes */
238 cmp/eq REG_DST,REG_PTR
241 cmp/eq REG_DST,REG_PTR
242 1: mov.l REG_C,@-REG_PTR
244 cmp/eq REG_DST,REG_PTR
245 mov.l REG_C,@-REG_PTR
247 cmp/eq REG_DST,REG_PTR
248 mov.l REG_C,@-REG_PTR
250 cmp/eq REG_DST,REG_PTR
251 mov.l REG_C,@-REG_PTR
253 cmp/eq REG_DST,REG_PTR
266 tst REG_TMP1,REG_DST /* if (dst & 1) { */
270 mov.b REG_C,@REG_DST /* *dst++ = c; */
276 mov.w REG_C,@REG_DST /* *(uint16_t*)dst++ = c; */
281 tst #3,REG_PTR /* if (ptr & 3) { */
284 tst #1,REG_PTR /* if (ptr & 1) { */
287 mov.b REG_C,@-REG_PTR /* --ptr = c; */
291 mov.w REG_C,@-REG_PTR /* *--(uint16_t*)ptr = c; */