Skip to content

Commit 923bd12

Browse files
committed
Use propt::lcnf instead of propt::l_set_to{true,false}
l_set_to{true,false} will do one unnecessary call to lcnf; several locations also permitted further optimisation as l_set_to_true(limplies(a, b)) is lcnf(!a, b).
1 parent 600c3fa commit 923bd12

10 files changed

+42
-53
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void arrayst::add_array_constraint(const lazy_constraintt &lazy, bool refine)
253253
else
254254
{
255255
// add the constraint eagerly
256-
prop.l_set_to_true(convert(lazy.lazy));
256+
prop.lcnf(bvt(1, convert(lazy.lazy)));
257257
}
258258
}
259259

src/solvers/flattening/boolbv_bv_rel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ literalt boolbvt::convert_bv_rel(const exprt &expr)
7676
literalt equal_lit=equality(op0, op1);
7777
7878
if(or_equal)
79-
prop.l_set_to_true(prop.limplies(equal_lit, literal));
79+
prop.lcnf(!equal_lit, literal);
8080
else
81-
prop.l_set_to_true(prop.limplies(equal_lit, !literal));
81+
prop.lcnf(!equal_lit, !literal);
8282
}
8383
}
8484

src/solvers/flattening/boolbv_byte_extract.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,17 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
129129

130130
typet constant_type=offset.type(); // type of index operand
131131

132-
bvt equal_bv;
133-
equal_bv.resize(width);
134-
135132
for(std::size_t i=0; i<bytes; i++)
136133
{
137134
equality.rhs()=from_integer(i, constant_type);
135+
const bvt &eq_bv = convert_bv(equality);
136+
CHECK_RETURN(eq_bv.size() == 1);
137+
literalt index_not_eq_lit = !eq_bv[0];
138138

139139
std::size_t offset=i*byte_width;
140140

141-
for(std::size_t j=0; j<width; j++)
142-
if(offset+j<op_bv.size())
143-
equal_bv[j]=prop.lequal(bv[j], op_bv[offset+j]);
144-
else
145-
equal_bv[j]=const_literal(true);
146-
147-
const bvt &eq_bv = convert_bv(equality);
148-
CHECK_RETURN(eq_bv.size() == 1);
149-
prop.l_set_to_true(prop.limplies(eq_bv[0], prop.land(equal_bv)));
141+
for(std::size_t j=0; j<width && offset+j<op_bv.size(); j++)
142+
prop.lcnf(index_not_eq_lit, prop.lequal(bv[j], op_bv[offset+j]));
150143
}
151144
}
152145
else

src/solvers/flattening/boolbv_case.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ bvt boolbvt::convert_case(const exprt &expr)
7373
{
7474
literalt value_literal=bv_utils.equal(bv, op);
7575

76-
prop.l_set_to_true(
77-
prop.limplies(compare_literal, value_literal));
76+
prop.lcnf(!compare_literal, value_literal);
7877
}
7978

8079
what=COMPARE;

src/solvers/flattening/boolbv_cond.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bvt boolbvt::convert_cond(const exprt &expr)
6161

6262
literalt value_literal=bv_utils.equal(bv, op);
6363

64-
prop.l_set_to_true(prop.limplies(cond_literal, value_literal));
64+
prop.lcnf(!cond_literal, value_literal);
6565
}
6666

6767
condition=!condition;

src/solvers/flattening/boolbv_extractbit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ literalt boolbvt::convert_extractbit(const extractbit_exprt &expr)
7373
literalt equal=prop.lequal(l, bv0[i]);
7474
const bvt &eq_bv = convert_bv(equality);
7575
CHECK_RETURN(eq_bv.size() == 1);
76-
prop.l_set_to_true(prop.limplies(eq_bv[0], equal));
76+
prop.lcnf(!eq_bv[0], equal);
7777
}
7878

7979
return l;

src/solvers/flattening/boolbv_index.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
135135
simplify(implication, ns);
136136
const bvt &bv2 = convert_bv(implication);
137137
CHECK_RETURN(bv2.size() == 1);
138-
prop.l_set_to_true(bv2[0]);
138+
prop.lcnf(bv2);
139139

140140
return bv;
141141
}
@@ -189,10 +189,11 @@ bvt boolbvt::convert_index(const index_exprt &expr)
189189
value_equality.rhs()=*it++;
190190

191191
// Cache comparisons and equalities
192-
const bvt &bv2 =
193-
convert_bv(implies_exprt(index_equality, value_equality));
194-
CHECK_RETURN(bv2.size() == 1);
195-
prop.l_set_to_true(bv2[0]);
192+
const bvt &bv_index_eq = convert_bv(index_equality);
193+
CHECK_RETURN(bv_index_eq.size() == 1);
194+
const bvt &bv_value_eq = convert_bv(value_equality);
195+
CHECK_RETURN(bv_value_eq.size() == 1);
196+
prop.lcnf(!bv_index_eq[0], bv_value_eq[0]);
196197
}
197198

198199
return bv;
@@ -233,25 +234,26 @@ bvt boolbvt::convert_index(const index_exprt &expr)
233234
bv_utils.equal_const_register(convert_bv(index)); // Definitely
234235
#endif
235236

236-
bvt equal_bv;
237-
equal_bv.resize(width);
238-
239237
for(mp_integer i=0; i<array_size; i=i+1)
240238
{
241239
index_equality.rhs()=from_integer(i, index_equality.lhs().type());
242240

243241
if(index_equality.rhs().is_nil())
244242
throw "number conversion failed (1)";
245243

246-
mp_integer offset=i*width;
247-
248-
for(std::size_t j=0; j<width; j++)
249-
equal_bv[j]=prop.lequal(bv[j],
250-
array_bv[integer2size_t(offset+j)]);
251-
252244
const bvt &index_eq = convert_bv(index_equality);
253245
CHECK_RETURN(index_eq.size() == 1);
254-
prop.l_set_to_true(prop.limplies(index_eq[0], prop.land(equal_bv)));
246+
literalt index_not_eq_lit = !index_eq[0];
247+
248+
mp_integer offset=i*width;
249+
250+
bvt::const_iterator array_it =
251+
array_bv.begin() + integer2size_t(offset);
252+
for(const auto &bit : bv)
253+
{
254+
prop.lcnf(index_not_eq_lit, prop.lequal(bit, *array_it));
255+
++array_it;
256+
}
255257
}
256258
}
257259
else

src/solvers/flattening/boolbv_unary_minus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ bvt boolbvt::convert_unary_minus(const unary_exprt &expr)
104104
(bvtype==bvtypet::IS_SIGNED || bvtype==bvtypet::IS_UNSIGNED))
105105
{
106106
if(no_overflow)
107-
prop.l_set_to_false(bv_utils.overflow_negate(op_bv));
107+
prop.lcnf(bvt(1, !bv_utils.overflow_negate(op_bv)));
108108

109109
if(no_overflow)
110110
return bv_utils.negate_no_overflow(op_bv);

src/solvers/flattening/bv_pointers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ void bv_pointerst::do_postponed(
741741
if(!is_dynamic)
742742
l2=!l2;
743743

744-
prop.l_set_to_true(prop.limplies(l1, l2));
744+
prop.lcnf(!l1, l2);
745745
}
746746
}
747747
else if(postponed.expr.id()==ID_object_size)
@@ -793,7 +793,7 @@ void bv_pointerst::do_postponed(
793793
bvt size_bv=bv_utils.build_constant(object_size, postponed.bv.size());
794794
literalt l2=bv_utils.equal(postponed.bv, size_bv);
795795

796-
prop.l_set_to_true(prop.limplies(l1, l2));
796+
prop.lcnf(!l1, l2);
797797
}
798798
}
799799
else

src/solvers/flattening/bv_utils.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ void bv_utilst::adder_no_overflow(
434434
adder(sum, tmp_op, const_literal(subtract), carry);
435435

436436
// result of addition in sum
437-
prop.l_set_to_false(
438-
prop.land(sign_the_same, prop.lxor(sum[sum.size()-1], old_sign)));
437+
prop.lcnf(!sign_the_same, prop.lequal(sum[sum.size()-1], old_sign));
439438
}
440439
else if(rep==representationt::UNSIGNED)
441440
{
@@ -453,7 +452,7 @@ void bv_utilst::adder_no_overflow(bvt &sum, const bvt &op)
453452

454453
adder(sum, op, carry_out, carry_out);
455454

456-
prop.l_set_to_false(carry_out); // enforce no overflow
455+
prop.lcnf(bvt(1, !carry_out)); // enforce no overflow
457456
}
458457

459458
bvt bv_utilst::shift(const bvt &op, const shiftt s, const bvt &dist)
@@ -539,7 +538,7 @@ bvt bv_utilst::negate(const bvt &bv)
539538

540539
bvt bv_utilst::negate_no_overflow(const bvt &bv)
541540
{
542-
prop.l_set_to_false(overflow_negate(bv));
541+
prop.lcnf(bvt(1, !overflow_negate(bv)));
543542
return negate(bv);
544543
}
545544

@@ -733,7 +732,7 @@ bvt bv_utilst::unsigned_multiplier_no_overflow(
733732
adder_no_overflow(product, tmpop);
734733

735734
for(std::size_t idx=op1.size()-sum; idx<op1.size(); idx++)
736-
prop.l_set_to_false(prop.land(op1[idx], op0[sum]));
735+
prop.lcnf(!op1[idx], !op0[sum]);
737736
}
738737

739738
return product;
@@ -778,7 +777,7 @@ bvt bv_utilst::absolute_value(const bvt &bv)
778777

779778
bvt bv_utilst::cond_negate_no_overflow(const bvt &bv, literalt cond)
780779
{
781-
prop.l_set_to_true(prop.limplies(cond, !overflow_negate(bv)));
780+
prop.lcnf(!cond, !overflow_negate(bv));
782781

783782
return cond_negate(bv, cond);
784783
}
@@ -798,7 +797,7 @@ bvt bv_utilst::signed_multiplier_no_overflow(
798797

799798
bvt result=unsigned_multiplier_no_overflow(neg0, neg1);
800799

801-
prop.l_set_to_false(result[result.size()-1]);
800+
prop.lcnf(bvt(1, !result[result.size()-1]));
802801

803802
literalt result_sign=prop.lxor(sign0, sign1);
804803

@@ -957,19 +956,15 @@ void bv_utilst::unsigned_divider(
957956

958957
literalt is_equal=equal(sum, op0);
959958

960-
prop.l_set_to_true(prop.limplies(is_not_zero, is_equal));
959+
prop.lcnf(!is_not_zero, is_equal);
961960

962961
// op1!=0 => rem < op1
963962

964-
prop.l_set_to_true(
965-
prop.limplies(
966-
is_not_zero, lt_or_le(false, rem, op1, representationt::UNSIGNED)));
963+
prop.lcnf(!is_not_zero, lt_or_le(false, rem, op1, representationt::UNSIGNED));
967964

968965
// op1!=0 => res <= op0
969966

970-
prop.l_set_to_true(
971-
prop.limplies(
972-
is_not_zero, lt_or_le(true, res, op0, representationt::UNSIGNED)));
967+
prop.lcnf(!is_not_zero, lt_or_le(true, res, op0, representationt::UNSIGNED));
973968
}
974969

975970

@@ -1174,7 +1169,7 @@ literalt bv_utilst::lt_or_le(
11741169

11751170
// When comparing signs we are comparing the top bit
11761171
#ifdef INCLUDE_REDUNDANT_CLAUSES
1177-
prop.l_set_to_true(compareBelow[start + 1])
1172+
prop.lcnf(compareBelow[start + 1])
11781173
#endif
11791174

11801175
// Four cases...
@@ -1192,7 +1187,7 @@ literalt bv_utilst::lt_or_le(
11921187
{
11931188
// Unsigned is much easier
11941189
start = compareBelow.size() - 1;
1195-
prop.l_set_to_true(compareBelow[start]);
1190+
prop.lcnf(compareBelow[start]);
11961191
}
11971192

11981193
// Determine the output

0 commit comments

Comments
 (0)