3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 00:55:32 +00:00

sv: auto add nosync to certain always_comb local vars

If a local variable is always assigned before it is used, then adding
nosync prevents latches from being needlessly generated.
This commit is contained in:
Zachary Snow 2022-01-06 22:04:00 -07:00 committed by Zachary Snow
parent 828e85068f
commit aa35f24290
10 changed files with 265 additions and 0 deletions

View file

@ -0,0 +1,13 @@
read_verilog -sv <<EOF
module top;
logic x;
always_comb begin
logic y;
if (x)
y = 1;
x = y;
end
endmodule
EOF
logger -expect error "^Latch inferred for signal `\\top\.\$unnamed_block\$1\.y' from always_comb process" 1
proc

View file

@ -0,0 +1,15 @@
read_verilog -sv <<EOF
module top;
logic x;
always_comb begin
logic y;
if (x)
x = 1;
else
y = 1;
x = y;
end
endmodule
EOF
logger -expect error "^Latch inferred for signal `\\top\.\$unnamed_block\$1\.y' from always_comb process" 1
proc

View file

@ -0,0 +1,20 @@
read_verilog -sv <<EOF
module top;
logic x;
logic z;
assign z = 1'b1;
always_comb begin
logic y;
case (x)
1'b0:
y = 1;
endcase
if (z)
x = y;
else
x = 1'b0;
end
endmodule
EOF
logger -expect error "^Latch inferred for signal `\\top\.\$unnamed_block\$1\.y' from always_comb process" 1
proc

View file

@ -0,0 +1,17 @@
read_verilog -sv <<EOF
module top;
parameter AVOID_LATCH = 0;
logic x, z;
assign z = 1'b1;
always_comb begin
logic y;
if (z)
y = 0;
for (int i = 1; i == AVOID_LATCH; i++)
y = 1;
x = z ? y : 1'b0;
end
endmodule
EOF
logger -expect error "^Latch inferred for signal `\\top\.\$unnamed_block\$3\.y' from always_comb process" 1
proc

View file

@ -0,0 +1,16 @@
read_verilog -sv <<EOF
module top;
logic [4:0] x;
logic z;
assign z = 1'b1;
always_comb begin
x = '0;
if (z) begin
for (int i = 0; i < 5; i++) begin
x[i] = 1'b1;
end
end
end
endmodule
EOF
proc

View file

@ -0,0 +1,17 @@
read_verilog -sv <<EOF
module top;
logic [4:0] x;
logic z;
assign z = 1'b1;
always_comb begin
x = '0;
if (z) begin
int i;
for (i = 0; i < 5; i++) begin
x[i] = 1'b1;
end
end
end
endmodule
EOF
proc

View file

@ -0,0 +1,21 @@
read_verilog -sv <<EOF
module top;
logic x;
logic z;
assign z = 1'b1;
always_comb begin
logic y;
case (x)
1'b0:
y = 1;
default:
y = 0;
endcase
if (z)
x = y;
else
x = 1'b0;
end
endmodule
EOF
proc

View file

@ -0,0 +1,16 @@
read_verilog -sv <<EOF
module top;
parameter AVOID_LATCH = 1;
logic x, z;
assign z = 1'b1;
always_comb begin
logic y;
if (z)
y = 0;
for (int i = 1; i == AVOID_LATCH; i++)
y = 1;
x = z ? y : 1'b0;
end
endmodule
EOF
proc