On Fri, Jul 23, 2010 at 12:34 PM, Christian Franke < christian.fra...@t-online.de> 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.
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel