Skip to content

Commit d935c4e

Browse files
committed
SystemVerilog: conversion functions
This adds the conversion functions from 1800-2017 20.5.
1 parent 68c8662 commit d935c4e

19 files changed

+371
-83
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Verilog: fix for primitive gates with more than two inputs
55
* Verilog: Support $past when using AIG-based engines
66
* Verilog: fix for nor/nand/xnor primitive gates
7+
* SystemVerilog: $bitstoreal/$bitstoshortreal, $realtobits/$shortrealtobits
8+
* SystemVerilog: $itor, $rtoi
79

810
# EBMC 5.4
911

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KNOWNBUG
2+
cast_from_real1.sv
3+
--bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Verilog casts from real to integer round, and do not truncate.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module main;
2+
3+
always assert (integer'(1.0) == 1);
4+
always assert (integer'(-1.0) == -1);
5+
6+
// Casting rounds away from zero (1800-2017 6.12.2)
7+
always assert (integer'(1.9) == 2);
8+
9+
endmodule

regression/verilog/expressions/cast_to_real1.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module main;
44
p0: assert final (real'(0) == 0.0);
55
p1: assert final (real'(1) == 1.0);
66

7-
// rounding
7+
// rounding, away from zero
88
p2: assert final (real'('hffff_ffff_ffff_ffff) == real'('h1_0000_0000_0000_0000));
99
p3: assert final (real'(-'sh0_ffff_ffff_ffff_ffff) == real'(-'sh1_0000_0000_0000_0000));
1010

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
bitstoreal1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
3+
// Not a conversion, just reinterpretation
4+
always assert ($bitstoreal(0)==0.0);
5+
always assert ($bitstoreal('h3ff00000_00000000)==1);
6+
always assert ($bitstoreal('hc0000000_00000000)==-2.0);
7+
8+
// good as constant
9+
parameter p = $bitstoreal(0);
10+
11+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
bitstoshortreal1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
3+
// Not a conversion, just reinterpretation
4+
always assert ($bitstoshortreal(0)==0.0);
5+
always assert ($bitstoshortreal('h3f80_0000)==1.0);
6+
always assert ($bitstoshortreal('hc000_0000)==-2.0);
7+
8+
// good as constant
9+
parameter p = $bitstoshortreal(0);
10+
11+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
itor1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module main;
2+
3+
always assert ($itor(1)==1.0);
4+
always assert ($itor(-1)==-1.0);
5+
6+
// good as constant
7+
parameter p = $itor(1);
8+
9+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
realtobits1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
3+
// Not a conversion, just reinterpretation
4+
always assert ($realtobits(0.0)==0);
5+
always assert ($realtobits(1.0)=='h3ff00000_00000000);
6+
always assert ($realtobits(-2.0)=='hc0000000_00000000);
7+
8+
// good as constant
9+
parameter p = $realtobits(0.0);
10+
11+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
rtoi1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module main;
2+
3+
// These truncate
4+
always assert ($rtoi(1.9)==1);
5+
always assert ($rtoi(-1.9)==-1);
6+
7+
// good as constant
8+
parameter p = $rtoi(1.9);
9+
10+
endmodule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
shortrealtobits1.sv
3+
--module main --bound 0
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module main;
2+
3+
// Not a conversion, just reinterpretation
4+
always assert ($shortrealtobits(0.0)==0);
5+
always assert ($shortrealtobits(1.0)=='h3f80_0000);
6+
always assert ($shortrealtobits(-2.0)=='hc000_0000);
7+
8+
// good as constant
9+
parameter p = $shortrealtobits(0.0);
10+
11+
endmodule

0 commit comments

Comments
 (0)