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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [infra/] [current/] [src/] [memcpy.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*===========================================================================
2
//
3
//      memcpy.c
4
//
5
//      ANSI standard memcpy() routine
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####
9
// -------------------------------------------
10
// This file is part of eCos, the Embedded Configurable Operating System.
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under
14
// the terms of the GNU General Public License as published by the Free
15
// Software Foundation; either version 2 or (at your option) any later
16
// version.
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21
// for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
26
//
27
// As a special exception, if other files instantiate templates or use
28
// macros or inline functions from this file, or you compile this file
29
// and link it with other works to produce a work based on this file,
30
// this file does not by itself cause the resulting work to be covered by
31
// the GNU General Public License. However the source code for this file
32
// must still be made available in accordance with section (3) of the GNU
33
// General Public License v2.
34
//
35
// This exception does not invalidate any other reasons why a work based
36
// on this file might be covered by the GNU General Public License.
37
// -------------------------------------------
38
// ####ECOSGPLCOPYRIGHTEND####
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):   jlarmour
43
// Contributors:  jlarmour
44
// Date:        1998-06-04
45
// Purpose:     This file implements the ANSI memcpy() function
46
// Description: This file implements the memcpy() function defined in ANSI para
47
//              7.11.2.1. This is implemented in the kernel rather than the
48
//              C library due to it being required by gcc whether or not the
49
//              C library has been configured in.
50
//
51
//####DESCRIPTIONEND####
52
//
53
//==========================================================================*/
54
 
55
 
56
/* INCLUDES */
57
 
58
#include <pkgconf/infra.h>      /* Configuration of infra package */
59
 
60
#include <cyg/infra/cyg_type.h> /* Common type definitions */
61
#include <cyg/infra/cyg_trac.h> /* Tracing support */
62
#include <cyg/infra/cyg_ass.h>  /* Assertion support */
63
#include <stddef.h>             /* Compiler defns such as size_t, NULL etc. */
64
 
65
/* MACROS */
66
 
67
/* Nonzero if either X or Y is not aligned on a word boundary. */
68
#define CYG_STR_UNALIGNED(X, Y) \
69
     (((CYG_WORD)(X) & (sizeof (CYG_WORD) - 1)) | \
70
      ((CYG_WORD)(Y) & (sizeof (CYG_WORD) - 1)))
71
 
72
/* How many bytes are copied each iteration of the 4X unrolled loop in the
73
 * optimised string implementation
74
 */
75
#define CYG_STR_OPT_BIGBLOCKSIZE     (sizeof(CYG_WORD) << 2)
76
 
77
 
78
/* How many bytes are copied each iteration of the word copy loop in the
79
 * optimised string implementation
80
 */
81
#define CYG_STR_OPT_LITTLEBLOCKSIZE (sizeof (CYG_WORD))
82
 
83
/* EXPORTED SYMBOLS */
84
 
85
externC void *
86
memcpy( void *s1, const void *s2, size_t n ) __attribute__((weak,
87
                                                            alias("_memcpy")));
88
 
89
/* FUNCTIONS */
90
 
91
void *
92
_memcpy( void *s1, const void *s2, size_t n )
93
{
94
    char *dst = (char *) s1;
95
    const char *src = (const char *) s2;
96
 
97
    CYG_ASSERT((dst >= (src+n)) || ((dst+n) <= src),
98
               "memcpy() has undefined result for overlapping copies");
99
 
100
#if defined(CYGIMP_INFRA_PREFER_SMALL_TO_FAST_MEMCPY) || defined(__OPTIMIZE_SIZE__)
101
 
102
#ifdef CYG_TRACING_FIXED
103
    CYG_REPORT_FUNCNAMETYPE( "_memcpy", "returning %08x" );
104
    CYG_REPORT_FUNCARG3( "dst=%08x, src=%08x, n=%d", dst, src, n );
105
 
106
    if (n != 0)
107
    {
108
        CYG_CHECK_DATA_PTR( dst, "dst is not a valid pointer!" );
109
        CYG_CHECK_DATA_PTR( src, "src is not a valid pointer!" );
110
        CYG_CHECK_DATA_PTR( dst+n-1, "dst+n-1 is not a valid address!" );
111
        CYG_CHECK_DATA_PTR( src+n-1, "src+n-1 is not a valid address!" );
112
    }
113
#endif
114
 
115
    while (n--)
116
    {
117
        *dst++ = *src++;
118
    } /* while */
119
 
120
#ifdef CYG_TRACING_FIXED
121
    CYG_REPORT_RETVAL( s1 );
122
#endif
123
    return s1;
124
#else
125
    CYG_WORD *aligned_dst;
126
    const CYG_WORD *aligned_src;
127
 
128
#ifdef CYG_TRACING_FIXED
129
    CYG_REPORT_FUNCNAMETYPE( "_memcpy", "returning %08x" );
130
#endif
131
 
132
 
133
#ifdef CYG_TRACING_FIXED
134
    CYG_REPORT_FUNCARG3( "dst=%08x, src=%08x, n=%d", dst, src, n );
135
 
136
    if (n != 0)
137
    {
138
        CYG_CHECK_DATA_PTR( dst, "dst is not a valid pointer!" );
139
        CYG_CHECK_DATA_PTR( src, "src is not a valid pointer!" );
140
        CYG_CHECK_DATA_PTR( dst+n-1, "dst+n-1 is not a valid address!" );
141
        CYG_CHECK_DATA_PTR( src+n-1, "src+n-1 is not a valid address!" );
142
    }
143
#endif
144
 
145
    /* If the size is small, or either SRC or DST is unaligned,
146
     * then punt into the byte copy loop.  This should be rare.
147
     */
148
    if (n < sizeof(CYG_WORD) || CYG_STR_UNALIGNED (src, dst))
149
    {
150
        while (n--)
151
            *dst++ = *src++;
152
#ifdef CYG_TRACING_FIXED
153
        CYG_REPORT_RETVAL( s1 );
154
#endif
155
        return s1;
156
    } /* if */
157
 
158
    aligned_dst = (CYG_WORD *)dst;
159
    aligned_src = (const CYG_WORD *)src;
160
 
161
    /* Copy 4X long words at a time if possible.  */
162
    while (n >= CYG_STR_OPT_BIGBLOCKSIZE)
163
    {
164
        *aligned_dst++ = *aligned_src++;
165
        *aligned_dst++ = *aligned_src++;
166
        *aligned_dst++ = *aligned_src++;
167
        *aligned_dst++ = *aligned_src++;
168
        n -= CYG_STR_OPT_BIGBLOCKSIZE;
169
    } /* while */
170
 
171
    /* Copy one long word at a time if possible.  */
172
    while (n >= CYG_STR_OPT_LITTLEBLOCKSIZE)
173
    {
174
        *aligned_dst++ = *aligned_src++;
175
        n -= CYG_STR_OPT_LITTLEBLOCKSIZE;
176
    } /* while */
177
 
178
    /* Pick up any residual with a byte copier.  */
179
    dst = (char*)aligned_dst;
180
    src = (const char*)aligned_src;
181
    while (n--)
182
        *dst++ = *src++;
183
 
184
#ifdef CYG_TRACING_FIXED
185
    CYG_REPORT_RETVAL( s1 );
186
#endif
187
    return s1;
188
#endif /* not defined(CYGIMP_PREFER_SMALL_TO_FAST_MEMCPY) ||
189
        * defined(__OPTIMIZE_SIZE__) */
190
} /* _memcpy() */
191
 
192
/* EOF memcpy.c */

powered by: WebSVN 2.1.0

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