Home | History | Annotate | Line # | Download | only in timing
      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 int
      5  1.1  joerg #define INPUT_SIZE 512
      6  1.1  joerg #define FUNCTION_NAME __ashldi3
      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 int64_t FUNCTION_NAME(int64_t input, INPUT_TYPE count);
     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] = rand() & 0x3f;
     27  1.1  joerg 
     28  1.1  joerg 	int64_t fixedInput = INT64_C(0x1234567890ABCDEF);
     29  1.1  joerg 
     30  1.1  joerg 	double bestTime = __builtin_inf();
     31  1.1  joerg 	void *dummyp;
     32  1.1  joerg 	for (j=0; j<1024; ++j) {
     33  1.1  joerg 
     34  1.1  joerg 		uint64_t startTime = mach_absolute_time();
     35  1.1  joerg 		for (i=0; i<INPUT_SIZE; ++i)
     36  1.1  joerg 			FUNCTION_NAME(fixedInput, input[i]);
     37  1.1  joerg 		uint64_t endTime = mach_absolute_time();
     38  1.1  joerg 
     39  1.1  joerg 		double thisTime = intervalInCycles(startTime, endTime);
     40  1.1  joerg 		bestTime = __builtin_fmin(thisTime, bestTime);
     41  1.1  joerg 
     42  1.1  joerg 		// Move the stack alignment between trials to eliminate (mostly) aliasing effects
     43  1.1  joerg 		dummyp = alloca(1);
     44  1.1  joerg 	}
     45  1.1  joerg 
     46  1.1  joerg 	printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE);
     47  1.1  joerg 
     48  1.1  joerg 	return 0;
     49  1.1  joerg }
     50