Ok, since when I asked about NextPower2 I got so many answers, and everyone seemed to have fun. Lets try a little challenge.
Create the fastest cross platform implementation of NextPower2 that takes and returns a LongInt.
[pascal]function NextPow2(aVal : LongInt) : LongInt;
if aVal >= (1 shl 31) then
result := 1 shl 31;
result := 1;
while result < aVal do
result := result shl 1;
* Must compile in FPC for Windows, Linux, and Mac
* You can't simply extend cairnswm fixed lookup table method, as this will always be the fastest possible, and eventually memory comes into concern.
I haven't thought of a benchmark or anything just yet, any suggestions?
PS: I think that if there is interest in this sort of thing, then WILL or Dom should create a place for us to post the winning code snippets for when people ask how to do something quickly