macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libc / vax / string / memmove.s
CommitLineData
a8cf7539
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9 .asciz "@(#)memmove.s 5.1 (Berkeley) %G%"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * void *memmove(dst, src, size)
14 * returns dst
15 *
16 * This optimises the usual case (count < 65536) at the expense
17 * of some extra memory references and branches when count >= 65536.
18 */
19
20#include "DEFS.h"
21
22ENTRY(memmove, 0)
23 movzwl $65535,r0 /* r0 = 64K (needed below) */
24 movq 8(ap),r1 /* r1 = src, r2 = length */
25 movl 4(ap),r3 /* r3 = dst */
26 cmpl r1,r3
27 bgtru 1f /* normal forward case */
28 beql 2f /* equal, nothing to do */
29 addl2 r2,r1 /* overlaps iff src<dst but src+len>dst */
30 cmpl r1,r3
31 bgtru 4f /* overlapping, must move backwards */
32 subl2 r2,r1
33
341: /* move forward */
35 cmpl r2,r0
36 bgtru 3f /* stupid movc3 limitation */
37 movc3 r2,(r1),(r3) /* move it all */
382:
39 movl 4(ap),r0 /* return original dst */
40 ret
413:
42 subl2 r0,12(ap) /* adjust length by 64K */
43 movc3 r0,(r1),(r3) /* move 64K */
44 movl 12(ap),r2
45 decw r0 /* from 0 to 65535 */
46 brb 1b /* retry */
47
484: /* move backward */
49 addl2 r2,r3
505:
51 cmpl r2,r0
52 bgtru 6f /* stupid movc3 limitation */
53 subl2 r2,r1
54 subl2 r2,r3
55 movc3 r2,(r1),(r3) /* move it all */
56 movl 4(ap),r0 /* return original dst */
57 ret
586:
59 subl2 r0,12(ap) /* adjust length by 64K */
60 subl2 r0,r1
61 subl2 r0,r3
62 movc3 r0,(r1),(r3) /* move 64K */
63 movl 12(ap),r2
64 decw r0
65 subl2 r0,r1
66 subl2 r0,r3
67 brb 5b