CBMC
Loading...
Searching...
No Matches
float_utils.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_UTILS_H
11#define CPROVER_SOLVERS_FLOATBV_FLOAT_UTILS_H
12
13#include <util/ieee_float.h>
14
16
18{
19public:
72
74
76 prop(_prop),
78 {
79 }
80
83 prop(_prop),
85 {
86 }
87
88 void set_rounding_mode(const bvt &);
89
90 virtual ~float_utilst()
91 {
92 }
93
95
97
98 static inline literalt sign_bit(const bvt &src)
99 {
100 // this is the top bit
101 return src[src.size()-1];
102 }
103
104 // extraction
105 bvt get_exponent(const bvt &); // still biased
106 bvt get_fraction(const bvt &); // without hidden bit
107 literalt is_normal(const bvt &);
108 literalt is_zero(const bvt &); // this returns true on both 0 and -0
109 literalt is_infinity(const bvt &);
110 literalt is_plus_inf(const bvt &);
111 literalt is_minus_inf(const bvt &);
112 literalt is_NaN(const bvt &);
113
114 // add/sub
115 virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract);
116
117 bvt add(const bvt &src1, const bvt &src2)
118 {
119 return add_sub(src1, src2, false);
120 }
121
122 bvt sub(const bvt &src1, const bvt &src2)
123 {
124 return add_sub(src1, src2, true);
125 }
126
127 // mul/div/rem
128 virtual bvt mul(const bvt &src1, const bvt &src2);
129 virtual bvt div(const bvt &src1, const bvt &src2);
130 virtual bvt rem(const bvt &src1, const bvt &src2);
131
137 bvt fma(const bvt &multiply_lhs, const bvt &multiply_rhs, const bvt &addend);
138
139 bvt abs(const bvt &);
140 bvt negate(const bvt &);
141
142 // conversion
144 bvt from_signed_integer(const bvt &);
145 bvt to_integer(const bvt &src, std::size_t int_width, bool is_signed);
146 bvt to_signed_integer(const bvt &src, std::size_t int_width);
147 bvt to_unsigned_integer(const bvt &src, std::size_t int_width);
148 bvt conversion(const bvt &src, const ieee_float_spect &dest_spec);
149 bvt round_to_integral(const bvt &);
150
151 // relations
152 enum class relt { LT, LE, EQ, GT, GE };
153 literalt relation(const bvt &src1, relt rel, const bvt &src2);
154
155 // constants
156 ieee_float_valuet get(const bvt &) const;
157
158 // helpers
162
163 // debugging hooks
164 bvt debug1(const bvt &op0, const bvt &op1);
165 bvt debug2(const bvt &op0, const bvt &op1);
166
167protected:
170
171 // unpacked
172 virtual void normalization_shift(bvt &fraction, bvt &exponent);
173 void denormalization_shift(bvt &fraction, bvt &exponent);
174
175 bvt add_bias(const bvt &exponent);
176 bvt sub_bias(const bvt &exponent);
177
179
193
194 // this has a biased exponent
195 // and an _implicit_ hidden bit
197 {
198 };
199
200 // the hidden bit is explicit,
201 // and the exponent is not biased
203 {
204 };
205
206 unbiased_floatt unpack(const bvt &);
208
209 // takes unpacked, returns unpacked
211
212 // this takes unpacked format, and returns packed
214 bvt pack(const biased_floatt &);
215
216 void round_fraction(unbiased_floatt &result);
217 void round_exponent(unbiased_floatt &result);
218
219 // rounding decision for fraction
221 const std::size_t dest_bits,
222 const literalt sign,
223 const bvt &fraction);
224
225 // helpers for adder
226
227 // computes src1.exponent-src2.exponent with extension
229 const unbiased_floatt &src1,
230 const unbiased_floatt &src2);
231
232 // computes the "sticky-bit"
234 const bvt &op,
235 const bvt &dist,
237};
238
239#endif // CPROVER_SOLVERS_FLOATBV_FLOAT_UTILS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
unbiased_floatt rounder(const unbiased_floatt &)
float_utilst(propt &_prop, const floatbv_typet &type)
Definition float_utils.h:81
bvt to_integer(const bvt &src, std::size_t int_width, bool is_signed)
virtual ~float_utilst()
Definition float_utils.h:90
literalt is_NaN(const bvt &)
virtual void normalization_shift(bvt &fraction, bvt &exponent)
normalize fraction/exponent pair returns 'zero' if fraction is zero
bv_utilst bv_utils
bvt debug2(const bvt &op0, const bvt &op1)
virtual bvt rem(const bvt &src1, const bvt &src2)
bvt round_to_integral(const bvt &)
literalt is_plus_inf(const bvt &)
ieee_float_valuet get(const bvt &) const
literalt is_infinity(const bvt &)
void set_rounding_mode(const bvt &)
void round_exponent(unbiased_floatt &result)
void round_fraction(unbiased_floatt &result)
bvt sticky_right_shift(const bvt &op, const bvt &dist, literalt &sticky)
unbiased_floatt unpack(const bvt &)
bvt from_unsigned_integer(const bvt &)
virtual bvt mul(const bvt &src1, const bvt &src2)
bvt debug1(const bvt &op0, const bvt &op1)
bvt add_bias(const bvt &exponent)
bvt round_and_pack(const unbiased_floatt &)
bvt subtract_exponents(const unbiased_floatt &src1, const unbiased_floatt &src2)
Subtracts the exponents.
bvt get_fraction(const bvt &)
Gets the fraction without hidden bit in a floating-point bit-vector src.
literalt is_minus_inf(const bvt &)
literalt fraction_rounding_decision(const std::size_t dest_bits, const literalt sign, const bvt &fraction)
rounding decision for fraction using sticky bit
bvt get_exponent(const bvt &)
Gets the unbiased exponent in a floating-point bit-vector.
void denormalization_shift(bvt &fraction, bvt &exponent)
make sure exponent is not too small; the exponent is unbiased
bvt to_unsigned_integer(const bvt &src, std::size_t int_width)
bvt build_constant(const ieee_float_valuet &)
virtual bvt div(const bvt &src1, const bvt &src2)
bvt negate(const bvt &)
bvt add(const bvt &src1, const bvt &src2)
literalt exponent_all_zeros(const bvt &)
literalt fraction_all_zeros(const bvt &)
bvt fma(const bvt &multiply_lhs, const bvt &multiply_rhs, const bvt &addend)
Fused multiply-add: round(multiply_lhs * multiply_rhs + addend) with a single rounding step.
bvt from_signed_integer(const bvt &)
literalt is_zero(const bvt &)
bvt sub(const bvt &src1, const bvt &src2)
bvt sub_bias(const bvt &exponent)
bvt limit_distance(const bvt &dist, mp_integer limit)
Limits the shift distance.
bvt conversion(const bvt &src, const ieee_float_spect &dest_spec)
bvt pack(const biased_floatt &)
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
bvt abs(const bvt &)
static literalt sign_bit(const bvt &src)
Definition float_utils.h:98
float_utilst(propt &_prop)
Definition float_utils.h:75
ieee_float_spect spec
Definition float_utils.h:94
literalt exponent_all_ones(const bvt &)
bvt to_signed_integer(const bvt &src, std::size_t int_width)
literalt is_normal(const bvt &)
literalt relation(const bvt &src1, relt rel, const bvt &src2)
rounding_mode_bitst rounding_mode_bits
Definition float_utils.h:73
biased_floatt bias(const unbiased_floatt &)
takes an unbiased float, and applies the bias
Fixed-width bit-vector with IEEE floating-point interpretation.
An IEEE 754 floating-point value, including specificiation.
Definition ieee_float.h:117
TO_BE_DOCUMENTED.
Definition prop.h:25
std::vector< literalt > bvt
Definition literal.h:201
literalt const_literal(bool value)
Definition literal.h:188
BigInt mp_integer
Definition smt_terms.h:17
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
void set(const ieee_floatt::rounding_modet mode)
Definition float_utils.h:39
bool is_signed(const typet &t)
Convenience function – is the type signed?
Definition util.cpp:45