diff mbox

x86_64/lib: improve the performance of memmove

Message ID 4C91F5DF.9060001@cn.fujitsu.com
State Not Applicable, archived
Headers show

Commit Message

Miao Xie Sept. 16, 2010, 10:47 a.m. UTC
None
diff mbox

Patch

diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
index bcbcd1e..9de5e9a 100644
--- a/arch/x86/lib/memcpy_64.S
+++ b/arch/x86/lib/memcpy_64.S
@@ -141,3 +141,32 @@  ENDPROC(__memcpy)
  	.byte .Lmemcpy_e - .Lmemcpy_c
  	.byte .Lmemcpy_e - .Lmemcpy_c
  	.previous
+
+/*
+ * Copy memory backwards (for memmove)
+ * rdi target
+ * rsi source
+ * rdx count
+ */
+
+ENTRY(memcpy_backwards)
+	CFI_STARTPROC
+	std
+	movq %rdi, %rax
+	movl %edx, %ecx
+	addq %rdx, %rdi
+	addq %rdx, %rsi
+	leaq -8(%rdi), %rdi
+	leaq -8(%rsi), %rsi
+	shrl $3, %ecx
+	andl $7, %edx
+	rep movsq
+	addq $7, %rdi
+	addq $7, %rsi
+	movl %edx, %ecx
+	rep movsb
+	cld
+	ret
+	CFI_ENDPROC
+ENDPROC(memcpy_backwards)
+	
diff --git a/arch/x86/lib/memmove_64.c b/arch/x86/lib/memmove_64.c
index 0a33909..6774fd8 100644
--- a/arch/x86/lib/memmove_64.c
+++ b/arch/x86/lib/memmove_64.c
@@ -5,16 +5,16 @@ 
  #include <linux/string.h>
  #include <linux/module.h>
  
+extern void * asmlinkage memcpy_backwards(void *dst, const void *src,
+				        size_t count);
+
  #undef memmove
  void *memmove(void *dest, const void *src, size_t count)
  {
  	if (dest < src) {
  		return memcpy(dest, src, count);
  	} else {
-		char *p = dest + count;
-		const char *s = src + count;
-		while (count--)
-			*--p = *--s;
+		return memcpy_backwards(dest, src, count);
  	}
  	return dest;
  }