Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Bask the glory of optimized C code

Name: FV waifu 2011-12-10 23:03

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-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);
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List