home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / memory / src / copymemquick.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.8 KB  |  113 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: copymemquick.c 1.1 1995/11/14 22:31:07 digulla Exp digulla $
  4.     $Log: copymemquick.c $
  5.  * Revision 1.1  1995/11/14  22:31:07  digulla
  6.  * Initial revision
  7.  *
  8.     Desc:
  9.     Lang: english
  10. */
  11. #include "exec_intern.h"
  12.  
  13. /*****************************************************************************
  14.  
  15.     NAME */
  16.     #include <clib/exec_protos.h>
  17.  
  18.     __AROS_LH3I(void, CopyMemQuick,
  19.  
  20. /*  SYNOPSIS */
  21.     __AROS_LA(APTR         , source, A0),
  22.     __AROS_LA(APTR         , dest, A1),
  23.     __AROS_LA(unsigned long, size, D0),
  24.  
  25. /*  LOCATION */
  26.     struct ExecBase *, SysBase, 105, Exec)
  27.  
  28. /*  FUNCTION
  29.     This routine copies areas of memory very fast. To achieve this
  30.     speed, the user of the function has to take care that the
  31.     arguments match certain requirements. Both pointers (source
  32.     and dest) must be longword aligned ("unsigned long") and the
  33.     size must be divisible by "sizeof (unsigned long)". No checks
  34.     are performed by the function to check these requirements but
  35.     on some hardwares, the system will crash if the requirements
  36.     are not met.
  37.  
  38.     INPUTS
  39.     source - Pointer to the source area. Must be longword aligned.
  40.     dest - Pointer to the destination area. Must be longword aligned.
  41.     size - The number of bytes to copy. This number must by
  42.         divisible by "sizeof (unsigned long)".
  43.  
  44.     RESULT
  45.     None.
  46.  
  47.     NOTES
  48.     The routine can't handle situations where the destination is
  49.     somewhere in source (eg. insert elements in an array).
  50.  
  51.     EXAMPLE
  52.     long ptr1[] = { 'Hell', 'o Wo', 'rld\0' };
  53.     long ptr2[3];
  54.  
  55.     CopyMemQuick (ptr1, ptr2, sizeof (ptr1));
  56.  
  57.     BUGS
  58.  
  59.     SEE ALSO
  60.     CopyMem()
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.     21-10-95    digulla automatically created from
  66.                 include:clib/exec_protos.h
  67.                 Written the code.
  68.     26-10-95    digulla adjusted to new calling scheme
  69.     17-12-95    digulla Incorporated code by Matthias Fleischner
  70.  
  71. *****************************************************************************/
  72. {
  73.     __AROS_FUNC_INIT
  74.     ULONG low,high;
  75.     ULONG * dptr, * sptr;
  76.  
  77.     /* Calculate number of ULONGs to copy */
  78.     size/=sizeof(ULONG);
  79.     sptr = (ULONG *)source;
  80.     dptr = (ULONG *)dest;
  81.  
  82.     /*
  83.     To minimize the loop overhead I copy more than one (eight) ULONG per
  84.     iteration. Therefore I need to split size into size/8 and the rest.
  85.     */
  86.     low =size&7;
  87.     high=size>>3;
  88.  
  89.     /* Then copy for both parts */
  90.     if(low)
  91.     do
  92.         *dptr++=*sptr++;
  93.     while(--low);
  94.  
  95.     /*
  96.     Partly unrolled copying loop. The predecrement helps the compiler to
  97.     find the best possible loop. The if is necessary to do this.
  98.     */
  99.     if(high)
  100.     do
  101.     {
  102.         *dptr++=*sptr++;
  103.         *dptr++=*sptr++;
  104.         *dptr++=*sptr++;
  105.         *dptr++=*sptr++;
  106.         *dptr++=*sptr++;
  107.         *dptr++=*sptr++;
  108.         *dptr++=*sptr++;
  109.         *dptr++=*sptr++;
  110.     }while(--high);
  111.     __AROS_FUNC_EXIT
  112. } /* CopyMemQuick */
  113.