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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*===========================================================================
2
//
3
//      memset.c
4
//
5
//      ANSI standard memset() 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 memset() function
46
// Description: This file implements the memset() function defined in ANSI para
47
//              7.11.6.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 X is not aligned on a word boundary. */
68
#define CYG_STR_UNALIGNED(X) ((CYG_WORD)(X) & (sizeof (CYG_WORD) - 1))
69
 
70
/* How many bytes are copied each iteration of the word copy loop in the
71
 * optimised string implementation
72
 */
73
#define CYG_STR_OPT_LITTLEBLOCKSIZE (sizeof (CYG_WORD))
74
 
75
/* EXPORTED SYMBOLS */
76
 
77
externC void *
78
memset( void *s, int c, size_t n ) __attribute__ ((weak, alias("_memset")));
79
 
80
/* FUNCTIONS */
81
 
82
void *
83
_memset( void *s, int c, size_t n )
84
{
85
#if defined(CYGIMP_INFRA_PREFER_SMALL_TO_FAST_MEMSET) || defined(__OPTIMIZE_SIZE__)
86
    char *char_ptr = (char *)s;
87
 
88
#ifdef CYG_TRACING_FIXED
89
    CYG_REPORT_FUNCNAMETYPE( "_memset", "returning %08x" );
90
    CYG_REPORT_FUNCARG3( "s=%08x, c=%d, n=%d", s, c, n );
91
 
92
    if (n != 0)
93
    {
94
        CYG_CHECK_DATA_PTR( char_ptr, "s is not a valid pointer!" );
95
        CYG_CHECK_DATA_PTR( (&char_ptr[n-1]), "s+n-1 is not a valid address!" );
96
    }
97
#endif
98
 
99
    while (n-- != 0)
100
    {
101
        *char_ptr++ = (char) c;
102
    }
103
 
104
#ifdef CYG_TRACING_FIXED
105
    CYG_REPORT_RETVAL( s );
106
#endif
107
    return s;
108
#else
109
    char *char_ptr = (char *)s;
110
    cyg_ucount8 count;
111
    CYG_WORD buffer;
112
    CYG_WORD *aligned_addr;
113
    char *unaligned_addr;
114
 
115
#ifdef CYG_TRACING_FIXED
116
    CYG_REPORT_FUNCNAMETYPE( "_memset", "returning %08x" );
117
    CYG_REPORT_FUNCARG3( "s=%08x, c=%d, n=%d", s, c, n );
118
 
119
    if (n != 0)
120
    {
121
        CYG_CHECK_DATA_PTR( s, "s is not a valid pointer!" );
122
        CYG_CHECK_DATA_PTR( (char *)s+n-1, "s+n-1 is not a valid address!" );
123
    }
124
#endif
125
 
126
    if (n < sizeof(CYG_WORD) || CYG_STR_UNALIGNED (s))
127
    {
128
        while (n-- != 0)
129
        {
130
            *char_ptr++ = (char) c;
131
        }
132
#ifdef CYG_TRACING_FIXED
133
        CYG_REPORT_RETVAL( s );
134
#endif
135
        return s;
136
    }
137
 
138
    /* If we get this far, we know that n is large and s is word-aligned. */
139
 
140
    aligned_addr = (CYG_WORD *)s;
141
 
142
    /* Store C into each char sized location in BUFFER so that
143
     * we can set large blocks quickly.
144
     */
145
    c &= 0xff;
146
    if (CYG_STR_OPT_LITTLEBLOCKSIZE == 4)
147
    {
148
        buffer = (c << 8) | c;
149
        buffer |= (buffer << 16);
150
    }
151
    else
152
    {
153
        buffer = 0;
154
        for (count = 0; count < CYG_STR_OPT_LITTLEBLOCKSIZE; count++)
155
            buffer = (buffer << 8) | c;
156
    }
157
 
158
    while (n >= CYG_STR_OPT_LITTLEBLOCKSIZE*4)
159
    {
160
        *aligned_addr++ = buffer;
161
        *aligned_addr++ = buffer;
162
        *aligned_addr++ = buffer;
163
        *aligned_addr++ = buffer;
164
        n -= 4*CYG_STR_OPT_LITTLEBLOCKSIZE;
165
    }
166
 
167
    while (n >= CYG_STR_OPT_LITTLEBLOCKSIZE)
168
    {
169
        *aligned_addr++ = buffer;
170
        n -= CYG_STR_OPT_LITTLEBLOCKSIZE;
171
    }
172
 
173
    /* Pick up the remainder with a bytewise loop. */
174
    unaligned_addr = (char*)aligned_addr;
175
    while (n)
176
    {
177
        *unaligned_addr++ = (char)c;
178
        n--;
179
    }
180
 
181
#ifdef CYG_TRACING_FIXED
182
    CYG_REPORT_RETVAL( s );
183
#endif
184
    return s;
185
#endif /* not defined(CYGIMP_PREFER_SMALL_TO_FAST_MEMSET) ||
186
        * defined(__OPTIMIZE_SIZE__) */
187
} /* _memset() */
188
 
189
/* EOF memset.c */

powered by: WebSVN 2.1.0

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