Re: [RFC, 2.6] a simple FIFO implementation

From: Andrea Arcangeli
Date: Fri Sep 17 2004 - 17:04:23 EST


On Fri, Sep 17, 2004 at 02:54:00PM -0700, Ryan Cumming wrote:
> On Friday 17 September 2004 14:28, Andrea Arcangeli wrote:
> > I also wonder if a O(1) algorithm exists to roundup to the next power of
> > two (doesn't come to mind by memory, hmm maybe it's not that easy
> > problem).
>
> Assuming that the architecture has an O(1) fls() function, this should work
> for non-zero values:
>
> inline unsigned int roundup(unsigned int x)
> {
> return (1 << fls(x));
> }

looks good, hardware helps here ;) really I was trying to do it with
math, not with hardware but sounds like this is the best we can do.

doing it with unsigned long retval and 1UL is probably better.

This is likely a candidate to go in include/linux/kernel.h (maybe under
the name roundup_pow_of_two to avoid misunderstanding with the much more
common PAGE_SIZE roundups)

thanks!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/