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