@@ -687,66 +687,51 @@ bvt bv_utilst::wallace_tree(const std::vector<bvt> &pps)
687
687
}
688
688
}
689
689
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
+
690
694
bvt bv_utilst::unsigned_multiplier (const bvt &_op0, const bvt &_op1)
691
695
{
692
- #if 1
693
696
bvt op0=_op0, op1=_op1;
694
697
695
698
if (is_constant (op1))
696
699
std::swap (op0, op1);
697
700
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
-
721
701
// 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
-
728
702
std::vector<bvt> pps;
729
703
pps.reserve (op0.size ());
730
704
731
705
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 ;
737
709
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 ());
740
713
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
+ }
743
719
744
720
if (pps.empty ())
745
721
return zeros (op0.size ());
746
722
else
723
+ {
724
+ #ifdef WALLACE_TREE
747
725
return wallace_tree (pps);
726
+ #else
727
+ bvt product = pps.front ();
748
728
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
+ }
750
735
}
751
736
752
737
bvt bv_utilst::unsigned_multiplier_no_overflow (
0 commit comments