19 expr.
id() == ID_plus || expr.
id() == ID_minus ||
20 expr.
id() ==
"no-overflow-plus" || expr.
id() ==
"no-overflow-minus");
24 if(type.id()!=ID_unsignedbv &&
25 type.id()!=ID_signedbv &&
26 type.id()!=ID_fixedbv &&
27 type.id()!=ID_floatbv &&
28 type.id()!=ID_range &&
29 type.id()!=ID_complex &&
42 "operator " + expr.
id_string() +
" takes at least one operand");
46 op0.type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
50 bool subtract=(expr.
id()==ID_minus ||
51 expr.
id()==
"no-overflow-minus");
53 bool no_overflow=(expr.
id()==
"no-overflow-plus" ||
54 expr.
id()==
"no-overflow-minus");
56 typet arithmetic_type=
57 (type.id()==ID_vector || type.id()==ID_complex)?
61 (arithmetic_type.
id()==ID_signedbv ||
65 for(exprt::operandst::const_iterator
66 it=operands.begin()+1;
67 it!=operands.end(); it++)
70 it->type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
74 if(type.id()==ID_vector || type.id()==ID_complex)
78 INVARIANT(sub_width != 0,
"vector elements shall have nonzero bit width");
80 width % sub_width == 0,
81 "total vector bit width shall be a multiple of the element bit width");
83 std::size_t size=width/sub_width;
86 for(std::size_t i=0; i<size; i++)
89 tmp_op.resize(sub_width);
91 for(std::size_t j=0; j<tmp_op.size(); j++)
93 const std::size_t index = i * sub_width + j;
94 INVARIANT(index < op.size(),
"bit index shall be within bounds");
95 tmp_op[j] = op[index];
99 tmp_result.resize(sub_width);
101 for(std::size_t j=0; j<tmp_result.size(); j++)
103 const std::size_t index = i * sub_width + j;
104 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
105 tmp_result[j] = bv[index];
108 if(type.subtype().id()==ID_floatbv)
112 tmp_result=float_utils.
add_sub(tmp_result, tmp_op, subtract);
118 tmp_result.size() == sub_width,
119 "applying the add/sub operation shall not change the bitwidth");
121 for(std::size_t j=0; j<tmp_result.size(); j++)
123 const std::size_t index = i * sub_width + j;
124 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
125 bv[index] = tmp_result[j];
129 else if(type.id()==ID_floatbv)
133 bv=float_utils.
add_sub(bv, op, subtract);
The type of an expression, extends irept.
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
boolbv_widtht boolbv_width
typet & type()
Return the type of the expression.
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
const irep_idt & id() const
virtual bvt convert_add_sub(const exprt &expr)
void conversion_failed(const exprt &expr, bvt &bv)
#define PRECONDITION(CONDITION)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
std::vector< exprt > operandst
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
Base class for all expressions.
const std::string & id_string() const
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions, goto_programs, exprts, etc.
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
std::vector< literalt > bvt