From patchwork Fri Jul 26 06:53:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: warmcat X-Patchwork-Id: 18600 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f198.google.com (mail-ye0-f198.google.com [209.85.213.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3E97027746 for ; Fri, 26 Jul 2013 06:53:31 +0000 (UTC) Received: by mail-ye0-f198.google.com with SMTP id m13sf1410580yen.1 for ; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to:subject:to :from:cc:date:message-id:user-agent:mime-version:x-gm-message-state :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-google-group-id:list-post:list-help :list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=/EPDfym77tkaNnia+/fFXeDba+Qwv8cykYBp0b5SI1g=; b=UXgMP254mhIXyN0H3mfa0RqfEg8D67AAFyx5dTEnyxEQyTZz3sJ92CXOX+0afuv8al 8BVLhBqniCOVvIxR02/K0B93rjfnYn9VNUOHhKJdQZ/5oVGFniMuu9wkGuUGutM1eUn9 NwuscUKs62ZWz69bF0SnAY+sd/C2DawOB0Y7WIfi13bP92HN5wWPWlH0xmEybWhH1jyc FaoiFvle3jOn+y8IfRF5wYjoTwp6z8MauohIUmvoGvVl1aFkMWSSgunsdijGV6lejKoX Apsxy6F1QH+DAVfbU8HKx0DH6QVbGb97ikEtcPzQ3FSxZRPjgJGmiIQyLenOd6elODhm 5U0A== X-Received: by 10.236.148.33 with SMTP id u21mr720726yhj.37.1374821609437; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.106.134 with SMTP id gu6ls927549qeb.83.gmail; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) X-Received: by 10.52.97.100 with SMTP id dz4mr5122369vdb.113.1374821609216; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by mx.google.com with ESMTPS id uf1si1605590vcb.7.2013.07.25.23.53.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Jul 2013 23:53:29 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.46; Received: by mail-vb0-f46.google.com with SMTP id w8so993068vbf.33 for ; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) X-Received: by 10.220.53.7 with SMTP id k7mr2455401vcg.52.1374821609053; Thu, 25 Jul 2013 23:53:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp6833veb; Thu, 25 Jul 2013 23:53:28 -0700 (PDT) X-Received: by 10.66.154.1 with SMTP id vk1mr45636708pab.85.1374821605997; Thu, 25 Jul 2013 23:53:25 -0700 (PDT) Received: from localhost.localdomain (114-25-201-216.dynamic.hinet.net. [114.25.201.216]) by mx.google.com with ESMTPS id to1si1105823pab.341.2013.07.25.23.53.24 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Jul 2013 23:53:25 -0700 (PDT) Received-SPF: neutral (google.com: 114.25.201.216 is neither permitted nor denied by best guess record for domain of andy.green@linaro.org) client-ip=114.25.201.216; Received: from localhost.localdomain (localhost [127.0.0.1]) by localhost.localdomain (8.14.7/8.14.7) with ESMTP id r6Q6rNG8027355; Fri, 26 Jul 2013 14:53:23 +0800 Subject: [PATCH] uboot optimize memmove To: u-boot@lists.denx.de From: Andy Green Cc: linaro-dev@lists.linaro.org, patches@linaro.org Date: Fri, 26 Jul 2013 14:53:23 +0800 Message-ID: <20130726065323.27333.82421.stgit@localhost.localdomain> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlrRL4OHslfqDYc0M1oKCVsncXV5JKqEkUUCV+qZ5PgwcCZYDdH4Y5pHCQ6emzAyxa9isng X-Original-Sender: andy.green@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.46 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , While studying the reason why kernel copy from NOR was so slow on our platform, I realized U-Boot is pulling it from 32-bit NOR in 8-bit chunks needlessly. bootm uses memmove() and that just takes the approach by default to move u8s around. This optimization prefers memcpy() implementation (done mostly in 32-bit reads and writes) if there's no overlap in source and dest, resulting in a huge speedup on our platform (480ms copy from 32-bit NOR ---> 140ms) Signed-off-by: Andy Green --- lib/string.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/string.c b/lib/string.c index c3ad055..96d66e0 100644 --- a/lib/string.c +++ b/lib/string.c @@ -542,13 +542,21 @@ void * memmove(void * dest,const void *src,size_t count) if (src == dest) return dest; - if (dest <= src) { + if (dest < src) { + + if ((unsigned long)dest + count <= (unsigned long)src) + return memcpy(dest, src, count); + tmp = (char *) dest; s = (char *) src; while (count--) *tmp++ = *s++; } else { + + if ((unsigned long)src + count <= (unsigned long)dest) + return memcpy(dest, src, count); + tmp = (char *) dest + count; s = (char *) src + count; while (count--)