OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [mp3_stable/] [mp3/] [sw/] [mad-xess/] [memcpy.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 291 simons
/*
2
FUNCTION
3
        <<memcpy>>---copy memory regions
4
 
5
ANSI_SYNOPSIS
6
        #include <string.h>
7
        void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
8
 
9
TRAD_SYNOPSIS
10
        void *memcpy(<[out]>, <[in]>, <[n]>
11
        void *<[out]>;
12
        void *<[in]>;
13
        size_t <[n]>;
14
 
15
DESCRIPTION
16
        This function copies <[n]> bytes from the memory region
17
        pointed to by <[in]> to the memory region pointed to by
18
        <[out]>.
19
 
20
        If the regions overlap, the behavior is undefined.
21
 
22
RETURNS
23
        <<memcpy>> returns a pointer to the first byte of the <[out]>
24
        region.
25
 
26
PORTABILITY
27
<<memcpy>> is ANSI C.
28
 
29
<<memcpy>> requires no supporting OS subroutines.
30
 
31
QUICKREF
32
        memcpy ansi pure
33
        */
34
#ifdef HAVE_CONFIG_H
35
# include "config.h"
36
#endif 
37
 
38
#ifdef EMBED
39
#include <_ansi.h>
40
#include <stddef.h>
41
#include <limits.h>
42
 
43
/* Nonzero if either X or Y is not aligned on a "long" boundary.  */
44
#define UNALIGNED(X, Y) \
45
  (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
46
 
47
/* How many bytes are copied each iteration of the 4X unrolled loop.  */
48
#define BIGBLOCKSIZE    (sizeof (long) << 2)
49
 
50
/* How many bytes are copied each iteration of the word copy loop.  */
51
#define LITTLEBLOCKSIZE (sizeof (long))
52
 
53
/* Threshhold for punting to the byte copier.  */
54
#define TOO_SMALL(LEN)  ((LEN) < BIGBLOCKSIZE)
55
 
56
_PTR
57
_DEFUN (memcpy, (dst0, src0, len0),
58
        _PTR dst0 _AND
59
        _CONST _PTR src0 _AND
60
        size_t len0)
61
{
62
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
63
  char *dst = (char *) dst0;
64
  char *src = (char *) src0;
65
 
66
  _PTR save = dst0;
67
 
68
  while (len0--)
69
    {
70
      *dst++ = *src++;
71
    }
72
 
73
  return save;
74
#else
75
  char *dst = dst0;
76
  _CONST char *src = src0;
77
  long *aligned_dst;
78
  _CONST long *aligned_src;
79
  int   len =  len0;
80
 
81
  /* If the size is small, or either SRC or DST is unaligned,
82
     then punt into the byte copy loop.  This should be rare.  */
83
  if (!TOO_SMALL(len) && !UNALIGNED (src, dst))
84
    {
85
      aligned_dst = (long*)dst;
86
      aligned_src = (long*)src;
87
 
88
      /* Copy 4X long words at a time if possible.  */
89
      while (len >= BIGBLOCKSIZE)
90
        {
91
          *aligned_dst++ = *aligned_src++;
92
          *aligned_dst++ = *aligned_src++;
93
          *aligned_dst++ = *aligned_src++;
94
          *aligned_dst++ = *aligned_src++;
95
          len -= BIGBLOCKSIZE;
96
        }
97
 
98
      /* Copy one long word at a time if possible.  */
99
      while (len >= LITTLEBLOCKSIZE)
100
        {
101
          *aligned_dst++ = *aligned_src++;
102
          len -= LITTLEBLOCKSIZE;
103
        }
104
 
105
       /* Pick up any residual with a byte copier.  */
106
      dst = (char*)aligned_dst;
107
      src = (char*)aligned_src;
108
    }
109
 
110
  while (len--)
111
    *dst++ = *src++;
112
 
113
  return dst0;
114
#endif /* not PREFER_SIZE_OVER_SPEED */
115
}
116
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.