diff options
author | Jannis Harder <me@jix.one> | 2022-05-20 21:46:39 +0200 |
---|---|---|
committer | Zachary Snow <zachary.j.snow@gmail.com> | 2022-05-30 09:11:31 -0400 |
commit | 4bfaaea0d52c235bb51c4dc54b07fe301eebe473 (patch) | |
tree | ff66a42daace95c965c6851036f907771d61af25 /tests | |
parent | ce24208a8bf74c25868c5073b0ff68a76b71d99f (diff) | |
download | yosys-4bfaaea0d52c235bb51c4dc54b07fe301eebe473.tar.gz yosys-4bfaaea0d52c235bb51c4dc54b07fe301eebe473.tar.bz2 yosys-4bfaaea0d52c235bb51c4dc54b07fe301eebe473.zip |
verilog: fix size and signedness of array querying functions
genrtlil.cc and simplify.cc had inconsistent and slightly broken
handling of signedness for array querying functions. These functions are
defined to return a signed result. Simplify always produced an unsigned
and genrtlil always a signed 32-bit result ignoring the context.
Includes tests for the the relvant edge cases for context dependent
conversions.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/verilog/sign_array_query.ys | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/verilog/sign_array_query.ys b/tests/verilog/sign_array_query.ys new file mode 100644 index 000000000..f955450b7 --- /dev/null +++ b/tests/verilog/sign_array_query.ys @@ -0,0 +1,52 @@ +logger -expect-no-warnings + +read_verilog -formal <<EOT +module top(input clk); + reg [-1:-1] x; + reg good = 0; + reg signed [31:0] zero = 0; + + always @(posedge clk) begin + case ($left(x) + zero) 36'shfffffffff: good = 1; endcase + assert (good); + end +endmodule +EOT + +prep -top top +sim -n 3 -clock clk + +design -reset + +read_verilog -formal <<EOT +module top(input clk); + reg [-1:-1] x; + reg good = 0; + + always @(posedge clk) begin + case ($left(x)) 36'sh0ffffffff: good = 1; (32'h0 + $left(good)): ; endcase + assert (good); + end + +endmodule +EOT + +prep -top top +sim -n 3 -clock clk + +design -reset + +read_verilog -formal <<EOT +module top(input clk); + reg [-1:-1] x; + reg good = 1; + + always @(posedge clk) begin + case (36'sh100000000 + $left(x)) -1: good = 0; endcase + assert (good); + end +endmodule +EOT + +prep -top top +sim -n 3 -clock clk |