Skip to content

Commit 0bbbe19

Browse files
authored
Merge pull request #6288 from diffblue/floatbv_rounding_mode
Introduce floatbv_rounding_mode(unsigned)
2 parents 91c18f6 + bd9520c commit 0bbbe19

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

src/util/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SRC = allocate_objects.cpp \
2222
find_macros.cpp \
2323
find_symbols.cpp \
2424
fixedbv.cpp \
25+
floatbv_expr.cpp \
2526
format_constant.cpp \
2627
format_expr.cpp \
2728
format_number_range.cpp \

src/util/floatbv_expr.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*******************************************************************\
2+
3+
Module: API to expression classes for floating-point arithmetic
4+
5+
Author: Daniel Kroening, kroening@kroening.com
6+
7+
\*******************************************************************/
8+
9+
#include "floatbv_expr.h"
10+
11+
#include "arith_tools.h"
12+
#include "bitvector_types.h"
13+
14+
constant_exprt floatbv_rounding_mode(unsigned rm)
15+
{
16+
// The 32 bits are an arbitrary choice;
17+
// e.g., float_utilst consumes other widths as well.
18+
// The type is signed to match the signature of fesetround.
19+
return ::from_integer(rm, signedbv_typet(32));
20+
}

src/util/floatbv_expr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,9 @@ inline ieee_float_op_exprt &to_ieee_float_op_expr(exprt &expr)
438438
return ret;
439439
}
440440

441+
/// \brief returns the a rounding mode expression for a given
442+
/// IEEE rounding mode, encoded using the recommendation in
443+
/// C11 5.2.4.2.2
444+
constant_exprt floatbv_rounding_mode(unsigned);
445+
441446
#endif // CPROVER_UTIL_FLOATBV_EXPR_H

src/util/ieee_float.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Author: Daniel Kroening, kroening@kroening.com
1212

1313
#include "arith_tools.h"
1414
#include "bitvector_types.h"
15-
#include "c_types.h"
15+
#include "floatbv_expr.h"
1616
#include "invariant.h"
1717
#include "std_expr.h"
1818

@@ -58,7 +58,7 @@ void ieee_float_spect::from_type(const floatbv_typet &type)
5858

5959
constant_exprt ieee_floatt::rounding_mode_expr(rounding_modet rm)
6060
{
61-
return ::from_integer(static_cast<int>(rm), unsigned_int_type());
61+
return floatbv_rounding_mode(static_cast<unsigned>(rm));
6262
}
6363

6464
void ieee_floatt::print(std::ostream &out) const

src/util/ieee_float.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class ieee_floatt
120120
public:
121121
// ROUND_TO_EVEN is also known as "round to nearest, ties to even", and
122122
// is the IEEE default.
123-
// The numbering below is what x86 uses in the control word.
123+
// The numbering below is what x86 uses in the control word and
124+
// what is recommended in C11 5.2.4.2.2
124125
enum rounding_modet
125126
{
126127
ROUND_TO_EVEN=0, ROUND_TO_MINUS_INF=1,

0 commit comments

Comments
 (0)