From patchwork Wed Sep 1 10:36:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 146671 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o81Ac1a6016692 for ; Wed, 1 Sep 2010 10:38:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754781Ab0IAKhM (ORCPT ); Wed, 1 Sep 2010 06:37:12 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:65356 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754738Ab0IAKhC (ORCPT ); Wed, 1 Sep 2010 06:37:02 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id D4603170186; Wed, 1 Sep 2010 18:37:00 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o81AXZmU002519; Wed, 1 Sep 2010 18:33:35 +0800 Received: from [10.167.141.211] (unknown [10.167.141.211]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 5ACAE14C030; Wed, 1 Sep 2010 18:38:19 +0800 (CST) Message-ID: <4C7E2CAC.6080102@cn.fujitsu.com> Date: Wed, 01 Sep 2010 18:36:28 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Ingo Molnar , Andrew Morton , Chris Mason , "Theodore Ts'o" , Andreas Dilger CC: Linux Kernel , Linux Btrfs , Linux Ext4 Subject: [PATCH 2/3] lib: improve the performance of memcpy and memmove of the general version Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 01 Sep 2010 10:38:03 +0000 (UTC) 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 #include #include +#include #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; }