- Removed unnecessary casts.
[AROS.git] / arch / m68k-amiga / c / copymem_060.S
blob3c0a0ab41bf581ef32d81660f3bf4c96fbd3a841
1 /*
2     Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3     $Id: $
5     Desc: 68060 optimized CopyMem/Quick by Matt Hey.
6     Lang: english
7 */
9         .text
10         .chip 68040
12 #define SAFE_MOVE16 0
14 /**********************************
15  *
16  * CopyMem( source, dest, size )
17  *            %a0     %a1    %d0
18  *
19  *      source & dest = any aligned
20  *      size = in bytes
21  */
23         .balign 4
24         .globl copymem_060
25         .globl copymeme_060
26 copymem_060:
27         subq.l #4,%d0                   // size is 4 less than actual!
28         bls.b smallcopy         // if size<=4 bytes
29         move.l %a1,%d1
30         lsr.l #1,%d1                            //btst #0,%d1
31         bcc.b   daligned2               //beq.b daligned2
32         move.b (%a0)+,(%a1)+
33         addq.l #1,%d1
34         subq.l #1,%d0
35 daligned2:                                      // dest should be WORD aligned now
36         lsr.l #1,%d1                            //btst #1,%d1
37         bcc.b   daligned4               //beq.b daligned4
38         move.w (%a0)+,(%a1)+
39         subq.l #2,%d0
40         bcs.b last2                             // if size<0
41 daligned4:                                      // dest should be LONG aligned now
42         cmp.l #2048-4,%d0               // min size for move16, less than 252 is dangerous!
43         bcc.b bigmove
44 move4loop:
45         move.l (%a0)+,(%a1)+
46         subq.l #4,%d0
47         bhi.b move4loop         // if size>0
48         bne.b last2
49 move4:
50         move.l (%a0)+,(%a1)+
51         rts
52 move1:
53         move.b (%a0)+,(%a1)+
54         rts
55 smallcopy:
56         beq.b move4
57 last2:
58         btst #1,%d0
59         beq.b last1
60         move.w (%a0)+,(%a1)+
61 last1:
62         lsr.l #1,%d0                            //btst #0,%d0
63         bcs.b move1                             //bne.b move1
64         rts
66 bigmove:
67         move.l %a1,%d1
68         lsr.l #3,%d1                            // destination aligned by 8 if bit3/bit#2=0
69         bcc.b disal8                    // if bit3/bit#2=0
70         move.l (%a0)+,(%a1)+
71         addq.l #1,%d1                   // addq.l #4,%d1
72         subq.l #4,%d0
73 disal8:
74         lsr.l #1,%d1                            // destination aligned by 16 if bit4/bit#3=0
75         bcc.b disal16                   // if bit4/bit#3=0
76         move.l (%a0)+,(%a1)+
77         subq.l #8,%d0
78         move.l (%a0)+,(%a1)+
79 disal16:
80         move.l %a0,%d1
81         and.w #15,%d1
82         bne.b move4loop         // if source not aligned by 16
84 #if SAFE_MOVE16
85         cmp.l #$01000000,%a1    // destination must be in 24 bit space
86         bcs.b move4loop
87         moveq #128-4,%d1
88         cmp.l #$01000000,%a0    // source must be in 24 bit space
89         bcs.b move4loop
90 #else
91         moveq #128-4,%d1
92 #endif
94         sub.l %d1,%d0                           // size is now 128 less than actual
95         addq.l #4,%d1                   // %d1=128=bytes to move per loop
96 move16loop:
97         move16 (%a0)+,(%a1)+
98         move16 (%a0)+,(%a1)+
99         move16 (%a0)+,(%a1)+
100         move16 (%a0)+,(%a1)+
101         move16 (%a0)+,(%a1)+
102         move16 (%a0)+,(%a1)+
103         move16 (%a0)+,(%a1)+
104         move16 (%a0)+,(%a1)+
105         sub.l %d1,%d0                           // %d0=%d0-128
106         bcc.b move16loop                // if %d0>=0
107         moveq #128-4,%d1
108         add.l %d1,%d0                           // %d0=%d0+124, size is actual-4
109         bcs.b move4loop         // if %d0>=0
111         btst #1,%d0
112         beq.b l1
113         move.w (%a0)+,(%a1)+
115         lsr.l #1,%d0
116         bcs.b move1
117         rts
118 copymeme_060:
120 /***********************************
122  * CopyMemQuick( source, dest, size )
123  *                 %a0     %a1    %d0
125  *      source & dest = long word aligned
126  *      size = in bytes (divisable by 4)
127  */
129         .balign 4
130         .globl copymemquick_060
131         .globl copymemquicke_060
132 copymemquick_060:
133         subq.l #4,%d0           // size is 4.b less than actual
134         bls.b ism4or0           // if %d0<=0
135 prem4:
136         cmp.l #2048-4,%d0       // min size for move16, less than 252 is dangerous!
137         bcc.b bigmov
138 m4loop:
139         move.l (%a0)+,(%a1)+
140         move.l (%a0)+,(%a1)+
141         subq.l #8,%d0                   // 8 less bytes to MOVE
142         bhi.b m4loop                    // if %d0>0
143         beq.b lastm4
144         rts
145 lastm4:
146         move.l (%a0)+,(%a1)+
147         rts
148 ism4or0:
149         beq.b lastm4
150         rts
152 lastloop:
153         move.l (%a0)+,(%a1)+
154         subq.l #4,%d0
155         bhi.b lastloop                  // if %d0>0
156         rts
158 bigmov:
159         move.l %a1,%d1
160         lsr.l #3,%d1                            // destination aligned by 8 if bit3/bit#2=0
161         bcc.b destisal8         // if bit3/bit#2=0
162         move.l (%a0)+,(%a1)+
163         addq.l #1,%d1                   //addq.l #4,%d1
164         subq.l #4,%d0
165 destisal8:
166         lsr.l #1,%d1                            // destination aligned by 16 if bit4/bit#3=0
167         bcc.b destisal16                // if bit4/bit#3=0
168         move.l (%a0)+,(%a1)+
169         subq.l #8,%d0
170         move.l (%a0)+,(%a1)+
171 destisal16:
172         move.l %a0,%d1
173         and.w #15,%d1
174         bne.b m4loop                    // if source not aligned by 16
176 #if SAFE_MOVE16
177         cmp.l   #$01000000,%a1  // destination must be in 24 bit space
178         bcs.b   m4loop
179         moveq #128-4,%d1
180         cmp.l   #$01000000,%a0  // source must be in 24 bit space
181         bcs.b   m4loop
182 #else
183         moveq #128-4,%d1        
184 #endif
186         sub.l %d1,%d0                           // size is now 128 less than actual
187         addq.l #4,%d1                   // %d1=128=bytes to move per loop
188 mov16loop:
189         move16 (%a0)+,(%a1)+
190         move16 (%a0)+,(%a1)+
191         move16 (%a0)+,(%a1)+
192         move16 (%a0)+,(%a1)+
193         move16 (%a0)+,(%a1)+
194         move16 (%a0)+,(%a1)+
195         move16 (%a0)+,(%a1)+
196         move16 (%a0)+,(%a1)+
197         sub.l   %d1,%d0                         // %d0=%d0-128
198         bcc.b   mov16loop               // if %d0>=0
199         add.l %d1,%d0                           // %d0=%d0+128, back to positive
200         bne.b lastloop
201         rts
202 copymemquicke_060: