]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/68000/memcpy.s
marshal(1): fix example: upas/mail -> mail (thanks fulton)
[plan9front.git] / sys / src / libc / 68000 / memcpy.s
1         TEXT    memcpy(SB), $0
2
3         MOVL    n+8(FP), R0     /* count */
4         BEQ     return
5         BGT     ok
6         MOVL    0, R0
7 ok:
8         MOVL    s1+0(FP), A2    /* dest pointer */
9         MOVL    s2+4(FP), A1    /* source pointer */
10
11         CMPL    A2,A1
12         BHI     back
13
14 /*
15  * byte-at-a-time foreward copy to
16  * get source (A1) alligned.
17  */
18 f1:
19         MOVL    A1, R1
20         ANDL    $3, R1
21         BEQ     f2
22         SUBL    $1, R0
23         BLT     return
24         MOVB    (A1)+, (A2)+
25         BRA     f1
26
27 /*
28  * check that dest is alligned
29  * if not, just go byte-at-a-time
30  */
31 f2:
32         MOVL    A2, R1
33         ANDL    $3, R1
34         BEQ     f3
35         SUBL    $1, R0
36         BLT     return
37         BRA     f5
38 /*
39  * quad-long-at-a-time forward copy
40  */
41 f3:
42         SUBL    $16, R0
43         BLT     f4
44         MOVL    (A1)+, (A2)+
45         MOVL    (A1)+, (A2)+
46         MOVL    (A1)+, (A2)+
47         MOVL    (A1)+, (A2)+
48         BRA     f3
49
50 /*
51  * cleanup byte-at-a-time
52  */
53 f4:
54         ADDL    $15, R0
55         BLT     return
56 f5:
57         MOVB    (A1)+, (A2)+
58         SUBL    $1, R0
59         BGE     f5
60         BRA     return
61
62 return:
63         MOVL    s1+0(FP),R0
64         RTS
65
66 /*
67  * everything the same, but
68  * copy backwards
69  */
70 back:
71         ADDL    R0, A1
72         ADDL    R0, A2
73
74 /*
75  * byte-at-a-time backward copy to
76  * get source (A1) alligned.
77  */
78 b1:
79         MOVL    A1, R1
80         ANDL    $3, R1
81         BEQ     b2
82         SUBL    $1, R0
83         BLT     return
84         MOVB    -(A1), -(A2)
85         BRA     b1
86
87 /*
88  * check that dest is alligned
89  * if not, just go byte-at-a-time
90  */
91 b2:
92         MOVL    A2, R1
93         ANDL    $3, R1
94         BEQ     b3
95         SUBL    $1, R0
96         BLT     return
97         BRA     b5
98 /*
99  * quad-long-at-a-time backward copy
100  */
101 b3:
102         SUBL    $16, R0
103         BLT     b4
104         MOVL    -(A1), -(A2)
105         MOVL    -(A1), -(A2)
106         MOVL    -(A1), -(A2)
107         MOVL    -(A1), -(A2)
108         BRA     b3
109
110 /*
111  * cleanup byte-at-a-time backward
112  */
113 b4:
114         ADDL    $15, R0
115         BLT     return
116 b5:
117         MOVB    -(A1), -(A2)
118         SUBL    $1, R0
119         BGE     b5
120         BRA     return