178828Sobrien#include "timing.h" 233965Sjdp#include <stdio.h> 333965Sjdp 433965Sjdp#define INPUT_TYPE int64_t 533965Sjdp#define INPUT_SIZE 256 633965Sjdp#define FUNCTION_NAME __divdi3 733965Sjdp 833965Sjdp#ifndef LIBNAME 933965Sjdp#define LIBNAME UNKNOWN 1033965Sjdp#endif 1133965Sjdp 1233965Sjdp#define LIBSTRING LIBSTRINGX(LIBNAME) 1333965Sjdp#define LIBSTRINGX(a) LIBSTRINGXX(a) 1433965Sjdp#define LIBSTRINGXX(a) #a 1533965Sjdp 1633965SjdpINPUT_TYPE FUNCTION_NAME(INPUT_TYPE input1, INPUT_TYPE input2); 1733965Sjdp 18218822Sdimint main(int argc, char *argv[]) { 19218822Sdim INPUT_TYPE input1[INPUT_SIZE]; 2033965Sjdp INPUT_TYPE input2[INPUT_SIZE]; 2133965Sjdp int i, j; 2233965Sjdp 2333965Sjdp srand(42); 2433965Sjdp 2533965Sjdp // Initialize the input array with data of various sizes. 2633965Sjdp for (i=0; i<INPUT_SIZE; ++i) { 2733965Sjdp input1[i] = (((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63); 2833965Sjdp input2[i] = ((((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63)) + 1LL; 2933965Sjdp } 3033965Sjdp 3133965Sjdp int64_t fixedInput = INT64_C(0x1234567890ABCDEF); 3233965Sjdp 3333965Sjdp double bestTime = __builtin_inf(); 3433965Sjdp void *dummyp; 3533965Sjdp for (j=0; j<1024; ++j) { 3633965Sjdp 3733965Sjdp uint64_t startTime = mach_absolute_time(); 3833965Sjdp for (i=0; i<INPUT_SIZE; ++i) 3933965Sjdp FUNCTION_NAME(input1[i], input2[i]); 4033965Sjdp uint64_t endTime = mach_absolute_time(); 4133965Sjdp 4233965Sjdp double thisTime = intervalInCycles(startTime, endTime); 4333965Sjdp bestTime = __builtin_fmin(thisTime, bestTime); 4433965Sjdp 4533965Sjdp // Move the stack alignment between trials to eliminate (mostly) aliasing effects 4633965Sjdp dummyp = alloca(1); 4733965Sjdp } 4833965Sjdp 4933965Sjdp printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE); 5033965Sjdp 5133965Sjdp return 0; 5233965Sjdp} 5333965Sjdp