//SPARCv9 [p.160]
void dec_add(instruct *inst)
{
    char cmd[16];
    char op1[16];
    char op2[16];
    char op3[16];
    int items;

    items = sscanf(inst->string, "%s %s %s %s", cmd, op1, op2, op3); 
    assert(items == 4);

    inst->op = 2;
    inst->op3 = 0;
    inst->rs1 = dec_reg(op1);
    inst->rd = dec_reg(op3);
    if (op2[0] == '%') {
        inst->i = 0;
        inst->rs2 = dec_reg(op2);
    } else {
        inst->i = 1;
        inst->simm13 = atoi(op2);
    }
}
示例#2
0
static int shift_ll(LIKELIHOOD **** ll_pym,
		    struct Region *region, int block_size)
{
    static int first = 1;
    static int xoffset[20];
    static int yoffset[20];

    int xdelta;
    int ystart, ystop, ydelta;
    int D;
    int k, i;
    int block_size_k;
    struct Region region_buff;

    /* if first time, set offsets to 0 */
    if (first) {
	D = levels(block_size, block_size);
	for (k = 0; k <= D; k++)
	    xoffset[k] = yoffset[k] = 0;
	first = 0;
    }

    /* save region information */
    copy_reg(region, &region_buff);

    /* subtract pointer offsets for each scale */
    D = levels(block_size, block_size);
    block_size_k = block_size;
    for (k = 0; k <= D; k++) {
	xdelta = region->xmin - xoffset[k];
	ydelta = region->ymin - yoffset[k];
	xoffset[k] = region->xmin;
	yoffset[k] = region->ymin;

	ystart = region->ymin;
	ystop = ystart + block_size_k;

	ll_pym[k] -= ydelta;
	for (i = ystart; i < ystop; i++)
	    ll_pym[k][i] -= xdelta;
	dec_reg(region);
	block_size_k = block_size_k / 2;
    }

    /* replace region information */
    copy_reg(&region_buff, region);

    return 0;
}
示例#3
0
static void seq_MAP_routine(unsigned char ***sf_pym,	/* pyramid of segmentations */
			    struct Region *region,	/* specifies image subregion */
			    LIKELIHOOD **** ll_pym,	/* pyramid of class statistics */
			    int M,	/* number of classes */
			    double *alpha_dec	/* decimation parameters returned by seq_MAP */
    )
{
    int j, k;			/* loop index */
    int wd, ht;			/* width and height at each resolution */
    int *period;		/* sampling period at each resolution */
    int D;			/* number of resolutions -1 */
    double ***N;		/* transition probability statistics; N[2][3][2] */
    double alpha[3];		/* transition probability parameters */
    double tmp[3];		/* temporary transition probability parameters */
    double diff1;		/* change in parameter estimates */
    double diff2;		/* change in log likelihood */
    struct Region *regionary;	/* array of region stuctures */

    /* determine number of resolutions */
    D = levels_reg(region);

    /* allocate memory */
    if ((N = (double ***)multialloc(sizeof(double), 3, 2, 3, 2)) == NULL)
	G_fatal_error(_("Unable to allocate memory"));

    regionary = (struct Region *)G_malloc((D + 1) * sizeof(struct Region));
    period = (int *)G_malloc(D * sizeof(int));

    /* Compute the image region at each resolution.       */
    k = 0;
    copy_reg(region, &(regionary[k]));
    reg_to_wdht(&(regionary[k]), &wd, &ht);
    while ((wd > 2) && (ht > 2)) {
	copy_reg(&(regionary[k]), &(regionary[k + 1]));
	dec_reg(&(regionary[k + 1]));
	reg_to_wdht(&(regionary[k + 1]), &wd, &ht);
	k++;
    }

    /* Compute sampling period for EM algorithm at each resolution. */
    for (k = 0; k < D; k++) {
	period[k] = (int)pow(2.0, (D - k - 2) / 2.0);
	if (period[k] < 1)
	    period[k] = 1;
    }

    /* Compute Maximum Likelihood estimate at coarsest resolution */
    MLE(sf_pym[D], ll_pym[D], &(regionary[D]), M);

    /* Initialize the transition parameters */
    alpha[0] = 0.5 * (3.0 / 7.0);
    alpha[1] = 0.5 * (2.0 / 7.0);
    alpha[2] = 0.0;

    /* Interpolate the classification at each resolution */
    for (D--; D >= 0; D--) {
	G_debug(1, "Resolution = %d; period = %d", D, period[D]);

	for (j = 0; j < 3; j++)
	    alpha[j] *= (1 - EM_PRECISION * 10);
	print_alpha(alpha);
	/* Apply EM algorithm to estimate alpha. Continue for *
	 * fixed number of iterations or until convergence.   */
	do {
	    interp(sf_pym[D], &(regionary[D]), sf_pym[D + 1], ll_pym[D], M,
		   alpha, period[D], N, 1);
	    print_N(N);
	    G_debug(4, "log likelihood = %f", log_like(N, alpha, M));
	    for (j = 0; j < 3; j++)
		tmp[j] = alpha[j];

	    alpha_max(N, alpha, M, ML_PRECISION);
	    print_alpha(alpha);
	    G_debug(4, "log likelihood = %f", log_like(N, alpha, M));

	    for (diff1 = j = 0; j < 3; j++)
		diff1 += fabs(tmp[j] - alpha[j]);
	    diff2 = log_like(N, alpha, M) - log_like(N, tmp, M);
	} while ((diff1 > EM_PRECISION) && (diff2 > 0));
	interp(sf_pym[D], &(regionary[D]), sf_pym[D + 1], ll_pym[D], M, alpha,
	       1, N, 0);
	alpha_dec[D] = alpha_dec_max(N);

	print_N(N);
	alpha_max(N, alpha, M, ML_PRECISION);
	print_alpha(alpha);
    }

    /* free up N */
    G_free((char *)regionary);
    G_free((char *)period);
    multifree((char *)N, 3);
}