33 const typet &src_type,
35 const typet &dest_type,
55 std::size_t src_width = src.size();
58 if(dest_width == 0 || src_width == 0)
62 dest.reserve(dest_width);
64 if(dest_type.
id() == ID_complex)
68 dest.insert(dest.end(), src.begin(), src.end());
71 for(std::size_t i = src.size(); i < dest_width; i++)
76 else if(src_type.
id() == ID_complex)
79 bvt lower, upper, lower_res, upper_res;
80 lower.assign(src.begin(), src.begin() + src.size() / 2);
81 upper.assign(src.begin() + src.size() / 2, src.end());
93 lower_res.size() + upper_res.size() == dest_width,
94 "lower result bitvector size plus upper result bitvector size shall "
95 "equal the destination bitvector size");
97 dest.insert(dest.end(), upper_res.begin(), upper_res.end());
102 if(src_type.
id() == ID_complex)
105 dest_type.
id() == ID_complex,
106 "destination type shall be of complex type when source type is of "
109 dest_type.
id() == ID_signedbv || dest_type.
id() == ID_unsignedbv ||
110 dest_type.
id() == ID_floatbv || dest_type.
id() == ID_fixedbv ||
111 dest_type.
id() == ID_c_enum || dest_type.
id() == ID_c_enum_tag ||
112 dest_type.
id() == ID_bool)
117 tmp_src.resize(src.size() / 2);
133 bv_utils.zero_extension(src, dest_width),
134 bv_utils.build_constant(offset, dest_width));
143 bv_utils.sign_extension(src, dest_width),
144 bv_utils.build_constant(offset, dest_width));
156 bv_utils.zero_extension(src, dest_width),
157 bv_utils.build_constant(offset, dest_width));
161 else if(src_type.
id() == ID_bool)
166 bv_utils.zero_extension(src, dest_width),
167 bv_utils.build_constant(offset, dest_width));
197 INVARIANT(src_width >= dest_width,
"cannot extend bv-typed bitvector");
199 if(dest_width < src_width)
200 dest.resize(dest_width);
209 if(src_type.
id() == ID_bool)
218 src_width == 1,
"bitvector of type boolean shall have width one");
220 for(
auto &literal : dest)
221 literal =
prop.land(literal, src[0]);
234 std::size_t dest_fraction_bits =
236 std::size_t dest_int_bits = dest_width - dest_fraction_bits;
237 std::size_t op_fraction_bits =
239 std::size_t op_int_bits = src_width - op_fraction_bits;
241 dest.resize(dest_width);
246 for(std::size_t i = 0; i < dest_fraction_bits; i++)
249 std::size_t p = dest_fraction_bits - i - 1;
251 if(i < op_fraction_bits)
252 dest[p] = src[op_fraction_bits - i - 1];
257 for(std::size_t i = 0; i < dest_int_bits; i++)
260 std::size_t p = dest_fraction_bits + i;
261 INVARIANT(p < dest_width,
"bit index shall be within bounds");
264 dest[p] = src[i + op_fraction_bits];
266 dest[p] = src[src_width - 1];
273 INVARIANT(src_width >= dest_width,
"cannot extend bv-typed bitvector");
275 if(dest_width < src_width)
276 dest.resize(dest_width);
285 std::size_t dest_fraction_bits =
288 for(std::size_t i = 0; i < dest_fraction_bits; i++)
291 for(std::size_t i = 0; i < dest_width - dest_fraction_bits; i++)
302 l = src[src_width - 1];
312 else if(src_type.
id() == ID_bool)
315 std::size_t fraction_bits =
319 src_width == 1,
"bitvector of type boolean shall have width one");
321 for(std::size_t i = 0; i < dest_width; i++)
323 if(i == fraction_bits)
324 dest.push_back(src[0]);
346 std::size_t op_fraction_bits =
349 for(std::size_t i = 0; i < dest_width; i++)
351 if(i < src_width - op_fraction_bits)
352 dest.push_back(src[i + op_fraction_bits]);
356 dest.push_back(src[src_width - 1]);
365 bvt fraction_bits_bv = src;
366 fraction_bits_bv.resize(op_fraction_bits);
369 dest =
bv_utils.incrementer(dest, round_up);
383 bool sign_extension =
386 for(std::size_t i = 0; i < dest_width; i++)
389 dest.push_back(src[i]);
390 else if(sign_extension)
391 dest.push_back(src[src_width - 1]);
401 for(std::size_t i = 0; i < dest_width; i++)
403 std::size_t src_index = i * 2;
405 if(src_index < src_width)
406 dest.push_back(src[src_index]);
417 for(std::size_t i = 0; i < dest_width; i++)
419 std::size_t src_index = i * 2;
421 if(src_index < src_width)
422 dest.push_back(src[src_index]);
424 dest.push_back(src.back());
432 INVARIANT(src_width >= dest_width,
"cannot extend bv-typed bitvector");
434 if(dest_width < src_width)
435 dest.resize(dest_width);
441 if(src_type.
id() == ID_bool)
446 src_width == 1,
"bitvector of type boolean shall have width one");
448 for(std::size_t i = 0; i < dest_width; i++)
451 dest.push_back(src[0]);
465 src_type.
id() == ID_bool)
467 for(std::size_t i = 0, j = 0; i < dest_width; i += 2, j++)
470 dest.push_back(src[j]);
481 for(std::size_t i = 0, j = 0; i < dest_width; i += 2, j++)
484 dest.push_back(src[j]);
486 dest.push_back(src.back());
498 if(dest_width < src_width)
499 dest.resize(dest_width);
503 while(dest.size() < dest_width)
514 INVARIANT(src_width >= dest_width,
"cannot extend bv-typed bitvector");
516 if(dest_width < src_width)
517 dest.resize(dest_width);
526 dest[0] = !float_utils.
is_zero(src);
538 if(dest_type.
id() == ID_array)
540 if(src_width == dest_width)
546 else if(dest_type.
id() == ID_struct || dest_type.
id() == ID_struct_tag)
549 dest_type.
id() == ID_struct_tag
553 if(src_type.
id() == ID_struct || src_type.
id() == ID_struct_tag)
560 src_type.
id() == ID_struct_tag
573 typedef std::map<irep_idt, std::size_t> op_mapt;
576 for(std::size_t i = 0; i < op_comp.size(); i++)
577 op_map[op_comp[i].get_name()] = i;
580 for(std::size_t i = 0; i < dest_comp.size(); i++)
582 std::size_t offset = dest_offsets[i];
583 std::size_t comp_width =
boolbv_width(dest_comp[i].type());
587 op_mapt::const_iterator it = op_map.find(dest_comp[i].get_name());
589 if(it == op_map.end())
594 for(std::size_t j = 0; j < comp_width; j++)
595 dest[offset + j] =
prop.new_variable();
600 if(dest_comp[i].type() != dest_comp[it->second].type())
603 for(std::size_t j = 0; j < comp_width; j++)
604 dest[offset + j] =
prop.new_variable();
608 std::size_t op_offset = op_offsets[it->second];
609 for(std::size_t j = 0; j < comp_width; j++)
610 dest[offset + j] = src[op_offset + j];