23 else if(expr.
id()==ID_unary_minus)
25 else if(expr.
id()==ID_ieee_float_equal)
29 equal_expr.lhs(), equal_expr.rhs(),
get_spec(equal_expr.lhs()));
31 else if(expr.
id()==ID_ieee_float_notequal)
35 notequal_expr.lhs(), notequal_expr.rhs(),
get_spec(notequal_expr.lhs())));
37 else if(expr.
id()==ID_floatbv_typecast)
40 const auto &op = floatbv_typecast_expr.op();
41 const typet &src_type = floatbv_typecast_expr.op().type();
42 const typet &dest_type = floatbv_typecast_expr.type();
43 const auto &rounding_mode = floatbv_typecast_expr.rounding_mode();
45 if(dest_type.
id()==ID_signedbv &&
46 src_type.
id()==ID_floatbv)
52 else if(dest_type.
id()==ID_unsignedbv &&
53 src_type.
id()==ID_floatbv)
59 else if(src_type.
id()==ID_signedbv &&
60 dest_type.
id()==ID_floatbv)
62 else if(src_type.
id()==ID_unsignedbv &&
63 dest_type.
id()==ID_floatbv)
67 else if(dest_type.
id()==ID_floatbv &&
68 src_type.
id()==ID_floatbv)
82 expr.
id() == ID_typecast && expr.
type().
id() == ID_bv &&
97 else if(expr.
id()==ID_floatbv_plus)
104 float_expr.rounding_mode(),
107 else if(expr.
id()==ID_floatbv_minus)
114 float_expr.rounding_mode(),
117 else if(expr.
id()==ID_floatbv_mult)
123 float_expr.rounding_mode(),
126 else if(expr.
id()==ID_floatbv_div)
132 float_expr.rounding_mode(),
135 else if(expr.
id() == ID_floatbv_fma)
140 fma_expr.op_multiply_lhs(),
141 fma_expr.op_multiply_rhs(),
143 fma_expr.rounding_mode(),
146 else if(expr.
id()==ID_isnan)
151 else if(expr.
id()==ID_isfinite)
156 else if(expr.
id()==ID_isinf)
161 else if(expr.
id()==ID_isnormal)
166 else if(expr.
id()==ID_lt)
172 else if(expr.
id()==ID_gt)
178 else if(expr.
id()==ID_le)
184 else if(expr.
id()==ID_ge)
190 else if(expr.
id()==ID_sign)
230 const and_exprt both_zero(is_zero0, is_zero1);
291 exprt round_to_plus_inf_const=
293 exprt round_to_minus_inf_const=
296 exprt round_to_away_const =
334 return rounder(result, rm, spec);
356 return rounder(result, rm, spec);
361 std::size_t dest_width,
365 return to_integer(src, dest_width,
true, rm, spec);
370 std::size_t dest_width,
374 return to_integer(src, dest_width,
false, rm, spec);
379 std::size_t dest_width,
395 const std::size_t fraction_width =
401 std::size_t effective_width = fraction_width;
403 if(dest_width > fraction_width)
405 effective_width = dest_width;
419 static_cast<std::size_t
>(spec.
e),
address_bits(effective_width) + 1));
423 const lshr_exprt shift_result(fraction, distance);
426 exprt result=shift_result;
470 int sourceSmallestNormalExponent = -((1 << (src_spec.
e - 1)) - 1);
471 int sourceSmallestDenormalExponent =
472 sourceSmallestNormalExponent - src_spec.
f;
476 int destSmallestNormalExponent = -((1 << (dest_spec.
e - 1)) - 1);
478 if(dest_spec.
e>=src_spec.
e &&
479 dest_spec.
f>=src_spec.
f &&
480 !(sourceSmallestDenormalExponent < destSmallestNormalExponent))
486 std::size_t padding=dest_spec.
f-src_spec.
f;
496 "the exponent needs to have a signed type");
502 if(dest_spec.
e > src_spec.
e)
514 result.
NaN=unpacked_src.
NaN;
518 return pack(
bias(result, dest_spec), dest_spec);
524 return rounder(result, rm, dest_spec);
554 return minus_exprt(extended_exponent1, extended_exponent2);
573 const sign_exprt src2_bigger(exponent_difference);
575 const exprt bigger_exponent=
579 const exprt new_fraction1=
582 const exprt new_fraction2=
586 const exprt distance=
595 const exprt fraction1_padded=
597 const exprt fraction2_padded=
602 const exprt fraction1_shifted=fraction1_padded;
604 fraction2_padded, limited_dist, sticky_bit);
612 fraction2_shifted.
type()));
615 const exprt fraction1_ext=
617 const exprt fraction2_ext=
699 return rounder(result, rm, spec);
710 if(dist_width<=nb_bits)
738 const exprt fraction1 =
740 const exprt fraction2 =
753 const plus_exprt added_exponent(exponent1, exponent2);
774 return rounder(result, rm, spec);
787 std::size_t fraction_width=
789 std::size_t div_width=fraction_width*2+1;
825 const minus_exprt added_exponent(exponent1, exponent2);
863 return rounder(result, rm, spec);
867 const exprt &multiply_lhs,
868 const exprt &multiply_rhs,
881 const std::size_t frac_size = spec.
f + 1;
882 const std::size_t prod_width = frac_size * 2;
886 const exprt fraction1 =
888 const exprt fraction2 =
901 const std::size_t c_pad = prod_width - frac_size;
912 exprt bigger_exp =
if_exprt(c_bigger, c_exponent, prod_exponent);
913 exprt big_frac =
if_exprt(c_bigger, c_fraction, prod_fraction);
914 exprt small_frac =
if_exprt(c_bigger, prod_fraction, c_fraction);
929 exprt small_shifted =
947 exprt fraction_sign =
963 if_exprt(c_bigger, unpacked_add.
sign, prod_sign), fraction_sign);
964 result.
sign = add_sub_sign;
969 {
isnan(multiply_lhs, spec),
970 isnan(multiply_rhs, spec),
982 return rounder(result, rm, spec);
998 "relation should be equality, less-than, or less-or-equal");
1003 const and_exprt both_zero(is_zero1, is_zero2);
1008 const or_exprt nan(isnan1, isnan2);
1044 return std::move(and_bv);
1048 or_exprt or_bv{{less_than3, both_zero, bitwise_equal}};
1060 or_exprt(bitwise_equal, both_zero),
1127 for(
int d=depth-1; d>=0; d--)
1129 unsigned distance=(1<<d);
1131 fraction_bits > distance,
1132 "distance must be within the range of fraction bits");
1141 const shl_exprt shifted(fraction, distance);
1144 if_exprt(prefix_is_zero, shifted, fraction);
1148 d < (
signed int)exponent_bits,
1149 "depth must be smaller than exponent bits");
1199 if(fraction_bits < spec.
f+3)
1208 exprt denormalisedFraction = fraction;
1211 denormalisedFraction =
1214 denormalisedFraction=
1221 denormalisedFraction,
1251 std::size_t exponent_bits = std::max(
address_bits(spec.
f), spec.
e) + 1;
1277 return pack(
bias(result, spec), spec);
1282 const std::size_t dest_bits,
1284 const exprt &fraction,
1287 std::size_t fraction_bits=
1293 std::size_t extra_bits=fraction_bits-dest_bits;
1311 extra_bits >= 1,
"the extra bits contain at least the rounding bit");
1319 rounding_bit,
or_exprt(rounding_least, sticky_bit));
1332 const auto round_to_away = rounding_bit;
1350 std::size_t fraction_size=spec.
f+1;
1351 std::size_t result_fraction_size=
1355 if(result_fraction_size<fraction_size)
1358 std::size_t padding=fraction_size-result_fraction_size;
1365 else if(result_fraction_size==fraction_size)
1371 std::size_t extra_bits=result_fraction_size-fraction_size;
1373 extra_bits >= 1,
"the extra bits include at least the rounding bit");
1377 fraction_size, result.
sign, result.
fraction, rounding_mode_bits);
1396 bv_utils.incrementer(result.
exponent, overflow);
1401 const or_exprt new_integer_part(integer_part1, integer_part0);
1404 result.
fraction.back()=new_integer_part;
1435 or_exprt(overflow, subnormal_to_normal),
1456 std::size_t result_exponent_size=
1462 if(result_exponent_size == spec.
e)
1495 exprt largest_normal_exponent=
1628 {std::move(
sign_bit), std::move(exponent), std::move(fraction)},
1644 for(std::size_t stage=0; stage<dist_width; stage++)
1664 result=
if_exprt(dist_bit, tmp, result);
API to expression classes for bitvectors.
Pre-defined bitvector types.
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
Boolean AND All operands must be boolean, and the result is always boolean.
A base class for relations, i.e., binary predicates whose two operands have the same type.
Bit-wise AND Any number of operands that is greater or equal one.
Bit-wise OR Any number of operands that is greater or equal one.
Base class of fixed-width bit-vector types.
std::size_t get_width() const
Bit-wise XOR Any number of operands that is greater or equal one.
Fixed-width bit-vector without numerical interpretation.
Concatenation of bit-vector operands.
A constant literal expression.
Base class for all expressions.
bool is_boolean() const
Return whether the expression represents a Boolean.
typet & type()
Return the type of the expression.
The Boolean constant false.
static unbiased_floatt unpack(const exprt &, const ieee_float_spect &)
static void normalization_shift(exprt &fraction, exprt &exponent)
normalize fraction/exponent pair returns 'zero' if fraction is zero
static exprt get_fraction(const exprt &, const ieee_float_spect &)
Gets the fraction without hidden bit in a floating-point bit-vector src.
static exprt sub_bias(const exprt &exponent, const ieee_float_spect &)
static exprt exponent_all_ones(const exprt &, const ieee_float_spect &)
static exprt to_integer(const exprt &src, std::size_t dest_width, bool is_signed, const exprt &rm, const ieee_float_spect &)
exprt from_unsigned_integer(const exprt &, const exprt &rm, const ieee_float_spect &) const
static exprt isfinite(const exprt &, const ieee_float_spect &)
static exprt isnormal(const exprt &, const ieee_float_spect &)
exprt from_signed_integer(const exprt &, const exprt &rm, const ieee_float_spect &) const
exprt add_sub(bool subtract, const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
static exprt is_zero(const exprt &)
static exprt abs(const exprt &, const ieee_float_spect &)
static void round_fraction(unbiased_floatt &result, const rounding_mode_bitst &, const ieee_float_spect &)
static exprt fraction_rounding_decision(const std::size_t dest_bits, const exprt sign, const exprt &fraction, const rounding_mode_bitst &)
rounding decision for fraction using sticky bit
exprt conversion(const exprt &src, const exprt &rm, const ieee_float_spect &src_spec, const ieee_float_spect &dest_spec) const
static exprt isnan(const exprt &, const ieee_float_spect &)
static biased_floatt bias(const unbiased_floatt &, const ieee_float_spect &)
takes an unbiased float, and applies the bias
static exprt get_exponent(const exprt &, const ieee_float_spect &)
Gets the unbiased exponent in a floating-point bit-vector.
static void denormalization_shift(exprt &fraction, exprt &exponent, const ieee_float_spect &)
make sure exponent is not too small; the exponent is unbiased
static exprt add_bias(const exprt &exponent, const ieee_float_spect &)
static exprt sticky_right_shift(const exprt &op, const exprt &dist, exprt &sticky)
exprt rounder(const unbiased_floatt &, const exprt &rm, const ieee_float_spect &) const
exprt fma(const exprt &multiply_lhs, const exprt &multiply_rhs, const exprt &addend, const exprt &rm, const ieee_float_spect &) const
Fused multiply-add: round(multiply_lhs * multiply_rhs + addend) with a single rounding step.
static exprt subtract_exponents(const unbiased_floatt &src1, const unbiased_floatt &src2)
Subtracts the exponents.
exprt div(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
exprt convert(const exprt &) const
static ieee_float_spect get_spec(const exprt &)
static exprt to_unsigned_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &)
static exprt negation(const exprt &, const ieee_float_spect &)
static exprt relation(const exprt &, relt rel, const exprt &, const ieee_float_spect &)
static exprt isinf(const exprt &, const ieee_float_spect &)
static exprt sign_bit(const exprt &)
exprt mul(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
static exprt fraction_all_zeros(const exprt &, const ieee_float_spect &)
static exprt exponent_all_zeros(const exprt &, const ieee_float_spect &)
static exprt is_equal(const exprt &, const exprt &, const ieee_float_spect &)
static exprt to_signed_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &)
static exprt limit_distance(const exprt &dist, mp_integer limit)
Limits the shift distance.
static exprt pack(const biased_floatt &, const ieee_float_spect &)
static void round_exponent(unbiased_floatt &result, const rounding_mode_bitst &, const ieee_float_spect &)
Fixed-width bit-vector with IEEE floating-point interpretation.
class floatbv_typet to_type() const
mp_integer max_exponent() const
std::size_t width() const
An IEEE 754 floating-point value, including specificiation.
constant_exprt to_expr() const
The trinary if-then-else operator.
constant_exprt largest_expr() const
Return an expression representing the largest value of this type.
constant_exprt zero_expr() const
Return an expression representing the zero value of this type.
const irep_idt & id() const
Modulo defined as lhs-(rhs * truncate(lhs/rhs)).
Binary multiplication Associativity is not specified.
Boolean OR All operands must be boolean, and the result is always boolean.
The plus expression Associativity is not specified.
Sign of an expression Predicate is true if _op is negative, false otherwise.
Fixed-width bit-vector with two's complement interpretation.
Semantic type conversion.
The type of an expression, extends irept.
The unary minus expression.
Fixed-width bit-vector with unsigned binary interpretation.
zero extension The operand is converted to the given type by either a) truncating if the new type is ...
API to expression classes for floating-point arithmetic.
const ieee_float_op_exprt & to_ieee_float_op_expr(const exprt &expr)
Cast an exprt to an ieee_float_op_exprt.
const floatbv_fma_exprt & to_floatbv_fma_expr(const exprt &expr)
const ieee_float_notequal_exprt & to_ieee_float_notequal_expr(const exprt &expr)
Cast an exprt to an ieee_float_notequal_exprt.
const ieee_float_equal_exprt & to_ieee_float_equal_expr(const exprt &expr)
Cast an exprt to an ieee_float_equal_exprt.
const floatbv_typecast_exprt & to_floatbv_typecast_expr(const exprt &expr)
Cast an exprt to a floatbv_typecast_exprt.
const std::size_t sharing_mapt< keyT, valueT, fail_if_equal, hashT, equalT >::mask
#define UNREACHABLE
This should be used to mark dead code.
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...
API to expression classes.
const binary_relation_exprt & to_binary_relation_expr(const exprt &expr)
Cast an exprt to a binary_relation_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const abs_exprt & to_abs_expr(const exprt &expr)
Cast an exprt to a abs_exprt.
const unary_minus_exprt & to_unary_minus_expr(const exprt &expr)
Cast an exprt to a unary_minus_exprt.
void get(const exprt &rm)
bool is_signed(const typet &t)
Convenience function – is the type signed?