Skip to content

Commit 752a285

Browse files
authored
Merge pull request #681 from larsclausen/signal-real-type
Use `real_type_t` as the data type for `real` type signals
2 parents 760ecfc + 4ae2eec commit 752a285

File tree

10 files changed

+82
-21
lines changed

10 files changed

+82
-21
lines changed

elab_sig.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,7 @@ bool test_ranges_eeq(const vector<netrange_t>&lef, const vector<netrange_t>&rig)
937937
ivl_type_t PWire::elaborate_type(Design*des, NetScope*scope,
938938
const std::vector<netrange_t>&packed_dimensions) const
939939
{
940-
if (dynamic_cast<struct_type_t*>(set_data_type_) ||
941-
dynamic_cast<enum_type_t*>(set_data_type_) ||
942-
dynamic_cast<string_type_t*>(set_data_type_) ||
943-
dynamic_cast<class_type_t*>(set_data_type_) ||
944-
dynamic_cast<parray_type_t*>(set_data_type_) ||
945-
dynamic_cast<atom_type_t*>(set_data_type_)) {
940+
if (set_data_type_ && !dynamic_cast<vector_type_t*>(set_data_type_)) {
946941
ivl_type_t use_type = set_data_type_->elaborate_type(des, scope);
947942
ivl_assert(*this, packed_dimensions.empty());
948943
return use_type;
@@ -962,8 +957,7 @@ ivl_type_t PWire::elaborate_type(Design*des, NetScope*scope,
962957
}
963958

964959
ivl_assert(*this, use_data_type == IVL_VT_LOGIC ||
965-
use_data_type == IVL_VT_BOOL ||
966-
use_data_type == IVL_VT_REAL);
960+
use_data_type == IVL_VT_BOOL);
967961

968962
netvector_t*vec = new netvector_t(packed_dimensions, use_data_type);
969963
vec->set_signed(get_signed());

ivtest/ivltests/vams_abs3.v

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Check that VAMS `abs()` functions works if its argument is a function call
2+
3+
module main;
4+
5+
function reg signed [7:0] fv(input reg signed [7:0] x);
6+
fv = x;
7+
endfunction
8+
9+
function real fr(input real x);
10+
fr = x;
11+
endfunction
12+
13+
reg signed [7:0] a;
14+
wire signed [7:0] vala = abs(fv(a));
15+
16+
reg real b;
17+
wire real valb = abs(fr(b));
18+
19+
initial begin
20+
a = 0;
21+
b = 0;
22+
#1 if (vala !== 0) begin
23+
$display("FAILED -- a=%b, vala=%b", a, vala);
24+
$finish;
25+
end
26+
27+
#1 if (valb != 0) begin
28+
$display("FAILED -- b=%g valb=%g", b, valb);
29+
$finish;
30+
end
31+
32+
a = 1;
33+
b = 1;
34+
#1 if (vala !== 1) begin
35+
$display("FAILED -- a=%b, vala=%b", a, vala);
36+
$finish;
37+
end
38+
39+
#1 if (valb != 1) begin
40+
$display("FAILED -- b=%g valb=%g", b, valb);
41+
$finish;
42+
end
43+
44+
a = -1;
45+
b = -1;
46+
#1 if (vala !== 1) begin
47+
$display("FAILED -- a=%b, vala=%b", a, vala);
48+
$finish;
49+
end
50+
51+
#1 if (valb != 1) begin
52+
$display("FAILED -- b=%g valb=%g", b, valb);
53+
$finish;
54+
end
55+
56+
$display("PASSED");
57+
end
58+
59+
endmodule // main

ivtest/regress-vams.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ value_range2 normal,-gverilog-ams ivltests
8181
value_range3 CE,-gverilog-ams ivltests
8282
vams_abs1 normal,-gverilog-ams ivltests
8383
vams_abs2 normal,-gverilog-ams ivltests
84+
vams_abs3 normal,-gverilog-ams ivltests
8485
wreal normal,-gverilog-ams ivltests
8586
# Verilog functions added in a VAMS simulator
8687
constfunc6_ams normal ivltests

ivtest/regress-vlog95.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ real_wire_force_rel CE ivltests
158158
tern8 CE ivltests
159159
v2005_math CE ivltests
160160
vams_abs2 CE,-gverilog-ams,-pallowsigned=1 ivltests
161+
vams_abs3 CE,-gverilog-ams,-pallowsigned=1 ivltests
161162
vhdl_real CE,-g2009,ivltests/vhdl_real.vhd ivltests
162163
vhdl_unbounded CE,-g2009,ivltests/vhdl_unbounded.vhd ivltests
163164
wreal CE ivltests

netlist.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# include "netdarray.h"
3333
# include "netenum.h"
3434
# include "netparray.h"
35+
# include "netscalar.h"
3536
# include "netqueue.h"
3637
# include "netstruct.h"
3738
# include "netvector.h"
@@ -715,10 +716,8 @@ bool NetNet::get_signed() const
715716

716717
bool NetNet::get_scalar() const
717718
{
718-
if (const netvector_t*vec = dynamic_cast<const netvector_t*> (net_type_))
719-
return vec->get_scalar();
720-
else
721-
return false;
719+
ivl_assert(*this, net_type_);
720+
return net_type_->get_scalar();
722721
}
723722

724723
const netenum_t*NetNet::enumeration(void) const

netscalar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class netreal_t : public ivl_type_s {
2828
~netreal_t();
2929

3030
ivl_variable_type_t base_type() const;
31+
bool get_signed() const { return true; }
32+
bool get_scalar() const { return true; }
3133

3234
std::ostream& debug_dump(std::ostream&) const;
3335

nettypes.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ bool ivl_type_s::get_signed() const
5656
return false;
5757
}
5858

59+
bool ivl_type_s::get_scalar() const
60+
{
61+
return false;
62+
}
63+
5964
bool ivl_type_s::type_compatible(ivl_type_t that) const
6065
{
6166
if (this == that)

nettypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ivl_type_s {
4545
// those specific types.
4646
virtual ivl_variable_type_t base_type() const;
4747
virtual bool get_signed() const;
48+
virtual bool get_scalar() const;
4849

4950
// Return true if "that" type is compatible with this
5051
// type. Compatible means the types are essentially the same.

pform.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,6 @@ void pform_module_define_port(const struct vlltype&li,
25692569
list<named_pexpr_t>*attr,
25702570
bool keep_attr)
25712571
{
2572-
data_type_t*packed_type = 0;
25732572
ivl_variable_type_t data_type = IVL_VT_NO_TYPE;
25742573
bool signed_flag = false;
25752574

@@ -2601,6 +2600,7 @@ void pform_module_define_port(const struct vlltype&li,
26012600
data_type = vec_type->base_type;
26022601
signed_flag = vec_type->signed_flag;
26032602
prange = vec_type->pdims.get();
2603+
vtype = 0;
26042604
} else if (real_type_t*rtype = dynamic_cast<real_type_t*>(vtype)) {
26052605
data_type = IVL_VT_REAL;
26062606
signed_flag = true;
@@ -2614,7 +2614,6 @@ void pform_module_define_port(const struct vlltype&li,
26142614
} else if (vtype) {
26152615
if (vtype->figure_packed_base_type() != IVL_VT_NO_TYPE) {
26162616
data_type = vtype->figure_packed_base_type();
2617-
packed_type = vtype;
26182617
} else {
26192618
VLerror(li, "sorry: Given type %s not supported here (%s:%d).",
26202619
typeid(*vtype).name(), __FILE__, __LINE__);
@@ -2631,10 +2630,10 @@ void pform_module_define_port(const struct vlltype&li,
26312630

26322631
cur->set_signed(signed_flag);
26332632

2634-
if (packed_type) {
2635-
cur->set_data_type(packed_type);
2633+
if (vtype)
2634+
cur->set_data_type(vtype);
26362635

2637-
} else if (prange == 0) {
2636+
if (prange == 0) {
26382637
cur->set_range_scalar((type == NetNet::IMPLICIT) ? SR_PORT : SR_BOTH);
26392638

26402639
} else {
@@ -2966,8 +2965,7 @@ vector<pform_tf_port_t>*pform_make_task_ports(const struct vlltype&loc,
29662965
}
29672966

29682967
if (/*real_type_t*real_type = */ dynamic_cast<real_type_t*> (vtype)) {
2969-
ret = pform_make_task_ports(loc, pt, IVL_VT_REAL,
2970-
true, 0, ports);
2968+
ret = do_make_task_ports(loc, pt, IVL_VT_REAL, vtype, ports);
29712969
}
29722970

29732971
if (dynamic_cast<string_type_t*> (vtype)) {
@@ -3442,7 +3440,6 @@ void pform_set_data_type(const struct vlltype&li, data_type_t*data_type, list<pe
34423440
}
34433441

34443442
else if (/*real_type_t*real_type =*/ dynamic_cast<real_type_t*> (data_type)) {
3445-
pform_set_net_range(names, 0, true, 0);
34463443
vt = IVL_VT_REAL;
34473444
}
34483445

pform_disciplines.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ void pform_attach_discipline(const struct vlltype&loc,
209209
error_count += 1;
210210

211211
} else {
212-
cur_net->set_data_type(IVL_VT_REAL);
212+
data_type_t *type = new real_type_t(real_type_t::REAL);
213+
FILE_NAME(type, loc);
214+
cur_net->set_data_type(type);
213215
cur_net->set_discipline(discipline);
214216
}
215217
}

0 commit comments

Comments
 (0)