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++)
792 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++)
899 std::size_t width=op0.size();
904 std::size_t one_count=0, non_const_count=0, one_pos=0;
906 for(std::size_t i=0; i<op1.size(); i++)
918 if(non_const_count==0 && one_count==1 && one_pos!=0)
921 res=
shift(op0, LRIGHT, one_pos);
925 for(std::size_t i=one_pos; i<rem.size(); i++)
944 for(std::size_t i=0; i<width; i++)
979 #ifdef COMPACT_EQUAL_CONST
985 void bv_utilst::equal_const_register(
const bvt &var)
988 equal_const_registered.insert(var);
1000 std::size_t size = var.size();
1010 constant.pop_back();
1015 var_constant_pairt index(var, constant);
1017 equal_const_cachet::iterator entry = equal_const_cache.find(index);
1019 if(entry != equal_const_cache.end())
1021 return entry->second;
1027 constant.pop_back();
1029 literalt rec = equal_const_rec(var, constant);
1032 equal_const_cache.insert(
1033 std::pair<var_constant_pairt, literalt>(index, compare));
1048 literalt bv_utilst::equal_const(
const bvt &var,
const bvt &constant)
1050 std::size_t size = constant.size();
1068 literalt top_bit = constant[size - 1];
1070 std::size_t split = size - 1;
1071 var_upper.push_back(var[size - 1]);
1072 constant_upper.push_back(constant[size - 1]);
1074 for(split = size - 2; split != 0; --split)
1076 if(constant[split] != top_bit)
1082 var_upper.push_back(var[split]);
1083 constant_upper.push_back(constant[split]);
1087 for(std::size_t i = 0; i <= split; ++i)
1089 var_lower.push_back(var[i]);
1090 constant_lower.push_back(constant[i]);
1095 var_upper.size() + var_lower.size() == size,
1096 "lower size plus upper size should equal the total size");
1098 constant_upper.size() + constant_lower.size() == size,
1099 "lower size plus upper size should equal the total size");
1101 literalt top_comparison = equal_const_rec(var_upper, constant_upper);
1102 literalt bottom_comparison = equal_const_rec(var_lower, constant_lower);
1104 return prop.
land(top_comparison, bottom_comparison);
1117 #ifdef COMPACT_EQUAL_CONST
1121 equal_const_registered.find(op1) != equal_const_registered.end())
1122 return equal_const(op1, op0);
1124 equal_const_registered.find(op0) != equal_const_registered.end())
1125 return equal_const(op0, op1);
1129 equal_bv.resize(op0.size());
1131 for(std::size_t i=0; i<op0.size(); i++)
1161 top1=bv1[bv1.size()-1];
1163 #ifdef COMPACT_LT_OR_LE
1171 compareBelow.resize(bv0.size());
1178 bv0.size() >= 2,
"signed bitvectors should have at least two bits");
1179 start = compareBelow.size() - 2;
1181 literalt firstComp=compareBelow[start];
1184 #ifdef INCLUDE_REDUNDANT_CLAUSES
1192 prop.
lcnf(!top0, !top1, firstComp);
1194 #ifdef INCLUDE_REDUNDANT_CLAUSES
1195 prop.
lcnf(top0, !top1, !firstComp);
1196 prop.
lcnf(!top0, top1, !firstComp);
1202 start = compareBelow.size() - 1;
1212 prop.
lcnf(!compareBelow[i], bv0[i], !bv1[i], result);
1213 prop.
lcnf(!compareBelow[i], !bv0[i], bv1[i], !result);
1220 for(i = start; i > 0; i--)
1222 prop.
lcnf(!compareBelow[i], !bv0[i], !bv1[i], compareBelow[i-1]);
1223 prop.
lcnf(!compareBelow[i], bv0[i], bv1[i], compareBelow[i-1]);
1227 #ifdef INCLUDE_REDUNDANT_CLAUSES
1232 for(i = start; i > 0; i--)
1234 prop.
lcnf(compareBelow[i], !compareBelow[i-1]);
1235 prop.
lcnf(!compareBelow[i], bv0[i], !bv1[i], !compareBelow[i-1]);
1236 prop.
lcnf(!compareBelow[i], !bv0[i], bv1[i], !compareBelow[i-1]);
1241 prop.
lcnf(!compareBelow[0], !bv0[0], !bv1[0], (or_equal)?result:!result);
1242 prop.
lcnf(!compareBelow[0], bv0[0], bv1[0], (or_equal)?result:!result);
1260 "representation has either value signed or unsigned");
1275 #ifdef COMPACT_LT_OR_LE
1276 return lt_or_le(
false, op0, op1, UNSIGNED);
1297 return equal(bv0, bv1);
1298 else if(
id==ID_notequal)
1299 return !
equal(bv0, bv1);
1301 return lt_or_le(
true, bv0, bv1, rep);
1303 return lt_or_le(
false, bv0, bv1, rep);
1305 return lt_or_le(
true, bv1, bv0, rep);
1307 return lt_or_le(
false, bv1, bv0, rep);
1315 if(!it->is_constant())
1330 for(std::size_t i=0; i<a.size(); i++)
1347 odd_bits.reserve(src.size()/2);
1350 for(std::size_t i=0; i<src.size(); i++)
1353 odd_bits.push_back(src[i]);
1362 even_bits.reserve(src.size()/2);
1365 for(std::size_t i=0; i<src.size(); i++)
1368 even_bits.push_back(src[i]);