CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
132 bvt abs(const bvt &);
133 bvt negate(const bvt &);
134
135 // conversion
137 bvt from_signed_integer(const bvt &);
138 bvt to_integer(const bvt &src, std::size_t int_width, bool is_signed);
139 bvt to_signed_integer(const bvt &src, std::size_t int_width);
140 bvt to_unsigned_integer(const bvt &src, std::size_t int_width);
141 bvt conversion(const bvt &src, const ieee_float_spect &dest_spec);
142 bvt round_to_integral(const bvt &);
143
144 // relations
145 enum class relt { LT, LE, EQ, GT, GE };
146 literalt relation(const bvt &src1, relt rel, const bvt &src2);
147
148 // constants
149 ieee_float_valuet get(const bvt &) const;
150
151 // helpers
155
156 // debugging hooks
157 bvt debug1(const bvt &op0, const bvt &op1);
158 bvt debug2(const bvt &op0, const bvt &op1);
159
160protected:
163
164 // unpacked
165 virtual void normalization_shift(bvt &fraction, bvt &exponent);
166 void denormalization_shift(bvt &fraction, bvt &exponent);
167
168 bvt add_bias(const bvt &exponent);
169 bvt sub_bias(const bvt &exponent);
170
172
186
187 // this has a biased exponent
188 // and an _implicit_ hidden bit
190 {
191 };
192
193 // the hidden bit is explicit,
194 // and the exponent is not biased
196 {
197 };
198
199 unbiased_floatt unpack(const bvt &);
201
202 // takes unpacked, returns unpacked
204
205 // this takes unpacked format, and returns packed
207 bvt pack(const biased_floatt &);
208
209 void round_fraction(unbiased_floatt &result);
210 void round_exponent(unbiased_floatt &result);
211
212 // rounding decision for fraction
214 const std::size_t dest_bits,
215 const literalt sign,
216 const bvt &fraction);
217
218 // helpers for adder
219
220 // computes src1.exponent-src2.exponent with extension
222 const unbiased_floatt &src1,
223 const unbiased_floatt &src2);
224
225 // computes the "sticky-bit"
227 const bvt &op,
228 const bvt &dist,
230};
231
232#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:562
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 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