19 bvt round_to_plus_inf=
21 bvt round_to_minus_inf=
69 std::size_t dest_width)
76 std::size_t dest_width)
83 std::size_t dest_width,
95 if(dest_width > fraction.size())
100 fraction.begin(), lsb_extension.begin(), lsb_extension.end());
111 bvt result = shift_result;
114 for(std::size_t i = 0; i < result.size(); i++)
115 result[i] =
prop.
land(result[i], !exponent_sign);
118 if(result.size() > dest_width)
120 result.resize(dest_width);
124 result.size() == dest_width,
125 "result bitvector width should equal the destination bitvector width");
169 int sourceSmallestNormalExponent=-((1 << (
spec.
e - 1)) - 1);
170 int sourceSmallestDenormalExponent =
171 sourceSmallestNormalExponent -
spec.
f;
175 int destSmallestNormalExponent=-((1 << (dest_spec.
e - 1)) - 1);
179 !(sourceSmallestDenormalExponent < destSmallestNormalExponent))
185 std::size_t padding=dest_spec.
f-
spec.
f;
202 result.
NaN=unpacked_src.
NaN;
232 bvt extended_exponent1=
234 bvt extended_exponent2=
237 PRECONDITION(extended_exponent1.size() == extended_exponent2.size());
240 return bv_utils.
sub(extended_exponent1, extended_exponent2);
257 literalt src2_bigger=exponent_difference.back();
259 const bvt bigger_exponent=
263 const bvt new_fraction1=
266 const bvt new_fraction2=
276 const bvt fraction1_padded=
278 const bvt fraction2_padded=
283 const bvt fraction1_shifted=fraction1_padded;
285 fraction2_padded, limited_dist, sticky_bit);
288 bvt fraction2_stickied=fraction2_shifted;
289 fraction2_stickied[0]=
prop.
lor(fraction2_shifted[0], sticky_bit);
292 const bvt fraction1_ext=
294 const bvt fraction2_ext=
375 for(std::size_t i=0; i<result.
fraction.size(); i++)
376 result.
fraction[i]=new_fraction2[i];
392 upper_bits.erase(upper_bits.begin(), upper_bits.begin()+nb_bits);
396 lower_bits.resize(nb_bits);
399 result.resize(lower_bits.size());
402 for(std::size_t i=0; i<result.size(); i++)
403 result[i]=
prop.
lor(lower_bits[i], or_upper_bits);
447 NaN_cond.push_back(
is_NaN(src1));
448 NaN_cond.push_back(
is_NaN(src2));
466 std::size_t div_width=unpacked1.
fraction.size()*2+1;
470 fraction1.reserve(div_width);
471 while(fraction1.size()<div_width)
489 result.
fraction.begin(), have_remainder);
622 and_bv.push_back(less_than3);
623 and_bv.push_back(!bitwise_equal);
624 and_bv.push_back(!both_zero);
625 and_bv.push_back(!NaN);
632 or_bv.push_back(less_than3);
633 or_bv.push_back(both_zero);
634 or_bv.push_back(bitwise_equal);
646 prop.
lor(bitwise_equal, both_zero),
660 all_but_sign.resize(all_but_sign.size()-1);
712 exponent.erase(exponent.begin(), exponent.begin()+
spec.
f);
715 exponent.resize(
spec.
e);
725 exponent.erase(exponent.begin(), exponent.begin()+
spec.
f);
728 exponent.resize(
spec.
e);
752 for(std::size_t i=0; i<fraction.size(); i++)
757 for(std::size_t j=0; j<i; j++)
759 !fraction[fraction.size()-1-j]);
762 equal.push_back(fraction[fraction.size()-1-i]);
784 fraction=new_fraction;
785 exponent=new_exponent;
795 if(exponent.size()<depth)
800 for(
int d=depth-1; d>=0; d--)
802 std::size_t distance=(1<<d);
804 fraction.size() > distance,
"fraction must be larger than distance");
820 d < (
signed)exponent_delta.size(),
821 "depth must be smaller than exponent size");
822 exponent_delta[d]=prefix_is_zero;
864 if(fraction.size() < (
spec.
f + 3))
872 bvt denormalisedFraction=fraction;
875 denormalisedFraction =
877 denormalisedFraction[0]=
prop.
lor(denormalisedFraction[0], sticky_bit);
882 denormalisedFraction,
912 if(aligned_exponent.size()<exponent_bits)
939 const std::size_t dest_bits,
946 std::size_t extra_bits=fraction.size()-dest_bits;
963 extra_bits >= 1,
"the extra bits include at least the rounding bit");
964 literalt rounding_bit=fraction[extra_bits-1];
967 literalt rounding_least=fraction[extra_bits];
972 prop.
lor(rounding_least, sticky_bit));
977 prop.
lor(rounding_bit, sticky_bit));
982 prop.
lor(rounding_bit, sticky_bit));
998 std::size_t fraction_size=
spec.
f+1;
1001 if(result.
fraction.size()<fraction_size)
1004 std::size_t padding=fraction_size-result.
fraction.size();
1011 result.
fraction.size() == fraction_size,
1012 "sizes should be equal as result.fraction was zero-padded");
1014 else if(result.
fraction.size()==fraction_size)
1020 std::size_t extra_bits=result.
fraction.size()-fraction_size;
1023 "the extra bits should at least include the rounding bit");
1034 result.
fraction.size() == fraction_size,
1035 "sizes should be equal as extra bits were chopped off from "
1059 result.
fraction.back()=new_integer_part;
1085 prop.
lor(overflow, subnormal_to_normal));
1133 prop.
land(exponent_too_large, !overflow_to_inf);
1136 bvt largest_normal_exponent=
1181 for(std::size_t i=0; i<result.
exponent.size(); i++)
1245 result[result.size()-1]=
1252 for(std::size_t i=0; i<
spec.
f; i++)
1258 for(std::size_t i=0; i<
spec.
e; i++)
1270 for(std::size_t i=0; i<src.size(); i++)
1275 result.
unpack(int_value);
1289 for(std::size_t stage=0; stage<dist.size(); stage++)
1297 if(d<=result.size())