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