19 expr.
id() == ID_plus || expr.
id() == ID_minus ||
20 expr.
id() ==
"no-overflow-plus" || expr.
id() ==
"no-overflow-minus");
25 type.
id() != ID_unsignedbv && type.
id() != ID_signedbv &&
26 type.
id() != ID_fixedbv && type.
id() != ID_floatbv &&
27 type.
id() != ID_range && type.
id() != ID_complex)
38 "operator " + expr.
id_string() +
" takes at least one operand");
42 op0.
type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
46 bool subtract=(expr.
id()==ID_minus ||
47 expr.
id()==
"no-overflow-minus");
49 bool no_overflow=(expr.
id()==
"no-overflow-plus" ||
50 expr.
id()==
"no-overflow-minus");
52 typet arithmetic_type =
56 (arithmetic_type.
id()==ID_signedbv ||
60 for(exprt::operandst::const_iterator
61 it=operands.begin()+1;
62 it!=operands.end(); it++)
65 it->type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
69 if(type.
id() == ID_complex)
71 std::size_t sub_width =
75 sub_width != 0,
"complex elements shall have nonzero bit width");
77 width % sub_width == 0,
78 "total complex bit width shall be a multiple of the element bit width");
80 std::size_t size=width/sub_width;
83 for(std::size_t i=0; i<size; i++)
86 tmp_op.resize(sub_width);
88 for(std::size_t j=0; j<tmp_op.size(); j++)
90 const std::size_t index = i * sub_width + j;
91 INVARIANT(index < op.size(),
"bit index shall be within bounds");
92 tmp_op[j] = op[index];
96 tmp_result.resize(sub_width);
98 for(std::size_t j=0; j<tmp_result.size(); j++)
100 const std::size_t index = i * sub_width + j;
101 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
102 tmp_result[j] = bv[index];
110 tmp_result=float_utils.
add_sub(tmp_result, tmp_op, subtract);
116 tmp_result.size() == sub_width,
117 "applying the add/sub operation shall not change the bitwidth");
119 for(std::size_t j=0; j<tmp_result.size(); j++)
121 const std::size_t index = i * sub_width + j;
122 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
123 bv[index] = tmp_result[j];
127 else if(type.
id() == ID_range)
136 else if(type.
id()==ID_floatbv)
140 bv=float_utils.
add_sub(bv, op, subtract);
154 expr.
id() == ID_saturating_minus || expr.
id() == ID_saturating_plus);
159 type.
id() != ID_unsignedbv && type.
id() != ID_signedbv &&
160 type.
id() != ID_fixedbv && type.
id() != ID_complex)
169 "saturating add/sub with mixed types:\n" + expr.
pretty());
171 const bool subtract = expr.
id() == ID_saturating_minus;
173 typet arithmetic_type =
177 (arithmetic_type.
id() == ID_signedbv || arithmetic_type.
id() == ID_fixedbv)
184 if(type.
id() != ID_complex)
189 INVARIANT(sub_width != 0,
"complex elements shall have nonzero bit width");
191 width % sub_width == 0,
192 "total complex bit width shall be a multiple of the element bit width");
194 std::size_t size = width / sub_width;
196 for(std::size_t i = 0; i < size; i++)
199 tmp_op.resize(sub_width);
201 for(std::size_t j = 0; j < tmp_op.size(); j++)
203 const std::size_t index = i * sub_width + j;
204 INVARIANT(index < op.size(),
"bit index shall be within bounds");
205 tmp_op[j] = op[index];
209 tmp_result.resize(sub_width);
211 for(std::size_t j = 0; j < tmp_result.size(); j++)
213 const std::size_t index = i * sub_width + j;
214 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
215 tmp_result[j] = bv[index];
221 tmp_result.size() == sub_width,
222 "applying the add/sub operation shall not change the bitwidth");
224 for(std::size_t j = 0; j < tmp_result.size(); j++)
226 const std::size_t index = i * sub_width + j;
227 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
228 bv[index] = tmp_result[j];
Pre-defined bitvector types.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
A base class for binary expressions.
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
virtual bvt convert_add_sub(const exprt &expr)
virtual bvt convert_saturating_add_sub(const binary_exprt &expr)
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
virtual std::size_t boolbv_width(const typet &type) const
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
static bvt build_constant(const mp_integer &i, std::size_t width)
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
bvt saturating_add_sub(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
const std::string & id_string() const
const irep_idt & id() const
mp_integer get_from() const
const typet & subtype() const
The type of an expression, extends irept.
std::vector< literalt > bvt
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const range_typet & to_range_type(const typet &type)
Cast a typet to a range_typet.
const type_with_subtypet & to_type_with_subtype(const typet &type)