-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
When’ Requirement: Merging ‘setWhen’ and ‘clearWhen’ in Verilog Output #1419
Comments
I think there is a misunderstanding where this behavior comes from: it's not the current implementation of You can easily test this by adding another variant: val test = RegInit(False)
when(start) { test := True} elsewhen(end){ test := False} Which will generate if(start) begin
test <= 1'b1;
end else begin
if(end_1) begin
test <= 1'b0;
end
end so as long as you use So why does this happen with
TBH I don't see a simple way of changing this in the frontend, simply because stuff like this is totally allowed:
One could group those assignments in the backend, not rocket-science but also not trivial - and in general we try to do as few "optimizations" in the backend. Output that's not matching the SpinalHDL would be one of the worst case bugs - and less modifications means less that can go wrong. PS: which scala version are you using, the example that you posted did not compile for me as-is for 2.12 |
Thank you very much for your detailed reply. Regarding this issue, opinions vary from person to person, and it mainly depends on the thoughts of the majority and the actual necessity. The code I provided can be compiled and generate Verilog in my environment. In environments 2.11.12, 2.12.4, and 2.12.18, the aforementioned code can run (since it is AI-generated code (quite cheeky, I will eventually delegate some authority to AI, so might as well start sooner rather than later)), it does have some compatibility issues, IntelliJ will show red bars, but it does not affect the compilation and generation. I am using our project without any special settings, and I am also very curious about this issue! |
Damn me, I trusted IntelliJ - not the first "good code red" that I've seen... |
I wrote RTL code using SpinalHDL and generated Verilog. When I checked the output using Spyglass software, I encountered numerous warnings related to ‘multiple if statements assigning the same variable.’ Upon reviewing the code, I realized that these warnings were caused by the usage of setWhen and clearWhen. After discussing this, we believe that it’s better to use if/else if constructs whenever possible, as it improves code readability. What are your thoughts on this? Below is my demo code (where the AI_* case class were generated by AI prompts)
The text was updated successfully, but these errors were encountered: