22 for(std::size_t i=0; i<width; i++)
30 const std::size_t width = bv.size();
31 std::string s(width,
'0');
32 for(std::size_t i = 0; i < width; i++)
33 s[width - i - 1] = bv[i].
is_true() ?
'1' :
'0';
49 for(std::size_t i=0; i<
a.size(); i++)
61 result.resize(last+1);
63 result.erase(result.begin(), result.begin()+first);
75 result.erase(result.begin(), result.begin()+(result.size()-
n));
95 result.resize(
a.size()+
b.size());
97 for(std::size_t i=0; i<
a.size(); i++)
100 for(std::size_t i=0; i<
b.size(); i++)
101 result[i+
a.size()]=
b[i];
113 result.resize(
a.size());
114 for(std::size_t i=0; i<result.size(); i++)
149#define OPTIMAL_FULL_ADDER
157 #ifdef OPTIMAL_FULL_ADDER
170 else if(
b.is_constant())
249 a.is_constant() +
b.is_constant() +
c.is_constant();
308std::pair<bvt, literalt>
314 result.first.reserve(op0.size());
317 for(std::size_t i = 0; i < op0.size(); i++)
334 for(std::size_t i=0; i<op0.size(); i++)
515 "representation has either value signed or unsigned");
518 return std::move(result.first);
529 std::size_t d=1, width=op.size();
538 for(std::size_t i=0; i<width; i++)
551 result.resize(src.size());
557 for(std::size_t i=0; i<src.size(); i++)
582 l=src[(src.size()+i-(
dist%src.size()))%src.size()];
587 l=src[(i+(
dist%src.size()))%src.size()];
662 else if(
pps.size()==2)
676 INVARIANT(
a.size() ==
b.size(),
"groups should be of equal size");
677 INVARIANT(
a.size() ==
c.size(),
"groups should be of equal size");
686 if(
bit + 1 <
a.size())
690 new_pps.push_back(std::move(s));
691 new_pps.push_back(std::move(t));
707 using columnt = std::list<literalt>;
708 std::vector<columnt>
columns(
pps.front().size());
709 for(
const auto &
pp :
pps)
712 for(std::size_t i = 0; i <
pp.size(); ++i)
720 for(std::size_t d = 2; d <
pps.front().size(); d = (d * 3) / 2)
729 else if(
col_it->size() == d + 1)
736 *std::next(
col_it->begin()),
752 *std::next(
col_it->begin()),
753 *std::next(std::next(
col_it->begin())),
765 a.reserve(
pps.front().size());
766 b.reserve(
pps.front().size());
778 a.push_back(
col.front());
782 a.push_back(
col.front());
783 b.push_back(
col.back());
938 std::vector<bvt>
pps;
939 pps.reserve(op0.size());
941 for(std::size_t
bit=0;
bit<op0.size();
bit++)
948 pp.reserve(op0.size());
950 for(std::size_t idx =
bit; idx < op0.size(); idx++)
957 return zeros(op0.size());
962#elif defined(DADDA_TREE)
967 for(
auto it = std::next(
pps.begin()); it !=
pps.end(); ++it)
989 for(std::size_t i=0; i<
product.size(); i++)
992 for(std::size_t
sum=0;
sum<op0.size();
sum++)
999 for(std::size_t idx=0; idx<
sum; idx++)
1002 for(std::size_t idx=
sum; idx<
product.size(); idx++)
1007 for(std::size_t idx=op1.size()-
sum; idx<op1.size(); idx++)
1016 if(op0.empty() || op1.empty())
1037 result.resize(bv.size());
1039 for(std::size_t i=0; i<bv.size(); i++)
1062 if(op0.empty() || op1.empty())
1121 if(op0.empty() || op1.empty())
1131 for(std::size_t i=0; i<
_op0.size(); i++)
1134 for(std::size_t i=0; i<
_op1.size(); i++)
1143 for(std::size_t i=0; i<
res.size(); i++)
1146 for(std::size_t i=0; i<
res.size(); i++)
1175 std::size_t width=op0.size();
1198 for(std::size_t i=0; i<op1.size(); i++)
1217 for(std::size_t i=
one_pos; i<rem.size(); i++)
1263#ifdef COMPACT_EQUAL_CONST
1269void bv_utilst::equal_const_register(
const bvt &var)
1284 std::size_t size = var.size();
1294 constant.pop_back();
1305 return entry->second;
1311 constant.pop_back();
1317 std::pair<var_constant_pairt, literalt>(index, compare));
1332literalt bv_utilst::equal_const(
const bvt &var,
const bvt &constant)
1334 std::size_t size = constant.size();
1354 std::size_t
split = size - 1;
1371 for(std::size_t i = 0; i <=
split; ++i)
1380 "lower size plus upper size should equal the total size");
1383 "lower size plus upper size should equal the total size");
1401 #ifdef COMPACT_EQUAL_CONST
1415 for(std::size_t i=0; i<op0.size(); i++)
1426#define COMPACT_LT_OR_LE
1441#ifdef COMPACT_LT_OR_LE
1448 if(
top0.is_false() &&
top1.is_true())
1450 else if(
top0.is_true() &&
top1.is_false())
1464 "the compact signed comparison encoding requires at least two bits");
1472 else if(
top0.is_true())
1474 else if(
top1.is_false())
1476 else if(
top1.is_true())
1488#ifdef INCLUDE_REDUNDANT_CLAUSES
1509 for(i = start; i > 0; i--)
1515# ifdef INCLUDE_REDUNDANT_CLAUSES
1520 for(i = start; i > 0; i--)
1542 size_t start =
bv0.size() - 1;
1560 else if(
bv0[i] ==
bv1[i])
1583 for(i = start; i > 0; i--)
1589#ifdef INCLUDE_REDUNDANT_CLAUSES
1594 for(i = start; i > 0; i--)
1626 "representation has either value signed or unsigned");
1693 for(std::size_t i=0; i<
a.size(); i++)
1713 for(std::size_t i=0; i<src.size(); i++)
1728 for(std::size_t i=0; i<src.size(); i++)
1772 mask.reserve(
x.size());
1773 for(std::size_t i = 0; i <
x.size(); i++)
1786 for(std::size_t i = 0; i <
x.size(); i++)
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
static bvt inverted(const bvt &op)
literalt signed_less_than(const bvt &bv0, const bvt &bv1)
static bool is_constant(const bvt &bv)
std::pair< bvt, literalt > adder(const bvt &op0, const bvt &op1, literalt carry_in)
Return the sum and carry-out when adding op0 and op1 under initial carry carry_in.
bvt wallace_tree(const std::vector< bvt > &pps)
literalt is_not_zero(const bvt &op)
static bvt verilog_bv_normal_bits(const bvt &)
literalt is_int_min(const bvt &op)
static bvt extract_msb(const bvt &a, std::size_t n)
static mp_integer from_constant(const bvt &bv)
Returns the unsigned integer value of the constant bitvector bv.
void set_equal(const bvt &a, const bvt &b)
static literalt sign_bit(const bvt &op)
bvt multiplier_no_overflow(const bvt &op0, const bvt &op1, representationt rep)
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
bvt add(const bvt &op0, const bvt &op1)
bvt absolute_value(const bvt &op)
bvt select(literalt s, const bvt &a, const bvt &b)
If s is true, selects a otherwise selects b.
static bvt build_constant(const mp_integer &i, std::size_t width)
void signed_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem)
literalt is_zero(const bvt &op)
literalt equal(const bvt &op0, const bvt &op1)
Bit-blasting ID_equal and use in other encodings.
bvt popcount(const bvt &bv)
Symbolic implementation of popcount (count of 1 bits in a bit vector) Based on the pop0 algorithm fro...
bvt signed_multiplier(const bvt &op0, const bvt &op1)
literalt overflow_add(const bvt &op0, const bvt &op1, representationt rep)
literalt is_one(const bvt &op)
bvt cond_negate_no_overflow(const bvt &bv, const literalt cond)
literalt overflow_sub(const bvt &op0, const bvt &op1, representationt rep)
void cond_implies_equal(literalt cond, const bvt &a, const bvt &b)
literalt unsigned_less_than(const bvt &bv0, const bvt &bv1)
bvt signed_multiplier_no_overflow(const bvt &op0, const bvt &op1)
bvt incrementer(const bvt &op, literalt carry_in)
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
static bvt shift(const bvt &op, const shiftt shift, std::size_t distance)
literalt lt_or_le(bool or_equal, const bvt &bv0, const bvt &bv1, representationt rep)
literalt overflow_negate(const bvt &op)
static bvt concatenate(const bvt &a, const bvt &b)
literalt full_adder(const literalt a, const literalt b, const literalt carry_in, literalt &carry_out)
bvt negate_no_overflow(const bvt &op)
static bvt extract(const bvt &a, std::size_t first, std::size_t last)
bvt unsigned_multiplier(const bvt &op0, const bvt &op1)
bvt divider(const bvt &op0, const bvt &op1, representationt rep)
void unsigned_divider(const bvt &op0, const bvt &op1, bvt &res, bvt &rem)
bvt multiplier(const bvt &op0, const bvt &op1, representationt rep)
bvt cond_negate(const bvt &bv, const literalt cond)
bvt dadda_tree(const std::vector< bvt > &pps)
literalt carry_out(const bvt &op0, const bvt &op1, literalt carry_in)
bvt negate(const bvt &op)
static bvt extension(const bvt &bv, std::size_t new_size, representationt rep)
static bvt extract_lsb(const bvt &a, std::size_t n)
literalt verilog_bv_has_x_or_z(const bvt &)
literalt carry(literalt a, literalt b, literalt c)
bvt unsigned_multiplier_no_overflow(const bvt &op0, const bvt &op1)
static bvt zeros(std::size_t new_size)
literalt rel(const bvt &bv0, irep_idt id, const bvt &bv1, representationt rep)
bvt adder_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
bvt saturating_add_sub(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
void l_set_to_true(literalt a)
virtual literalt land(literalt a, literalt b)=0
virtual literalt limplies(literalt a, literalt b)=0
virtual literalt lselect(literalt a, literalt b, literalt c)=0
virtual bool cnf_handled_well() const
virtual void l_set_to(literalt a, bool value)
virtual literalt lxor(literalt a, literalt b)=0
void lcnf(literalt l0, literalt l1)
virtual void set_equal(literalt a, literalt b)
asserts a==b in the propositional formula
virtual bvt new_variables(std::size_t width)
generates a bitvector of given width with new variables
virtual literalt new_variable()=0
virtual literalt lequal(literalt a, literalt b)=0
virtual literalt lor(literalt a, literalt b)=0
void l_set_to_false(literalt a)
virtual bool has_set_to() const
bool is_false(const literalt &l)
bool is_true(const literalt &l)
std::vector< literalt > bvt
literalt const_literal(bool value)
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
const std::string integer2binary(const mp_integer &n, std::size_t width)
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define POSTCONDITION(CONDITION)