Skip to content

Commit 22616da

Browse files
updates
1 parent 5be8872 commit 22616da

9 files changed

+101
-55
lines changed

src/ast/sls/bv_sls.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ namespace bv {
4040
m_eval.init_eval(m_terms.assertions(), eval);
4141
m_eval.tighten_range(m_terms.assertions());
4242
init_repair();
43-
display(verbose_stream());
44-
exit(0);
4543
}
4644

4745
void sls::init_repair() {

src/ast/sls/bv_sls_eval.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ namespace bv {
15981598
b.clear_overflow_bits(m_tmp);
15991599
r = b.try_set(m_tmp);
16001600
}
1601-
verbose_stream() << e << " := " << a << " " << b << "\n";
1601+
//verbose_stream() << e << " := " << a << " " << b << "\n";
16021602
return r;
16031603
}
16041604

@@ -1625,7 +1625,12 @@ namespace bv {
16251625
a.get(m_tmp);
16261626
for (unsigned i = 0; i < e.bw; ++i)
16271627
m_tmp.set(i + lo, e.get(i));
1628-
return a.try_set(m_tmp);
1628+
if (a.try_set(m_tmp))
1629+
return true;
1630+
a.get_variant(m_tmp, m_rand);
1631+
bool res = a.set_repair(random_bool(), m_tmp);
1632+
// verbose_stream() << "try set " << res << " " << m_tmp[0] << " " << a << "\n";
1633+
return res;
16291634
}
16301635

16311636
void sls_eval::set_div(bvect const& a, bvect const& b, unsigned bw,
@@ -1660,19 +1665,22 @@ namespace bv {
16601665
}
16611666
if (bv.is_bv(e)) {
16621667
auto& v = eval(to_app(e));
1668+
// verbose_stream() << "committing: " << v << "\n";
16631669
for (unsigned i = 0; i < v.nw; ++i)
16641670
if (0 != (v.fixed[i] & (v.bits()[i] ^ v.eval[i]))) {
16651671
v.bits().copy_to(v.nw, v.eval);
16661672
return false;
16671673
}
1668-
v.commit_eval();
1669-
return true;
1674+
if (v.commit_eval())
1675+
return true;
1676+
v.bits().copy_to(v.nw, v.eval);
1677+
return false;
16701678
}
16711679
return false;
16721680
}
16731681

16741682
sls_valuation& sls_eval::wval(expr* e) const {
1675-
if (!m_values[e->get_id()]) verbose_stream() << mk_bounded_pp(e, m) << "\n";
1683+
// if (!m_values[e->get_id()]) verbose_stream() << mk_bounded_pp(e, m) << "\n";
16761684
return *m_values[e->get_id()];
16771685
}
16781686

src/ast/sls/bv_sls_fixed.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace bv {
2525
{}
2626

2727
void sls_fixed::init(expr_ref_vector const& es) {
28-
init_ranges(es);
2928
ev.sort_assertions(es);
3029
for (expr* e : ev.m_todo) {
3130
if (!is_app(e))
@@ -40,6 +39,7 @@ namespace bv {
4039
;
4140
}
4241
ev.m_todo.reset();
42+
init_ranges(es);
4343
}
4444

4545

@@ -185,7 +185,6 @@ namespace bv {
185185
auto& val_el = wval(e->get_arg(2));
186186
for (unsigned i = 0; i < val.nw; ++i)
187187
val.fixed[i] = val_el.fixed[i] & val_th.fixed[i] & ~(val_el.bits(i) ^ val_th.bits(i));
188-
val.tighten_range();
189188
}
190189
}
191190

@@ -420,6 +419,5 @@ namespace bv {
420419
UNREACHABLE();
421420
break;
422421
}
423-
v.tighten_range();
424422
}
425423
}

src/ast/sls/sls_valuation.cpp

+63-36
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ namespace bv {
9999
for (unsigned i = 0; i < nw; ++i)
100100
if (0 != (fixed[i] & (m_bits[i] ^ eval[i])))
101101
return false;
102+
if (!in_range(eval))
103+
return false;
102104
for (unsigned i = 0; i < nw; ++i)
103105
m_bits[i] = eval[i];
104106
SASSERT(well_formed());
@@ -110,6 +112,7 @@ namespace bv {
110112
auto c = m.compare(m_lo.data(), nw, m_hi.data(), nw);
111113
SASSERT(!has_overflow(bits));
112114
// full range
115+
113116
if (c == 0)
114117
return true;
115118
// lo < hi: then lo <= bits & bits < hi
@@ -328,13 +331,35 @@ namespace bv {
328331
bool sls_valuation::set_repair(bool try_down, bvect& dst) {
329332
for (unsigned i = 0; i < nw; ++i)
330333
dst[i] = (~fixed[i] & dst[i]) | (fixed[i] & m_bits[i]);
331-
bool ok = try_down ? round_down(dst) : round_up(dst);
332-
if (!ok)
333-
VERIFY(try_down ? round_up(dst) : round_down(dst));
334-
DEBUG_CODE(SASSERT(0 == (mask & (fixed[nw-1] & (m_bits[nw-1] ^ dst[nw-1])))); for (unsigned i = 0; i + 1 < nw; ++i) SASSERT(0 == (fixed[i] & (m_bits[i] ^ dst[i]))););
335-
set(eval, dst);
336-
SASSERT(well_formed());
337-
return true;
334+
335+
if (in_range(dst)) {
336+
set(eval, dst);
337+
return true;
338+
}
339+
bool repaired = false;
340+
dst.set_bw(bw);
341+
if (m_lo < m_hi) {
342+
for (unsigned i = bw; m_hi <= dst && !in_range(dst) && i-- > 0; )
343+
if (!fixed.get(i) && dst.get(i))
344+
dst.set(i, false);
345+
for (unsigned i = 0; i < bw && dst < m_lo && !in_range(dst); ++i)
346+
if (!fixed.get(i) && !dst.get(i))
347+
dst.set(i, true);
348+
}
349+
else {
350+
for (unsigned i = 0; !in_range(dst); ++i)
351+
if (!fixed.get(i) && !dst.get(i))
352+
dst.set(i, true);
353+
for (unsigned i = bw; !in_range(dst) && i-- > 0;)
354+
if (!fixed.get(i) && dst.get(i))
355+
dst.set(i, false);
356+
}
357+
if (in_range(dst)) {
358+
set(eval, dst);
359+
repaired = true;
360+
}
361+
dst.set_bw(0);
362+
return repaired;
338363
}
339364

340365
void sls_valuation::min_feasible(bvect& out) const {
@@ -406,6 +431,7 @@ namespace bv {
406431
//
407432
bool sls_valuation::can_set(bvect const& new_bits) const {
408433
SASSERT(!has_overflow(new_bits));
434+
// verbose_stream() << "can set " << bw << " " << new_bits[0] << " " << in_range(new_bits) << "\n";
409435
for (unsigned i = 0; i < nw; ++i)
410436
if (0 != ((new_bits[i] ^ m_bits[i]) & fixed[i]))
411437
return false;
@@ -446,10 +472,8 @@ namespace bv {
446472
if (h == l)
447473
return;
448474

449-
verbose_stream() << "[" << l << ", " << h << "[\n";
450-
verbose_stream() << *this << "\n";
451-
452-
SASSERT(is_zero(fixed)); // ranges can only be added before fixed bits are set.
475+
//verbose_stream() << "[" << l << ", " << h << "[\n";
476+
//verbose_stream() << *this << "\n";
453477

454478
if (m_lo == m_hi) {
455479
set_value(m_lo, l);
@@ -481,13 +505,14 @@ namespace bv {
481505

482506
SASSERT(!has_overflow(m_lo));
483507
SASSERT(!has_overflow(m_hi));
484-
if (!in_range(m_bits))
485-
set(m_bits, m_lo);
508+
509+
tighten_range();
486510
SASSERT(well_formed());
487-
verbose_stream() << *this << "\n";
511+
// verbose_stream() << *this << "\n";
488512
}
489513

490514
//
515+
// update bits based on ranges
491516
// tighten lo/hi based on fixed bits.
492517
// lo[bit_i] != fixedbit[bit_i]
493518
// let bit_i be most significant bit position of disagreement.
@@ -502,35 +527,19 @@ namespace bv {
502527
//
503528
void sls_valuation::tighten_range() {
504529

505-
verbose_stream() << "tighten " << *this << "\n";
530+
// verbose_stream() << "tighten " << *this << "\n";
506531
if (m_lo == m_hi)
507532
return;
508-
for (unsigned i = bw; i-- > 0; ) {
509-
if (!fixed.get(i))
510-
continue;
511-
if (m_bits.get(i) == m_lo.get(i))
512-
continue;
513-
if (m_bits.get(i)) {
514-
m_lo.set(i, true);
515-
for (unsigned j = i; j-- > 0; )
516-
m_lo.set(j, fixed.get(j) && m_bits.get(j));
517-
}
518-
else {
519-
for (unsigned j = bw; j-- > 0; )
520-
m_lo.set(j, fixed.get(j) && m_bits.get(j));
521-
}
522-
break;
523-
}
524533

525534
if (!in_range(m_bits)) {
526-
verbose_stream() << "not in range\n";
535+
// verbose_stream() << "not in range\n";
527536
bool compatible = true;
528537
for (unsigned i = 0; i < nw && compatible; ++i)
529-
compatible = 0 == (fixed[i] && (m_bits[i] ^ m_lo[i]));
530-
verbose_stream() << (fixed[0] && (m_bits[0] ^ m_lo[0])) << "\n";
531-
538+
compatible = 0 == (fixed[i] & (m_bits[i] ^ m_lo[i]));
539+
//verbose_stream() << (fixed[0] & (m_bits[0] ^ m_lo[0])) << "\n";
540+
//verbose_stream() << bw << " " << m_lo[0] << " " << m_bits[0] << "\n";
532541
if (compatible) {
533-
verbose_stream() << "compatible\n";
542+
//verbose_stream() << "compatible\n";
534543
set(m_bits, m_lo);
535544
}
536545
else {
@@ -561,6 +570,24 @@ namespace bv {
561570
set(m_bits, tmp);
562571
}
563572
}
573+
// update lo, hi to be feasible.
574+
575+
for (unsigned i = bw; i-- > 0; ) {
576+
if (!fixed.get(i))
577+
continue;
578+
if (m_bits.get(i) == m_lo.get(i))
579+
continue;
580+
if (m_bits.get(i)) {
581+
m_lo.set(i, true);
582+
for (unsigned j = i; j-- > 0; )
583+
m_lo.set(j, fixed.get(j) && m_bits.get(j));
584+
}
585+
else {
586+
for (unsigned j = bw; j-- > 0; )
587+
m_lo.set(j, fixed.get(j) && m_bits.get(j));
588+
}
589+
break;
590+
}
564591

565592
SASSERT(well_formed());
566593
}

src/tactic/core/simplify_tactic.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ struct simplify_tactic::imp {
4242
m_num_steps = 0;
4343
}
4444

45+
void collect_statistics(statistics& st) {
46+
st.update("rewriter.steps", m_num_steps);
47+
}
48+
4549
void operator()(goal & g) {
4650
tactic_report report("simplifier", g);
4751
m_num_steps = 0;
@@ -108,6 +112,11 @@ void simplify_tactic::cleanup() {
108112
new (m_imp) imp(m, p);
109113
}
110114

115+
void simplify_tactic::collect_statistics(statistics& st) const {
116+
if (m_imp)
117+
m_imp->collect_statistics(st);
118+
}
119+
111120
unsigned simplify_tactic::get_num_steps() const {
112121
return m_imp->get_num_steps();
113122
}

src/tactic/core/simplify_tactic.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class simplify_tactic : public tactic {
8181
static void get_param_descrs(param_descrs & r);
8282

8383
void collect_param_descrs(param_descrs & r) override { get_param_descrs(r); }
84+
85+
void collect_statistics(statistics& st) const override;
8486

8587
void operator()(goal_ref const & in, goal_ref_buffer & result) override;
8688

src/tactic/dependent_expr_state_tactic.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class dependent_expr_state_tactic : public tactic, public dependent_expr_state {
6262
if (m_simp)
6363
pop(1);
6464
}
65-
65+
6666
/**
6767
* size(), [](), update() and inconsistent() implement the abstract interface of dependent_expr_state
6868
*/
@@ -140,6 +140,12 @@ class dependent_expr_state_tactic : public tactic, public dependent_expr_state {
140140
cleanup();
141141
}
142142

143+
void collect_statistics(statistics& st) const override {
144+
if (m_simp)
145+
m_simp->collect_statistics(st);
146+
st.copy(m_st);
147+
}
148+
143149
void cleanup() override {
144150
if (m_simp) {
145151
m_simp->collect_statistics(m_st);
@@ -151,13 +157,6 @@ class dependent_expr_state_tactic : public tactic, public dependent_expr_state {
151157
m_dep = dependent_expr(m, m.mk_true(), nullptr, nullptr);
152158
}
153159

154-
void collect_statistics(statistics& st) const override {
155-
if (m_simp)
156-
m_simp->collect_statistics(st);
157-
else
158-
st.copy(m_st);
159-
}
160-
161160
void reset_statistics() override {
162161
if (m_simp)
163162
m_simp->reset_statistics();

src/tactic/tactic.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class tactic : public user_propagator::core {
6262
*/
6363
virtual void operator()(goal_ref const & in, goal_ref_buffer& result) = 0;
6464

65-
virtual void collect_statistics(statistics & st) const { }
65+
virtual void collect_statistics(statistics& st) const { }
6666
virtual void reset_statistics() {}
6767
virtual void cleanup() = 0;
6868
virtual void reset() { cleanup(); }
@@ -130,6 +130,7 @@ class skip_tactic : public tactic {
130130
void cleanup() override {}
131131
tactic * translate(ast_manager & m) override { return this; }
132132
char const* name() const override { return "skip"; }
133+
void collect_statistics(statistics& st) const override {}
133134
};
134135

135136
tactic * mk_skip_tactic();

src/tactic/tactical.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ class fail_if_tactic : public tactic {
11901190
tactic * translate(ast_manager & m) override {
11911191
return this;
11921192
}
1193+
1194+
void collect_statistics(statistics& st) const override {
1195+
}
11931196
};
11941197

11951198
tactic * fail_if(probe * p) {
@@ -1216,6 +1219,7 @@ class if_no_proofs_tactical : public unary_tactical {
12161219
}
12171220

12181221
tactic * translate(ast_manager & m) override { return translate_core<if_no_proofs_tactical>(m); }
1222+
12191223
};
12201224

12211225
class if_no_unsat_cores_tactical : public unary_tactical {

0 commit comments

Comments
 (0)