1*7c3d14c8STreehugger Robot #include "timing.h" 2*7c3d14c8STreehugger Robot #include <stdio.h> 3*7c3d14c8STreehugger Robot 4*7c3d14c8STreehugger Robot #define INPUT_TYPE int64_t 5*7c3d14c8STreehugger Robot #define INPUT_SIZE 256 6*7c3d14c8STreehugger Robot #define FUNCTION_NAME __divdi3 7*7c3d14c8STreehugger Robot 8*7c3d14c8STreehugger Robot #ifndef LIBNAME 9*7c3d14c8STreehugger Robot #define LIBNAME UNKNOWN 10*7c3d14c8STreehugger Robot #endif 11*7c3d14c8STreehugger Robot 12*7c3d14c8STreehugger Robot #define LIBSTRING LIBSTRINGX(LIBNAME) 13*7c3d14c8STreehugger Robot #define LIBSTRINGX(a) LIBSTRINGXX(a) 14*7c3d14c8STreehugger Robot #define LIBSTRINGXX(a) #a 15*7c3d14c8STreehugger Robot 16*7c3d14c8STreehugger Robot INPUT_TYPE FUNCTION_NAME(INPUT_TYPE input1, INPUT_TYPE input2); 17*7c3d14c8STreehugger Robot main(int argc,char * argv[])18*7c3d14c8STreehugger Robotint main(int argc, char *argv[]) { 19*7c3d14c8STreehugger Robot INPUT_TYPE input1[INPUT_SIZE]; 20*7c3d14c8STreehugger Robot INPUT_TYPE input2[INPUT_SIZE]; 21*7c3d14c8STreehugger Robot int i, j; 22*7c3d14c8STreehugger Robot 23*7c3d14c8STreehugger Robot srand(42); 24*7c3d14c8STreehugger Robot 25*7c3d14c8STreehugger Robot // Initialize the input array with data of various sizes. 26*7c3d14c8STreehugger Robot for (i=0; i<INPUT_SIZE; ++i) { 27*7c3d14c8STreehugger Robot input1[i] = (((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63); 28*7c3d14c8STreehugger Robot input2[i] = ((((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63)) + 1LL; 29*7c3d14c8STreehugger Robot } 30*7c3d14c8STreehugger Robot 31*7c3d14c8STreehugger Robot int64_t fixedInput = INT64_C(0x1234567890ABCDEF); 32*7c3d14c8STreehugger Robot 33*7c3d14c8STreehugger Robot double bestTime = __builtin_inf(); 34*7c3d14c8STreehugger Robot void *dummyp; 35*7c3d14c8STreehugger Robot for (j=0; j<1024; ++j) { 36*7c3d14c8STreehugger Robot 37*7c3d14c8STreehugger Robot uint64_t startTime = mach_absolute_time(); 38*7c3d14c8STreehugger Robot for (i=0; i<INPUT_SIZE; ++i) 39*7c3d14c8STreehugger Robot FUNCTION_NAME(input1[i], input2[i]); 40*7c3d14c8STreehugger Robot uint64_t endTime = mach_absolute_time(); 41*7c3d14c8STreehugger Robot 42*7c3d14c8STreehugger Robot double thisTime = intervalInCycles(startTime, endTime); 43*7c3d14c8STreehugger Robot bestTime = __builtin_fmin(thisTime, bestTime); 44*7c3d14c8STreehugger Robot 45*7c3d14c8STreehugger Robot // Move the stack alignment between trials to eliminate (mostly) aliasing effects 46*7c3d14c8STreehugger Robot dummyp = alloca(1); 47*7c3d14c8STreehugger Robot } 48*7c3d14c8STreehugger Robot 49*7c3d14c8STreehugger Robot printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE); 50*7c3d14c8STreehugger Robot 51*7c3d14c8STreehugger Robot return 0; 52*7c3d14c8STreehugger Robot } 53