Skip to content

Commit 40d4ab9

Browse files
authored
Merge pull request #7122 from tautschnig/cleanup/zeros
bv_utilst::zeros: code cleanup, use more widely
2 parents 782c222 + 047c065 commit 40d4ab9

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

src/solvers/flattening/boolbv_div.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ bvt boolbvt::convert_div(const div_exprt &expr)
3737
std::size_t fraction_bits=
3838
to_fixedbv_type(expr.type()).get_fraction_bits();
3939

40-
bvt zeros;
41-
zeros.resize(fraction_bits, const_literal(false));
40+
bvt zeros = bv_utils.zeros(fraction_bits);
4241

4342
// add fraction_bits least-significant bits
4443
op0.insert(op0.begin(), zeros.begin(), zeros.end());

src/solvers/flattening/bv_utils.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,10 @@ literalt bv_utilst::overflow_negate(const bvt &bv)
615615
// a overflow on unary- can only happen with the smallest
616616
// representable number 100....0
617617

618-
bvt zeros(bv);
619-
zeros.erase(--zeros.end());
618+
bvt should_be_zeros(bv);
619+
should_be_zeros.pop_back();
620620

621-
return prop.land(bv[bv.size()-1], !prop.lor(zeros));
621+
return prop.land(bv[bv.size() - 1], !prop.lor(should_be_zeros));
622622
}
623623

624624
void bv_utilst::incrementer(
@@ -715,13 +715,9 @@ bvt bv_utilst::unsigned_multiplier(const bvt &_op0, const bvt &_op1)
715715
for(std::size_t sum=0; sum<op0.size(); sum++)
716716
if(op0[sum]!=const_literal(false))
717717
{
718-
bvt tmpop;
719-
718+
bvt tmpop = zeros(sum);
720719
tmpop.reserve(op0.size());
721720

722-
for(std::size_t idx=0; idx<sum; idx++)
723-
tmpop.push_back(const_literal(false));
724-
725721
for(std::size_t idx=sum; idx<op0.size(); idx++)
726722
tmpop.push_back(prop.land(op1[idx-sum], op0[sum]));
727723

@@ -746,13 +742,9 @@ bvt bv_utilst::unsigned_multiplier(const bvt &_op0, const bvt &_op1)
746742
for(std::size_t bit=0; bit<op0.size(); bit++)
747743
if(op0[bit]!=const_literal(false))
748744
{
749-
bvt pp;
750-
751-
pp.reserve(op0.size());
752-
753745
// zeros according to weight
754-
for(std::size_t idx=0; idx<bit; idx++)
755-
pp.push_back(const_literal(false));
746+
bvt pp = zeros(bit);
747+
pp.reserve(op0.size());
756748
757749
for(std::size_t idx=bit; idx<op0.size(); idx++)
758750
pp.push_back(prop.land(op1[idx-bit], op0[bit]));

src/solvers/flattening/bv_utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ class bv_utilst
191191

192192
static bvt zeros(std::size_t new_size)
193193
{
194-
bvt result;
195-
result.resize(new_size, const_literal(false));
196-
return result;
194+
return bvt(new_size, const_literal(false));
197195
}
198196

199197
void set_equal(const bvt &a, const bvt &b);

0 commit comments

Comments
 (0)