21 for(std::size_t i=0; i<width; i++)
31 tmp.erase(tmp.begin(), tmp.begin()+1);
38 for(std::size_t i=0; i<a.size(); i++)
50 result.resize(last+1);
52 result.erase(result.begin(), result.begin()+first);
64 result.erase(result.begin(), result.begin()+(result.size()-n));
84 result.resize(a.size()+b.size());
86 for(std::size_t i=0; i<a.size(); i++)
89 for(std::size_t i=0; i<b.size(); i++)
90 result[i+a.size()]=b[i];
102 result.resize(a.size());
103 for(std::size_t i=0; i<result.size(); i++)
111 std::size_t new_size,
114 std::size_t old_size=bv.size();
118 result.resize(new_size);
124 for(std::size_t i=old_size; i<new_size; i++)
125 result[i]=extend_with;
138 #define OPTIMAL_FULL_ADDER
146 #ifdef OPTIMAL_FULL_ADDER
151 int constantProp = -1;
157 constantProp = (a.
is_true()) ? 1 : 0;
163 constantProp = (b.
is_true()) ? 1 : 0;
169 constantProp = (carry_in.
is_true()) ? 1 : 0;
175 if(constantProp == 1)
181 else if(constantProp == 0)
220 #endif // OPTIMAL_FULL_ADDER
229 #define COMPACT_CARRY
237 const auto const_count =
284 #endif // COMPACT_CARRY
307 for(std::size_t i=0; i<sum.size(); i++)
322 for(std::size_t i=0; i<op0.size(); i++)
356 const bvt op1_sign_applied=
375 literalt old_sign=op0[op0.size()-1];
400 literalt op0_is_negative=op0[op0.size()-1];
429 literalt old_sign=sum[sum.size()-1];
431 prop.
lequal(sum[sum.size()-1], tmp_op[tmp_op.size()-1]);
444 "representation has either value signed or unsigned");
462 std::size_t d=1, width=op.size();
465 for(std::size_t stage=0; stage<dist.size(); stage++)
471 for(std::size_t i=0; i<width; i++)
472 result[i]=
prop.
lselect(dist[stage], tmp[i], result[i]);
484 result.resize(src.size());
490 for(std::size_t i=0; i<src.size(); i++)
504 l=(dist<src.size()-i?src[i+dist]:src[src.size()-1]);
515 l=src[(src.size()+i-(dist%src.size()))%src.size()];
520 l=src[(i+(dist%src.size()))%src.size()];
595 else if(pps.size()==2)
596 return add(pps[0], pps[1]);
599 std::vector<bvt> new_pps;
600 std::size_t no_full_adders=pps.size()/3;
603 for(std::size_t i=0; i<no_full_adders; i++)
605 const bvt &a=pps[i*3+0],
609 INVARIANT(a.size() == b.size(),
"groups should be of equal size");
610 INVARIANT(a.size() == c.size(),
"groups should be of equal size");
612 bvt s(a.size()), t(a.size());
614 for(std::size_t bit=0; bit<a.size(); bit++)
619 carry(a[bit-1], b[bit-1], c[bit-1]);
622 new_pps.push_back(s);
623 new_pps.push_back(t);
627 for(std::size_t i=no_full_adders*3; i<pps.size(); i++)
628 new_pps.push_back(pps[i]);
638 bvt op0=_op0, op1=_op1;
644 product.resize(op0.size());
646 for(std::size_t i=0; i<product.size(); i++)
649 for(std::size_t sum=0; sum<op0.size(); sum++)
654 tmpop.reserve(op0.size());
656 for(std::size_t idx=0; idx<sum; idx++)
659 for(std::size_t idx=sum; idx<op0.size(); idx++)
660 tmpop.push_back(
prop.
land(op1[idx-sum], op0[sum]));
662 product=
add(product, tmpop);
672 bvt op0=_op0, op1=_op1;
677 std::vector<bvt> pps;
678 pps.reserve(op0.size());
680 for(std::size_t bit=0; bit<op0.size(); bit++)
685 pp.reserve(op0.size());
688 for(std::size_t idx=0; idx<bit; idx++)
691 for(std::size_t idx=bit; idx<op0.size(); idx++)
692 pp.push_back(
prop.
land(op1[idx-bit], op0[bit]));
698 return zeros(op0.size());
709 bvt _op0=op0, _op1=op1;
717 product.resize(_op0.size());
719 for(std::size_t i=0; i<product.size(); i++)
722 for(std::size_t sum=0; sum<op0.size(); sum++)
727 tmpop.reserve(product.size());
729 for(std::size_t idx=0; idx<sum; idx++)
732 for(std::size_t idx=sum; idx<product.size(); idx++)
733 tmpop.push_back(
prop.
land(op1[idx-sum], op0[sum]));
737 for(std::size_t idx=op1.size()-sum; idx<op1.size(); idx++)
746 if(op0.empty() || op1.empty())
767 result.resize(bv.size());
769 for(std::size_t i=0; i<bv.size(); i++)
794 if(op0.empty() || op1.empty())
846 if(op0.empty() || op1.empty())
849 bvt _op0(op0), _op1(op1);
851 literalt sign_0=_op0[_op0.size()-1];
852 literalt sign_1=_op1[_op1.size()-1];
856 for(std::size_t i=0; i<_op0.size(); i++)
859 for(std::size_t i=0; i<_op1.size(); i++)
868 for(std::size_t i=0; i<res.size(); i++)
869 res[i]=
prop.
lselect(result_sign, neg_res[i], res[i]);
871 for(std::size_t i=0; i<res.size(); i++)
901 std::size_t width=op0.size();
906 std::size_t one_count=0, non_const_count=0, one_pos=0;
908 for(std::size_t i=0; i<op1.size(); i++)
920 if(non_const_count==0 && one_count==1 && one_pos!=0)
923 res=
shift(op0, LRIGHT, one_pos);
927 for(std::size_t i=one_pos; i<rem.size(); i++)
946 for(std::size_t i=0; i<width; i++)
981 #ifdef COMPACT_EQUAL_CONST
987 void bv_utilst::equal_const_register(
const bvt &var)
990 equal_const_registered.insert(var);
1003 std::size_t size = var.size();
1013 constant.pop_back();
1018 var_constant_pairt index(var, constant);
1020 equal_const_cachet::iterator entry = equal_const_cache.find(index);
1022 if(entry != equal_const_cache.end())
1024 return entry->second;
1030 constant.pop_back();
1032 literalt rec = equal_const_rec(var, constant);
1035 equal_const_cache.insert(
1036 std::pair<var_constant_pairt, literalt>(index, compare));
1051 literalt bv_utilst::equal_const(
const bvt &var,
const bvt &constant)
1053 std::size_t size = constant.size();
1071 literalt top_bit = constant[size - 1];
1073 std::size_t split = size - 1;
1074 var_upper.push_back(var[size - 1]);
1075 constant_upper.push_back(constant[size - 1]);
1077 for(split = size - 2; split != 0; --split)
1079 if(constant[split] != top_bit)
1085 var_upper.push_back(var[split]);
1086 constant_upper.push_back(constant[split]);
1090 for(std::size_t i = 0; i <= split; ++i)
1092 var_lower.push_back(var[i]);
1093 constant_lower.push_back(constant[i]);
1098 var_upper.size() + var_lower.size() == size,
1099 "lower size plus upper size should equal the total size");
1101 constant_upper.size() + constant_lower.size() == size,
1102 "lower size plus upper size should equal the total size");
1104 literalt top_comparison = equal_const_rec(var_upper, constant_upper);
1105 literalt bottom_comparison = equal_const_rec(var_lower, constant_lower);
1107 return prop.
land(top_comparison, bottom_comparison);
1120 #ifdef COMPACT_EQUAL_CONST
1124 equal_const_registered.find(op1) != equal_const_registered.end())
1125 return equal_const(op1, op0);
1127 equal_const_registered.find(op0) != equal_const_registered.end())
1128 return equal_const(op0, op1);
1132 equal_bv.resize(op0.size());
1134 for(std::size_t i=0; i<op0.size(); i++)
1164 top1=bv1[bv1.size()-1];
1166 #ifdef COMPACT_LT_OR_LE
1174 compareBelow.resize(bv0.size());
1181 bv0.size() >= 2,
"signed bitvectors should have at least two bits");
1182 start = compareBelow.size() - 2;
1184 literalt firstComp=compareBelow[start];
1187 #ifdef INCLUDE_REDUNDANT_CLAUSES
1195 prop.
lcnf(!top0, !top1, firstComp);
1197 #ifdef INCLUDE_REDUNDANT_CLAUSES
1198 prop.
lcnf(top0, !top1, !firstComp);
1199 prop.
lcnf(!top0, top1, !firstComp);
1205 start = compareBelow.size() - 1;
1215 prop.
lcnf(!compareBelow[i], bv0[i], !bv1[i], result);
1216 prop.
lcnf(!compareBelow[i], !bv0[i], bv1[i], !result);
1223 for(i = start; i > 0; i--)
1225 prop.
lcnf(!compareBelow[i], !bv0[i], !bv1[i], compareBelow[i-1]);
1226 prop.
lcnf(!compareBelow[i], bv0[i], bv1[i], compareBelow[i-1]);
1230 #ifdef INCLUDE_REDUNDANT_CLAUSES
1235 for(i = start; i > 0; i--)
1237 prop.
lcnf(compareBelow[i], !compareBelow[i-1]);
1238 prop.
lcnf(!compareBelow[i], bv0[i], !bv1[i], !compareBelow[i-1]);
1239 prop.
lcnf(!compareBelow[i], !bv0[i], bv1[i], !compareBelow[i-1]);
1244 prop.
lcnf(!compareBelow[0], !bv0[0], !bv1[0], (or_equal)?result:!result);
1245 prop.
lcnf(!compareBelow[0], bv0[0], bv1[0], (or_equal)?result:!result);
1263 "representation has either value signed or unsigned");
1278 #ifdef COMPACT_LT_OR_LE
1279 return lt_or_le(
false, op0, op1, UNSIGNED);
1300 return equal(bv0, bv1);
1301 else if(
id==ID_notequal)
1302 return !
equal(bv0, bv1);
1304 return lt_or_le(
true, bv0, bv1, rep);
1306 return lt_or_le(
false, bv0, bv1, rep);
1308 return lt_or_le(
true, bv1, bv0, rep);
1310 return lt_or_le(
false, bv1, bv0, rep);
1318 if(!it->is_constant())
1333 for(std::size_t i=0; i<a.size(); i++)
1350 odd_bits.reserve(src.size()/2);
1353 for(std::size_t i=0; i<src.size(); i++)
1356 odd_bits.push_back(src[i]);
1365 even_bits.reserve(src.size()/2);
1368 for(std::size_t i=0; i<src.size(); i++)
1371 even_bits.push_back(src[i]);