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