-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functions should avoid non-local references #66
Functions should avoid non-local references #66
Conversation
VerilogCodingStyle.md
Outdated
); | ||
|
||
function automatic myfunc; | ||
return in_i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fact that functions reference anything non-local is bad.
The whole "continuous assignment from function" issue is moot if we just disallow the function from referencing anything non-local.
Gary has commented already, but I thought it might be worth adding a bit of background. Firstly, thank you very much for the contribution! It's really wonderful for us to be having an impact like you describe. About the technical side of things, I think @nbdd0121 is probably right: we'll end up with a simpler style guide if we just tell people not to have a function that refers to anything that isn't an argument. This will also have the property you want, and disallows other things that are probably not a great idea. Would you be happy to put together a version like that? We'd be very grateful! |
Thanks for the feedback! Yes, it seems that openTitan, Ibex, and CVA6 already follow that stricter rule. I did find one exception in Ibex, but it is for DV, so it probably doesn't matter: |
How does this look? |
Yup that's fine as it's not used by synthesisable code. It exists to give the testbench an easy way to read out performance counters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes, I think this is a really valuable addition to the style guide. I just added a few minor comments. Would you mind squashing your commits into one commit? If you don't know how to do that, I can do it for you.
added always@* note revert functions and non-local references improved wording applied requested changes Update VerilogCodingStyle.md
3acde29
to
f79b11c
Compare
Just squashed. Thanks for all the feedback! Although I wanted to get your opinion on another issue with functions. VCS 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 Maybe this should be a separate issue, but I wonder if there should be another rule against blanket calling of functions from assign/wire. It works fine if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks excellent! Thank you very much for the improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these changes!
Following up on the question about functions and continuous assignments: I didn't know that VCS wasn't happy with that! I just looked at IEEE 1800, and there's no mention of a constraint: the right hand side of a "net declaration assignment" seems to be an arbitrary expression in the syntax, at least. If we want to think carefully about style guide recommendations for this, maybe we should start a separate issue. |
We can probably add this in a separate PR, but it sounds like we should restrict assigning a functions output directly to a wire and mandate that this happens in an always_comb block. |
I think I'd prefer to outright ban style-guides/VerilogCodingStyle.md Lines 2702 to 2725 in 5cd912c
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 |
I personally don't think we should get rid of the wire shorthand. It is orthogonal to the reported VCS issue. The VCS issue probably is caused by the function being zero argument (and therefore not sensitive to anything). I think we should ban functions with no input instead. It could be a localparam instead. |
(pedantic mode on) Unfortunately, because many, many people have received the same poor instruction, that This language maybe gets a little too cute with defaults: // Equivalent variable declarations with initial values.
logic foo = bar;
var logic foo = bar;
// Equivalent net declarations with continuous assignment.
wire foo = bar;
wire logic foo = bar; |
I just created a new issue for this. We can discuss more here: #67 |
Hello. I'm a huge fan of this style guide, and I enforce it for all my students. Thank you!
In an Icarus issue (steveicarus/iverilog#983), we agreed that using continuous assignment from functions is inconsistent among tools and may deserve its own warning. I don't believe that the lowRISC style guide mentions this issue, so I wrote up a section on it.