1 /* $NetBSD: memcpy.S,v 1.2 2006/04/22 23:53:47 uwe Exp $ */
4 * Copyright (c) 2000 SHIMIZU Ryo <ryo@misakimix.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <machine/asm.h>
32 #if defined(LIBC_SCCS) && !defined(lint)
33 RCSID("$NetBSD: memcpy.S,v 1.2 2006/04/22 23:53:47 uwe Exp $")
36 #if !defined(MEMCOPY) && !defined(MEMMOVE) && !defined(BCOPY)
40 #if defined(MEMCOPY) || defined(MEMMOVE)
53 #elif defined(MEMMOVE)
61 cmp/eq REG_DST,REG_SRC /* if ( src == dst ) return; */
63 cmp/hi REG_DST,REG_SRC
70 tst r0,r0 /* (src ^ dst) & 3 */
74 tst REG_LEN,REG_LEN /* if ( len==0 ) return; */
79 tst #1,r0 /* if ( src & 1 ) */
81 mov.b @REG_SRC+,r0 /* *dst++ = *src++; */
89 cmp/hi r0,REG_LEN /* if ( (len > 1) && */
92 tst #2,r0 /* (src & 2) { */
94 mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */
95 add #-2,REG_LEN /* len -= 2; */
97 add #2,REG_DST /* } */
102 cmp/hi r1,REG_LEN /* while ( len > 3 ) { */
106 mov.l @REG_SRC+,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */
107 add #-4,REG_LEN /* len -= 4; */
111 add #4,REG_DST /* } */
121 tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */
125 mov REG_SRC,r0 /* if ( src & 1 ) */
128 mov.b @REG_SRC+,r0 /* *dst++ = *src++; */
136 cmp/hi r1,REG_LEN /* while ( len > 1 ) { */
140 mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */
141 add #-2,REG_LEN /* len -= 2; */
145 add #2,REG_DST /* } */
149 tst REG_LEN,REG_LEN /* while ( len!= ) { */
153 mov.b @REG_SRC+,r0 /* *dst++ = *src++; */
154 add #-1,REG_LEN /* len--; */
158 add #1,REG_DST /* } */
176 tst r0,r0 /* (src ^ dst) & 3 */
180 tst REG_LEN,REG_LEN /* if ( len==0 ) return; */
185 tst #1,r0 /* if ( src & 1 ) */
187 add #-1,REG_SRC /* *--dst = *--src; */
195 cmp/hi r0,REG_LEN /* if ( (len > 1) && */
198 tst #2,r0 /* (src & 2) { */
200 add #-2,REG_SRC /* *--((unsigned short*)dst) = *--((unsigned short*)src); */
202 add #-2,REG_LEN /* len -= 2; */
203 mov.w r0,@-REG_DST /* } */
208 cmp/hi r1,REG_LEN /* while ( len > 3 ) { */
209 bf/s ov_no_align_delay
213 mov.l @REG_SRC,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */
214 add #-4,REG_LEN /* len -= 4; */
217 mov.l r0,@-REG_DST /* } */
219 bra ov_no_align_delay
226 bf/s ov_no_align_delay
227 tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */
231 mov REG_SRC,r0 /* if ( src & 1 ) */
235 mov.b @REG_SRC,r0 /* *--dst = *--src; */
242 cmp/hi r1,REG_LEN /* while ( len > 1 ) { */
243 bf/s ov_no_align_delay
247 mov.w @REG_SRC,r0 /* *--((unsigned short*)dst) = *--((unsigned short*)src); */
248 add #-2,REG_LEN /* len -= 2; */
251 mov.w r0,@-REG_DST /* } */
255 tst REG_LEN,REG_LEN /* while ( len!= ) { */
260 mov.b @REG_SRC,r0 /* *--dst = *--src; */
261 add #-1,REG_LEN /* len--; */
264 mov.b r0,@-REG_DST /* } */