From 2a17b06fc447a15164a9ab90780df71869e299a3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 26 Jun 2023 06:06:07 -0700 Subject: [PATCH] Add regression test for bit select on multi-dimensional signed packed array Check that element and bit select on multi-dimensional signed packed arrays are unsigned. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/bitsel11.v | 63 ++++++++++++++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/bitsel11.json | 5 +++ 3 files changed, 69 insertions(+) create mode 100644 ivtest/ivltests/bitsel11.v create mode 100644 ivtest/vvp_tests/bitsel11.json diff --git a/ivtest/ivltests/bitsel11.v b/ivtest/ivltests/bitsel11.v new file mode 100644 index 000000000..74196cc79 --- /dev/null +++ b/ivtest/ivltests/bitsel11.v @@ -0,0 +1,63 @@ +// Check that element and bit select on multi-dimensional signed packed arrays +// are unsigned. + +module test; + + bit failed = 1'b0; + +`define check(val, exp) do begin \ + if (val !== exp) begin \ + $display("FAILED(%0d): Expected `%b`, got `%b`.", `__LINE__, exp, val); \ + failed = 1'b1; \ + end \ + end while (0) + + reg signed [3:0][3:0] arr; + integer idx; + reg [7:0] x; + reg [3:0] y; + reg [31:0] z; + + initial begin + // Set lowest element to all 1 + arr = 16'hffff; + + // Elements of a signed packed array are unsigned, no sign extensions + idx = 0; + x = arr[idx]; + `check(x, 8'h0f); + + // Out-of-bounds + idx = -1; + x = arr[idx]; + `check(x, 8'h0x); + + // Undefined + idx = 'bx; + x = arr[idx]; + `check(x, 8'h0x); + + // Bit selects on a signed packed array are unsigned, no sign extensions + idx = 0; + y = arr[0][idx]; + `check(y, 4'b0001); + + // Out-of-bounds + idx = -1; + y = arr[0][idx]; + `check(y, 4'b000x); + + // Undefined + idx = 'bx; + y = arr[0][idx]; + `check(y, 4'b000x); + + // The array as a primary is signed, sign extension + z = arr; + `check(z, 32'hffffffff); + + if (!failed) begin + $display("PASSED"); + end + end +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 8ab931c1a..6fe3647ff 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 +bitsel11 vvp_tests/bitsel11.json br_gh13a vvp_tests/br_gh13a.json br_gh13a-vlog95 vvp_tests/br_gh13a-vlog95.json br_gh939 vvp_tests/br_gh939.json diff --git a/ivtest/vvp_tests/bitsel11.json b/ivtest/vvp_tests/bitsel11.json new file mode 100644 index 000000000..ecfa7c265 --- /dev/null +++ b/ivtest/vvp_tests/bitsel11.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "bitsel11.v", + "iverilog-args" : [ "-g2005-sv" ] +}