Exemplo n.º 1
0
void expand_bvpprod(bvexp_table_t *table, bvarith_buffer_t *buffer, pp_buffer_t *p, uint32_t n, uint32_t *c) {
  bv_vartable_t *vtbl;
  bvmlist_t *q;
  pp_buffer_t *aux;
  pprod_t *r;
  uint32_t *a;
  uint32_t i, m, d, e, k;
  thvar_t x;


  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  bvarith_buffer_prepare(buffer, n);
  bvarith_buffer_set_one(buffer);
  aux = p;

  vtbl = table->vtbl;

  if (total_degree_test(table, vtbl, p)) {
    aux = &table->pp;
    pp_buffer_reset(aux);

    // make a copy of c in the internal bvconst buffer
    bvconstant_copy(&table->bvconst, n, c);
    c = table->bvconst.data;

    k = (n + 31) >> 5;
    m = p->len;
    for (i=0; i<m; i++) {
      x = p->prod[i].var;
      d = p->prod[i].exp;
      if (bvvar_is_const(vtbl, x)) {
        a = bvvar_val(vtbl, x);
        bvconst_mulpower(c, k, a, d);
      } else {
        q = bvexp_def(table, x);
        if (q != NULL && mlist_is_short(q, &e) && d * e <= BVEXP_DEGREE_LIMIT) {
          bvarith_buffer_mul_mlist_power(buffer, q, d, &table->aux);
        } else {
          pp_buffer_mul_varexp(aux, x, d);
        }
      }
    }

    // normalize
    bvconst_normalize(c, n);
    pp_buffer_normalize(aux);
  }

  /*
   * The result is c * aux * buffer
   */
  r = pprod_from_buffer(&table->pprods, aux);
  bvarith_buffer_mul_mono(buffer, c, r);
  bvarith_buffer_normalize(buffer);
}
Exemplo n.º 2
0
void expand_bvpoly(bvexp_table_t *table, bvarith_buffer_t *buffer, bvpoly_buffer_t *p) {
  bv_vartable_t *vtbl;
  bvmlist_t *q;
  uint32_t *c;
  uint32_t i, n;
  thvar_t x;

  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  bvarith_buffer_prepare(buffer, bvpoly_buffer_bitsize(p));

  n = bvpoly_buffer_num_terms(p);
  if (n > 0) {
    vtbl = table->vtbl;
    i = 0;

    // constant term of p
    if (bvpoly_buffer_var(p, 0) == const_idx) {
      bvarith_buffer_add_const(buffer, bvpoly_buffer_coeff(p, 0));
      i ++;
    }

    // non-constant terms
    while (i < n) {
      x = bvpoly_buffer_var(p, i);
      c = bvpoly_buffer_coeff(p, i);
      i ++;
      if (bvvar_is_const(vtbl, x)) {
        bvarith_buffer_add_const_times_const(buffer, c, bvvar_val(vtbl, x));
      } else {
        q = bvexp_def(table, x);
        if (q != NULL) {
          bvarith_buffer_add_const_times_mlist(buffer, q, c);
        } else {
          bvarith_buffer_add_varmono(buffer, c, x);
        }
      }
    }

    bvarith_buffer_normalize(buffer);
  }
}
Exemplo n.º 3
0
/*
 * Print the definition of x in vtbl
 */
static void print_bv_vardef(FILE *f, bv_vartable_t *vtbl, thvar_t x) {
  uint32_t nbits;

  assert(valid_bvvar(vtbl, x));

  nbits = bvvar_bitsize(vtbl, x);
  print_bvvar(f, x);
  fprintf(f, ":bv[%"PRIu32"] = ", nbits);
  switch (bvvar_tag(vtbl, x)) {
  case BVTAG_VAR:
    fputs("var", f);
    break;

  case BVTAG_CONST64:
    bvconst64_print(f, bvvar_val64(vtbl, x), nbits);
    break;

  case BVTAG_CONST:
    bvconst_print(f, bvvar_val(vtbl, x), nbits);
    break;

  case BVTAG_POLY64:
    print_bv_poly64(f, bvvar_poly64_def(vtbl, x));
    break;

  case BVTAG_POLY:
    print_bv_poly(f, bvvar_poly_def(vtbl, x));
    break;

  case BVTAG_PPROD:
    print_bv_product(f, bvvar_pprod_def(vtbl, x));
    break;

  case BVTAG_BIT_ARRAY:
    print_litarray(f, nbits, bvvar_bvarray_def(vtbl, x));
    break;

  case BVTAG_ITE:
    print_bv_ite(f, bvvar_ite_def(vtbl, x));
    break;

  case BVTAG_UDIV:
    print_bv_binop(f, "div", bvvar_binop(vtbl, x));
    break;

  case BVTAG_UREM:
    print_bv_binop(f, "rem", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SDIV:
    print_bv_binop(f, "sdiv", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SREM:
    print_bv_binop(f, "srem", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SMOD:
    print_bv_binop(f, "smod", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SHL:
    print_bv_binop(f, "shl", bvvar_binop(vtbl, x));
    break;

  case BVTAG_LSHR:
    print_bv_binop(f, "lshr", bvvar_binop(vtbl, x));
    break;

  case BVTAG_ASHR:
    print_bv_binop(f, "ashr", bvvar_binop(vtbl, x));
    break;

  case BVTAG_ADD:
    print_bv_binop(f, "add", bvvar_binop(vtbl, x));
    break;

  case BVTAG_SUB:
    print_bv_binop(f, "sub", bvvar_binop(vtbl, x));
    break;

  case BVTAG_MUL:
    print_bv_binop(f, "mul", bvvar_binop(vtbl, x));
    break;

  case BVTAG_NEG:
    print_bvneg(f, bvvar_binop(vtbl, x));
    break;
  }
}