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