grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Optimise memset on i386


From: address@hidden
Subject: Re: [PATCH] Optimise memset on i386
Date: Fri, 23 Jul 2010 14:48:12 -0500



On Fri, Jul 23, 2010 at 12:34 PM, Christian Franke <address@hidden> wrote:
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.


Ok then, a compile-time conditional should fix that.
 
unsigned long patternl = pattern8;
if (8 < sizeof patternl) patternl |= patternl << 8;
if (16 < sizeof patternl) patternl |= patternl << 16;
if (32 < sizeof patternl) patternl |= patternl << 32;
if (64 < sizeof patternl) patternl |= patternl << 64;

I'm pretty confident in gcc's ability to optimize this version.  I hope.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]