Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-12 5:39
In theory this should produce faster code by removing the IF branching, though its harder to optimize(so compiler produces worse code):
#include <stdio.h>
long long rdtsc(){__asm{RDTSC}}
void main() {
long long b,a = rdtsc();
int nlen=1,n=1,counter,i,m=100000,w;
long long number;
for (i=2; i<=m; ++i) {
for (number=i,counter=1; number!=1; ++counter){
w=number&1;number=((w)+(number+(number<<(w))))>>((((w)^1)<<1));
}
if (counter > nlen){ nlen = counter; n = i;}
}
b = rdtsc();
printf("result:%i cycles:%lld\n",n,b-a);
}