|
@@ -26,6 +26,7 @@ FILE_LICENCE ( PUBLIC_DOMAIN );
|
26
|
26
|
#define __HAVE_ARCH_MEMCPY
|
27
|
27
|
|
28
|
28
|
extern void * __memcpy ( void *dest, const void *src, size_t len );
|
|
29
|
+extern void * __memcpy_reverse ( void *dest, const void *src, size_t len );
|
29
|
30
|
|
30
|
31
|
static inline __attribute__ (( always_inline )) void *
|
31
|
32
|
__constant_memcpy ( void *dest, const void *src, size_t len ) {
|
|
@@ -144,29 +145,30 @@ __constant_memcpy ( void *dest, const void *src, size_t len ) {
|
144
|
145
|
__memcpy ( (dest), (src), (len) ) )
|
145
|
146
|
|
146
|
147
|
#define __HAVE_ARCH_MEMMOVE
|
147
|
|
-static inline void * memmove(void * dest,const void * src, size_t n)
|
148
|
|
-{
|
149
|
|
-int d0, d1, d2;
|
150
|
|
-if (dest<src)
|
151
|
|
-__asm__ __volatile__(
|
152
|
|
- "cld\n\t"
|
153
|
|
- "rep\n\t"
|
154
|
|
- "movsb"
|
155
|
|
- : "=&c" (d0), "=&S" (d1), "=&D" (d2)
|
156
|
|
- :"0" (n),"1" (src),"2" (dest)
|
157
|
|
- : "memory");
|
158
|
|
-else
|
159
|
|
-__asm__ __volatile__(
|
160
|
|
- "std\n\t"
|
161
|
|
- "rep\n\t"
|
162
|
|
- "movsb\n\t"
|
163
|
|
- "cld"
|
164
|
|
- : "=&c" (d0), "=&S" (d1), "=&D" (d2)
|
165
|
|
- :"0" (n),
|
166
|
|
- "1" (n-1+(const char *)src),
|
167
|
|
- "2" (n-1+(char *)dest)
|
168
|
|
- :"memory");
|
169
|
|
-return dest;
|
|
148
|
+
|
|
149
|
+extern void * __memmove ( void *dest, const void *src, size_t len );
|
|
150
|
+
|
|
151
|
+/**
|
|
152
|
+ * Copy (possibly overlapping) memory area
|
|
153
|
+ *
|
|
154
|
+ * @v dest Destination address
|
|
155
|
+ * @v src Source address
|
|
156
|
+ * @v len Length
|
|
157
|
+ * @ret dest Destination address
|
|
158
|
+ */
|
|
159
|
+static inline __attribute__ (( always_inline )) void *
|
|
160
|
+memmove ( void *dest, const void *src, size_t len ) {
|
|
161
|
+ ssize_t offset = ( dest - src );
|
|
162
|
+
|
|
163
|
+ if ( __builtin_constant_p ( offset ) ) {
|
|
164
|
+ if ( offset <= 0 ) {
|
|
165
|
+ return memcpy ( dest, src, len );
|
|
166
|
+ } else {
|
|
167
|
+ return __memcpy_reverse ( dest, src, len );
|
|
168
|
+ }
|
|
169
|
+ } else {
|
|
170
|
+ return __memmove ( dest, src, len );
|
|
171
|
+ }
|
170
|
172
|
}
|
171
|
173
|
|
172
|
174
|
#define __HAVE_ARCH_MEMSET
|