Commit | Line | Data |
---|---|---|
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 | ||
22 | ENTRY(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 | ||
34 | 1: /* move forward */ | |
35 | cmpl r2,r0 | |
36 | bgtru 3f /* stupid movc3 limitation */ | |
37 | movc3 r2,(r1),(r3) /* move it all */ | |
38 | 2: | |
39 | movl 4(ap),r0 /* return original dst */ | |
40 | ret | |
41 | 3: | |
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 | ||
48 | 4: /* move backward */ | |
49 | addl2 r2,r3 | |
50 | 5: | |
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 | |
58 | 6: | |
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 |