linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
@ 2010-09-02  5:46 Miao Xie
  0 siblings, 0 replies; 6+ messages in thread
From: Miao Xie @ 2010-09-02  5:46 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Andrew Morton, Theodore Ts'o,
	Andreas Dilger
  Cc: Linux Kernel, Linux Btrfs, Linux Ext4

the performance of memcpy and memmove of the general version is
very inefficient, this patch improved them.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 lib/string.c |   32 ++++++++++++++------------------
 1 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index f71bead..6cbf6d8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
+#include <linux/memcopy.h>
 
 #ifndef __HAVE_ARCH_STRNICMP
 /**
@@ -567,11 +568,12 @@ EXPORT_SYMBOL(memset);
  */
 void *memcpy(void *dest, const void *src, size_t count)
 {
-	char *tmp = dest;
-	const char *s = src;
+	unsigned long dstp = (unsigned long)dest;
+	unsigned long srcp = (unsigned long)src;
+
+	/* Copy from the beginning to the end */
+	mem_copy_fwd(dstp, srcp, count);
 
-	while (count--)
-		*tmp++ = *s++;
 	return dest;
 }
 EXPORT_SYMBOL(memcpy);
@@ -588,21 +590,15 @@ EXPORT_SYMBOL(memcpy);
  */
 void *memmove(void *dest, const void *src, size_t count)
 {
-	char *tmp;
-	const char *s;
-
-	if (dest <= src) {
-		tmp = dest;
-		s = src;
-		while (count--)
-			*tmp++ = *s++;
+	unsigned long dstp = (unsigned long)dest;
+	unsigned long srcp = (unsigned long)src;
+
+	if (dest - src >= count) {
+		/* Copy from the beginning to the end */
+		mem_copy_fwd(dstp, srcp, count);
 	} else {
-		tmp = dest;
-		tmp += count;
-		s = src;
-		s += count;
-		while (count--)
-			*--tmp = *--s;
+		/* Copy from the end to the beginning */
+		mem_copy_bwd(dstp, srcp, count);
 	}
 	return dest;
 }
-- 
1.7.0.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version
@ 2010-09-01 10:36 Miao Xie
  2010-09-03 11:03 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Miao Xie @ 2010-09-01 10:36 UTC (permalink / raw)
  To: Ingo Molnar, Andrew Morton, Chris Mason, Theodore Ts'o,
	Andreas Dilger
  Cc: Linux Kernel, Linux Btrfs, Linux Ext4

the performance of memcpy and memmove of the general version is
very inefficient, this patch improved them.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 lib/string.c |   32 ++++++++++++++------------------
 1 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index f71bead..6cbf6d8 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -23,6 +23,7 @@
 #include <linux/string.h>
 #include <linux/ctype.h>
 #include <linux/module.h>
+#include <linux/memcopy.h>
 
 #ifndef __HAVE_ARCH_STRNICMP
 /**
@@ -567,11 +568,12 @@ EXPORT_SYMBOL(memset);
  */
 void *memcpy(void *dest, const void *src, size_t count)
 {
-	char *tmp = dest;
-	const char *s = src;
+	unsigned long dstp = (unsigned long)dest;
+	unsigned long srcp = (unsigned long)src;
+
+	/* Copy from the beginning to the end */
+	mem_copy_fwd(dstp, srcp, count);
 
-	while (count--)
-		*tmp++ = *s++;
 	return dest;
 }
 EXPORT_SYMBOL(memcpy);
@@ -588,21 +590,15 @@ EXPORT_SYMBOL(memcpy);
  */
 void *memmove(void *dest, const void *src, size_t count)
 {
-	char *tmp;
-	const char *s;
-
-	if (dest <= src) {
-		tmp = dest;
-		s = src;
-		while (count--)
-			*tmp++ = *s++;
+	unsigned long dstp = (unsigned long)dest;
+	unsigned long srcp = (unsigned long)src;
+
+	if (dest - src >= count) {
+		/* Copy from the beginning to the end */
+		mem_copy_fwd(dstp, srcp, count);
 	} else {
-		tmp = dest;
-		tmp += count;
-		s = src;
-		s += count;
-		while (count--)
-			*--tmp = *--s;
+		/* Copy from the end to the beginning */
+		mem_copy_bwd(dstp, srcp, count);
 	}
 	return dest;
 }
-- 
1.7.0.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-09-04 14:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-02  5:46 [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version Miao Xie
  -- strict thread matches above, loose matches on Subject: below --
2010-09-01 10:36 Miao Xie
2010-09-03 11:03 ` Florian Weimer
2010-09-03 18:16   ` Andreas Dilger
2010-09-04 12:59   ` Calvin Walton
2010-09-04 14:41     ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).