2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
8 #include <aros/libcall.h>
9 #include <proto/exec.h>
11 /*****************************************************************************
15 AROS_LH3I(void, CopyMem
,
18 AROS_LHA(CONST_APTR
, source
, A0
),
19 AROS_LHA(APTR
, dest
, A1
),
20 AROS_LHA(IPTR
, size
, D0
),
23 struct ExecBase
*, SysBase
, 104, Exec
)
26 Copy some memory from one destination in memory to another using
27 a fast copying method.
30 source - Pointer to source area
31 dest - Pointer to destination
32 size - number of bytes to copy (may be zero)
37 The source and destination area are not allowed to overlap.
47 64-bit sizes are not handled yet.
49 ******************************************************************************/
57 I try to fall back to copying LONGs if possible. To do this I copy
58 the misaligned leading bytes of the source first. I use sizeof(LONG)
59 instead of LONGALIGN because it is sometimes faster.
64 src
= (UBYTE
*)source
;
67 #if 0 /* stegerg: this is the wrong way round??? */
68 mis
=(IPTR
)src
&(sizeof(LONG
)-1);
70 mis
= (sizeof(LONG
) - 1) - (((IPTR
)src
- 1) & (sizeof(LONG
) - 1));
82 The source has the right alignment now. All I need to do is to
83 check if this is true for the destination, too.
85 if(!((IPTR
)dst
&(AROS_LONGALIGN
-1)))
87 /* Yes. I may copy LONGs. */
88 LONG
*s
=(LONG
*)src
,*d
=(LONG
*)dst
;
91 /* How many of them? */
92 longs
=size
/sizeof(LONG
);
95 To minimize the loop overhead I copy more than one (eight) LONG per
96 iteration. Therefore I need to split size into size/8 and the rest.
101 /* Then copy for both parts */
122 size
&=sizeof(LONG
)-1;
128 /* The remaining job can only be done by copying single bytes. */
132 /* Copy for both parts */
139 Partly unrolled copying loop. The predecrement helps the compiler to
140 find the best possible loop. The if is necessary to do this.