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