[sldev] getting serious about software.
Callum Lerwick
seg at haxxed.com
Sat Jun 23 13:08:56 PDT 2007
On Sat, 2007-06-23 at 15:28 +0200, Nicholaz Beresford wrote:
> Just for the fun of it, here's my version
> (it's exactly the same behavior as the float
> version, not rounding up numbers that are already
> powers of two).
> +S32 next_power_of_two(S32 n)
> +{
> + S32 res = (n<(1<<15)) ? (1<<15) : (1<<30);
> +
> + while (res>=n) {
> + res>>= 1;
> + }
> +
> + return (res<<1);
> +}
This is a little over twice as fast on my Athlon 64, about a third
faster on my PIII, and a quarter faster on my G3 iMac:
int next_power_of_two2(int v){
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return v;
}
(Snagged from here:
http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2Float )
At any rate, the existing version is reeeally slow. Please Jira this.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.secondlife.com/pipermail/sldev/attachments/20070623/f23e284b/attachment.pgp
More information about the SLDev
mailing list