Skip to content

Commit 5021afa

Browse files
committed
Cleanup unsigned_multiplier
De-duplicate code paths to reduce the amount of code that is defined-out for the Wallace Tree reduction.
1 parent 25cb64d commit 5021afa

File tree

1 file changed

+25
-40
lines changed

1 file changed

+25
-40
lines changed

src/solvers/flattening/bv_utils.cpp

+25-40
Original file line numberDiff line numberDiff line change
@@ -687,66 +687,51 @@ bvt bv_utilst::wallace_tree(const std::vector<bvt> &pps)
687687
}
688688
}
689689

690+
// Wallace tree multiplier. This is disabled, as runtimes have
691+
// been observed to go up by 5%-10%, and on some models even by 20%.
692+
// #define WALLACE_TREE
693+
690694
bvt bv_utilst::unsigned_multiplier(const bvt &_op0, const bvt &_op1)
691695
{
692-
#if 1
693696
bvt op0=_op0, op1=_op1;
694697

695698
if(is_constant(op1))
696699
std::swap(op0, op1);
697700

698-
bvt product;
699-
product.resize(op0.size());
700-
701-
for(std::size_t i=0; i<product.size(); i++)
702-
product[i]=const_literal(false);
703-
704-
for(std::size_t sum=0; sum<op0.size(); sum++)
705-
if(op0[sum]!=const_literal(false))
706-
{
707-
bvt tmpop = zeros(sum);
708-
tmpop.reserve(op0.size());
709-
710-
for(std::size_t idx=sum; idx<op0.size(); idx++)
711-
tmpop.push_back(prop.land(op1[idx-sum], op0[sum]));
712-
713-
product=add(product, tmpop);
714-
}
715-
716-
return product;
717-
#else
718-
// Wallace tree multiplier. This is disabled, as runtimes have
719-
// been observed to go up by 5%-10%, and on some models even by 20%.
720-
721701
// build the usual quadratic number of partial products
722-
723-
bvt op0=_op0, op1=_op1;
724-
725-
if(is_constant(op1))
726-
std::swap(op0, op1);
727-
728702
std::vector<bvt> pps;
729703
pps.reserve(op0.size());
730704

731705
for(std::size_t bit=0; bit<op0.size(); bit++)
732-
if(op0[bit]!=const_literal(false))
733-
{
734-
// zeros according to weight
735-
bvt pp = zeros(bit);
736-
pp.reserve(op0.size());
706+
{
707+
if(op0[bit] == const_literal(false))
708+
continue;
737709

738-
for(std::size_t idx=bit; idx<op0.size(); idx++)
739-
pp.push_back(prop.land(op1[idx-bit], op0[bit]));
710+
// zeros according to weight
711+
bvt pp = zeros(bit);
712+
pp.reserve(op0.size());
740713

741-
pps.push_back(pp);
742-
}
714+
for(std::size_t idx = bit; idx < op0.size(); idx++)
715+
pp.push_back(prop.land(op1[idx - bit], op0[bit]));
716+
717+
pps.push_back(pp);
718+
}
743719

744720
if(pps.empty())
745721
return zeros(op0.size());
746722
else
723+
{
724+
#ifdef WALLACE_TREE
747725
return wallace_tree(pps);
726+
#else
727+
bvt product = pps.front();
748728

749-
#endif
729+
for(auto it = std::next(pps.begin()); it != pps.end(); ++it)
730+
product = add(product, *it);
731+
732+
return product;
733+
#endif
734+
}
750735
}
751736

752737
bvt bv_utilst::unsigned_multiplier_no_overflow(

0 commit comments

Comments
 (0)