summaryrefslogtreecommitdiff
path: root/klibc/klibc/memmove.c
diff options
context:
space:
mode:
Diffstat (limited to 'klibc/klibc/memmove.c')
-rw-r--r--klibc/klibc/memmove.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/klibc/klibc/memmove.c b/klibc/klibc/memmove.c
new file mode 100644
index 0000000000..c1f042af39
--- /dev/null
+++ b/klibc/klibc/memmove.c
@@ -0,0 +1,34 @@
+/*
+ * memmove.c
+ */
+
+#include <string.h>
+
+void *memmove(void *dst, const void *src, size_t n)
+{
+ const char *p = src;
+ char *q = dst;
+#if defined(__i386__) || defined(__x86_64__)
+ if ( q < p ) {
+ asm volatile("cld ; rep ; movsb" : "+c" (n), "+S" (p), "+D" (q));
+ } else {
+ p += (n-1);
+ q += (n-1);
+ asm volatile("std ; rep ; movsb" : "+c" (n), "+S" (p), "+D" (q));
+ }
+#else
+ if ( q < p ) {
+ while ( n-- ) {
+ *q++ = *p++;
+ }
+ } else {
+ p += n;
+ q += n;
+ while ( n-- ) {
+ *--q = *--p;
+ }
+ }
+#endif
+
+ return dst;
+}