From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OcM9K-0004Bi-8A for mharc-grub-devel@gnu.org; Fri, 23 Jul 2010 13:35:06 -0400 Received: from [140.186.70.92] (port=41919 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OcM9H-00049f-Uw for grub-devel@gnu.org; Fri, 23 Jul 2010 13:35:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OcM9G-0003gR-Qs for grub-devel@gnu.org; Fri, 23 Jul 2010 13:35:03 -0400 Received: from mailout05.t-online.de ([194.25.134.82]:51698) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OcM9G-0003ff-MA for grub-devel@gnu.org; Fri, 23 Jul 2010 13:35:02 -0400 Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de ) by mailout05.t-online.de with smtp id 1OcM9D-0001IE-Uv; Fri, 23 Jul 2010 19:34:59 +0200 Received: from [192.168.2.100] (bKdLEcZEohCp1SlZZ1+mDGN-Gmp5c9w-aAvH5q+PTe4L-Cr452UIa1EvKpR7uSIg56@[79.224.125.132]) by fwd02.aul.t-online.de with esmtp id 1OcM95-0j4Mzo0; Fri, 23 Jul 2010 19:34:51 +0200 Message-ID: <4C49D2BB.4050901@t-online.de> Date: Fri, 23 Jul 2010 19:34:51 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.10) Gecko/20100504 SeaMonkey/2.0.5 MIME-Version: 1.0 To: The development of GNU GRUB References: <20100623213838.GI21862@riva.ucam.org> <4C24F508.6040501@gmail.com> <20100723111440.GU21862@riva.ucam.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ID: bKdLEcZEohCp1SlZZ1+mDGN-Gmp5c9w-aAvH5q+PTe4L-Cr452UIa1EvKpR7uSIg56 X-TOI-MSGID: c738019e-d478-4cf5-9056-8b9ed1c72530 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: Fri, 23 Jul 2010 17:35:05 -0000 richardvoigt wrote: > > 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. The latter is unfortunately not the case. At least gcc 4.5.0 prints a warning but still produces code. $ cat <f.c unsigned long f(unsigned long x) { x |= x << 32; x |= x << 64; return x; } $ gcc -O3 -S f.c x.c: In function ‘f’: x.c:3: warning: left shift count >= width of type x.c:4: warning: left shift count >= width of type $ cat f.s ... pushl %ebp movl $32, %ecx movl %esp, %ebp movl 8(%ebp), %eax popl %ebp movl %eax, %edx sall %cl, %edx movl $64, %ecx orl %eax, %edx movl %edx, %eax sall %cl, %eax orl %edx, %eax ret -- Regards, Christian Franke