Registers which have dangling input generates incorrect verilog
See original GitHub issueTicket migrated from:
https://github.com/ucb-bar/chisel3/issues/621
Correct behavior for register declaration in chisel is for register to keep the previous value even if the input is dangling. Current verilog generation does not have that behavior, instead the register is taken out to be a wire, so in synthesis, the wire is always floating instead of able to keep the initial random value.
Relevent portion from the chisel thread: Firrtl:
circuit RandTop :
module RandTop :
input clock : Clock
input reset : UInt<1>
output io : {out : UInt<32>}
clock is invalid
reset is invalid
io is invalid
reg rand : UInt<32>, clock @[Rand.scala 8:17]
io.out <= rand @[Rand.scala 9:10]
Current Verilog:
module RandTop(
input clock,
input reset,
output [31:0] io_out
);
reg [31:0] rand$;
reg [31:0] _GEN_0;
assign io_out = rand$;
`ifdef RANDOMIZE
integer initvar;
initial begin
`ifndef verilator
#0.002 begin end
`endif
`ifdef RANDOMIZE_REG_INIT
_GEN_0 = {1{$random}};
rand$ = _GEN_0[31:0];
`endif
end
`endif
endmodule
Should have:
module RandTop(
input clock,
input reset,
output [31:0] io_out
);
reg [31:0] rand$;
reg [31:0] _GEN_0;
assign io_out = rand$;
`ifdef RANDOMIZE
integer initvar;
initial begin
`ifndef verilator
#0.002 begin end
`endif
`ifdef RANDOMIZE_REG_INIT
_GEN_0 = {1{$random}};
rand$ = _GEN_0[31:0];
`endif
end
`endif
always @(posedge clock) begin
rand$ <= rand$;
// or perhaps
rand$ <= _GEN_0;
end
endmodule
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (17 by maintainers)
Top Results From Across the Web
Registers which have dangling input generates incorrect verilog
Best fix for this (IMO): tie it to 0 to match synthesis behavior, as we will actually simulate the case that's going on...
Read more >Errors and Warnings — Verilator 5.005 documentation
This usually indicates that the profile data was generated from a different Verilog source code than Verilator is currently running against. It is...
Read more >Systemverilog - Register Chain Simulation Problem
I wrote a Systemverilog code that gets an input and connects it to a chain of registers (I.E: a "word shift register"). The...
Read more >Verilog Coding Standard - fpgacpu.ca
When dealing with dangling wires. This is a rare case which usually happens when a module in a generate block is conditionally instantiated,...
Read more >SystemVerilog 3.1a Language Reference Manual - Index of /
This SystemVerilog Language Reference Manual was developed by experts from many different fields, includ- ing design and verification engineers, Electronic ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Registers should definitely still be randomized, as this is a fairly realistic model of the hardware.
There is a legitimate question as to whether disconnected wires should be, though. @jchang0 raises a good point that synthesis is more conservative than our simulation model by driving floating wires to 0. We should seriously consider following suit. Note, this will also improve simulation performance, possibly dramatically, as we can then constant-propagate code dependent on disconnected wires.
Similarly, constant-propagating registers that are not reset and never assigned makes sense.