memcpy.S revision 1.1 1 /* $NetBSD: memcpy.S,v 1.1 2008/02/21 17:35:47 garbled Exp $ */
2
3 /* stropt/memcpy_440.S, pl_string_common, pl_linux 10/11/04 11:45:36
4 * ==========================================================================
5 * Optimized memcpy implementation for IBM PowerPC 440.
6 *
7 * Copyright (c) 2003, IBM Corporation
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * * Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 * * Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials
20 * provided with the distribution.
21 * * Neither the name of IBM nor the names of its contributors
22 * may be used to endorse or promote products derived from this
23 * software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
31 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
34 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 * ==========================================================================
39 *
40 * Function: Copy n bytes of the source to the destination. Behavior is
41 * undefined for objects that overlap.
42 *
43 *
44 * void *memcpy(void * dest, const void * src, int n)
45 *
46 * Input: r3 - destination address
47 * r4 - source address
48 * r5 - byte count
49 * Output: r3 - destination address
50 *
51 * ==========================================================================
52 */
53
54 #define _NOREGNAMES
55 #include <machine/asm.h>
56 #ifdef _KERNEL
57 #include <assym.h>
58 #endif
59
60 .text
61 .align 4
62 /* LINTSTUB: Func: void *memcpy(void *, const void *, size_t) */
63 ENTRY(memcpy)
64 /*
65 * Check count passed in R5. If zero, return; otherwise continue.
66 */
67 cmpwi %r5,0
68 beqlr-
69
70 mr %r8, %r3 /* Copy dst (return value) */
71
72 addi %r4, %r4, -4 /* Prepare for main loop's auto */
73 addi %r8, %r8, -4 /* update */
74
75 srwi. %r9,%r5,2 /* Word count -> r9 */
76 beq- last1 /* Partial copy if <4 bytes */
77
78 mtctr %r9 /* Word cnt in CTR for loop */
79 lwzu %r7, 4(%r4) /* Preload for main loop */
80
81 b g1
82
83 g0: /* Main loop */
84
85 lwzu %r7, 4(%r4) /* Load a new word */
86 stwu %r6, 4(%r8) /* Store previous word */
87
88 g1:
89
90 bdz- last /* Dec ctr and exit loop if no */
91 /* more words */
92 lwzu %r6, 4(%r4) /* Load another word */
93 stwu %r7, 4(%r8) /* Store previous word */
94 bdnz+ g0 /* Dec ctr and continue loop if */
95 /* more words */
96
97 mr %r7, %r6
98
99 last:
100
101 stwu %r7, 4(%r8) /* Store last word */
102
103 last1: /* Byte-by-byte copy */
104
105 clrlwi. %r5,%r5,30
106 beqlr
107
108 mtctr %r5
109
110 lbzu %r6, 4(%r4) /* 1st byte: update by word */
111 stbu %r6, 4(%r8)
112 bdzlr-
113
114 last2:
115
116 lbzu %r6, 1(%r4) /* Handle the rest */
117 stbu %r6, 1(%r8)
118 bdnz+ last2
119
120 blr
121
122