Пример #1
0
int main(void)
{
  do_mult("1", "3");
  do_mult("9", "2");
  do_mult("10", "42");
  do_mult("9", "99");
  do_convert("101010", "01");
  do_convert("2A", "0123456789ABCDEF");
  do_substract("10", "5");
  do_substract("11", "9");
  do_substract("100", "99");
  do_divide("10", "2");
  do_divide("21", "2");
  do_divide("500", "4");
  do_divide("500", "25");
  do_divide("500000000000000005", "5");
  do_divide("500000000500000005", "5");
  do_divide("500000000500000005", "2");
  do_divide("833", "42");
  do_divide("50458", "357");
  do_divide("80303", "42");
  do_mod("10", "2");
  do_mod("11", "2");
  do_mod("50", "4");
  do_mod("50000", "7");
  do_mod("50000", "365");
  converter("101010", "01", "0123456789ABCDEF");
  converter("101010", "01", "0123456789");
  converter("11101110", "01", "abcdefghij");
  converter("99989998", "89", "abcdefghij");
  return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
    if (argc < 3) {
        fprintf(stderr, "usage: %s infile outfile {o|m} [res_pic.png] [intermid_pic.png\n");
        return 2;
    }

    int err;
    int is_in_fmc  = (strstr(argv[1], ".mtx") != NULL);
    int is_out_fmc = (strstr(argv[2], ".mtx") != NULL);
    int type = (argv[3][0] == 'o') ? ALG_ORIG : ALG_MULT;

    TMatrix_DCSR _A,  *A  = &_A;
    TMatrix_DCSR _B,  *B  = &_B;
    TWGraph      _gr, *gr = &_gr;
    if (is_in_fmc) err = matrix_load_fmc(A, argv[1]);
    else err = matrix_load(A, argv[1]);
    if (err != ERROR_NO_ERROR)
        PRINT_ERROR_MESSAGE_AND_EXIT(err);

    int size = A->size;
    int *xadj, *adjncy;
    int *perm, *invp;

    if (!perm || !invp)
        PRINT_ERROR_MESSAGE_AND_EXIT(ERROR_MEMORY_ALLOCATION);

    switch (type) {
        case ALG_ORIG: do_orig(A, &xadj, &adjncy); break;
        case ALG_MULT: do_mult(A, &xadj, &adjncy); break;
    }

    TWGraph igr = { NULL, adjncy, xadj, NULL, size, xadj[size] };

    tnd_perm(&igr, &perm, &invp);

    SAFE(build_graph(gr, A));
    SAFE(graph_reorder(gr, perm, invp));
    SAFE(build_matrix(gr, B, 1));

    if (argc > 4) matrix_portrait(B, argv[4], 0, 0, NULL);
    if (is_out_fmc) matrix_save_fmc(B, argv[2]);
    else matrix_save(B, argv[2]);

    free(xadj);
    free(adjncy);
    if (argc > 5) {
        switch (type) {
            case ALG_ORIG: do_orig(B, &xadj, &adjncy); break;
            case ALG_MULT: do_mult(B, &xadj, &adjncy); break;
        }
        igr = (TWGraph){ NULL, adjncy, xadj, NULL, size, 0 };
        graph_portrait(&igr, argv[5]);
    }

    return 0;
}
MainWindow::MainWindow()
{
    MatrixManager *mm = MatrixManager::get_instance();
    QVBoxLayout *layout = new QVBoxLayout;
    setLayout(layout);

// operations chain
    operations = new QHBoxLayout;

    leftOp = new LiveMatrixView( mm->create_matrix(2, 2) );
    rightOp = new LiveMatrixView( mm->create_matrix(2, 2) );
    result = new LiveMatrixView( mm->create_matrix(2, 2) );

    QPushButton *btnMult = new QPushButton("Multiply");

    operations->addWidget(leftOp);
    operations->addWidget(btnMult);
    operations->addWidget(rightOp);
    operations->addWidget(new QPushButton("Result:"));
    operations->addWidget(result);

    layout->addLayout(operations); // add operations layout

    QObject::connect(btnMult, SIGNAL(clicked()), this, SLOT(do_mult()));

}
Пример #4
0
void
process_line(longint_t vars[], char *line) {
	int varnum, optype, status;
	longint_t second_value;

	/* determine the LHS variable, it
	 * must be first character in line
	 */
	varnum = to_varnum(line[0]);
	if (varnum==ERROR) {
		printf("Invalid LHS variable\n");
		return;
	}

	/* more testing for validity 
	 */
	if (strlen(line)<2) {
		printf("No operator supplied\n");
		return;
	}

	/* determine the operation to be performed, it
	 * must be second character in line
	 */
	optype = line[1];
	if (strchr(ALLOPS, optype) == NULL) {
		printf("Unknown operator\n");
		return;
	}

	/* determine the RHS argument (if one is required),
	 * it must start in third character of line
	 */
	if (optype != PRINT) {
		if (strlen(line)<3) {
			printf("No RHS supplied\n");
			return;
		}
		status = get_second_value(vars, line+2, &second_value);
		if (status==ERROR) {
			printf("RHS argument is invalid\n");
			return;
		}
	}

	/* finally, do the actual operation
	 */
	if (optype == PRINT) {
		do_print(vars+varnum);
	} else if (optype == ASSIGN) {
		do_assign(vars+varnum, &second_value);
	} else if (optype == PLUS) {
		do_plus(vars+varnum, &second_value);
	} else if (optype == MULT) {
		do_mult(vars+varnum, &second_value);
	} else if (optype == POWER) {
		do_power(vars+varnum, &second_value);
	}
	return;
}
Пример #5
0
void measure_mult(int size_input, mpz_t *vec1, mpz_t *vec2,
                  mpz_t *vec3, int operand_size1, int operand_size2) {

    vector<double> measurements(NUM_SAMPLES, 0);
    char scratch_str[BUFLEN];

    for (int i=0; i<NUM_SAMPLES; i++)
        measurements[i] =
            do_mult(size_input, vec1, vec2, vec3, operand_size1, operand_size2)/size_input;

    snprintf(scratch_str, BUFLEN-1, "f_%d_%d", operand_size1, operand_size2);
    print_stats(scratch_str, measurements);
}
Пример #6
0
static void
codegen14(enum node_op op, 
          enum size_tag size,
          gp_boolean is_const,
          int value,
          char *name)
{
  switch (op) {
  case op_assign:
    assert(0);
    break;
  case op_add:
    do_add(size, is_const, value, name);
    break;
  case op_sub:
    do_sub(size, is_const, value, name);
    break;
  case op_neg:
    do_neg(size, is_const, value, name);
    break;
  case op_com:
    do_com(size, is_const, value, name);
    break;
  case op_and:
    do_and(size, is_const, value, name);
    break;
  case op_or:
    do_or(size, is_const, value, name);
    break;
  case op_xor:
    do_xor(size, is_const, value, name);
    break;
  case op_not:
    do_not(size, is_const, value, name);
    break;
  case op_lsh:
    do_lsh(size, is_const, value, name);
    break;
  case op_rsh:
    do_rsh(size, is_const, value, name);
    break;
  case op_land:
    do_and(size_uint8, is_const, value, name);
    break;
  case op_lor:
    do_or(size_uint8, is_const, value, name);
    break;
  case op_eq:
    do_eq(size, is_const, value, name);
    break;
  case op_ne:
    do_ne(size, is_const, value, name);
    break;
  case op_lt:
    do_lt(size, is_const, value, name);
    break;
  case op_lte:
    do_lte(size, is_const, value, name);
    break;
  case op_gt:
  case op_gte:
    /* This is replaced in the optimizer.*/
    assert(0);
    break;
  case op_mult:
    do_mult(size, is_const, value, name);
    break;
  case op_div:
    do_div(size, is_const, value, name);
    break;
  case op_mod:
    do_mod(size, is_const, value, name);
    break;
  case op_clr:
  case op_inc:
  case op_dec:
    /* Shoud use unopgen14.*/
    assert(0);
    break;
  default:
    assert(0); /* Unhandled binary operator */
  }

}