From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751384AbdJDQ5Q (ORCPT ); Wed, 4 Oct 2017 12:57:16 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36729 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751259AbdJDQ5O (ORCPT ); Wed, 4 Oct 2017 12:57:14 -0400 X-Google-Smtp-Source: AOwi7QBc7eqQEsfmegyHim8NJnv5uP74+vUFY8+P3AJVjpZX6TzHXjHITiz60m+qZsG/RuKLjcmSLw== From: PrasannaKumar Muralidharan To: linux-kernel@vger.kernel.org, dan.carpenter@oracle.com, mchehab@kernel.org, paul.burton@imgtec.com Cc: PrasannaKumar Muralidharan Subject: [PATCH] lib: memmove: Use optimised memcpy if possible Date: Wed, 4 Oct 2017 22:26:05 +0530 Message-Id: <20171004165605.17123-1-prasannatsmkumar@gmail.com> X-Mailer: git-send-email 2.10.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there is no overlap between src and dst use optimised memcpy if it is available. Signed-off-by: Paul Burton Signed-off-by: PrasannaKumar Muralidharan --- 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