1144730Salc/*-
2144730Salc * Copyright (c) 1990 The Regents of the University of California.
3144730Salc * All rights reserved.
4144730Salc *
5144730Salc * This code is derived from locore.s.
6144730Salc *
7144730Salc * Redistribution and use in source and binary forms, with or without
8144730Salc * modification, are permitted provided that the following conditions
9144730Salc * are met:
10144730Salc * 1. Redistributions of source code must retain the above copyright
11144730Salc *    notice, this list of conditions and the following disclaimer.
12144730Salc * 2. Redistributions in binary form must reproduce the above copyright
13144730Salc *    notice, this list of conditions and the following disclaimer in the
14144730Salc *    documentation and/or other materials provided with the distribution.
15144730Salc * 3. Neither the name of the University nor the names of its contributors
16144730Salc *    may be used to endorse or promote products derived from this software
17144730Salc *    without specific prior written permission.
18144730Salc *
19144730Salc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20144730Salc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21144730Salc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22144730Salc * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23144730Salc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24144730Salc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25144730Salc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26144730Salc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27144730Salc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28144730Salc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29144730Salc * SUCH DAMAGE.
30144730Salc */
31144730Salc
32144730Salc#include <machine/asm.h>
33144730Salc__FBSDID("$FreeBSD$");
34144730Salc
35144730Salc#if 0
36144730Salc	RCSID("$NetBSD: bcopy.S,v 1.2 2003/08/07 16:42:36 agc Exp $")
37144730Salc#endif
38144730Salc
39144730Salc	/*
40144730Salc	 * (ov)bcopy (src,dst,cnt)
41144730Salc	 *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
42144730Salc	 */
43144730Salc
44144730Salc#ifdef MEMCOPY
45144730SalcENTRY(memcpy)
46144730Salc#else
47144730Salc#ifdef MEMMOVE
48144730SalcENTRY(memmove)
49144730Salc#else
50144730SalcENTRY(bcopy)
51144730Salc#endif
52144730Salc#endif
53144730Salc#if defined(MEMCOPY) || defined(MEMMOVE)
54144779Salc	movq	%rdi,%rax	/* return dst */
55144730Salc#else
56144730Salc	xchgq	%rdi,%rsi
57144730Salc#endif
58144730Salc	movq	%rdx,%rcx
59144779Salc	movq	%rdi,%r8
60144779Salc	subq	%rsi,%r8
61144779Salc	cmpq	%rcx,%r8	/* overlapping? */
62144730Salc	jb	1f
63144730Salc	cld			/* nope, copy forwards. */
64144730Salc	shrq	$3,%rcx		/* copy by words */
65144730Salc	rep
66144730Salc	movsq
67144730Salc	movq	%rdx,%rcx
68144730Salc	andq	$7,%rcx		/* any bytes left? */
69144730Salc	rep
70144730Salc	movsb
71144730Salc	ret
72144730Salc1:
73144730Salc	addq	%rcx,%rdi	/* copy backwards. */
74144730Salc	addq	%rcx,%rsi
75144730Salc	std
76144730Salc	andq	$7,%rcx		/* any fractional bytes? */
77144730Salc	decq	%rdi
78144730Salc	decq	%rsi
79144730Salc	rep
80144730Salc	movsb
81144730Salc	movq	%rdx,%rcx	/* copy remainder by words */
82144730Salc	shrq	$3,%rcx
83144730Salc	subq	$7,%rsi
84144730Salc	subq	$7,%rdi
85144730Salc	rep
86144730Salc	movsq
87144730Salc	cld
88144730Salc	ret
89184547Speter#ifdef MEMCOPY
90184547SpeterEND(memcpy)
91184547Speter#else
92184547Speter#ifdef MEMMOVE
93184547SpeterEND(memmove)
94184547Speter#else
95184547SpeterEND(bcopy)
96184547Speter#endif
97184547Speter#endif
98217106Skib
99217106Skib	.section .note.GNU-stack,"",%progbits
100