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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [loader/] [libs/] [c/] [src/] [memcpy.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Australian Public Licence B (OZPLB)
3
 *
4
 * Version 1-0
5
 *
6
 * Copyright (c) 2004 University of New South Wales
7
 *
8
 * All rights reserved.
9
 *
10
 * Developed by: Operating Systems and Distributed Systems Group (DiSy)
11
 *               University of New South Wales
12
 *               http://www.disy.cse.unsw.edu.au
13
 *
14
 * Permission is granted by University of New South Wales, free of charge, to
15
 * any person obtaining a copy of this software and any associated
16
 * documentation files (the "Software") to deal with the Software without
17
 * restriction, including (without limitation) the rights to use, copy,
18
 * modify, adapt, merge, publish, distribute, communicate to the public,
19
 * sublicense, and/or sell, lend or rent out copies of the Software, and
20
 * to permit persons to whom the Software is furnished to do so, subject
21
 * to the following conditions:
22
 *
23
 *     * Redistributions of source code must retain the above copyright
24
 *       notice, this list of conditions and the following disclaimers.
25
 *
26
 *     * Redistributions in binary form must reproduce the above
27
 *       copyright notice, this list of conditions and the following
28
 *       disclaimers in the documentation and/or other materials provided
29
 *       with the distribution.
30
 *
31
 *     * Neither the name of University of New South Wales, nor the names of its
32
 *       contributors, may be used to endorse or promote products derived
33
 *       from this Software without specific prior written permission.
34
 *
35
 * EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
36
 * PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
37
 * NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
38
 * WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
39
 * BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
40
 * REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
41
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
42
 * THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
43
 * ERRORS, WHETHER OR NOT DISCOVERABLE.
44
 *
45
 * TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
46
 * NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
47
 * THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
48
 * NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
49
 * LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
50
 * OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
51
 * OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
52
 * OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
53
 * CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
54
 * CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
55
 * DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
56
 * CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
57
 * DAMAGES OR OTHER LIABILITY.
58
 *
59
 * If applicable legislation implies representations, warranties, or
60
 * conditions, or imposes obligations or liability on University of New South
61
 * Wales or one of its contributors in respect of the Software that
62
 * cannot be wholly or partly excluded, restricted or modified, the
63
 * liability of University of New South Wales or the contributor is limited, to
64
 * the full extent permitted by the applicable legislation, at its
65
 * option, to:
66
 * a.  in the case of goods, any one or more of the following:
67
 * i.  the replacement of the goods or the supply of equivalent goods;
68
 * ii.  the repair of the goods;
69
 * iii. the payment of the cost of replacing the goods or of acquiring
70
 *  equivalent goods;
71
 * iv.  the payment of the cost of having the goods repaired; or
72
 * b.  in the case of services:
73
 * i.  the supplying of the services again; or
74
 * ii.  the payment of the cost of having the services supplied again.
75
 *
76
 * The construction, validity and performance of this licence is governed
77
 * by the laws in force in New South Wales, Australia.
78
 */
79
/*
80
 Author: Carl van Schaik
81
*/
82
#include <string.h>
83
#include <stdint.h>
84
 
85
/*
86
 * copy n bytes from s to d; the regions must not overlap
87
 */
88
/* THREAD SAFE */
89
void *
90
memcpy(void *d, const void *s, size_t n)
91
{
92
        size_t i;
93
        uintptr_t align = sizeof(uintptr_t)-1;
94
 
95
        if (((uintptr_t)d & align) || ((uintptr_t)s & align) || (n & align))
96
        {
97
                char *bs = (char *)s;
98
                char *bd = (char *)d;
99
 
100
                /* XXX - optimize this */
101
                for (i = 0; i < n; i++)
102
                        *bd++ = *bs++;
103
        }
104
        else
105
        {       /* memcpy - word aligned */
106
                uintptr_t *ws = (uintptr_t*)s;
107
                uintptr_t *wd = (uintptr_t*)d;
108
 
109
                n /= sizeof(uintptr_t);
110
 
111
                for (i = 0; i < n; i++)
112
                        *wd++ = *ws++;
113
        }
114
        return d;
115
}

powered by: WebSVN 2.1.0

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