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