xref: /386bsd/usr/src/kernel/kern/i386/memmove_i386.s (revision a2142627)
1/*
2 * Copyright (c) 1994 William F. Jolitz.
3 * 386BSD Copyright Restrictions Apply. All Other Rights Reserved.
4 *
5 * $Id: memmove_i386.s,v 1.1 94/10/19 17:40:01 bill Exp $
6 * POSIX (overlapping) block memory move.
7 */
8
9#include "asm.h"
10#include "assym.s"
11
12ENTRY(memmove)
13	pushl	%esi
14	pushl	%edi
15	movl	12(%esp),%edi
16	movl	16(%esp),%esi
17	movl	20(%esp),%ecx
18	cmpl	%esi,%edi	/* potentially overlapping? */
19	jnb	1f
20	cld			/* nope, copy forwards. */
21	shrl	$2,%ecx		/* copy by words */
22	rep
23	movsl
24	movl	20(%esp),%ecx
25	andl	$3,%ecx		/* any bytes left? */
26	rep
27	movsb
28	popl	%edi
29	popl	%esi
30	xorl	%eax,%eax
31	ret
321:
33	addl	%ecx,%edi	/* copy backwards. */
34	addl	%ecx,%esi
35	std
36	andl	$3,%ecx		/* any fractional bytes? */
37	decl	%edi
38	decl	%esi
39	rep
40	movsb
41	movl	20(%esp),%ecx	/* copy remainder by words */
42	shrl	$2,%ecx
43	subl	$3,%esi
44	subl	$3,%edi
45	rep
46	movsl
47	popl	%edi
48	popl	%esi
49	xorl	%eax,%eax
50	cld
51	ret
52