1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/export.h>
28#include <linux/types.h>
29#include <linux/stddef.h>
30#include <linux/compiler.h>
31#include <linux/string.h>
32
33#ifdef __HAVE_ARCH_MEMMOVE
34#ifndef CONFIG_OPT_LIB_FUNCTION
35void *memmove(void *v_dst, const void *v_src, __kernel_size_t c)
36{
37 const char *src = v_src;
38 char *dst = v_dst;
39
40 if (!c)
41 return v_dst;
42
43
44 if (v_dst <= v_src)
45 return memcpy(v_dst, v_src, c);
46
47
48 src += c;
49 dst += c;
50
51
52 while (c--)
53 *--dst = *--src;
54
55 return v_dst;
56}
57#else
58void *memmove(void *v_dst, const void *v_src, __kernel_size_t c)
59{
60 const char *src = v_src;
61 char *dst = v_dst;
62 const uint32_t *i_src;
63 uint32_t *i_dst;
64
65 if (!c)
66 return v_dst;
67
68
69 if (v_dst <= v_src)
70 return memcpy(v_dst, v_src, c);
71
72
73
74
75
76
77
78
79
80 dst += c;
81 src += c;
82
83 if (c >= 4) {
84 unsigned value, buf_hold;
85
86
87
88
89 switch ((unsigned long)dst & 3) {
90 case 3:
91 *--dst = *--src;
92 --c;
93 case 2:
94 *--dst = *--src;
95 --c;
96 case 1:
97 *--dst = *--src;
98 --c;
99 }
100
101 i_dst = (void *)dst;
102
103
104 switch ((unsigned long)src & 3) {
105 case 0x0:
106
107 i_src = (const void *)src;
108
109 for (; c >= 4; c -= 4)
110 *--i_dst = *--i_src;
111
112 src = (const void *)i_src;
113 break;
114 case 0x1:
115
116 i_src = (const void *) (((unsigned)src + 4) & ~3);
117#ifndef __MICROBLAZEEL__
118
119 buf_hold = *--i_src >> 24;
120
121 for (; c >= 4; c -= 4) {
122 value = *--i_src;
123 *--i_dst = buf_hold << 8 | value;
124 buf_hold = value >> 24;
125 }
126#else
127
128 buf_hold = (*--i_src & 0xFF) << 24;
129
130 for (; c >= 4; c -= 4) {
131 value = *--i_src;
132 *--i_dst = buf_hold |
133 ((value & 0xFFFFFF00) >> 8);
134 buf_hold = (value & 0xFF) << 24;
135 }
136#endif
137
138 src = (const void *)i_src;
139 src += 1;
140 break;
141 case 0x2:
142
143 i_src = (const void *) (((unsigned)src + 4) & ~3);
144#ifndef __MICROBLAZEEL__
145
146 buf_hold = *--i_src >> 16;
147
148 for (; c >= 4; c -= 4) {
149 value = *--i_src;
150 *--i_dst = buf_hold << 16 | value;
151 buf_hold = value >> 16;
152 }
153#else
154
155 buf_hold = (*--i_src & 0xFFFF) << 16;
156
157 for (; c >= 4; c -= 4) {
158 value = *--i_src;
159 *--i_dst = buf_hold |
160 ((value & 0xFFFF0000) >> 16);
161 buf_hold = (value & 0xFFFF) << 16;
162 }
163#endif
164
165 src = (const void *)i_src;
166 src += 2;
167 break;
168 case 0x3:
169
170 i_src = (const void *) (((unsigned)src + 4) & ~3);
171#ifndef __MICROBLAZEEL__
172
173 buf_hold = *--i_src >> 8;
174
175 for (; c >= 4; c -= 4) {
176 value = *--i_src;
177 *--i_dst = buf_hold << 24 | value;
178 buf_hold = value >> 8;
179 }
180#else
181
182 buf_hold = (*--i_src & 0xFFFFFF) << 8;
183
184 for (; c >= 4; c -= 4) {
185 value = *--i_src;
186 *--i_dst = buf_hold |
187 ((value & 0xFF000000) >> 24);
188 buf_hold = (value & 0xFFFFFF) << 8;
189 }
190#endif
191
192 src = (const void *)i_src;
193 src += 3;
194 break;
195 }
196 dst = (void *)i_dst;
197 }
198
199
200
201 switch (c) {
202 case 4:
203 *--dst = *--src;
204 case 3:
205 *--dst = *--src;
206 case 2:
207 *--dst = *--src;
208 case 1:
209 *--dst = *--src;
210 }
211 return v_dst;
212}
213#endif
214EXPORT_SYMBOL(memmove);
215#endif
216