]> git.saurik.com Git - apple/libc.git/blob - i386/string/bcopy_scalar.s
Libc-825.40.1.tar.gz
[apple/libc.git] / i386 / string / bcopy_scalar.s
1 /*
2 * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*-
30 * Copyright (c) 1990 The Regents of the University of California.
31 * All rights reserved.
32 *
33 * This code is derived from locore.s.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 */
63
64 #include <sys/appleapiopts.h>
65 #include <machine/cpu_capabilities.h>
66 #include <platfunc.h>
67 #include <machine/asm.h>
68
69 /*
70 * (ov)bcopy (src,dst,cnt)
71 * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
72 */
73
74 PLATFUNC_FUNCTION_START_GENERIC(bcopy, scalar, 32, 5)
75 pushl %ebp /* set up a frame for backtraces */
76 movl %esp,%ebp
77 pushl %esi
78 pushl %edi
79 movl 8(%ebp),%esi
80 movl 12(%ebp),%edi
81 jmp 1f
82
83 PLATFUNC_FUNCTION_START_GENERIC(memcpy, scalar, 32, 0)
84 PLATFUNC_FUNCTION_START_GENERIC(memmove, scalar, 32, 0)
85 pushl %ebp /* set up a frame for backtraces */
86 movl %esp,%ebp
87 pushl %esi
88 pushl %edi
89 movl 8(%ebp),%edi
90 movl 12(%ebp),%esi
91 movl %edi,%eax
92 1:
93 movl 16(%ebp),%ecx
94 movl %edi,%edx
95 subl %esi,%edx
96 cmpl %ecx,%edx /* overlapping? */
97 jb 2f
98 cld /* nope, copy forwards. */
99 movl %ecx,%edx
100 shrl $2,%ecx /* copy by words */
101 rep
102 movsl
103 movl %edx,%ecx
104 andl $3,%ecx /* any bytes left? */
105 rep
106 movsb
107 popl %edi
108 popl %esi
109 popl %ebp
110 ret
111 2:
112 addl %ecx,%edi /* copy backwards. */
113 addl %ecx,%esi
114 std
115 movl %ecx,%edx
116 andl $3,%ecx /* any fractional bytes? */
117 decl %edi
118 decl %esi
119 rep
120 movsb
121 movl %edx,%ecx /* copy remainder by words */
122 shrl $2,%ecx
123 subl $3,%esi
124 subl $3,%edi
125 rep
126 movsl
127 popl %edi
128 popl %esi
129 popl %ebp
130 cld
131 ret
132
133 PLATFUNC_DESCRIPTOR(bcopy,scalar,0,0)
134 PLATFUNC_DESCRIPTOR(memcpy,scalar,0,0)
135 PLATFUNC_DESCRIPTOR(memmove,scalar,0,0)