inp004.c 8.04 KB
#include <bstring.h>
#include <math.h>
#include <stdio.h>

#include "inp.h"

static void varySubAInputs(void);
static void varySubBInputs(void);
static void varyMultInputs(void);
static void varyAddInputs(void);
static void monteCarlo(void);

int
main(int argc, char *argv[])
{
	printHeader();
	varySubAInputs();
	varySubBInputs();
	varyMultInputs();
	varyAddInputs();
	monteCarlo();
	printTrailingCycles();
}

static void
varySubAInputs(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;
	int env_values[] = {0x00, 0x01, 0xff };
	int tf_values[]  = {0x000, 0x001, 0x0ff, 0x100, 0x17f, 0x180, 0x1ff };

	printf("# Vary Subtractor A Inputs\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */

	/* Initialize (y,a,c) selects to produce (0,0xff,0) */

	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_a_sel_1_r = CC_MULT_LODF;
	ccp->cc_c_sel_1_r = CC_ADD_ZERO;

	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_LODF_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_ZERO_ALPHA;

	ccp->tf_lod_frac = 0xff;

	printf("# Walking 0's\n");

	ccp->cc_x_sel_1_r = CC_SUBA_TEX_1;
	ccp->cc_x_sel_1_a = CC_SUBA_TEX_1_ALPHA;

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x1ff;
	printVector(ccp, 1);

	for (i = 0; i < 9; i++) {
		ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a =
							~(1 << i) & 0x1ff;
		printVector(ccp, 1);
	}

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x0;

	printf("# Ones\n");

	ccp->cc_x_sel_1_r = CC_SUBA_ONE;
	ccp->cc_x_sel_1_a = CC_SUBA_ONE_ALPHA;

	printVector(ccp, 1);

	printf("# Zeroes\n");

	ccp->cc_x_sel_1_r = CC_SUBA_ZERO;
	ccp->cc_x_sel_1_a = CC_SUBA_ZERO_ALPHA;

	printVector(ccp, 1);

	printf("# Various borderline numbers through an 8 bit pathway\n");

	ccp->cc_x_sel_1_r = CC_SUBA_ENV_CLR;
	ccp->cc_x_sel_1_a = CC_SUBA_ENV_ALPHA;

	for (i = 0; i < sizeof(env_values)/sizeof(int); i++) {
	    ccp->env_r = ccp->env_g = ccp->env_b = ccp->env_a = env_values[i];

	    printVector(ccp, 1);
	}

	printf("# Various borderline numbers through a 9 bit pathway\n");

	ccp->cc_x_sel_1_r = CC_SUBA_TEX_1;
	ccp->cc_x_sel_1_a = CC_SUBA_TEX_1_ALPHA;

	for (i = 0; i < sizeof(tf_values)/sizeof(int); i++) {
	    ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = tf_values[i];

	    printVector(ccp, 1);
	}
}

static void
varySubBInputs(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;
	int env_values[] = {0x00, 0x01, 0xff };
	int tf_values[]  = {0x000, 0x001, 0x0ff, 0x100, 0x17f, 0x180, 0x1ff };

	printf("# Vary Subtractor B Inputs\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */

	/* Initialize (x,a,c) selects to produce (1,.ff,0) */

	ccp->cc_x_sel_1_r = CC_SUBA_ONE;
	ccp->cc_a_sel_1_r = CC_MULT_LODF;
	ccp->cc_c_sel_1_r = CC_ADD_ZERO;

	ccp->cc_x_sel_1_a = CC_SUBA_ONE_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_LODF_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_ZERO_ALPHA;

	ccp->tf_lod_frac = 0xff;

	printf("# Walking 0's\n");

	ccp->cc_y_sel_1_r = CC_SUBA_TEX_1;
	ccp->cc_y_sel_1_a = CC_SUBA_TEX_1_ALPHA;

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x1ff;
	printVector(ccp, 1);

	for (i = 0; i < 9; i++) {
		ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a =
							~(1 << i) & 0x1ff;
		printVector(ccp, 1);
	}

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x0;

	printf("# Zeroes\n");

	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;

	printVector(ccp, 1);

	printf("# Ones\n");

	ccp->cc_y_sel_1_a = CC_SUBB_ONE_ALPHA;

	printVector(ccp, 1);

	printf("# Various borderline numbers through an 8 bit pathway\n");

	ccp->cc_y_sel_1_r = CC_SUBB_ENV_CLR;
	ccp->cc_y_sel_1_a = CC_SUBB_ENV_ALPHA;

	for (i = 0; i < sizeof(env_values)/sizeof(int); i++) {
	    ccp->env_r = ccp->env_g = ccp->env_b = ccp->env_a = env_values[i];

	    printVector(ccp, 1);
	}

	printf("# Various borderline numbers through a 9 bit pathway\n");

	ccp->cc_y_sel_1_r = CC_SUBB_TEX_1;
	ccp->cc_y_sel_1_a = CC_SUBB_TEX_1_ALPHA;

	for (i = 0; i < sizeof(tf_values)/sizeof(int); i++) {
	    ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = tf_values[i];

	    printVector(ccp, 1);
	}
}

static void
varyMultInputs(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;
	int env_values[] = {0x00, 0x01, 0xff };
	int tf_values[]  = {0x000, 0x001, 0x0ff, 0x100, 0x17f, 0x180, 0x1ff };

	printf("# Vary Multiplier Inputs\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */

	/* Initialize (x,y,c) selects to produce (1,0,0) */

	ccp->cc_x_sel_1_r = CC_SUBA_ONE;
	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_c_sel_1_r = CC_ADD_ZERO;

	ccp->cc_x_sel_1_a = CC_SUBA_ONE_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_ZERO_ALPHA;

	printf("# Walking 0's\n");

	ccp->cc_a_sel_1_r = CC_MULT_TEX_1;
	ccp->cc_a_sel_1_a = CC_MULT_TEX_1_ALPHA;

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x1ff;

	printVector(ccp, 1);

	for (i = 0; i < 9; i++) {
		ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a =
							~(1 << i) & 0x1ff;
		printVector(ccp, 1);
	}

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x0;

	printf("# Zeroes\n");

	ccp->cc_a_sel_1_r = CC_MULT_ZERO;
	ccp->cc_a_sel_1_a = CC_MULT_ZERO_ALPHA;

	printVector(ccp, 1);

	printf("# Various borderline numbers through an 8 bit pathway\n");

	ccp->cc_a_sel_1_r = CC_MULT_ENV_CLR;
	ccp->cc_a_sel_1_a = CC_MULT_ENV_ALPHA;

	for (i = 0; i < sizeof(env_values)/sizeof(int); i++) {
	    ccp->env_r = ccp->env_g = ccp->env_b = ccp->env_a = env_values[i];

	    printVector(ccp, 1);
	}

	printf("# Various borderline numbers through a 9 bit pathway\n");

	ccp->cc_a_sel_1_r = CC_MULT_TEX_1;
	ccp->cc_a_sel_1_a = CC_MULT_TEX_1_ALPHA;

	for (i = 0; i < sizeof(tf_values)/sizeof(int); i++) {
	    ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = tf_values[i];

	    printVector(ccp, 1);
	}
}

static void
varyAddInputs(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;
	int env_values[] = {0x00, 0x01, 0xff };
	int tf_values[]  = {0x000, 0x001, 0x0ff, 0x100, 0x17f, 0x180, 0x1ff };

	printf("# Vary Adder Inputs\n");

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */

	/* Initialize (x,y,a) selects to produce (0,0,0) */

	ccp->cc_x_sel_1_r = CC_SUBA_ZERO;
	ccp->cc_y_sel_1_r = CC_SUBB_ZERO;
	ccp->cc_a_sel_1_r = CC_MULT_ZERO;

	ccp->cc_x_sel_1_a = CC_SUBA_ZERO_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_ZERO_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_ZERO_ALPHA;

	printf("# Walking 0's\n");

	ccp->cc_c_sel_1_r = CC_ADD_TEX_1;
	ccp->cc_c_sel_1_a = CC_ADD_TEX_1_ALPHA;

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x1ff;
	printVector(ccp, 1);

	for (i = 0; i < 9; i++) {
		ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a =
							~(1 << i) & 0x1ff;
		printVector(ccp, 1);
	}

	ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = 0x0;

	printf("# Ones\n");

	ccp->cc_c_sel_1_r = CC_ADD_ONE;
	ccp->cc_c_sel_1_a = CC_ADD_ONE_ALPHA;

	printVector(ccp, 1);

	printf("# Zeroes\n");

	ccp->cc_c_sel_1_r = CC_ADD_ZERO;
	ccp->cc_c_sel_1_a = CC_ADD_ZERO_ALPHA;

	printVector(ccp, 1);

	printf("# Various borderline numbers through an 8 bit pathway\n");

	ccp->cc_c_sel_1_r = CC_ADD_ENV_CLR;
	ccp->cc_c_sel_1_a = CC_ADD_ENV_ALPHA;

	for (i = 0; i < sizeof(env_values)/sizeof(int); i++) {
	    ccp->env_r = ccp->env_g = ccp->env_b = ccp->env_a = env_values[i];

	    printVector(ccp, 1);
	}

	printf("# Various borderline numbers through a 9 bit pathway\n");

	ccp->cc_c_sel_1_r = CC_ADD_TEX_1;
	ccp->cc_c_sel_1_a = CC_ADD_TEX_1_ALPHA;

	for (i = 0; i < sizeof(tf_values)/sizeof(int); i++) {
	    ccp->tf_r = ccp->tf_g = ccp->tf_b = ccp->tf_a = tf_values[i];

	    printVector(ccp, 1);
	}
}

static void
monteCarlo(void)
{
	cc_t cc;
	cc_t *ccp = &cc;
	int i;

	printf("# Monte Carlo\n");

	srandom(1);

	bzero(ccp, sizeof(cc));

	ccp->ncyc = 0;			/* single cycle mode */

	ccp->cc_x_sel_1_r = CC_SUBA_TEX_1;
	ccp->cc_y_sel_1_r = CC_SUBB_TEX_0;
	ccp->cc_a_sel_1_r = CC_MULT_LODF;
	ccp->cc_c_sel_1_r = CC_ADD_COMBO_CLR;

	ccp->cc_x_sel_1_a = CC_SUBA_TEX_1_ALPHA;
	ccp->cc_y_sel_1_a = CC_SUBB_TEX_0_ALPHA;
	ccp->cc_a_sel_1_a = CC_MULT_LODF_ALPHA;
	ccp->cc_c_sel_1_a = CC_ADD_COMBO_ALPHA;


	for (i = 0; i < 100; i++) {
		ccp->tf_r =  random() & 0x1ff;
		ccp->tf_g =  random() & 0x1ff;
		ccp->tf_b =  random() & 0x1ff;
		ccp->tf_a =  random() & 0x1ff;
		ccp->tf_lod_frac = random() & 0x1ff;
		printVector(ccp, 1);
	}
}