lowRISC / lowRISC/style-guides
Continuous assignment from argumentless functions
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 541
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
This is a dedicated location to discuss a potential addition to the style guide to cover the following edge case:
VCS (2020.12) will currently not run this correctly:
module test;
function automatic [7:0] test_func;
test_func = 1;
endfunction
wire [7:0] test_wire = test_func();
initial begin
#1;
$display("Expected %h, Recieved %h", test_func(), test_wire);
// Will fail because test_func() is never run
$finish;
end
endmodule
Possible solutions
This is a summary of the discussion made in #66.
- Disallow calling of functions from
assign/wire.always_combshould be used instead. By @sifferman and @marnovandermaas - Disallow all wire assignments during declaration, (
wire [7:0] test = test_func()). By @GregAC - Disallow argumentless functions. By @nbdd0121
Full explanation by @GregAC in https://github.com/lowRISC/style-guides/issues/66#issuecomment-1662118280
I think I'd prefer to outright ban
wire [7:0] test = test_func()type statements. This is because their semantics varies depending upon the net type. Forwireyou do get the equivilent to a continuous assignment but forlogicit's just an initial value setting (much like aninitialblock though not identical! Those initial assignments are made before anyinitialblocks are run). Switchingwiretologicmay otherwise appear innocuous so better to avoid the complexity altogether. I note we explicitly allowed this currently:Initial assignments can be useful in FPGA but are deadly for ASIC synthesis as it's a great way to get simulation/synthesis mismatch where the FPGA version agrees with the simulation but the ASIC synthesis doesn't. If you confine them to an
'initialblock at least it makes it far obvious you have one. We could consider sayinginitialblocks are only allowed in RTL that is strictly for FPGA usage (e.g. top-levels and wrappers etc that we may use on FPGA to instantiate IP)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the discussion in issue #66 and the linked VerilogCodingStyle.md section referenced in this issue. Compare the proposed rules for function calls and declaration-time wire assignments, then determine which policy the style guide should state. Done means the guide contains an agreed, unambiguous rule covering the shown SystemVerilog example.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100