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