Skip to content

Commit

Permalink
Merge pull request #3734 from jix/fix_unbased_unsized_const
Browse files Browse the repository at this point in the history
verilog: Fix const eval of unbased unsized constants
  • Loading branch information
jix authored Apr 24, 2023
2 parents 51dd029 + 985f492 commit cee3cb3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontends/ast/ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ RTLIL::Const AstNode::bitsAsConst(int width, bool is_signed)
bits.resize(width);
if (width >= 0 && width > int(bits.size())) {
RTLIL::State extbit = RTLIL::State::S0;
if (is_signed && !bits.empty())
if ((is_signed || is_unsized) && !bits.empty())
extbit = bits.back();
while (width > int(bits.size()))
bits.push_back(extbit);
Expand Down
28 changes: 28 additions & 0 deletions tests/verilog/unbased_unsized_shift.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module pass_through(
input [63:0] inp,
output [63:0] out
);
assign out = inp;
endmodule

module top;
logic [63:0] s0c, s1c, sxc, s0d, s1d, sxd, d;

pass_through pt(8, d);

assign s0c = '0 << 8;
assign s1c = '1 << 8;
assign sxc = 'x << 8;
assign s0d = '0 << d;
assign s1d = '1 << d;
assign sxd = 'x << d;

always @* begin
assert (s0c === 64'h0000_0000_0000_0000);
assert (s1c === 64'hFFFF_FFFF_FFFF_FF00);
assert (sxc === 64'hxxxx_xxxx_xxxx_xx00);
assert (s0d === 64'h0000_0000_0000_0000);
assert (s1d === 64'hFFFF_FFFF_FFFF_FF00);
assert (sxd === 64'hxxxx_xxxx_xxxx_xx00);
end
endmodule
7 changes: 7 additions & 0 deletions tests/verilog/unbased_unsized_shift.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
read_verilog -sv unbased_unsized_shift.sv
hierarchy
proc
flatten
opt -full
select -module top
sat -verify -seq 1 -tempinduct -prove-asserts -show-all

0 comments on commit cee3cb3

Please sign in to comment.