16 #include "../floatbv/float_utils.h" 29 if(src_type==dest_type)
36 if(src_type.
id()==ID_floatbv &&
37 dest_type.
id()==ID_floatbv)
45 else if(src_type.
id()==ID_signedbv &&
46 dest_type.
id()==ID_floatbv)
51 else if(src_type.
id()==ID_unsignedbv &&
52 dest_type.
id()==ID_floatbv)
57 else if(src_type.
id()==ID_floatbv &&
58 dest_type.
id()==ID_signedbv)
64 else if(src_type.
id()==ID_floatbv &&
65 dest_type.
id()==ID_unsignedbv)
79 if(operands.size()!=3)
80 throw "operator "+expr.
id_string()+
" takes three operands";
92 if(op0.
type()!=type || op1.
type()!=type)
94 std::cerr << expr.
pretty() <<
'\n';
95 throw "float op with mixed types";
102 if(type.
id()==ID_floatbv)
106 if(expr.
id()==ID_floatbv_plus)
107 return float_utils.
add_sub(bv0, bv1,
false);
108 else if(expr.
id()==ID_floatbv_minus)
109 return float_utils.
add_sub(bv0, bv1,
true);
110 else if(expr.
id()==ID_floatbv_mult)
111 return float_utils.
mul(bv0, bv1);
112 else if(expr.
id()==ID_floatbv_div)
113 return float_utils.
div(bv0, bv1);
114 else if(expr.
id()==ID_floatbv_rem)
115 return float_utils.
rem(bv0, bv1);
117 throw "unexpected operator "+expr.
id_string();
119 else if(type.
id()==ID_vector || type.
id()==ID_complex)
123 if(subtype.
id()==ID_floatbv)
130 if(sub_width==0 || width%sub_width!=0)
131 throw "convert_floatbv_op: unexpected vector operand width";
133 std::size_t size=width/sub_width;
137 for(std::size_t i=0; i<size; i++)
139 bvt tmp_bv0, tmp_bv1, tmp_bv;
141 tmp_bv0.assign(bv0.begin()+i*sub_width, bv0.begin()+(i+1)*sub_width);
142 tmp_bv1.assign(bv1.begin()+i*sub_width, bv1.begin()+(i+1)*sub_width);
144 if(expr.
id()==ID_floatbv_plus)
145 tmp_bv=float_utils.
add_sub(tmp_bv0, tmp_bv1,
false);
146 else if(expr.
id()==ID_floatbv_minus)
147 tmp_bv=float_utils.
add_sub(tmp_bv0, tmp_bv1,
true);
148 else if(expr.
id()==ID_floatbv_mult)
149 tmp_bv=float_utils.
mul(tmp_bv0, tmp_bv1);
150 else if(expr.
id()==ID_floatbv_div)
151 tmp_bv=float_utils.
div(tmp_bv0, tmp_bv1);
155 assert(tmp_bv.size()==sub_width);
156 assert(i*sub_width+sub_width-1<bv.size());
157 std::copy(tmp_bv.begin(), tmp_bv.end(), bv.begin()+i*sub_width);
The type of an expression.
virtual bvt convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
const typet & follow(const typet &src) const
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
boolbv_widtht boolbv_width
bvt to_signed_integer(const bvt &src, std::size_t int_width)
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
virtual bvt rem(const bvt &src1, const bvt &src2)
const irep_idt & id() const
virtual const bvt & convert_bv(const exprt &expr)
bvt to_unsigned_integer(const bvt &src, std::size_t int_width)
virtual bvt mul(const bvt &src1, const bvt &src2)
bvt conversion(const bvt &src, const ieee_float_spect &dest_spec)
virtual bvt convert_floatbv_op(const exprt &expr)
void conversion_failed(const exprt &expr, bvt &bv)
virtual bvt div(const bvt &src1, const bvt &src2)
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a generic typet to an unsignedbv_typet.
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
std::size_t get_width() const
std::vector< exprt > operandst
void set_rounding_mode(const bvt &)
bvt from_unsigned_integer(const bvt &)
semantic type conversion from/to floating-point formats
Base class for all expressions.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a generic typet to a signedbv_typet.
const std::string & id_string() const
bvt from_signed_integer(const bvt &)
const typet & subtype() const
std::vector< literalt > bvt