[linux-audio-dev] next power of two
Hannes Guddat
hannes.guddat at igd.fhg.de
Wed Sep 17 23:00:01 UTC 2003
Very interesting,
"in the name of all DSP programmers" - thanksalot!
Do you have any estimation how many cycles this would spend on a pentium? I
would have make a wild guess of about 16-21 cycles + call overhead (if not
inlined)..
Hannes
P.S. Maybe you have similar code for the "bitreverse" operation.. ? just
asking.. :)
//
// we apologize for the inconvenience
//
// Hannes Guddat
// Fraunhofer IGD
// A9 - Communication and Cooperation
// Rundeturmstrasse 6
// 64283 Darmstadt
//
// Tel.: +49 6151 155-217
// Fax.: +49 6151 155-559
//
> -----Original Message-----
> From: linux-audio-dev-admin at music.columbia.edu
> [mailto:linux-audio-dev-admin at music.columbia.edu]On Behalf Of
> Maarten de
> Boer
> Sent: Mittwoch, 17. September 2003 14:22
> To: linux-audio-dev at music.columbia.edu
> Subject: [linux-audio-dev] next power of two
>
>
> Hi,
>
> A colleague of mine found this very clever algoritm to calculate the
> next power of two for a given number. It comes from the
> Prophecy SDK for
> 3d game development
> http://www.twilight3d.com/modules.php?op=modload&name=Download
> s&file=index
>
> Since this is a kind of thing often needed in audio
> processing, I wanted
> to share it with you. I certainly can not think of a faster (or more
> elegant) way of doing it.
>
> Maarten
>
> //////
> /// Returns the closest power-of-two number greater or equal
> /// to n for the given (unsigned) integer n.
> /// Will return 0 when n = 0 and 1 when n = 1.
> //////
> inline uint32_t nextPowerOfTwo(uint32_t n)
> {
> --n;
> n |= n >> 16;
> n |= n >> 8;
> n |= n >> 4;
> n |= n >> 2;
> n |= n >> 1;
> ++n;
> return n;
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxaudio.org/pipermail/linux-audio-dev/attachments/20030917/1b1c671c/attachment.html>
More information about the Linux-audio-dev
mailing list