diff --git a/ivtest/ivltests/sv_soft_packed_union.v b/ivtest/ivltests/sv_soft_packed_union.v new file mode 100644 index 000000000..6b0e7abc3 --- /dev/null +++ b/ivtest/ivltests/sv_soft_packed_union.v @@ -0,0 +1,81 @@ +// Check that soft packed unions can have members with different widths. + +module test; + + bit failed = 1'b0; + + typedef union soft packed { + logic [31:0] w; + logic [15:0] h; + logic [7:0] b; + } data_t; + + typedef union soft { + logic [31:0] w; + logic [7:0] b; + } implicit_packed_t; + + typedef union soft packed { + logic [15:0] w; + union soft { + logic [7:0] b; + logic [3:0] n; + } part; + } nested_t; + + data_t data; + implicit_packed_t implicit_packed; + nested_t nested; + + `define check(val, exp) do \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %0h, got %0h", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end \ + while(0) + + initial begin + data.w = 32'h12345678; + `check($bits(data), 32); + `check($bits(data_t), 32); + `check(data.w, 32'h12345678); + `check(data.h, 16'h5678); + `check(data.b, 8'h78); + + data.h = 16'habcd; + `check(data.w, 32'h1234abcd); + `check(data.h, 16'habcd); + `check(data.b, 8'hcd); + + data.b = 8'hef; + `check(data.w, 32'h1234abef); + `check(data.h, 16'habef); + `check(data.b, 8'hef); + + implicit_packed.w = 32'hf0e1d2c3; + `check($bits(implicit_packed_t), 32); + `check(implicit_packed.b, 8'hc3); + + implicit_packed.b = 8'h34; + `check(implicit_packed.w, 32'hf0e1d234); + + nested.w = 16'hbeef; + `check($bits(nested_t), 16); + `check($bits(nested.part), 8); + `check(nested.part.b, 8'hef); + `check(nested.part.n, 4'hf); + + nested.part.n = 4'ha; + `check(nested.w, 16'hbeea); + `check(nested.part.b, 8'hea); + + nested.part.b = 8'h55; + `check(nested.w, 16'hbe55); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_soft_packed_union_fail1.v b/ivtest/ivltests/sv_soft_packed_union_fail1.v new file mode 100644 index 000000000..c54b12e76 --- /dev/null +++ b/ivtest/ivltests/sv_soft_packed_union_fail1.v @@ -0,0 +1,12 @@ +// Check that soft packed unions can not have default member values. + +module test; + + typedef union soft { + logic [31:0] w = 32'h1; + logic [7:0] b; + } data_t; + + data_t data; + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 412f724d4..9ffa708db 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -339,6 +339,8 @@ sv_package_lifetime vvp_tests/sv_package_lifetime.json sv_package_lifetime_fail vvp_tests/sv_package_lifetime_fail.json sv_parameter_type vvp_tests/sv_parameter_type.json sv_queue_assign_op vvp_tests/sv_queue_assign_op.json +sv_soft_packed_union vvp_tests/sv_soft_packed_union.json +sv_soft_packed_union_fail1 vvp_tests/sv_soft_packed_union_fail1.json sv_super_member_fail vvp_tests/sv_super_member_fail.json sv_wildcard_import8 vvp_tests/sv_wildcard_import8.json sdf_header vvp_tests/sdf_header.json diff --git a/ivtest/vvp_tests/sv_soft_packed_union.json b/ivtest/vvp_tests/sv_soft_packed_union.json new file mode 100644 index 000000000..073a76414 --- /dev/null +++ b/ivtest/vvp_tests/sv_soft_packed_union.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_soft_packed_union.v", + "iverilog-args" : [ "-g2023" ] +} diff --git a/ivtest/vvp_tests/sv_soft_packed_union_fail1.json b/ivtest/vvp_tests/sv_soft_packed_union_fail1.json new file mode 100644 index 000000000..bd50b1e04 --- /dev/null +++ b/ivtest/vvp_tests/sv_soft_packed_union_fail1.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_soft_packed_union_fail1.v", + "iverilog-args" : [ "-g2023" ] +}