11.1Sjoerg#include "timing.h"
21.1Sjoerg#include <stdio.h>
31.1Sjoerg
41.1Sjoerg#define INPUT_TYPE int64_t
51.1Sjoerg#define INPUT_SIZE 256
61.1Sjoerg#define FUNCTION_NAME __divdi3
71.1Sjoerg
81.1Sjoerg#ifndef LIBNAME
91.1Sjoerg#define LIBNAME UNKNOWN
101.1Sjoerg#endif
111.1Sjoerg
121.1Sjoerg#define LIBSTRING		LIBSTRINGX(LIBNAME)
131.1Sjoerg#define LIBSTRINGX(a)	LIBSTRINGXX(a)
141.1Sjoerg#define LIBSTRINGXX(a)	#a
151.1Sjoerg
161.1SjoergINPUT_TYPE FUNCTION_NAME(INPUT_TYPE input1, INPUT_TYPE input2);
171.1Sjoerg
181.1Sjoergint main(int argc, char *argv[]) {
191.1Sjoerg	INPUT_TYPE input1[INPUT_SIZE];
201.1Sjoerg	INPUT_TYPE input2[INPUT_SIZE];
211.1Sjoerg	int i, j;
221.1Sjoerg
231.1Sjoerg	srand(42);
241.1Sjoerg
251.1Sjoerg	// Initialize the input array with data of various sizes.
261.1Sjoerg	for (i=0; i<INPUT_SIZE; ++i) {
271.1Sjoerg		input1[i] = (((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63);
281.1Sjoerg		input2[i] = ((((int64_t)rand() << 36) | (uint64_t)rand()) >> (rand() & 63)) + 1LL;
291.1Sjoerg	}
301.1Sjoerg
311.1Sjoerg	int64_t fixedInput = INT64_C(0x1234567890ABCDEF);
321.1Sjoerg
331.1Sjoerg	double bestTime = __builtin_inf();
341.1Sjoerg	void *dummyp;
351.1Sjoerg	for (j=0; j<1024; ++j) {
361.1Sjoerg
371.1Sjoerg		uint64_t startTime = mach_absolute_time();
381.1Sjoerg		for (i=0; i<INPUT_SIZE; ++i)
391.1Sjoerg			FUNCTION_NAME(input1[i], input2[i]);
401.1Sjoerg		uint64_t endTime = mach_absolute_time();
411.1Sjoerg
421.1Sjoerg		double thisTime = intervalInCycles(startTime, endTime);
431.1Sjoerg		bestTime = __builtin_fmin(thisTime, bestTime);
441.1Sjoerg
451.1Sjoerg		// Move the stack alignment between trials to eliminate (mostly) aliasing effects
461.1Sjoerg		dummyp = alloca(1);
471.1Sjoerg	}
481.1Sjoerg
491.1Sjoerg	printf("%16s: %f cycles.\n", LIBSTRING, bestTime / (double) INPUT_SIZE);
501.1Sjoerg
511.1Sjoerg	return 0;
521.1Sjoerg}
53