diff options
author | Jannis Harder <me@jix.one> | 2022-05-31 15:56:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 15:56:36 +0200 |
commit | 01cb02c81df14762cce117a823af742ed044a5c4 (patch) | |
tree | e766145cefa1dc2acf65be28fc0f12e9d0c51e49 /tests | |
parent | a79a228c2ba3259a1d8783f69990acd10e0efb5a (diff) | |
parent | a650d9079fa4732a6d118f2764d5abc2522a6b37 (diff) | |
download | yosys-01cb02c81df14762cce117a823af742ed044a5c4.tar.gz yosys-01cb02c81df14762cce117a823af742ed044a5c4.tar.bz2 yosys-01cb02c81df14762cce117a823af742ed044a5c4.zip |
Merge pull request #3348 from zachjs/func-tern-hint
verilog: fix width/sign detection for functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/verilog/func_tern_hint.sv | 42 | ||||
-rw-r--r-- | tests/verilog/func_tern_hint.ys | 4 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/verilog/func_tern_hint.sv b/tests/verilog/func_tern_hint.sv new file mode 100644 index 000000000..3c58c9913 --- /dev/null +++ b/tests/verilog/func_tern_hint.sv @@ -0,0 +1,42 @@ +module top; + function automatic [30:0] func; + input integer inp; + func = { // self-determined context + ( + inp == 0 + ? -1 // causes whole ternary to be 32 bits + : func(inp - 1) // 31 bits, unsigned + ) >> 2}; + endfunction + function automatic signed [3:0] dunk; + input integer inp; + dunk = ( + inp == 0 + ? 4'hF + // shouldn't make the ternary signed + : dunk(inp - 1) + ) == -1; + endfunction + localparam A = func(0); + localparam B = func(1); + localparam C = func(2); + localparam D = func(3); + localparam X = dunk(0); + localparam Y = dunk(1); + initial begin + assert(A == 31'h3F_FFFFFF); + assert(B == 31'h0F_FFFFFF); + assert(C == 31'h03_FFFFFF); + assert(D == 31'h00_FFFFFF); + assert(X == 0); + assert(Y == 0); + end + initial begin + logic x; + case (1'b1) + dunk(0): x = 0; + default: x = 1; + endcase + assert(x); + end +endmodule diff --git a/tests/verilog/func_tern_hint.ys b/tests/verilog/func_tern_hint.ys new file mode 100644 index 000000000..ab8a1e032 --- /dev/null +++ b/tests/verilog/func_tern_hint.ys @@ -0,0 +1,4 @@ +read_verilog -sv func_tern_hint.sv +proc +opt +sat -verify -seq 1 -prove-asserts -show-all |