1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
/* $NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $ */
/*
* Mach Operating System
* Copyright (c) 1993 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* File: mips_bcopy.s
* Author: Chris Maeda
* Date: June 1993
*
* Fast copy routine. Derived from aligned_block_copy.
*/
#include <machine/asm.h>
__FBSDID("$FreeBSD$");
#define _LOCORE /* XXX not really, just assembly-code source */
#include <machine/endian.h>
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
ASMSTR("from: @(#)mips_bcopy.s 2.2 CMU 18/06/93")
#else
ASMSTR("$NetBSD: bcopy.S,v 1.3 2009/12/14 00:39:00 matt Exp $")
#endif
#endif /* LIBC_SCCS and not lint */
#ifdef __ABICALLS__
.abicalls
#endif
/*
* bcopy(caddr_t src, caddr_t dst, unsigned int len)
*
* a0 src address
* a1 dst address
* a2 length
*/
#if defined(MEMCOPY) || defined(MEMMOVE)
#ifdef MEMCOPY
#define FUNCTION memcpy
#else
#define FUNCTION memmove
#endif
#define SRCREG a1
#define DSTREG a0
#else
#define FUNCTION bcopy
#define SRCREG a0
#define DSTREG a1
#endif
#define SIZEREG a2
LEAF(FUNCTION)
.set noat
.set noreorder
#if defined(MEMCOPY) || defined(MEMMOVE)
/* set up return value, while we still can */
move v0,DSTREG
#endif
/*
* Make sure we can copy forwards.
*/
sltu t0,SRCREG,DSTREG # t0 == SRCREG < DSTREG
bne t0,zero,6f # copy backwards
/*
* There are four alignment cases (with frequency)
* (Based on measurements taken with a DECstation 5000/200
* inside a Mach kernel.)
*
* aligned -> aligned (mostly)
* unaligned -> aligned (sometimes)
* aligned,unaligned -> unaligned (almost never)
*
* Note that we could add another case that checks if
* the destination and source are unaligned but the
* copy is alignable. eg if src and dest are both
* on a halfword boundary.
*/
andi t1,DSTREG,(SZREG-1) # get last bits of dest
bne t1,zero,3f # dest unaligned
andi t0,SRCREG,(SZREG-1) # get last bits of src
bne t0,zero,5f
/*
* Forward aligned->aligned copy, 8 words at a time.
*/
98:
li AT,-(SZREG*8)
and t0,SIZEREG,AT # count truncated to multiples
PTR_ADDU a3,SRCREG,t0 # run fast loop up to this addr
sltu AT,SRCREG,a3 # any work to do?
beq AT,zero,2f
PTR_SUBU SIZEREG,t0
/*
* loop body
*/
1: # cp
REG_L t3,(0*SZREG)(SRCREG)
REG_L v1,(1*SZREG)(SRCREG)
REG_L t0,(2*SZREG)(SRCREG)
REG_L t1,(3*SZREG)(SRCREG)
PTR_ADDU SRCREG,SZREG*8
REG_S t3,(0*SZREG)(DSTREG)
REG_S v1,(1*SZREG)(DSTREG)
REG_S t0,(2*SZREG)(DSTREG)
REG_S t1,(3*SZREG)(DSTREG)
REG_L t1,(-1*SZREG)(SRCREG)
REG_L t0,(-2*SZREG)(SRCREG)
REG_L v1,(-3*SZREG)(SRCREG)
REG_L t3,(-4*SZREG)(SRCREG)
PTR_ADDU DSTREG,SZREG*8
REG_S t1,(-1*SZREG)(DSTREG)
REG_S t0,(-2*SZREG)(DSTREG)
REG_S v1,(-3*SZREG)(DSTREG)
bne SRCREG,a3,1b
REG_S t3,(-4*SZREG)(DSTREG)
/*
* Copy a word at a time, no loop unrolling.
*/
2: # wordcopy
andi t2,SIZEREG,(SZREG-1) # get byte count / SZREG
PTR_SUBU t2,SIZEREG,t2 # t2 = words to copy * SZREG
beq t2,zero,3f
PTR_ADDU t0,SRCREG,t2 # stop at t0
PTR_SUBU SIZEREG,SIZEREG,t2
1:
REG_L t3,0(SRCREG)
PTR_ADDU SRCREG,SZREG
REG_S t3,0(DSTREG)
bne SRCREG,t0,1b
PTR_ADDU DSTREG,SZREG
3: # bytecopy
beq SIZEREG,zero,4f # nothing left to do?
nop
1:
lb t3,0(SRCREG)
PTR_ADDU SRCREG,1
sb t3,0(DSTREG)
PTR_SUBU SIZEREG,1
bgtz SIZEREG,1b
PTR_ADDU DSTREG,1
4: # copydone
j ra
nop
/*
* Copy from unaligned source to aligned dest.
*/
5: # destaligned
andi t0,SIZEREG,(SZREG-1) # t0 = bytecount mod SZREG
PTR_SUBU a3,SIZEREG,t0 # number of words to transfer
beq a3,zero,3b
nop
move SIZEREG,t0 # this many to do after we are done
PTR_ADDU a3,SRCREG,a3 # stop point
1:
REG_LHI t3,0(SRCREG)
REG_LLO t3,SZREG-1(SRCREG)
PTR_ADDI SRCREG,SZREG
REG_S t3,0(DSTREG)
bne SRCREG,a3,1b
PTR_ADDI DSTREG,SZREG
b 3b
nop
6: # backcopy -- based on above
PTR_ADDU SRCREG,SIZEREG
PTR_ADDU DSTREG,SIZEREG
andi t1,DSTREG,SZREG-1 # get last 3 bits of dest
bne t1,zero,3f
andi t0,SRCREG,SZREG-1 # get last 3 bits of src
bne t0,zero,5f
/*
* Forward aligned->aligned copy, 8*4 bytes at a time.
*/
li AT,(-8*SZREG)
and t0,SIZEREG,AT # count truncated to multiple of 32
beq t0,zero,2f # any work to do?
PTR_SUBU SIZEREG,t0
PTR_SUBU a3,SRCREG,t0
/*
* loop body
*/
1: # cp
REG_L t3,(-4*SZREG)(SRCREG)
REG_L v1,(-3*SZREG)(SRCREG)
REG_L t0,(-2*SZREG)(SRCREG)
REG_L t1,(-1*SZREG)(SRCREG)
PTR_SUBU SRCREG,8*SZREG
REG_S t3,(-4*SZREG)(DSTREG)
REG_S v1,(-3*SZREG)(DSTREG)
REG_S t0,(-2*SZREG)(DSTREG)
REG_S t1,(-1*SZREG)(DSTREG)
REG_L t1,(3*SZREG)(SRCREG)
REG_L t0,(2*SZREG)(SRCREG)
REG_L v1,(1*SZREG)(SRCREG)
REG_L t3,(0*SZREG)(SRCREG)
PTR_SUBU DSTREG,8*SZREG
REG_S t1,(3*SZREG)(DSTREG)
REG_S t0,(2*SZREG)(DSTREG)
REG_S v1,(1*SZREG)(DSTREG)
bne SRCREG,a3,1b
REG_S t3,(0*SZREG)(DSTREG)
/*
* Copy a word at a time, no loop unrolling.
*/
2: # wordcopy
andi t2,SIZEREG,SZREG-1 # get byte count / 4
PTR_SUBU t2,SIZEREG,t2 # t2 = number of words to copy
beq t2,zero,3f
PTR_SUBU t0,SRCREG,t2 # stop at t0
PTR_SUBU SIZEREG,SIZEREG,t2
1:
REG_L t3,-SZREG(SRCREG)
PTR_SUBU SRCREG,SZREG
REG_S t3,-SZREG(DSTREG)
bne SRCREG,t0,1b
PTR_SUBU DSTREG,SZREG
3: # bytecopy
beq SIZEREG,zero,4f # nothing left to do?
nop
1:
lb t3,-1(SRCREG)
PTR_SUBU SRCREG,1
sb t3,-1(DSTREG)
PTR_SUBU SIZEREG,1
bgtz SIZEREG,1b
PTR_SUBU DSTREG,1
4: # copydone
j ra
nop
/*
* Copy from unaligned source to aligned dest.
*/
5: # destaligned
andi t0,SIZEREG,SZREG-1 # t0 = bytecount mod 4
PTR_SUBU a3,SIZEREG,t0 # number of words to transfer
beq a3,zero,3b
nop
move SIZEREG,t0 # this many to do after we are done
PTR_SUBU a3,SRCREG,a3 # stop point
1:
REG_LHI t3,-SZREG(SRCREG)
REG_LLO t3,-1(SRCREG)
PTR_SUBU SRCREG,SZREG
REG_S t3,-SZREG(DSTREG)
bne SRCREG,a3,1b
PTR_SUBU DSTREG,SZREG
b 3b
nop
.set reorder
.set at
END(FUNCTION)
|