mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
To: linux-kernel@vger.kernel.org, dan.carpenter@oracle.com,
	mchehab@kernel.org, paul.burton@imgtec.com
Cc: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Subject: [PATCH] lib: memmove: Use optimised memcpy if possible
Date: Wed,  4 Oct 2017 22:26:05 +0530	[thread overview]
Message-ID: <20171004165605.17123-1-prasannatsmkumar@gmail.com> (raw)

When there is no overlap between src and dst use optimised memcpy if it
is available.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Signed-off-by: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
---
This change is a small part of a patch [1] from Paul Burton. I have
added his Signed-off by. I do not know whether it is correct. Please let
me know if it has to be changed, I will send a v2.

This patch is boot tested with qemu for MIPS architecture by removing
mips's memmove routine. This patch does not contain MIPS changes. I
will try to find out why [1] was not taken already and figure out what
to do.

1. https://patchwork.linux-mips.org/patch/14517/

 lib/string.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/string.c b/lib/string.c
index 9921dc2..462ab7b 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -825,6 +825,17 @@ void *memmove(void *dest, const void *src, size_t count)
 	char *tmp;
 	const char *s;
 
+#ifdef __HAVE_ARCH_MEMCPY
+	/* Use optimised memcpy when there is no overlap */
+	const char *s_end = src + count;
+	const char *d = dest;
+	char *d_end = dest + count;
+
+	s = src;
+	if ((d_end <= s) || (s_end <= d))
+		return memcpy(dest, src, count);
+#endif /* __HAVE_ARCH_MEMCPY */
+
 	if (dest <= src) {
 		tmp = dest;
 		s = src;
-- 
2.10.0

             reply	other threads:[~2017-10-04 16:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 16:56 PrasannaKumar Muralidharan [this message]
2017-10-21  7:12 ` PrasannaKumar Muralidharan
2017-11-25 17:22 ` PrasannaKumar Muralidharan
2017-11-25 20:40   ` Dan Carpenter
2017-11-26 12:51     ` PrasannaKumar Muralidharan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171004165605.17123-1-prasannatsmkumar@gmail.com \
    --to=prasannatsmkumar@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=paul.burton@imgtec.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®