Re: [RFC, 2.6] a simple FIFO implementation

From: Ryan Cumming
Date: Fri Sep 17 2004 - 16:57:17 EST


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));
}

-Ryan

Attachment: pgp00000.pgp
Description: PGP signature