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