1/*	$OpenBSD: bcopy.S,v 1.5 2005/08/07 11:30:38 espie Exp $	*/
2
3/*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from locore.s.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <private/bionic_asm.h>
35
36	/*
37	 * (ov)bcopy (src,dst,cnt)
38	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
39	 */
40
41#if defined(MEMCOPY)
42ENTRY(memcpy)
43#elif defined(MEMMOVE)
44ENTRY(memmove)
45#else
46ENTRY(bcopy)
47#endif
48	pushl	%esi
49	pushl	%edi
50#if defined(MEMCOPY) || defined(MEMMOVE)
51	movl	12(%esp),%edi
52	movl	16(%esp),%esi
53	movl	%edi, %eax
54#else
55	movl	12(%esp),%esi
56	movl	16(%esp),%edi
57#endif
58	movl	20(%esp),%ecx
59	movl	%ecx,%edx
60	cmpl	%esi,%edi	/* potentially overlapping? */
61	jnb	1f
62	cld			/* nope, copy forwards. */
63	shrl	$2,%ecx		/* copy by words */
64	rep
65	movsl
66	movl	%edx,%ecx
67	andl	$3,%ecx		/* any bytes left? */
68	rep
69	movsb
70	popl	%edi
71	popl	%esi
72	ret
731:
74	addl	%ecx,%edi	/* copy backwards. */
75	addl	%ecx,%esi
76	std
77	andl	$3,%ecx		/* any fractional bytes? */
78	decl	%edi
79	decl	%esi
80	rep
81	movsb
82	movl	%edx,%ecx
83	shrl	$2,%ecx
84	subl	$3,%esi
85	subl	$3,%edi
86	rep
87	movsl
88	popl	%edi
89	popl	%esi
90	cld
91	ret
92#if defined(MEMCOPY)
93END(memcpy)
94#elif defined(MEMMOVE)
95END(memmove)
96#else
97END(bcopy)
98#endif
99