aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh64/lib/memcpy.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sh64/lib/memcpy.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sh64/lib/memcpy.c')
-rw-r--r--arch/sh64/lib/memcpy.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/arch/sh64/lib/memcpy.c b/arch/sh64/lib/memcpy.c
new file mode 100644
index 000000000000..c785d0aa194d
--- /dev/null
+++ b/arch/sh64/lib/memcpy.c
@@ -0,0 +1,82 @@
1/*
2 * Copyright (C) 2002 Mark Debbage (Mark.Debbage@superh.com)
3 *
4 * May be copied or modified under the terms of the GNU General Public
5 * License. See linux/COPYING for more information.
6 *
7 */
8
9#include <linux/config.h>
10#include <linux/types.h>
11#include <asm/string.h>
12
13// This is a simplistic optimization of memcpy to increase the
14// granularity of access beyond one byte using aligned
15// loads and stores. This is not an optimal implementation
16// for SH-5 (especially with regard to prefetching and the cache),
17// and a better version should be provided later ...
18
19void *memcpy(void *dest, const void *src, size_t count)
20{
21 char *d = (char *) dest, *s = (char *) src;
22
23 if (count >= 32) {
24 int i = 8 - (((unsigned long) d) & 0x7);
25
26 if (i != 8)
27 while (i-- && count--) {
28 *d++ = *s++;
29 }
30
31 if (((((unsigned long) d) & 0x7) == 0) &&
32 ((((unsigned long) s) & 0x7) == 0)) {
33 while (count >= 32) {
34 unsigned long long t1, t2, t3, t4;
35 t1 = *(unsigned long long *) (s);
36 t2 = *(unsigned long long *) (s + 8);
37 t3 = *(unsigned long long *) (s + 16);
38 t4 = *(unsigned long long *) (s + 24);
39 *(unsigned long long *) (d) = t1;
40 *(unsigned long long *) (d + 8) = t2;
41 *(unsigned long long *) (d + 16) = t3;
42 *(unsigned long long *) (d + 24) = t4;
43 d += 32;
44 s += 32;
45 count -= 32;
46 }
47 while (count >= 8) {
48 *(unsigned long long *) d =
49 *(unsigned long long *) s;
50 d += 8;
51 s += 8;
52 count -= 8;
53 }
54 }
55
56 if (((((unsigned long) d) & 0x3) == 0) &&
57 ((((unsigned long) s) & 0x3) == 0)) {
58 while (count >= 4) {
59 *(unsigned long *) d = *(unsigned long *) s;
60 d += 4;
61 s += 4;
62 count -= 4;
63 }
64 }
65
66 if (((((unsigned long) d) & 0x1) == 0) &&
67 ((((unsigned long) s) & 0x1) == 0)) {
68 while (count >= 2) {
69 *(unsigned short *) d = *(unsigned short *) s;
70 d += 2;
71 s += 2;
72 count -= 2;
73 }
74 }
75 }
76
77 while (count--) {
78 *d++ = *s++;
79 }
80
81 return d;
82}