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