xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/test/timing/floatdisf.c (revision b9829059e8a75f40496c2d279251f331078ac82e)
1*b9829059Sjoerg #include "timing.h"
2*b9829059Sjoerg #include <stdio.h>
3*b9829059Sjoerg 
4*b9829059Sjoerg #define INPUT_TYPE int64_t
5*b9829059Sjoerg #define INPUT_SIZE 512
6*b9829059Sjoerg #define FUNCTION_NAME __floatdisf
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 float FUNCTION_NAME(INPUT_TYPE x);
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] = (((uint64_t)rand() << 32) | (uint64_t)rand()) >> (rand() & 63);
27*b9829059Sjoerg 
28*b9829059Sjoerg 	double bestTime = __builtin_inf();
29*b9829059Sjoerg 	void *dummyp;
30*b9829059Sjoerg 	for (j=0; j<1024; ++j) {
31*b9829059Sjoerg 
32*b9829059Sjoerg 		uint64_t startTime = mach_absolute_time();
33*b9829059Sjoerg 		for (i=0; i<INPUT_SIZE; ++i)
34*b9829059Sjoerg 			FUNCTION_NAME(input[i]);
35*b9829059Sjoerg 		uint64_t endTime = mach_absolute_time();
36*b9829059Sjoerg 
37*b9829059Sjoerg 		double thisTime = intervalInCycles(startTime, endTime);
38*b9829059Sjoerg 		bestTime = __builtin_fmin(thisTime, bestTime);
39*b9829059Sjoerg 
40*b9829059Sjoerg 		// Move the stack alignment between trials to eliminate (mostly) aliasing effects
41*b9829059Sjoerg 		dummyp = alloca(1);
42*b9829059Sjoerg 	}
43*b9829059Sjoerg 
44*b9829059Sjoerg 	printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE);
45*b9829059Sjoerg 
46*b9829059Sjoerg 	return 0;
47*b9829059Sjoerg }
48