Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761AbbBWUlM (ORCPT ); Mon, 23 Feb 2015 15:41:12 -0500 Received: from mout.gmx.net ([212.227.15.18]:58743 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751861AbbBWUlL (ORCPT ); Mon, 23 Feb 2015 15:41:11 -0500 Message-ID: <54EB905B.8010704@gmx.de> Date: Mon, 23 Feb 2015 21:40:59 +0100 From: Heinrich Schuchardt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.4.0 MIME-Version: 1.0 To: OGAWA Hirofumi , Alexander Kuleshov CC: linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs/fat: calculate checksum in a loop instead of directly calculating References: <1424285300-14431-1-git-send-email-kuleshovmail@gmail.com> <878ufvowcd.fsf@mail.parknet.co.jp> <87wq3fnep7.fsf@mail.parknet.co.jp> In-Reply-To: <87wq3fnep7.fsf@mail.parknet.co.jp> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:IizgN5qJusu3/pQ23MlYp9g7Er43eMY4l/yJ83pgnGBXDHo69zu MarPBRLV0Z7Z79/86sU9wO9U7hiK4ZCxR0h8aYLnOFgR9fyf4dgnVPtScpiv1467w1AGvkk C4ZGbkMJKJR5d+pnqYtrlPyOlv2XW7yM1zkEGon13LdPWRee0R9OUKcFEPgWZ1Pjo+e6NsS mSpURxIqfYc7n6S/vlD3Q== X-UI-Out-Filterresults: notjunk:1; Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2852 Lines: 131 On 18.02.2015 21:32, OGAWA Hirofumi wrote: > Alexander Kuleshov writes: > >> time ./test_with_loop >> >> real 0m0.001s >> user 0m0.000s >> sys 0m0.001s >> >> And >> >> time ./test_direct_calculation: >> >> real 0m0.002s >> user 0m0.000s >> sys 0m0.001s > > Hm, > > #include > #include > #include > > typedef unsigned char __u8; > typedef unsigned char u8; > > #if 1 > static inline unsigned char fat_checksum(const __u8 *name) > { > unsigned char s = name[0]; > s = (s<<7) + (s>>1) + name[1]; s = (s<<7) + (s>>1) + name[2]; > s = (s<<7) + (s>>1) + name[3]; s = (s<<7) + (s>>1) + name[4]; > s = (s<<7) + (s>>1) + name[5]; s = (s<<7) + (s>>1) + name[6]; > s = (s<<7) + (s>>1) + name[7]; s = (s<<7) + (s>>1) + name[8]; > s = (s<<7) + (s>>1) + name[9]; s = (s<<7) + (s>>1) + name[10]; > return s; > } > #else > static inline unsigned char fat_checksum(const __u8 *name) > { > unsigned char s = name[0]; > u8 i; > for (i = 1; i < 11; i++) > s = (s << 7) + (s >> 1) + name[i]; > return s; > } > #endif > > static __attribute__ ((noinline)) int test(unsigned char *name) You have to put __attribute__((optimize("unroll-loops"))) here to unroll the loop inside the function: static __attribute__ ((noinline)) __attribute__((optimize("unroll-loops"))) int test(unsigned char *name) > { > long i; > for (i = 0; i < 100000000L; i++) > name[i % 11] = fat_checksum(name); > return name[0]; > } > > int main(int argc, char *argv[]) > { > printf("%u\n", test((unsigned char *)argv[1])); > return 0; > } > > > $ gcc --version > gcc (Debian 4.9.1-19) 4.9.1 > Copyright (C) 2014 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > $ gcc -O2 -o c.inline c.c > # change #if 1 => #if 0 > $ gcc -O2 -o c.loop c.c > > $ time ./c.inline aaaaaaaaaaa > 14 > > real 0m0.550s > user 0m0.548s > sys 0m0.000s > $ time ./c.loop aaaaaaaaaaa > 14 > > real 0m0.901s > user 0m0.896s > sys 0m0.004s > > This is my environment only? (gcc (Debian 4.9.1-19) 4.9.1) > $ time ./c.inline aaaaaaaaaaa 14 real 0m0.743s user 0m0.740s sys 0m0.000s Without __attribute__((optimize("unroll-loops"))) : $ time ./c.loop aaaaaaaaaaa 14 real 0m1.482s user 0m1.472s sys 0m0.004s With __attribute__((optimize("unroll-loops"))) : $ time ./c.loop aaaaaaaaaaa 14 real 0m0.742s user 0m0.740s sys 0m0.000s Best regards Heinrich Schuchardt -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/