Skip to content

Introduce floatbv_rounding_mode(unsigned) #6288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/util/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SRC = allocate_objects.cpp \
find_macros.cpp \
find_symbols.cpp \
fixedbv.cpp \
floatbv_expr.cpp \
format_constant.cpp \
format_expr.cpp \
format_number_range.cpp \
Expand Down
20 changes: 20 additions & 0 deletions src/util/floatbv_expr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************\

Module: API to expression classes for floating-point arithmetic

Author: Daniel Kroening, [email protected]

\*******************************************************************/

#include "floatbv_expr.h"

#include "arith_tools.h"
#include "bitvector_types.h"

constant_exprt floatbv_rounding_mode(unsigned rm)
{
// The 32 bits are an arbitrary choice;
// e.g., float_utilst consumes other widths as well.
// The type is signed to match the signature of fesetround.
return ::from_integer(rm, signedbv_typet(32));
}
5 changes: 5 additions & 0 deletions src/util/floatbv_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,4 +438,9 @@ inline ieee_float_op_exprt &to_ieee_float_op_expr(exprt &expr)
return ret;
}

/// \brief returns the a rounding mode expression for a given
/// IEEE rounding mode, encoded using the recommendation in
/// C11 5.2.4.2.2
constant_exprt floatbv_rounding_mode(unsigned);

#endif // CPROVER_UTIL_FLOATBV_EXPR_H
4 changes: 2 additions & 2 deletions src/util/ieee_float.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Author: Daniel Kroening, [email protected]

#include "arith_tools.h"
#include "bitvector_types.h"
#include "c_types.h"
#include "floatbv_expr.h"
#include "invariant.h"
#include "std_expr.h"

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

constant_exprt ieee_floatt::rounding_mode_expr(rounding_modet rm)
{
return ::from_integer(static_cast<int>(rm), unsigned_int_type());
return floatbv_rounding_mode(static_cast<unsigned>(rm));
}

void ieee_floatt::print(std::ostream &out) const
Expand Down
3 changes: 2 additions & 1 deletion src/util/ieee_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class ieee_floatt
public:
// ROUND_TO_EVEN is also known as "round to nearest, ties to even", and
// is the IEEE default.
// The numbering below is what x86 uses in the control word.
// The numbering below is what x86 uses in the control word and
// what is recommended in C11 5.2.4.2.2
enum rounding_modet
{
ROUND_TO_EVEN=0, ROUND_TO_MINUS_INF=1,
Expand Down