/*
 * Generate a C file to test the speed of ARM (and MaverickCrunch) instruction
 * sequences.
 *
 * To find the number of ARM clocks for a code fragment on a 200MHz CPU:
 *	vi gen_timing.c; make; time ./timing 200000000
 * where Makefile contains:
 *	CFLAGS=-mcpu=ep9312 -mfpu=maverick -mfloat-abi=softfp
 *
 *	all: timing
 *
 *	timing.c: gen_timing
 *		./gen_timing > timing.c
 */

#include <stdlib.h>
#include <stdio.h>

/* How many times to repeat the code block in the test function.
 * Should be large enough that the function call overhead is negligable,
 * but small enough that the code fits in the 16Kbyte instruction cache
 * (==4kword ==4000 instructions). 400 barely allows for max of 10 insns.
 */
#define GROUPS_PER_LOOP 400

main()
{
	int i;

	puts("/* Auto-generated C file to test Crunch insn speed  */");
	puts("#include <stdlib.h>");
	puts("#include <stdio.h>");
	puts("");
	puts("void foo(int *);");
	puts("int i32[20];	/* Somewhere to do memory load/stores */");
	puts("");
	puts("main(int argc, char **argv)");
	puts("{");
	puts("\tint niter = (argc <= 1) ? 1 : atoi(argv[1]);");
	puts("");
	printf("\tniter /= %d;\n", GROUPS_PER_LOOP);
	puts("\twhile (niter-- > 0) foo(i32);");
	puts("\texit(0);");
	puts("}");
	puts("void foo(int *i32p)");
	puts("{");
	for (i=GROUPS_PER_LOOP; i>0; i--) {
		puts("\tasm(\"\
cfldrs	mvf0,[r0];\
mov	r1,r1;\
mov	r1,r1;\
mov	r1,r1;\
				\");");
	}
	puts("}");

	exit(0);
}
