Example #1
0
static void test_buffer(bvexp_table_t *table, bvarith_buffer_t *b) {
  bvmlist_t *p;
  thvar_t x;
  uint32_t h, n;

  printf("=== test ===\n");
  n = b->bitsize;

  printf("poly = ");
  print_bvexp(stdout, b->list, n);
  printf("\n");

  h = hash_bvmlist(b->list, n);
  printf("hash code = %"PRIu32"\n", h);

  x = bvexp_table_find(table, b, h);
  if (x < 0) {
    printf("not in table\n");
    x = make_bvvar(table->vtbl, n);
    bvexp_table_add(table, x, b, h);
    printf("adding variable: ");
    print_def(stdout, table, x);
  } else {
    printf("found matching variable: ");
    print_def(stdout, table, x);
    p = bvexp_def(table, x);
    if (p == NULL || !equal_bvmlists(b->list, p, n) || bvvar_bitsize(table->vtbl, x) != n) {
      printf("BUG\n");
      exit(1);
    }
  }
  printf("\n");
}
Example #2
0
/*
 * Add the mapping def[v] = p to the table
 * - v must be a new variable (v >= table->nvars)
 * - p is the polynomial stored in buffer
 * - p must not be present in table (call find first)
 * - buffer must be normalized and h must be the hash code of p
 * Side effect: buffer is reset to the zero polynomial
 */
void bvexp_table_add(bvexp_table_t *table, thvar_t v, bvarith_buffer_t *buffer, uint32_t h) {
  bvmlist_t *p;

  assert(bvvar_bitsize(table->vtbl, v) > 64);
  assert(h == hash_bvmlist(buffer->list, buffer->bitsize));
  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  p = bvarith_buffer_get_mlist(buffer);
  bvexp_set_def(table, v, p);
  int_htbl_add_record(&table->htbl, h, v);
}
Example #3
0
/*
 * Check whether the polynomial p stored in buffer is present in table
 * - if so, return the variable index i such that def[i] = p
 *   otherwise, return -1
 * - buffer must be normalized and h must be the hash code of p
 * - buffer->store must be the same as table->store (or table->store64).
 * - two versions depending on the number of bits in p
 */
thvar_t bvexp_table_find(bvexp_table_t *table, bvarith_buffer_t *buffer, uint32_t h) {
  bvexp_hobj_t hobj;

  assert(h == hash_bvmlist(buffer->list, buffer->bitsize));
  assert(buffer->store == &table->store && buffer->ptbl == &table->pprods);

  hobj.m.hash = (hobj_hash_t) hash_bvexp_hobj;
  hobj.m.eq = (hobj_eq_t) eq_hash_bvexp_hobj;
  hobj.m.build = NULL;
  hobj.table = table;
  hobj.def = buffer->list;
  hobj.bitsize = buffer->bitsize;
  hobj.h = h;

  return int_htbl_find_obj(&table->htbl, &hobj.m);
}
Example #4
0
/*
 * Remove variable x from the table
 */
static void bvexp_table_remove_var(bvexp_table_t *table, thvar_t x) {
  void *p;
  uint32_t n, h;

  assert(0 <= x && x < table->nvars);
  p = table->def[x];
  if (p != NULL) {
    n = bvvar_bitsize(table->vtbl, x);
    if (n > 64) {
      h = hash_bvmlist(p, n);
      free_bvmlist(p, &table->store, n);
    } else {
      h = hash_bvmlist64(p, n);
      free_bvmlist64(p, &table->store64);
    }
    int_htbl_erase_record(&table->htbl, h, x);
  }
}