34 const typet &src_type,
const bvt &src,
56 std::size_t src_width=src.size();
59 if(dest_width==0 || src_width==0)
63 dest.reserve(dest_width);
65 if(dest_type.
id()==ID_complex)
67 if(src_type==dest_type.
subtype())
73 for(std::size_t i=src.size(); i<dest_width; i++)
78 else if(src_type.
id()==ID_complex)
81 bvt lower, upper, lower_res, upper_res;
82 lower.assign(src.begin(), src.begin()+src.size()/2);
83 upper.assign(src.begin()+src.size()/2, src.end());
89 lower_res.size() + upper_res.size() == dest_width,
90 "lower result bitvector size plus upper result bitvector size shall "
91 "equal the destination bitvector size");
93 dest.insert(dest.end(), upper_res.begin(), upper_res.end());
98 if(src_type.
id()==ID_complex)
101 dest_type.
id() == ID_complex,
102 "destination type shall be of complex type when source type is of "
104 if(dest_type.
id()==ID_signedbv ||
105 dest_type.
id()==ID_unsignedbv ||
106 dest_type.
id()==ID_floatbv ||
107 dest_type.
id()==ID_fixedbv ||
108 dest_type.
id()==ID_c_enum ||
109 dest_type.
id()==ID_c_enum_tag ||
110 dest_type.
id()==ID_bool)
115 tmp_src.resize(src.size()/2);
132 dest.resize(dest_width);
133 for(std::size_t i=0; i<dest.size(); i++)
144 if(dest_from==src_from)
189 src_width == dest_width,
190 "source bitvector size shall equal the destination bitvector size");
200 if(src_type.
id()==ID_bool)
211 src_width == 1,
"bitvector of type boolean shall have width one");
227 std::size_t dest_fraction_bits=
229 std::size_t dest_int_bits=dest_width-dest_fraction_bits;
230 std::size_t op_fraction_bits=
232 std::size_t op_int_bits=src_width-op_fraction_bits;
234 dest.resize(dest_width);
239 for(std::size_t i=0; i<dest_fraction_bits; i++)
242 std::size_t p=dest_fraction_bits-i-1;
244 if(i<op_fraction_bits)
245 dest[p]=src[op_fraction_bits-i-1];
250 for(std::size_t i=0; i<dest_int_bits; i++)
253 std::size_t p=dest_fraction_bits+i;
254 INVARIANT(p < dest_width,
"bit index shall be within bounds");
257 dest[p]=src[i+op_fraction_bits];
259 dest[p]=src[src_width-1];
267 src_width == dest_width,
268 "source bitvector width shall equal the destination bitvector width");
279 std::size_t dest_fraction_bits=
282 for(std::size_t i=0; i<dest_fraction_bits; i++)
285 for(std::size_t i=0; i<dest_width-dest_fraction_bits; i++)
304 else if(src_type.
id()==ID_bool)
307 std::size_t fraction_bits=
311 src_width == 1,
"bitvector of type boolean shall have width one");
313 for(std::size_t i=0; i<dest_width; i++)
316 dest.push_back(src[0]);
337 std::size_t op_fraction_bits=
340 for(std::size_t i=0; i<dest_width; i++)
342 if(i<src_width-op_fraction_bits)
343 dest.push_back(src[i+op_fraction_bits]);
347 dest.push_back(src[src_width-1]);
356 bvt fraction_bits_bv=src;
357 fraction_bits_bv.resize(op_fraction_bits);
378 for(std::size_t i=0; i<dest_width; i++)
381 dest.push_back(src[i]);
382 else if(sign_extension)
383 dest.push_back(src[src_width-1]);
393 for(std::size_t i=0; i<dest_width; i++)
395 std::size_t src_index=i*2;
397 if(src_index<src_width)
398 dest.push_back(src[src_index]);
409 for(std::size_t i=0; i<dest_width; i++)
411 std::size_t src_index=i*2;
413 if(src_index<src_width)
414 dest.push_back(src[src_index]);
416 dest.push_back(src.back());
425 src_width == dest_width,
426 "source bitvector width shall equal the destination bitvector width");
433 if(src_type.
id() == ID_bool)
438 src_width == 1,
"bitvector of type boolean shall have width one");
440 for(std::size_t i = 0; i < dest_width; i++)
443 dest.push_back(src[0]);
456 src_type.
id()==ID_bool)
458 for(std::size_t i=0, j=0; i<dest_width; i+=2, j++)
461 dest.push_back(src[j]);
472 for(std::size_t i=0, j=0; i<dest_width; i+=2, j++)
475 dest.push_back(src[j]);
477 dest.push_back(src.back());
489 if(dest_width<src_width)
490 dest.resize(dest_width);
494 while(dest.size()<dest_width)
506 src_width == dest_width,
507 "source bitvector width shall equal the destination bitvector width");
517 dest[0]=!float_utils.
is_zero(src);
529 if(dest_type.
id()==ID_array)
531 if(src_width==dest_width)
537 else if(
ns.
follow(dest_type).
id() == ID_struct)
560 typedef std::map<irep_idt, std::size_t> op_mapt;
563 for(std::size_t i=0; i<op_comp.size(); i++)
564 op_map[op_comp[i].get_name()]=i;
571 std::size_t offset=dest_offsets[i];
572 std::size_t comp_width=
boolbv_width(dest_comp[i].type());
576 op_mapt::const_iterator it=
577 op_map.find(dest_comp[i].get_name());
584 for(std::size_t j=0; j<comp_width; j++)
590 if(dest_comp[i].type()!=dest_comp[it->second].type())
593 for(std::size_t j=0; j<comp_width; j++)
598 std::size_t op_offset=op_offsets[it->second];
599 for(std::size_t j=0; j<comp_width; j++)
600 dest[offset+j]=src[op_offset+j];
616 if(expr.
op().
type().
id() == ID_range)
623 else if(from==0 && to==0)