Here is my full source code, just so there is no confusion - and by that I mean errors caused by me forgetting to make certain changes when copying the code over.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#define MAX 1000000000
#define NUM_FOR_AVG 1000000
#define SIZE 31
inline unsigned long long int smult( long long m, long long n )
{
unsigned long long x = m ^ ((m ^ n)& -(m > n)),\
y = m ^ ((m ^ n)& -(m<n)),\
a=0;
int i = 0;
do a += (y&-(x&1))<<(i++); while(x>>=1);
return a;
}
int main( int argc, char** argv )
{
clock_t begin1, end1, begin2, end2;
unsigned long long m = 2, n = 1;
double avg1, avg2;
int trials, trials1, i=0;
FILE *fp;
fp = fopen(argv[1], "w");
while( i++ < SIZE )
{
trials = NUM_FOR_AVG;
avg1 = avg2 = 0;
while( trials-- )
{
trials1 = MAX;
begin1 = clock();
while( trials1-- ) m*n;
end1 = clock();
avg1 += (double)(begin1 - end1);
trials1 = MAX;
begin2 = clock();
while( trials1-- ) smult(m,n);
end2 = clock();
avg2 += (double)(begin2 - end2);
}
avg1 /= CLOCKS_PER_SEC;
avg2 /= CLOCKS_PER_SEC;
m = (m<<1) -1;
n <<= 1;
fprintf( fp, "%d %g %g\n", i, avg1/NUM_FOR_AVG, avg2/NUM_FOR_AVG );
printf("%.2g%%\n", (double)i*100/SIZE);
}
fclose(fp);
}
Now running this code again with the NUM_FOR_AVG constant I seem to be getting more sensible results, such as mult() taking some constant time longer than the * operator