CBMC
Loading...
Searching...
No Matches
float_bv.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9
10#ifndef CPROVER_SOLVERS_FLOATBV_FLOAT_BV_H
11#define CPROVER_SOLVERS_FLOATBV_FLOAT_BV_H
12
13#include <util/ieee_float.h>
14#include <util/std_expr.h>
15
17{
18public:
19 exprt operator()(const exprt &src) const
20 {
21 return convert(src);
22 }
23
24 exprt convert(const exprt &) const;
25
26 static exprt negation(const exprt &, const ieee_float_spect &);
27 static exprt abs(const exprt &, const ieee_float_spect &);
28 static exprt is_equal(const exprt &, const exprt &, const ieee_float_spect &);
29 static exprt is_zero(const exprt &);
30 static exprt isnan(const exprt &, const ieee_float_spect &);
31 static exprt isinf(const exprt &, const ieee_float_spect &);
32 static exprt isnormal(const exprt &, const ieee_float_spect &);
33 static exprt isfinite(const exprt &, const ieee_float_spect &);
34
35 // add/sub
37 bool subtract,
38 const exprt &,
39 const exprt &,
40 const exprt &rm,
41 const ieee_float_spect &) const;
42
43 // mul/div
44 exprt
45 mul(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &)
46 const;
47 exprt
48 div(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &)
49 const;
50
58 exprt fma(
59 const exprt &multiply_lhs,
60 const exprt &multiply_rhs,
61 const exprt &addend,
62 const exprt &rm,
63 const ieee_float_spect &) const;
64
65 // conversion
67 const exprt &,
68 const exprt &rm,
69 const ieee_float_spect &) const;
71 const exprt &,
72 const exprt &rm,
73 const ieee_float_spect &) const;
75 const exprt &src,
76 std::size_t dest_width,
77 const exprt &rm,
78 const ieee_float_spect &);
80 const exprt &src,
81 std::size_t dest_width,
82 const exprt &rm,
83 const ieee_float_spect &);
84 static exprt to_integer(
85 const exprt &src,
86 std::size_t dest_width,
87 bool is_signed,
88 const exprt &rm,
89 const ieee_float_spect &);
91 const exprt &src,
92 const exprt &rm,
94 const ieee_float_spect &dest_spec) const;
95
96 // relations
97 enum class relt { LT, LE, EQ, GT, GE };
98 static exprt
99 relation(const exprt &, relt rel, const exprt &, const ieee_float_spect &);
100
101private:
102 // helpers
103 static ieee_float_spect get_spec(const exprt &);
104 // still biased
105 static exprt get_exponent(const exprt &, const ieee_float_spect &);
106 // without hidden bit
107 static exprt get_fraction(const exprt &, const ieee_float_spect &);
108 static exprt sign_bit(const exprt &);
109
110 static exprt exponent_all_ones(const exprt &, const ieee_float_spect &);
111 static exprt exponent_all_zeros(const exprt &, const ieee_float_spect &);
112 static exprt fraction_all_zeros(const exprt &, const ieee_float_spect &);
113
115 {
116 // these are mutually exclusive, obviously
122
123 void get(const exprt &rm);
124 explicit rounding_mode_bitst(const exprt &rm) { get(rm); }
125 };
126
127 // unpacked
128 static void normalization_shift(exprt &fraction, exprt &exponent);
129 static void denormalization_shift(
130 exprt &fraction,
131 exprt &exponent,
132 const ieee_float_spect &);
133
134 static exprt add_bias(const exprt &exponent, const ieee_float_spect &);
135 static exprt sub_bias(const exprt &exponent, const ieee_float_spect &);
136
138
152
153 // This has a biased exponent (unsigned)
154 // and an _implicit_ hidden bit.
156 {
157 };
158
159 // The hidden bit is explicit,
160 // and the exponent is not biased (signed)
162 {
163 };
164
165 static biased_floatt bias(const unbiased_floatt &, const ieee_float_spect &);
166
167 // this takes unpacked format, and returns packed
169 const unbiased_floatt &,
170 const exprt &rm,
171 const ieee_float_spect &) const;
172 static exprt pack(const biased_floatt &, const ieee_float_spect &);
173 static unbiased_floatt unpack(const exprt &, const ieee_float_spect &);
174
175 static void round_fraction(
176 unbiased_floatt &result,
177 const rounding_mode_bitst &,
178 const ieee_float_spect &);
179 static void round_exponent(
180 unbiased_floatt &result,
181 const rounding_mode_bitst &,
182 const ieee_float_spect &);
183
184 // rounding decision for fraction
186 const std::size_t dest_bits,
187 const exprt sign,
188 const exprt &fraction,
189 const rounding_mode_bitst &);
190
191 // helpers for adder
192
193 // computes src1.exponent-src2.exponent with extension
194 static exprt
196
197 // computes the "sticky-bit"
198 static exprt
199 sticky_right_shift(const exprt &op, const exprt &dist, exprt &sticky);
200};
201
202inline exprt float_bv(const exprt &src)
203{
204 return float_bvt()(src);
205}
206
207#endif // CPROVER_SOLVERS_FLOATBV_FLOAT_BV_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
Base class for all expressions.
Definition expr.h:57
The Boolean constant false.
Definition std_expr.h:3135
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 &)
Definition float_bv.cpp:260
static exprt to_integer(const exprt &src, std::size_t dest_width, bool is_signed, const exprt &rm, const ieee_float_spect &)
Definition float_bv.cpp:377
exprt from_unsigned_integer(const exprt &, const exprt &rm, const ieee_float_spect &) const
Definition float_bv.cpp:337
static exprt isfinite(const exprt &, const ieee_float_spect &)
static exprt isnormal(const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:499
exprt from_signed_integer(const exprt &, const exprt &rm, const ieee_float_spect &) const
Definition float_bv.cpp:313
exprt add_sub(bool subtract, const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
Definition float_bv.cpp:528
static exprt is_zero(const exprt &)
Definition float_bv.cpp:244
exprt operator()(const exprt &src) const
Definition float_bv.h:19
static exprt abs(const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:202
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
Definition float_bv.cpp:425
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.
Definition float_bv.cpp:837
static exprt subtract_exponents(const unbiased_floatt &src1, const unbiased_floatt &src2)
Subtracts the exponents.
Definition float_bv.cpp:509
exprt div(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
Definition float_bv.cpp:748
exprt convert(const exprt &) const
Definition float_bv.cpp:19
static ieee_float_spect get_spec(const exprt &)
Definition float_bv.cpp:196
static exprt to_unsigned_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &)
Definition float_bv.cpp:368
static exprt negation(const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:212
static exprt relation(const exprt &, relt rel, const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:956
static exprt isinf(const exprt &, const ieee_float_spect &)
static exprt sign_bit(const exprt &)
Definition float_bv.cpp:306
exprt mul(const exprt &, const exprt &, const exprt &rm, const ieee_float_spect &) const
Definition float_bv.cpp:697
static exprt fraction_all_zeros(const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:278
static exprt exponent_all_zeros(const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:269
static exprt is_equal(const exprt &, const exprt &, const ieee_float_spect &)
Definition float_bv.cpp:222
static exprt to_signed_integer(const exprt &src, std::size_t dest_width, const exprt &rm, const ieee_float_spect &)
Definition float_bv.cpp:359
static exprt limit_distance(const exprt &dist, mp_integer limit)
Limits the shift distance.
Definition float_bv.cpp:674
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 &)
exprt float_bv(const exprt &src)
Definition float_bv.h:202
BigInt mp_integer
Definition smt_terms.h:17
API to expression classes.
rounding_mode_bitst(const exprt &rm)
Definition float_bv.h:124
void get(const exprt &rm)
Definition float_bv.cpp:288
bool is_signed(const typet &t)
Convenience function – is the type signed?
Definition util.cpp:45