0 is not a power of 2

Jay Norwood via Digitalmars-d digitalmars-d at puremagic.com
Thu May 21 22:24:13 PDT 2015


This formula measures  a little faster on dmd.  Release build, 
three tests, find all values for 0..uint.max.

first result uses
if (((x-1)&(x|0x80000000))==0)

second result uses
if ((x & (x - 1) | !x) == 0)


D:\pow2\pow2\pow2\Release>pow2
duration(msec)=10259
duration(msec)=10689

D:\pow2\pow2\pow2\Release>pow2
duration(msec)=10256
duration(msec)=10695

D:\pow2\pow2\pow2\Release>pow2
duration(msec)=10264
duration(msec)=10726


More information about the Digitalmars-d mailing list