aboutsummaryrefslogtreecommitdiffstats
path: root/tests/simple/case_expr_non_const.v
diff options
context:
space:
mode:
authorZachary Snow <zach@zachjs.com>2021-03-25 14:06:05 -0400
committerZachary Snow <zachary.j.snow@gmail.com>2021-05-25 16:16:46 -0400
commit0795b3ec076d8d2c0aa0d954b707271bd2f064bf (patch)
tree5b6c7eaef762a9dc76bb0507c76d0addcbdbb736 /tests/simple/case_expr_non_const.v
parent15f35d6754af619accdf63030e0a5ad3085cec16 (diff)
downloadyosys-0795b3ec076d8d2c0aa0d954b707271bd2f064bf.tar.gz
yosys-0795b3ec076d8d2c0aa0d954b707271bd2f064bf.tar.bz2
yosys-0795b3ec076d8d2c0aa0d954b707271bd2f064bf.zip
verilog: fix case expression sign and width handling
- The case expression and case item expressions are extended to the maximum width among them, and are only interpreted as signed if all of them are signed - Add overall width and sign detection for AST_CASE - Add sign argument to genWidthRTLIL helper - Coverage for both const and non-const case statements
Diffstat (limited to 'tests/simple/case_expr_non_const.v')
-rw-r--r--tests/simple/case_expr_non_const.v59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/simple/case_expr_non_const.v b/tests/simple/case_expr_non_const.v
new file mode 100644
index 000000000..7856e781c
--- /dev/null
+++ b/tests/simple/case_expr_non_const.v
@@ -0,0 +1,59 @@
+// Note: case_expr_{,non_}const.v should be modified in tandem to ensure both
+// the constant and non-constant case evaluation logic is covered
+module top(
+ // expected to output all 1s
+ output reg a, b, c, d, e, f, g, h
+);
+ reg x_1b0 = 1'b0;
+ reg x_1b1 = 1'b1;
+ reg signed x_1sb0 = 1'sb0;
+ reg signed x_1sb1 = 1'sb1;
+ reg [1:0] x_2b0 = 2'b0;
+ reg [1:0] x_2b11 = 2'b11;
+ reg signed [1:0] x_2sb01 = 2'sb01;
+ reg signed [1:0] x_2sb11 = 2'sb11;
+ reg [2:0] x_3b0 = 3'b0;
+
+ initial begin
+ case (x_2b0)
+ x_1b0: a = 1;
+ default: a = 0;
+ endcase
+ case (x_2sb11)
+ x_2sb01: b = 0;
+ x_1sb1: b = 1;
+ endcase
+ case (x_2sb11)
+ x_1sb0: c = 0;
+ x_1sb1: c = 1;
+ endcase
+ case (x_2sb11)
+ x_1b0: d = 0;
+ x_1sb1: d = 0;
+ default: d = 1;
+ endcase
+ case (x_2b11)
+ x_1sb0: e = 0;
+ x_1sb1: e = 0;
+ default: e = 1;
+ endcase
+ case (x_1sb1)
+ x_1sb0: f = 0;
+ x_2sb11: f = 1;
+ default: f = 0;
+ endcase
+ case (x_1sb1)
+ x_1sb0: g = 0;
+ x_3b0: g = 0;
+ x_2sb11: g = 0;
+ default: g = 1;
+ endcase
+ case (x_1sb1)
+ x_1sb0: h = 0;
+ x_1b1: h = 1;
+ x_3b0: h = 0;
+ x_2sb11: h = 0;
+ default: h = 0;
+ endcase
+ end
+endmodule