brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 25c02bd Raw
45 lines · c
1#include "timing.h"2#include <stdio.h>3 4#ifndef LIBNAME5#define LIBNAME UNKNOWN6#endif7 8#define LIBSTRING		LIBSTRINGX(LIBNAME)9#define LIBSTRINGX(a)	LIBSTRINGXX(a)10#define LIBSTRINGXX(a)	#a11 12double __floatundidf(uint64_t x);13 14int main(int argc, char *argv[]) {15#define INPUT_SIZE 51216	uint64_t input[INPUT_SIZE];17	int i, j;18	19	srand(42);20	21	// Initialize the input array with data of various sizes.22	for (i=0; i<INPUT_SIZE; ++i)23		input[i] = (((uint64_t)rand() << 32) | (uint64_t)rand()) >> (rand() & 63);24	25	double bestTime = __builtin_inf();26	void *dummyp;27	for (j=0; j<1024; ++j) {28 29		uint64_t startTime = mach_absolute_time();30		for (i=0; i<INPUT_SIZE; ++i)31			__floatundidf(input[i]);32		uint64_t endTime = mach_absolute_time();33		34		double thisTime = intervalInCycles(startTime, endTime);35		bestTime = __builtin_fmin(thisTime, bestTime);36		37		// Move the stack alignment between trials to eliminate (mostly) aliasing effects38		dummyp = alloca(1);39	}40	41	printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE);42	43	return 0;44}45