From patchwork Mon May 23 09:03:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Weisser X-Patchwork-Id: 96841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C853EB6FAF for ; Mon, 23 May 2011 19:04:21 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1D3E6280D8; Mon, 23 May 2011 11:04:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Kmvr-eMICEH9; Mon, 23 May 2011 11:04:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A5D40280CF; Mon, 23 May 2011 11:04:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4F1FD280CF for ; Mon, 23 May 2011 11:04:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4GUuuf6qqUEh for ; Mon, 23 May 2011 11:04:11 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-in-01.arcor-online.net (mail-in-01.arcor-online.net [151.189.21.41]) by theia.denx.de (Postfix) with ESMTPS id 04F90280CE for ; Mon, 23 May 2011 11:04:09 +0200 (CEST) Received: from mail-in-13-z2.arcor-online.net (mail-in-13-z2.arcor-online.net [151.189.8.30]) by mx.arcor.de (Postfix) with ESMTP id E707C5A229; Mon, 23 May 2011 11:04:08 +0200 (CEST) Received: from mail-in-13.arcor-online.net (mail-in-13.arcor-online.net [151.189.21.53]) by mail-in-13-z2.arcor-online.net (Postfix) with ESMTP id BFF06E19BC; Mon, 23 May 2011 11:04:08 +0200 (CEST) Received: from localhost.localdomain (unknown [212.87.136.142]) (Authenticated sender: weisserm@arcor.de) by mail-in-13.arcor-online.net (Postfix) with ESMTPA id E23F421256A; Mon, 23 May 2011 11:04:07 +0200 (CEST) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-13.arcor-online.net E23F421256A From: Matthias Weisser To: u-boot@lists.denx.de Date: Mon, 23 May 2011 11:03:55 +0200 Message-Id: <1306141435-24001-1-git-send-email-weisserm@arcor.de> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1302591520-12517-1-git-send-email-weisserm@arcor.de> References: <1302591520-12517-1-git-send-email-weisserm@arcor.de> Subject: [U-Boot] [PATCH V2] memcpy/memmove: Do not copy to same address X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In some cases (e.g. bootm with a elf payload which is already at the right position) there is a in place copy of data to the same address. Catching this saves some ms while booting. Signed-off-by: Matthias Weisser --- Changes since V1: - Made subject more informative - Removed the optimization from bcopy as bcopy is not used anywhere lib/string.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/lib/string.c b/lib/string.c index b375b81..2c4f0ec 100644 --- a/lib/string.c +++ b/lib/string.c @@ -467,6 +467,9 @@ void * memcpy(void *dest, const void *src, size_t count) unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src; char *d8, *s8; + if (src == dest) + return dest; + /* while all data is aligned (common case), copy a word at a time */ if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) { while (count >= sizeof(*dl)) { @@ -497,6 +500,9 @@ void * memmove(void * dest,const void *src,size_t count) { char *tmp, *s; + if (src == dest) + return dest; + if (dest <= src) { tmp = (char *) dest; s = (char *) src;