From 79919e33a2147bd3e91c6f011fcbcd5a32b7eec0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 4 Feb 2023 21:15:53 -0800 Subject: [PATCH 1/2] Handle continuous assignment of assignment patterns to array elements Currently when creating the NetNet for a continuous assignment to an array element the type of the element is flattened into a canonical 1 dimensional form. This works for most cases because packed types are compatible if their total packed with is the same. But there are some contexts such as if the right-hand-side is an assignment pattern where the actual type matters and flattening the type will result in incorrect behavior. Retain the original type of the array element when creating the NetNet for the array element assignment. Signed-off-by: Lars-Peter Clausen --- elab_net.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/elab_net.cc b/elab_net.cc index 84bbcaa39..b8d561749 100644 --- a/elab_net.cc +++ b/elab_net.cc @@ -890,11 +890,8 @@ NetNet* PEIdent::elaborate_lnet_common_(Design*des, NetScope*scope, if (sig->pin_count() > 1 && widx_flag) { if (widx < 0 || widx >= (long) sig->pin_count()) return 0; - - netvector_t*tmp2_vec = new netvector_t(sig->data_type(), - sig->vector_width()-1,0); NetNet*tmp = new NetNet(scope, scope->local_symbol(), - sig->type(), tmp2_vec); + sig->type(), sig->net_type()); tmp->set_line(*this); tmp->local_flag(true); connect(sig->pin(widx), tmp->pin(0)); From d4c35340e0a9e4e7df94ba6336bfb38fc52a201a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 5 Mar 2023 00:17:07 -0800 Subject: [PATCH 2/2] Add regression tests for continuous assignment of assignment patterns Check that packed array assignment patterns and struct assignment patterns are supported for continuous assignments. Check for both assignment to variables as well as array elements. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_ap_parray3.v | 21 +++++++++++++++++++++ ivtest/ivltests/sv_ap_parray4.v | 21 +++++++++++++++++++++ ivtest/ivltests/sv_ap_struct3.v | 32 ++++++++++++++++++++++++++++++++ ivtest/ivltests/sv_ap_struct4.v | 32 ++++++++++++++++++++++++++++++++ ivtest/regress-sv.list | 4 ++++ ivtest/regress-vlog95.list | 2 ++ 6 files changed, 112 insertions(+) create mode 100644 ivtest/ivltests/sv_ap_parray3.v create mode 100644 ivtest/ivltests/sv_ap_parray4.v create mode 100644 ivtest/ivltests/sv_ap_struct3.v create mode 100644 ivtest/ivltests/sv_ap_struct4.v diff --git a/ivtest/ivltests/sv_ap_parray3.v b/ivtest/ivltests/sv_ap_parray3.v new file mode 100644 index 000000000..e1ec2bca8 --- /dev/null +++ b/ivtest/ivltests/sv_ap_parray3.v @@ -0,0 +1,21 @@ +// Check that positional assignment patterns are supported for packed arrays +// when doing continuous assignments. + +module test; + + wire [3:0][3:0] x; + wire [1:0][3:0][3:0] y; + + assign x = '{1'b1, 32'h2, 3.0, "TEST"}; + assign y = '{'{1'b1, 1 + 1, 3.0, "TEST"}, + '{5, 6, '{1'b0, 1 * 1, 3, 1.0}, 8}}; + + final begin + if (x === 16'h1234 && y == 32'h12345678) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_ap_parray4.v b/ivtest/ivltests/sv_ap_parray4.v new file mode 100644 index 000000000..722b03bb2 --- /dev/null +++ b/ivtest/ivltests/sv_ap_parray4.v @@ -0,0 +1,21 @@ +// Check that positional assignment patterns are supported for packed arrays +// when doing continuous assignments to array elements. + +module test; + + wire [3:0][3:0] x[2]; + wire [1:0][3:0][3:0] y[2]; + + assign x[0] = '{1'b1, 32'h2, 3.0, "TEST"}; + assign y[1] = '{'{1'b1, 1 + 1, 3.0, "TEST"}, + '{5, 6, '{1'b0, 1 * 1, 3, 1.0}, 8}}; + + final begin + if (x[0] === 16'h1234 && y[1] == 32'h12345678) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_ap_struct3.v b/ivtest/ivltests/sv_ap_struct3.v new file mode 100644 index 000000000..64f9cf17a --- /dev/null +++ b/ivtest/ivltests/sv_ap_struct3.v @@ -0,0 +1,32 @@ +// Check that positional assigment patterns are supported for structs when using +// continuous assignments. + +module test; + + typedef struct packed { + logic [31:0] x; + logic [15:0] y; + logic [7:0] z; + } T; + + T x; + + // Check nested assignment patterns + struct packed { + T x; + logic [2:0][3:0] y; + } y; + + assign x = '{1'b1, 2.0, 2 + 1}; + assign y = '{'{1'b1, 2.0, 2 + 1}, '{4, 5, 6}}; + + final begin + if (x === 56'h00000001000203 && + y === 68'h00000001000203456) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_ap_struct4.v b/ivtest/ivltests/sv_ap_struct4.v new file mode 100644 index 000000000..0bc8a5630 --- /dev/null +++ b/ivtest/ivltests/sv_ap_struct4.v @@ -0,0 +1,32 @@ +// Check that positional assigment patterns are supported for structs when using +// continuous assignments to array elements. + +module test; + + typedef struct packed { + logic [31:0] x; + logic [15:0] y; + logic [7:0] z; + } T; + + T x[2]; + + // Check nested assignment patterns + struct packed { + T x; + logic [2:0][3:0] y; + } y[2]; + + assign x[0] = '{1'b1, 2.0, 2 + 1}; + assign y[1] = '{'{1'b1, 2.0, 2 + 1}, '{4, 5, 6}}; + + final begin + if (x[0] === 56'h00000001000203 && + y[1] === 68'h00000001000203456) begin + $display("PASSED"); + end else begin + $display("FAILED"); + end + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index a3480f7a3..8048ad45d 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -521,11 +521,15 @@ struct_signed normal,-g2009 ivltests sv-constants normal,-g2005-sv ivltests sv_ap_parray1 normal,-g2005-sv ivltests sv_ap_parray2 normal,-g2005-sv ivltests +sv_ap_parray3 normal,-g2005-sv ivltests +sv_ap_parray4 normal,-g2005-sv ivltests sv_ap_parray_fail1 CE,-g2005-sv ivltests sv_ap_parray_fail2 CE,-g2005-sv ivltests sv_ap_parray_fail3 CE,-g2005-sv ivltests sv_ap_struct1 normal,-g2005-sv ivltests sv_ap_struct2 normal,-g2005-sv ivltests +sv_ap_struct3 normal,-g2005-sv ivltests +sv_ap_struct4 normal,-g2005-sv ivltests sv_ap_struct_fail1 CE,-g2005-sv ivltests sv_ap_struct_fail2 CE,-g2005-sv ivltests sv_assign_pattern_cast normal,-g2005-sv ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 8334da0eb..e901d8115 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -260,6 +260,8 @@ scan-invalid CE ivltests sel_rval_bit_ob CE ivltests sel_rval_part_ob CE ivltests signed_net_display CE,-pallowsigned=1 ivltests +sv_ap_parray4 CE,-g2005-sv ivltests +sv_ap_struct4 CE,-g2005-sv ivltests sv_array_cassign1 CE,-g2005-sv ivltests sv_array_cassign2 CE,-g2005-sv ivltests sv_array_cassign3 CE,-g2005-sv ivltests