1 /* $NetBSD: bcopy.S,v 1.2 2005/12/27 11:23:53 tsutsui Exp $ */
4 * Mach Operating System
5 * Copyright (c) 1993 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
34 * Fast copy routine. Derived from aligned_block_copy.
38 #include <machine/asm.h>
39 __FBSDID("$FreeBSD$");
41 #if defined(LIBC_SCCS) && !defined(lint)
42 ASMSTR("from: @(#)mips_bcopy.s 2.2 CMU 18/06/93")
43 ASMSTR("$NetBSD: bcopy.S,v 1.2 2005/12/27 11:23:53 tsutsui Exp $")
44 #endif /* LIBC_SCCS and not lint */
51 * bcopy(caddr_t src, caddr_t dst, unsigned int len)
58 #if defined(MEMCOPY) || defined(MEMMOVE)
60 #define FUNCTION memcpy
62 #define FUNCTION memmove
67 #define FUNCTION bcopy
78 #if defined(MEMCOPY) || defined(MEMMOVE)
79 /* set up return value, while we still can */
83 * Make sure we can copy forwards.
85 sltu t0,SRCREG,DSTREG # t0 == SRCREG < DSTREG
86 bne t0,zero,6f # copy backwards
89 * There are four alignment cases (with frequency)
90 * (Based on measurements taken with a DECstation 5000/200
91 * inside a Mach kernel.)
93 * aligned -> aligned (mostly)
94 * unaligned -> aligned (sometimes)
95 * aligned,unaligned -> unaligned (almost never)
97 * Note that we could add another case that checks if
98 * the destination and source are unaligned but the
99 * copy is alignable. eg if src and dest are both
100 * on a halfword boundary.
102 andi t1,DSTREG,3 # get last 3 bits of dest
104 andi t0,SRCREG,3 # get last 3 bits of src
108 * Forward aligned->aligned copy, 8*4 bytes at a time.
111 and t0,SIZEREG,AT # count truncated to multiple of 32 */
112 addu a3,SRCREG,t0 # run fast loop up to this address
113 sltu AT,SRCREG,a3 # any work to do?
142 * Copy a word at a time, no loop unrolling.
145 andi t2,SIZEREG,3 # get byte count / 4
146 subu t2,SIZEREG,t2 # t2 = number of words to copy * 4
148 addu t0,SRCREG,t2 # stop at t0
149 subu SIZEREG,SIZEREG,t2
158 beq SIZEREG,zero,4f # nothing left to do?
173 * Copy from unaligned source to aligned dest.
176 andi t0,SIZEREG,3 # t0 = bytecount mod 4
177 subu a3,SIZEREG,t0 # number of words to transfer
180 move SIZEREG,t0 # this many to do after we are done
181 addu a3,SRCREG,a3 # stop point
199 6: # backcopy -- based on above
202 andi t1,DSTREG,3 # get last 3 bits of dest
204 andi t0,SRCREG,3 # get last 3 bits of src
208 * Forward aligned->aligned copy, 8*4 bytes at a time.
211 and t0,SIZEREG,AT # count truncated to multiple of 32
212 beq t0,zero,2f # any work to do?
241 * Copy a word at a time, no loop unrolling.
244 andi t2,SIZEREG,3 # get byte count / 4
245 subu t2,SIZEREG,t2 # t2 = number of words to copy * 4
247 subu t0,SRCREG,t2 # stop at t0
248 subu SIZEREG,SIZEREG,t2
257 beq SIZEREG,zero,4f # nothing left to do?
272 * Copy from unaligned source to aligned dest.
275 andi t0,SIZEREG,3 # t0 = bytecount mod 4
276 subu a3,SIZEREG,t0 # number of words to transfer
279 move SIZEREG,t0 # this many to do after we are done
280 subu a3,SRCREG,a3 # stop point