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