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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [string/] [memcpy.c] - Blame information for rev 455

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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