1 /* $NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt 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 #include <machine/endian.h>
43 #if defined(LIBC_SCCS) && !defined(lint)
45 ASMSTR("from: @(#)mips_bcopy.s 2.2 CMU 18/06/93")
47 ASMSTR("$NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $")
49 #endif /* LIBC_SCCS and not lint */
56 * bcopy(caddr_t src, caddr_t dst, unsigned int len)
78 * Make sure we can copy forwards.
80 sltu t0,SRCREG,DSTREG # t0 == SRCREG < DSTREG
81 bne t0,zero,6f # copy backwards
84 * There are four alignment cases (with frequency)
85 * (Based on measurements taken with a DECstation 5000/200
86 * inside a Mach kernel.)
88 * aligned -> aligned (mostly)
89 * unaligned -> aligned (sometimes)
90 * aligned,unaligned -> unaligned (almost never)
92 * Note that we could add another case that checks if
93 * the destination and source are unaligned but the
94 * copy is alignable. eg if src and dest are both
95 * on a halfword boundary.
97 andi t1,DSTREG,(SZREG-1) # get last bits of dest
98 bne t1,zero,3f # dest unaligned
99 andi t0,SRCREG,(SZREG-1) # get last bits of src
103 * Forward aligned->aligned copy, 8 words at a time.
107 and t0,SIZEREG,AT # count truncated to multiples
108 PTR_ADDU a3,SRCREG,t0 # run fast loop up to this addr
109 sltu AT,SRCREG,a3 # any work to do?
117 REG_L t3,(0*SZREG)(SRCREG)
118 REG_L v1,(1*SZREG)(SRCREG)
119 REG_L t0,(2*SZREG)(SRCREG)
120 REG_L t1,(3*SZREG)(SRCREG)
121 PTR_ADDU SRCREG,SZREG*8
122 REG_S t3,(0*SZREG)(DSTREG)
123 REG_S v1,(1*SZREG)(DSTREG)
124 REG_S t0,(2*SZREG)(DSTREG)
125 REG_S t1,(3*SZREG)(DSTREG)
126 REG_L t1,(-1*SZREG)(SRCREG)
127 REG_L t0,(-2*SZREG)(SRCREG)
128 REG_L v1,(-3*SZREG)(SRCREG)
129 REG_L t3,(-4*SZREG)(SRCREG)
130 PTR_ADDU DSTREG,SZREG*8
131 REG_S t1,(-1*SZREG)(DSTREG)
132 REG_S t0,(-2*SZREG)(DSTREG)
133 REG_S v1,(-3*SZREG)(DSTREG)
135 REG_S t3,(-4*SZREG)(DSTREG)
138 * Copy a word at a time, no loop unrolling.
141 andi t2,SIZEREG,(SZREG-1) # get byte count / SZREG
142 PTR_SUBU t2,SIZEREG,t2 # t2 = words to copy * SZREG
144 PTR_ADDU t0,SRCREG,t2 # stop at t0
145 PTR_SUBU SIZEREG,SIZEREG,t2
148 PTR_ADDU SRCREG,SZREG
151 PTR_ADDU DSTREG,SZREG
154 beq SIZEREG,zero,4f # nothing left to do?
169 * Copy from unaligned source to aligned dest.
172 andi t0,SIZEREG,(SZREG-1) # t0 = bytecount mod SZREG
173 PTR_SUBU a3,SIZEREG,t0 # number of words to transfer
176 move SIZEREG,t0 # this many to do after we are done
177 PTR_ADDU a3,SRCREG,a3 # stop point
181 REG_LLO t3,SZREG-1(SRCREG)
182 PTR_ADDI SRCREG,SZREG
185 PTR_ADDI DSTREG,SZREG
190 6: # backcopy -- based on above
191 PTR_ADDU SRCREG,SIZEREG
192 PTR_ADDU DSTREG,SIZEREG
193 andi t1,DSTREG,SZREG-1 # get last 3 bits of dest
195 andi t0,SRCREG,SZREG-1 # get last 3 bits of src
199 * Forward aligned->aligned copy, 8*4 bytes at a time.
202 and t0,SIZEREG,AT # count truncated to multiple of 32
203 beq t0,zero,2f # any work to do?
205 PTR_SUBU a3,SRCREG,t0
211 REG_L t3,(-4*SZREG)(SRCREG)
212 REG_L v1,(-3*SZREG)(SRCREG)
213 REG_L t0,(-2*SZREG)(SRCREG)
214 REG_L t1,(-1*SZREG)(SRCREG)
215 PTR_SUBU SRCREG,8*SZREG
216 REG_S t3,(-4*SZREG)(DSTREG)
217 REG_S v1,(-3*SZREG)(DSTREG)
218 REG_S t0,(-2*SZREG)(DSTREG)
219 REG_S t1,(-1*SZREG)(DSTREG)
220 REG_L t1,(3*SZREG)(SRCREG)
221 REG_L t0,(2*SZREG)(SRCREG)
222 REG_L v1,(1*SZREG)(SRCREG)
223 REG_L t3,(0*SZREG)(SRCREG)
224 PTR_SUBU DSTREG,8*SZREG
225 REG_S t1,(3*SZREG)(DSTREG)
226 REG_S t0,(2*SZREG)(DSTREG)
227 REG_S v1,(1*SZREG)(DSTREG)
229 REG_S t3,(0*SZREG)(DSTREG)
232 * Copy a word at a time, no loop unrolling.
235 andi t2,SIZEREG,SZREG-1 # get byte count / 4
236 PTR_SUBU t2,SIZEREG,t2 # t2 = number of words to copy
238 PTR_SUBU t0,SRCREG,t2 # stop at t0
239 PTR_SUBU SIZEREG,SIZEREG,t2
241 REG_L t3,-SZREG(SRCREG)
242 PTR_SUBU SRCREG,SZREG
243 REG_S t3,-SZREG(DSTREG)
245 PTR_SUBU DSTREG,SZREG
248 beq SIZEREG,zero,4f # nothing left to do?
263 * Copy from unaligned source to aligned dest.
266 andi t0,SIZEREG,SZREG-1 # t0 = bytecount mod 4
267 PTR_SUBU a3,SIZEREG,t0 # number of words to transfer
270 move SIZEREG,t0 # this many to do after we are done
271 PTR_SUBU a3,SRCREG,a3 # stop point
274 REG_LHI t3,-SZREG(SRCREG)
275 REG_LLO t3,-1(SRCREG)
276 PTR_SUBU SRCREG,SZREG
277 REG_S t3,-SZREG(DSTREG)
279 PTR_SUBU DSTREG,SZREG