Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OcnOY-00010A-NI for mharc-grub-devel@gnu.org; Sat, 24 Jul 2010 18:40:38 -0400 Received: from [140.186.70.92] (port=53398 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcnOW-000105-8Y for grub-devel@gnu.org; Sat, 24 Jul 2010 18:40:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OcnOV-0000VC-8V for grub-devel@gnu.org; Sat, 24 Jul 2010 18:40:36 -0400 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:47148) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OcnOV-0000Ua-3F for grub-devel@gnu.org; Sat, 24 Jul 2010 18:40:35 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1OcnOS-00014U-Cn for grub-devel@gnu.org; Sat, 24 Jul 2010 22:40:32 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1OcnOR-0000lh-00; Sat, 24 Jul 2010 23:40:31 +0100 Date: Sat, 24 Jul 2010 23:40:31 +0100 From: Colin Watson To: The development of GNU GRUB Message-ID: <20100724224031.GZ21862@riva.ucam.org> References: <20100623213838.GI21862@riva.ucam.org> <4C24F508.6040501@gmail.com> <20100723111440.GU21862@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH] Optimise memset on i386 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jul 2010 22:40:37 -0000 On Fri, Jul 23, 2010 at 10:56:24AM -0500, richardvoigt@gmail.com wrote: > [snip] > > > + unsigned long patternl = 0; > > + grub_size_t i; > > + > > + for (i = 0; i < sizeof (unsigned long); i++) > > + patternl |= ((unsigned long) pattern8) << (8 * i); > > + > > might I suggest: > > unsigned long patternl = pattern8; > patternl |= patternl << 8; > patternl |= patternl << 16; > patternl |= patternl << 32; > patternl |= patternl << 64; > > O(lg N) instead of O(N), no loop, no branches, and the compiler should be > smart enough to optimize away the last two lines on systems with narrower > long. I no longer have the system on which I benchmarked this. However, since N is always either 4 or 8 on current targets, this can only amount to micro-optimisation which I don't think can possibly matter much; we're talking a handful of cycles at most. Do we really need to spend time bikeshedding this? The important thing is taking only a cache stall per long rather than a cache stall per byte; anything else is likely to be noise. -- Colin Watson [cjwatson@ubuntu.com]