r4684@vps: verhaegs | 2007-05-04 21:04:10 -0400
[AROS.git] / rom / exec / copymemquick.c
blob443e5d462ffe487f31fa9b0c3176883c71bb8e7b
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Copy aligned memory.
6 Lang: english
7 */
8 #include <aros/libcall.h>
9 #include <exec/types.h>
11 /*****************************************************************************
13 NAME */
15 AROS_LH3I(void, CopyMemQuick,
17 /* SYNOPSIS */
18 AROS_LHA(CONST_APTR, source, A0),
19 AROS_LHA(APTR, dest, A1),
20 AROS_LHA(ULONG, size, D0),
22 /* LOCATION */
23 struct ExecBase *, SysBase, 105, Exec)
25 /* FUNCTION
26 Copy some longwords from one destination in memory to another using
27 a fast copying method.
29 INPUTS
30 source - Pointer to source area (must be ULONG aligned)
31 dest - Pointer to destination (must be ULONG aligned)
32 size - number of bytes to copy (must be a multiple of sizeof(ULONG))
34 RESULT
36 NOTES
37 The source and destination area are not allowed to overlap.
39 EXAMPLE
41 BUGS
43 SEE ALSO
44 CopyMem()
46 INTERNALS
48 ******************************************************************************/
50 AROS_LIBFUNC_INIT
52 ULONG low,high;
53 const ULONG *src = source;
54 ULONG *dst = dest;
56 /* Calculate number of ULONGs to copy */
57 size/=sizeof(ULONG);
60 To minimize the loop overhead I copy more than one (eight) ULONG per
61 iteration. Therefore I need to split size into size/8 and the rest.
63 low =size&7;
64 high=size/8;
66 /* Then copy for both parts */
67 if(low)
69 *dst++=*src++;
70 while(--low);
73 Partly unrolled copying loop. The predecrement helps the compiler to
74 find the best possible loop. The if is necessary to do this.
76 if(high)
79 *dst++=*src++;
80 *dst++=*src++;
81 *dst++=*src++;
82 *dst++=*src++;
83 *dst++=*src++;
84 *dst++=*src++;
85 *dst++=*src++;
86 *dst++=*src++;
87 }while(--high);
88 AROS_LIBFUNC_EXIT
89 } /* CopyMemQuick */