1 /* $Id: U3memcpy.S,v 1.2 2000/11/01 09:29:19 davem Exp $
2 * U3memcpy.S: UltraSparc-III optimized memcpy.
4 * Copyright (C) 1999, 2000 David S. Miller (davem@redhat.com)
8 #include <asm/visasm.h>
11 #include <asm/spitfire.h>
12 #undef SMALL_COPY_USES_FPU
14 #define ASI_BLK_P 0xf0
16 #define VISEntryHalf rd %fprs, %o5; wr %g0, FPRS_FEF, %fprs
17 #define VISExitHalf and %o5, FPRS_FEF, %o5; wr %o5, 0x0, %fprs
18 #define SMALL_COPY_USES_FPU
21 /* Special/non-trivial issues of this code:
23 * 1) %o5 is preserved from VISEntryHalf to VISExitHalf
24 * 2) Only low 32 FPU registers are used so that only the
25 * lower half of the FPU register set is dirtied by this
26 * code. This is especially important in the kernel.
27 * 3) This code never prefetches cachelines past the end
28 * of the source buffer.
34 /* The cheetah's flexible spine, oversized liver, enlarged heart,
35 * slender muscular body, and claws make it the swiftest hunter
36 * in Africa and the fastest animal on land. Can reach speeds
37 * of up to 2.4GB per second.
41 U3memcpy: /* %o0=dst, %o1=src, %o2=len */
43 /* Save away original 'dst' for memcpy return value. */
44 mov %o0, %g3 ! A0 Group
46 /* Anything to copy at all? */
48 ble,pn %icc, U3memcpy_short_ret ! BR
50 /* Extremely small copy? */
51 cmp %o2, 31 ! A0 Group
52 ble,pn %icc, U3memcpy_short ! BR
54 /* Large enough to use unrolled prefetch loops? */
56 bge,a,pt %icc, U3memcpy_enter ! BR Group
57 andcc %o0, 0x3f, %g2 ! A0
59 ba,pt %xcc, U3memcpy_toosmall ! BR Group
60 andcc %o0, 0x7, %g2 ! A0
64 /* Copy %o2 bytes from src to dst, one byte at a time. */
65 ldub [%o1 + 0x00], %o3 ! MS Group
66 add %o1, 0x1, %o1 ! A0
67 add %o0, 0x1, %o0 ! A1
68 subcc %o2, 1, %o2 ! A0 Group
70 bg,pt %icc, U3memcpy_short ! BR
71 stb %o3, [%o0 + -1] ! MS Group (1-cycle stall)
75 retl ! BR Group (0-4 cycle stall)
78 retl ! BR Group (0-4 cycle stall)
82 /* Here len >= (6 * 64) and condition codes reflect execution
83 * of "andcc %o0, 0x7, %g2", done by caller.
87 /* Is 'dst' already aligned on an 64-byte boundary? */
90 /* Compute abs((dst & 0x3f) - 0x40) into %g2. This is the number
91 * of bytes to copy to make 'dst' 64-byte aligned. We pre-
92 * subtract this from 'len'.
94 sub %g2, 0x40, %g2 ! A0 Group
95 sub %g0, %g2, %g2 ! A0 Group
96 sub %o2, %g2, %o2 ! A0 Group
98 /* Copy %g2 bytes from src to dst, one byte at a time. */
99 1: ldub [%o1 + 0x00], %o3 ! MS (Group)
100 add %o1, 0x1, %o1 ! A1
101 add %o0, 0x1, %o0 ! A0 Group
102 subcc %g2, 0x1, %g2 ! A1
104 bg,pt %icc, 1b ! BR Group
105 stb %o3, [%o0 + -1] ! MS Group
107 2: VISEntryHalf ! MS+MS
108 and %o1, 0x7, %g1 ! A1
109 ba,pt %xcc, U3memcpy_begin ! BR
110 alignaddr %o1, %g0, %o1 ! MS (Break-after)
115 .globl U3memcpy_nop_1_6
117 ldxa [%g0] ASI_DCU_CONTROL_REG, %g3
118 sethi %uhi(DCU_PE), %o3
121 stxa %o3, [%g0] ASI_DCU_CONTROL_REG ! Enable P-cache
124 prefetch [%o1 + 0x000], #one_read ! MS Group1
125 prefetch [%o1 + 0x040], #one_read ! MS Group2
126 andn %o2, (0x40 - 1), %o4 ! A0
127 prefetch [%o1 + 0x080], #one_read ! MS Group3
129 prefetch [%o1 + 0x0c0], #one_read ! MS Group4
130 ldd [%o1 + 0x000], %f0 ! MS Group5 (%f0 results at G8)
131 bge,a,pt %icc, 1f ! BR
133 prefetch [%o1 + 0x100], #one_read ! MS Group6
134 1: ldd [%o1 + 0x008], %f2 ! AX (%f2 results at G9)
136 bge,a,pt %icc, 1f ! BR
137 prefetch [%o1 + 0x140], #one_read ! MS Group7
138 1: ldd [%o1 + 0x010], %f4 ! AX (%f4 results at G10)
140 bge,a,pt %icc, 1f ! BR
142 prefetch [%o1 + 0x180], #one_read ! MS Group8
143 1: faligndata %f0, %f2, %f16 ! FGA Group9 (%f16 at G12)
144 ldd [%o1 + 0x018], %f6 ! AX (%f6 results at G12)
145 faligndata %f2, %f4, %f18 ! FGA Group10 (%f18 results at G13)
146 ldd [%o1 + 0x020], %f8 ! MS (%f8 results at G13)
147 faligndata %f4, %f6, %f20 ! FGA Group12 (1-cycle stall,%f20 at G15)
148 ldd [%o1 + 0x028], %f10 ! MS (%f10 results at G15)
149 faligndata %f6, %f8, %f22 ! FGA Group13 (%f22 results at G16)
151 ldd [%o1 + 0x030], %f12 ! MS (%f12 results at G16)
152 faligndata %f8, %f10, %f24 ! FGA Group15 (1-cycle stall,%f24 at G18)
153 ldd [%o1 + 0x038], %f14 ! MS (%f14 results at G18)
154 faligndata %f10, %f12, %f26 ! FGA Group16 (%f26 results at G19)
155 ldd [%o1 + 0x040], %f0 ! MS (%f0 results at G19)
157 /* We only use the first loop if len > (7 * 64). */
158 subcc %o4, 0x1c0, %o4 ! A0 Group17
159 bg,pt %icc, U3memcpy_loop1 ! BR
160 add %o1, 0x40, %o1 ! A1
162 add %o4, 0x140, %o4 ! A0 Group18
163 ba,pt %xcc, U3memcpy_loop2 ! BR
164 srl %o4, 6, %o3 ! A0 Group19
174 /* This loop performs the copy and queues new prefetches.
175 * We drop into the second loop when len <= (5 * 64). Note
176 * that this (5 * 64) factor has been subtracted from len
180 ldd [%o1 + 0x008], %f2 ! MS Group2 (%f2 results at G5)
181 faligndata %f12, %f14, %f28 ! FGA (%f28 results at G5)
182 ldd [%o1 + 0x010], %f4 ! MS Group3 (%f4 results at G6)
183 faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall, %f30 at G7)
184 stda %f16, [%o0] ASI_BLK_P ! MS
185 ldd [%o1 + 0x018], %f6 ! AX (%f6 results at G7)
187 faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
188 ldd [%o1 + 0x020], %f8 ! MS (%f8 results at G15)
189 faligndata %f2, %f4, %f18 ! FGA Group13 (%f18 results at G16)
190 ldd [%o1 + 0x028], %f10 ! MS (%f10 results at G16)
191 faligndata %f4, %f6, %f20 ! FGA Group14 (%f20 results at G17)
192 ldd [%o1 + 0x030], %f12 ! MS (%f12 results at G17)
193 faligndata %f6, %f8, %f22 ! FGA Group15 (%f22 results at G18)
194 ldd [%o1 + 0x038], %f14 ! MS (%f14 results at G18)
196 faligndata %f8, %f10, %f24 ! FGA Group16 (%f24 results at G19)
197 ldd [%o1 + 0x040], %f0 ! AX (%f0 results at G19)
198 prefetch [%o1 + 0x180], #one_read ! MS
199 faligndata %f10, %f12, %f26 ! FGA Group17 (%f26 results at G20)
200 subcc %o4, 0x40, %o4 ! A0
201 add %o1, 0x40, %o1 ! A1
202 bg,pt %xcc, U3memcpy_loop1 ! BR
203 add %o0, 0x40, %o0 ! A0 Group18
205 U3memcpy_loop2_enter:
208 /* This loop performs on the copy, no new prefetches are
209 * queued. We do things this way so that we do not perform
210 * any spurious prefetches past the end of the src buffer.
213 ldd [%o1 + 0x008], %f2 ! MS
214 faligndata %f12, %f14, %f28 ! FGA Group2
215 ldd [%o1 + 0x010], %f4 ! MS
216 faligndata %f14, %f0, %f30 ! FGA Group4 (1-cycle stall)
217 stda %f16, [%o0] ASI_BLK_P ! MS
218 ldd [%o1 + 0x018], %f6 ! AX
219 faligndata %f0, %f2, %f16 ! FGA Group12 (7-cycle stall)
221 ldd [%o1 + 0x020], %f8 ! MS
222 faligndata %f2, %f4, %f18 ! FGA Group13
223 ldd [%o1 + 0x028], %f10 ! MS
224 faligndata %f4, %f6, %f20 ! FGA Group14
225 ldd [%o1 + 0x030], %f12 ! MS
226 faligndata %f6, %f8, %f22 ! FGA Group15
227 ldd [%o1 + 0x038], %f14 ! MS
228 faligndata %f8, %f10, %f24 ! FGA Group16
230 ldd [%o1 + 0x040], %f0 ! AX
231 faligndata %f10, %f12, %f26 ! FGA Group17
232 subcc %o3, 0x01, %o3 ! A0
233 add %o1, 0x40, %o1 ! A1
234 bg,pt %xcc, U3memcpy_loop2 ! BR
235 add %o0, 0x40, %o0 ! A0 Group18
237 /* Finally we copy the last full 64-byte block. */
239 ldd [%o1 + 0x008], %f2 ! MS
240 faligndata %f12, %f14, %f28 ! FGA
241 ldd [%o1 + 0x010], %f4 ! MS Group19
242 faligndata %f14, %f0, %f30 ! FGA
243 stda %f16, [%o0] ASI_BLK_P ! MS Group20
244 ldd [%o1 + 0x018], %f6 ! AX
245 faligndata %f0, %f2, %f16 ! FGA Group11 (7-cycle stall)
246 ldd [%o1 + 0x020], %f8 ! MS
247 faligndata %f2, %f4, %f18 ! FGA Group12
248 ldd [%o1 + 0x028], %f10 ! MS
249 faligndata %f4, %f6, %f20 ! FGA Group13
250 ldd [%o1 + 0x030], %f12 ! MS
251 faligndata %f6, %f8, %f22 ! FGA Group14
252 ldd [%o1 + 0x038], %f14 ! MS
253 faligndata %f8, %f10, %f24 ! FGA Group15
256 add %o0, 0x40, %o0 ! A1
257 ldd [%o1 + 0x040], %f0 ! MS
258 1: faligndata %f10, %f12, %f26 ! FGA Group16
259 faligndata %f12, %f14, %f28 ! FGA Group17
260 faligndata %f14, %f0, %f30 ! FGA Group18
261 stda %f16, [%o0] ASI_BLK_P ! MS
262 add %o0, 0x40, %o0 ! A0
263 add %o1, 0x40, %o1 ! A1
265 .globl U3memcpy_nop_2_3
267 mov PRIMARY_CONTEXT, %o3
268 stxa %g0, [%o3] ASI_DMMU ! Flush P-cache
269 stxa %g3, [%g0] ASI_DCU_CONTROL_REG ! Disable P-cache
271 membar #Sync ! MS Group26 (7-cycle stall)
273 /* Now we copy the (len modulo 64) bytes at the end.
274 * Note how we borrow the %f0 loaded above.
276 * Also notice how this code is careful not to perform a
277 * load past the end of the src buffer just like similar
278 * code found in U3memcpy_toosmall processing.
281 and %o2, 0x3f, %o2 ! A0 Group
282 andcc %o2, 0x38, %g2 ! A0 Group
283 be,pn %icc, U3memcpy_endcruft ! BR
284 subcc %g2, 0x8, %g2 ! A1
285 be,pn %icc, U3memcpy_endcruft ! BR Group
288 be,a,pt %icc, 1f ! BR Group
289 ldd [%o1 + 0x00], %f0 ! MS
291 1: ldd [%o1 + 0x08], %f2 ! MS Group
292 add %o1, 0x8, %o1 ! A0
293 sub %o2, 0x8, %o2 ! A1
294 subcc %g2, 0x8, %g2 ! A0 Group
295 faligndata %f0, %f2, %f8 ! FGA Group
296 std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
297 be,pn %icc, U3memcpy_endcruft ! BR
298 add %o0, 0x8, %o0 ! A0
299 ldd [%o1 + 0x08], %f0 ! MS Group
300 add %o1, 0x8, %o1 ! A0
301 sub %o2, 0x8, %o2 ! A1
302 subcc %g2, 0x8, %g2 ! A0 Group
303 faligndata %f2, %f0, %f8 ! FGA
304 std %f8, [%o0 + 0x00] ! MS (XXX does it stall here? XXX)
306 add %o0, 0x8, %o0 ! A0 Group
308 /* If anything is left, we copy it one byte at a time.
309 * Note that %g1 is (src & 0x3) saved above before the
310 * alignaddr was performed.
316 be,pn %icc, U3memcpy_short_ret
318 ba,a,pt %xcc, U3memcpy_short
320 /* If we get here, then 32 <= len < (6 * 64) */
323 #ifdef SMALL_COPY_USES_FPU
325 /* Is 'dst' already aligned on an 8-byte boundary? */
326 be,pt %xcc, 2f ! BR Group
328 /* Compute abs((dst & 7) - 8) into %g2. This is the number
329 * of bytes to copy to make 'dst' 8-byte aligned. We pre-
330 * subtract this from 'len'.
332 sub %g2, 0x8, %g2 ! A0
333 sub %g0, %g2, %g2 ! A0 Group (reg-dep)
334 sub %o2, %g2, %o2 ! A0 Group (reg-dep)
336 /* Copy %g2 bytes from src to dst, one byte at a time. */
337 1: ldub [%o1 + 0x00], %o3 ! MS (Group) (%o3 in 3 cycles)
338 add %o1, 0x1, %o1 ! A1
339 add %o0, 0x1, %o0 ! A0 Group
340 subcc %g2, 0x1, %g2 ! A1
342 bg,pt %icc, 1b ! BR Group
343 stb %o3, [%o0 + -1] ! MS Group
345 2: VISEntryHalf ! MS+MS
347 /* Compute (len - (len % 8)) into %g2. This is guaranteed
350 andn %o2, 0x7, %g2 ! A0 Group
352 /* You may read this and believe that it allows reading
353 * one 8-byte longword past the end of src. It actually
354 * does not, as %g2 is subtracted as loads are done from
355 * src, so we always stop before running off the end.
356 * Also, we are guaranteed to have at least 0x10 bytes
359 sub %g2, 0x8, %g2 ! A0 Group (reg-dep)
360 alignaddr %o1, %g0, %g1 ! MS (Break-after)
361 ldd [%g1 + 0x00], %f0 ! MS Group (1-cycle stall)
362 add %g1, 0x8, %g1 ! A0
364 1: ldd [%g1 + 0x00], %f2 ! MS Group
365 add %g1, 0x8, %g1 ! A0
366 sub %o2, 0x8, %o2 ! A1
367 subcc %g2, 0x8, %g2 ! A0 Group
369 faligndata %f0, %f2, %f8 ! FGA Group (1-cycle stall)
370 std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
371 add %o1, 0x8, %o1 ! A0
374 add %o0, 0x8, %o0 ! A1
375 ldd [%g1 + 0x00], %f0 ! MS Group
376 add %g1, 0x8, %g1 ! A0
377 sub %o2, 0x8, %o2 ! A1
379 subcc %g2, 0x8, %g2 ! A0 Group
380 faligndata %f2, %f0, %f8 ! FGA Group (1-cycle stall)
381 std %f8, [%o0 + 0x00] ! MS Group (2-cycle stall)
382 add %o1, 0x8, %o1 ! A0
385 add %o0, 0x8, %o0 ! A1
387 /* Nothing left to copy? */
388 2: cmp %o2, 0 ! A0 Group
390 be,pn %icc, U3memcpy_short_ret ! BR Group
392 ba,a,pt %xcc, U3memcpy_short ! BR Group
394 #else /* !(SMALL_COPY_USES_FPU) */
398 bne,pn %icc, U3memcpy_short
406 1: ldub [%o1 + 0x00], %o3
413 2: andn %o2, 0x7, %g2
416 3: ldx [%o1 + 0x00], %o3
424 bne,pn %icc, U3memcpy_short
426 ba,a,pt %xcc, U3memcpy_short_ret
428 #endif /* !(SMALL_COPY_USES_FPU) */