From 708f7bc6517f18bb20df7bb39e6431582433fc0a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 25 Jun 2023 09:04:34 -0700 Subject: [PATCH] Add regression test for $bits() on array identifiers Check that for array identifiers $bits() includes the total size of the signal. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/bits4.v | 37 +++++++++++++++++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/bits4.json | 5 +++++ 3 files changed, 43 insertions(+) create mode 100644 ivtest/ivltests/bits4.v create mode 100644 ivtest/vvp_tests/bits4.json diff --git a/ivtest/ivltests/bits4.v b/ivtest/ivltests/bits4.v new file mode 100644 index 000000000..cfd5b1837 --- /dev/null +++ b/ivtest/ivltests/bits4.v @@ -0,0 +1,37 @@ +// Check that passing a array identifiers and array slices to $bits works as expected + +module test; + + bit failed = 1'b0; + + `define check(expr, value) do begin \ + if ($bits(expr) !== value) begin \ + $display("FAILED(%d): $bits(", `"expr`", ") is %0d", `__LINE__, $bits(expr), " expected %0d", value); \ + failed = 1'b1; \ + end \ + end while (0) + + typedef bit T[3:0]; + + T x; + byte y[7:0][2:0]; + + initial begin + integer i; + i = 4; + + `check(x, 4); + `check(y, $bits(byte) * 3 * 8); + `check(y[0], $bits(byte) * 3); + `check(y[1:0], $bits(byte) * 3 * 2); + `check(y[1+:3], $bits(byte) * 3 * 3); + `check(y[4-:4], $bits(byte) * 3 * 4); + `check(y[i-:2], $bits(byte) * 3 * 2); + `check(y[i+:2], $bits(byte) * 3 * 2); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 6fe3647ff..281262924 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -3,6 +3,7 @@ # describes the test. array_packed_write_read vvp_tests/array_packed_write_read.json +bits4 vvp_tests/bits4.json bitsel11 vvp_tests/bitsel11.json br_gh13a vvp_tests/br_gh13a.json br_gh13a-vlog95 vvp_tests/br_gh13a-vlog95.json diff --git a/ivtest/vvp_tests/bits4.json b/ivtest/vvp_tests/bits4.json new file mode 100644 index 000000000..24e2cfdb7 --- /dev/null +++ b/ivtest/vvp_tests/bits4.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "bits4.v", + "iverilog-args" : [ "-g2005-sv" ] +}