Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolajBjorner committed Mar 5, 2024
1 parent d7e419b commit 9cde4f7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
9 changes: 5 additions & 4 deletions src/ast/sls/bv_sls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ namespace bv {

void sls::try_repair_up(app* e) {
m_repair_up.remove(e->get_id());
if (m_terms.is_assertion(e)) {
m_repair_down.insert(e->get_id());
}
if (m_terms.is_assertion(e) || !m_eval.repair_up(e))
m_repair_down.insert(e->get_id());
else {
m_eval.repair_up(e);
if (!eval_is_correct(e)) {
verbose_stream() << "incorrect eval #" << e->get_id() << " " << mk_bounded_pp(e, m) << "\n";
}
SASSERT(eval_is_correct(e));
for (auto p : m_terms.parents(e))
m_repair_up.insert(p->get_id());
Expand Down
46 changes: 31 additions & 15 deletions src/ast/sls/bv_sls_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Module Name:
--*/

#include "ast/ast_pp.h"
#include "ast/ast_ll_pp.h"
#include "ast/sls/bv_sls.h"

namespace bv {
Expand Down Expand Up @@ -178,7 +179,9 @@ namespace bv {
}
return m.are_equal(a, b);
}
case OP_DISTINCT:
default:
verbose_stream() << mk_bounded_pp(e, m) << "\n";
UNREACHABLE();
break;
}
Expand Down Expand Up @@ -511,14 +514,16 @@ namespace bv {
}
case OP_SIGN_EXT: {
auto& a = wval0(e->get_arg(0));
val.set(a.bits);
for (unsigned i = 0; i < a.bw; ++i)
val.set(val.bits, i, a.get(a.bits, i));
bool sign = a.sign();
val.set_range(val.bits, a.bw, val.bw, sign);
break;
}
case OP_ZERO_EXT: {
auto& a = wval0(e->get_arg(0));
val.set(a.bits);
for (unsigned i = 0; i < a.bw; ++i)
val.set(val.bits, i, a.get(a.bits, i));
val.set_range(val.bits, a.bw, val.bw, false);
break;
}
Expand Down Expand Up @@ -1268,6 +1273,7 @@ namespace bv {
a.set(m_tmp, i, e.get(e.bits, i - sh));
for (unsigned i = 0; i < sh; ++i)
a.set(m_tmp, i, a.get(a.bits, i));
a.clear_overflow_bits(m_tmp);
return a.try_set(m_tmp);
}
}
Expand Down Expand Up @@ -1500,7 +1506,7 @@ namespace bv {
}

bool sls_eval::try_repair_zero_ext(bvval const& e, bvval& a) {
for (unsigned i = 0; i < e.bw; ++i)
for (unsigned i = 0; i < a.bw; ++i)
if (!a.get(a.fixed, i))
a.set(a.bits, i, e.get(e.bits, i));
return true;
Expand All @@ -1509,21 +1515,25 @@ namespace bv {
bool sls_eval::try_repair_concat(bvval const& e, bvval& a, bvval& b, unsigned i) {
if (i == 0) {
for (unsigned i = 0; i < a.bw; ++i)
if (!a.get(a.fixed, i))
a.set(a.bits, i, e.get(e.bits, i + b.bw));
a.set(m_tmp, i, e.get(e.bits, i + b.bw));
a.clear_overflow_bits(m_tmp);
a.set_repair(random_bool(), m_tmp);
}
else {
for (unsigned i = 0; i < b.bw; ++i)
if (!b.get(b.fixed, i))
b.set(b.bits, i, e.get(e.bits, i));
b.set(m_tmp, i, e.get(e.bits, i));
b.clear_overflow_bits(m_tmp);
b.set_repair(random_bool(), m_tmp);
}
return true;
}

bool sls_eval::try_repair_extract(bvval const& e, bvval& a, unsigned lo) {
for (unsigned i = 0; i < e.bw; ++i)
if (!a.get(a.fixed, i + lo))
a.set(a.bits, i + lo, e.get(e.bits, i));
if (a.get(a.fixed, i + lo) && a.get(a.bits, i + lo) != e.get(e.bits, i))
return false;
for (unsigned i = 0; i < e.bw; ++i)
a.set(a.bits, i + lo, e.get(e.bits, i));
return true;
}

Expand All @@ -1547,12 +1557,18 @@ namespace bv {
}
}

void sls_eval::repair_up(expr* e) {
bool sls_eval::repair_up(expr* e) {
if (!is_app(e))
return;
if (m.is_bool(e))
set(e, bval1(to_app(e)));
else if (bv.is_bv(e))
wval0(e).set(wval1(to_app(e)));
return false;
if (m.is_bool(e)) {
auto b = bval1(to_app(e));
if (is_fixed0(e))
return b == bval0(e);
m_eval[e->get_id()] = b;
return true;
}
if (bv.is_bv(e))
return wval0(e).try_set(wval1(to_app(e)));
return false;
}
}
2 changes: 1 addition & 1 deletion src/ast/sls/bv_sls_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ namespace bv {
/*
* Propagate repair up to parent
*/
void repair_up(expr* e);
bool repair_up(expr* e);
};
}
19 changes: 14 additions & 5 deletions src/ast/sls/bv_sls_fixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Module Name:
--*/

#include "ast/ast_pp.h"
#include "ast/ast_ll_pp.h"
#include "ast/sls/bv_sls_fixed.h"
#include "ast/sls/bv_sls_eval.h"

Expand Down Expand Up @@ -138,6 +139,7 @@ namespace bv {
v.add_range(-b, a - b);
}
else if (!y) {

if (mod(b + 1, rational::power_of_two(bv.get_bv_size(x))) == 0)
return;
auto& v = wval0(x);
Expand Down Expand Up @@ -300,21 +302,28 @@ namespace bv {


if (j > 0 && k > 0) {
for (unsigned i = 0; i < std::min(k, j); ++i)
for (unsigned i = 0; i < std::min(k, j); ++i) {
SASSERT(!v.get(v.bits, i));
v.set(v.fixed, i, true);
}
}
// lower zj + jk bits are 0
if (zk > 0 || zj > 0) {
for (unsigned i = 0; i < zk + zj; ++i)
for (unsigned i = 0; i < zk + zj; ++i) {
SASSERT(!v.get(v.bits, i));
v.set(v.fixed, i, true);
}
}
// upper bits are 0, if enough high order bits of a, b are 0.
if (hzj < v.bw && hzk < v.bw && hzj + hzk > v.bw) {
// TODO - buggy
if (false && hzj < v.bw && hzk < v.bw && hzj + hzk > v.bw) {
hzj = v.bw - hzj;
hzk = v.bw - hzk;
for (unsigned i = hzj + hzk - 1; i < v.bw; ++i)
for (unsigned i = hzj + hzk - 1; i < v.bw; ++i) {
SASSERT(!v.get(v.bits, i));
v.set(v.fixed, i, true);
}
}
}
break;
}
case OP_CONCAT: {
Expand Down
7 changes: 7 additions & 0 deletions src/ast/sls/bv_sls_terms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ namespace bv {
else if (bv.is_concat(e)) {
FOLD_OP(bv.mk_concat);
}
else if (m.is_distinct(e)) {
expr_ref_vector es(m);
for (unsigned i = 0; i < num_args; ++i)
for (unsigned j = i + 1; j < num_args; ++j)
es.push_back(m.mk_not(m.mk_eq(arg(i), arg(j))));
r = m.mk_and(es);
}
else if (bv.is_bv_sdiv(e, x, y) || bv.is_bv_sdiv0(e, x, y) || bv.is_bv_sdivi(e, x, y)) {
r = mk_sdiv(x, y);
}
Expand Down

0 comments on commit 9cde4f7

Please sign in to comment.