ivtest: Add regression test to check that shift rhs is always unsigned

Add a regression test to check that the right-hand side of a shift
operation is always treated as unsigned, even if it is a signed registers
or a variation thereof.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2024-09-02 19:05:02 +02:00
parent 50d9a32d56
commit 841e5a9d9e
3 changed files with 57 additions and 0 deletions

51
ivtest/ivltests/shift6.v Normal file
View File

@ -0,0 +1,51 @@
module test;
// Check that the right hand side for a shift instruction is always treated as
// unsigned. Even if its a signed register, or a transformation thereof.
reg failed = 1'b0;
`define check(val, exp) \
if ((val) !== (exp)) begin \
$display("FAILED(%0d): `%s`, expected `%0d`, got `%0d`.", `__LINE__, \
`"val`", (exp), (val), 4); \
failed = 1'b1; \
end
reg signed [1:0] shift = 2'b10;
initial begin
`check(1 << shift, 4)
`check(1 << shift[1:0], 4)
`check(2 << shift[1], 4)
`check(1 << $unsigned(shift), 4)
`check(1 << $signed(shift), 4)
`check(1 << {shift}, 4)
`check(1 <<< shift, 4)
`check(1 <<< shift[1:0], 4)
`check(2 <<< shift[1], 4)
`check(1 <<< $unsigned(shift), 4)
`check(1 <<< $signed(shift), 4)
`check(1 <<< {shift}, 4)
`check(16 >> shift, 4)
`check(16 >> shift[1:0], 4)
`check(8 >> shift[1], 4)
`check(16 >> $unsigned(shift), 4)
`check(16 >> $signed(shift), 4)
`check(16 >> {shift}, 4)
`check(16 >>> shift, 4)
`check(16 >>> shift[1:0], 4)
`check(8 >>> shift[1], 4)
`check(16 >>> $unsigned(shift), 4)
`check(16 >>> $signed(shift), 4)
`check(16 >>> {shift}, 4)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -185,6 +185,7 @@ sf_countones_fail vvp_tests/sf_countones_fail.json
sf_isunknown_fail vvp_tests/sf_isunknown_fail.json
sf_onehot_fail vvp_tests/sf_onehot_fail.json
sf_onehot0_fail vvp_tests/sf_onehot0_fail.json
shift6 vvp_tests/shift6.json
single_element_array vvp_tests/single_element_array.json
struct_enum_partsel vvp_tests/struct_enum_partsel.json
struct_field_left_right vvp_tests/struct_field_left_right.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "shift6.v"
}