-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verilog: add rounding mode to casts to real/shortreal
Casts to real/shortreal may need to round, hence add the rounding mode during lowering.
- Loading branch information
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
KNOWNBUG | ||
cast_to_real1.sv | ||
--bound 0 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
Typechecking is failing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module main; | ||
|
||
p0: assert final (real'(0) == 0.0); | ||
p1: assert final (real'(1) == 1.0); | ||
p2: assert final (real'(-1) == -1.0); | ||
p3: assert final (real'(1'b1) == 1); | ||
p4: assert final (real'('hffff_ffff_ffff_ffff) == real'('h1_0000_0000_0000_0000)); | ||
p5: assert final (real'(-'sh0_ffff_ffff_ffff_ffff) == real'(-'sh1_0000_0000_0000_0000)); | ||
|
||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/arith_tools.h> | ||
#include <util/bitvector_expr.h> | ||
#include <util/c_types.h> | ||
#include <util/floatbv_expr.h> | ||
#include <util/ieee_float.h> | ||
|
||
#include "aval_bval_encoding.h" | ||
|
@@ -272,7 +273,18 @@ exprt verilog_lowering(exprt expr) | |
} | ||
} | ||
|
||
return expr; | ||
// Cast to float? Turn into floatbv_typecast, | ||
// with rounding mode. | ||
if(typecast_expr.type().id() == ID_floatbv) | ||
{ | ||
auto rm = ieee_floatt::rounding_mode_expr( | ||
ieee_floatt::rounding_modet::ROUND_TO_EVEN); | ||
auto floatbv_typecast = | ||
floatbv_typecast_exprt{typecast_expr.op(), rm, typecast_expr.type()}; | ||
return std::move(floatbv_typecast); | ||
} | ||
else | ||
return expr; | ||
} | ||
else if(expr.id() == ID_verilog_explicit_type_cast) | ||
{ | ||
|