xref: /csrg-svn/lib/libc/vax/string/memmove.s (revision 61222)
142078Sbostic/*-
2*61222Sbostic * Copyright (c) 1990, 1993
3*61222Sbostic *	The Regents of the University of California.  All rights reserved.
442078Sbostic *
542078Sbostic * %sccs.include.redist.c%
642078Sbostic */
742078Sbostic
842078Sbostic#if defined(LIBC_SCCS) && !defined(lint)
9*61222Sbostic	.asciz "@(#)memmove.s	8.1 (Berkeley) 06/04/93"
1042078Sbostic#endif /* LIBC_SCCS and not lint */
1142078Sbostic
1242078Sbostic/*
1342078Sbostic * void *memmove(dst, src, size)
1442078Sbostic * returns dst
1542078Sbostic *
1642078Sbostic * This optimises the usual case (count < 65536) at the expense
1742078Sbostic * of some extra memory references and branches when count >= 65536.
1842078Sbostic */
1942078Sbostic
2042078Sbostic#include "DEFS.h"
2142078Sbostic
2242078SbosticENTRY(memmove, 0)
2342078Sbostic	movzwl	$65535,r0	/* r0 = 64K (needed below) */
2442078Sbostic	movq	8(ap),r1	/* r1 = src, r2 = length */
2542078Sbostic	movl	4(ap),r3	/* r3 = dst */
2642078Sbostic	cmpl	r1,r3
2742078Sbostic	bgtru	1f		/* normal forward case */
2842078Sbostic	beql	2f		/* equal, nothing to do */
2942078Sbostic	addl2	r2,r1		/* overlaps iff src<dst but src+len>dst */
3042078Sbostic	cmpl	r1,r3
3142078Sbostic	bgtru	4f		/* overlapping, must move backwards */
3242078Sbostic	subl2	r2,r1
3342078Sbostic
3442078Sbostic1:	/* move forward */
3542078Sbostic	cmpl	r2,r0
3642078Sbostic	bgtru	3f		/* stupid movc3 limitation */
3742078Sbostic	movc3	r2,(r1),(r3)	/* move it all */
3842078Sbostic2:
3942078Sbostic	movl	4(ap),r0	/* return original dst */
4042078Sbostic	ret
4142078Sbostic3:
4242078Sbostic	subl2	r0,12(ap)	/* adjust length by 64K */
4342078Sbostic	movc3	r0,(r1),(r3)	/* move 64K */
4442078Sbostic	movl	12(ap),r2
4542078Sbostic	decw	r0		/* from 0 to 65535 */
4642078Sbostic	brb	1b		/* retry */
4742078Sbostic
4842078Sbostic4:	/* move backward */
4942078Sbostic	addl2	r2,r3
5042078Sbostic5:
5142078Sbostic	cmpl	r2,r0
5242078Sbostic	bgtru	6f		/* stupid movc3 limitation */
5342078Sbostic	subl2	r2,r1
5442078Sbostic	subl2	r2,r3
5542078Sbostic	movc3	r2,(r1),(r3)	/* move it all */
5642078Sbostic	movl	4(ap),r0	/* return original dst */
5742078Sbostic	ret
5842078Sbostic6:
5942078Sbostic	subl2	r0,12(ap)	/* adjust length by 64K */
6042078Sbostic	subl2	r0,r1
6142078Sbostic	subl2	r0,r3
6242078Sbostic	movc3	r0,(r1),(r3)	/* move 64K */
6342078Sbostic	movl	12(ap),r2
6442078Sbostic	decw	r0
6542078Sbostic	subl2	r0,r1
6642078Sbostic	subl2	r0,r3
6742078Sbostic	brb	5b
68