-
Notifications
You must be signed in to change notification settings - Fork 146
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
Slightly modernize compiler Verilog output #294
Slightly modernize compiler Verilog output #294
Conversation
I like the moving towards a more modern verilog as well as the move away from the synopsys pragmas from the early 90's. The changes always combinational blocks looks good. Vivado 2020.2 seems to like them. bsc generates codes like the following.
We should not add 'ifdef for YOSYS or any other 3rd party tool in generated code, setting BSV_NO_INITIAL_BLOCKS accompished the same. It is probably past time to deprecate the v95 flag. |
Ah, I forgot about the I can also work on removing the |
Hi! Regarding IEEE IEEE 1364.1 2005 at least specifies the use of
Many tools, including Yosys, Vivado, and Design Compiler support the |
I wonder if initial blocks should just be guarded by |
I agree that initial block should be made conditionally available for synthesis as well. |
I'd be content if we removed initial blocks. From a pure verilog
development view, they are a crutch to avoid X propagation issues. Within
bsc, they remained for legacy reasons to match simulation results with
bluesim.
However, the goal should be to support the various and conflicting
methodologies, which include both having initial blocks and not having
initial blocks. The use of BSV_NO_INITIAL_BLOCKS allows both extremes. The
-verilog-filter option can give you everything you might want.
Ed.
…On Wed, Jan 20, 2021 at 5:42 PM Kamyar Mohajerani ***@***.***> wrote:
I agree that initial block should be made conditionally available for
synthesis as well.
In addition, I'd very much like to have compiler flags which suppress
generation of macro-guarded blocks, such as these initialization blocks,
all together. Obviously initial blocks don't make sense for some targets
and applications (e.g. ASICs) and could potentially cause mismatches
between simulation and synthesis.
System task blocks on the other hand should be probably guarded with
SYNTHESIS. Some synthesis tools don't like them at all.
As for naming, BSC sounds like a better choice to me too, as long as it's
kept consistent.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#294 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB24HQGS77N4B54DSVXGD4LS25L5BANCNFSM4WFAAW4A>
.
|
The |
Sorry for the delay on this. Regarding all the comments on the output Verilog: I'm afraid I'm no expert in Verilog myself (I'm but a glorious, luxurious, exclusive user of alt-HDLs only, and only consider Verilog a "necessary evil"), but I agree there's definitely some design discussion to be had about the compiler output. I'll get this PR in shape so we can start thinking about the good stuff... I have a separate (somewhat radical) proposal that might hopefully lead to a useful discussion there, too. I'll try writing something up later. |
Synthesis tools like Yosys hate Synopsys pragmas, though they're supported (it doesn't support simulation constructs anyway, which is why.) It encourages `ifdef`s in order to handle this case, and always defines `YOSYS` to help -- they're more flexible and explicit. Currently for `initial` blocks in simulation that set initial register values, we use `translate_off` pragma to have the synthesis tool ignore things. But that block is already gated by `BSV_NO_INITIAL_BLOCKS` (so you can simulate without bogus default register content). So we extend that a bit. By nesting the `translate_off` and `_on` pragmas *inside* of an `ifndef YOSYS` clause (next to the `BSV_NO_INITIAL_BLOCKS` clause), Yosys will ignore the synopsys pragmas, and issue no warning for them at all. In the future, other tools or pragmas could be added to this chain, though this really is a specific workaround for a specific tool, to some extent. Though this also makes the resulting code *look* better IMO, since it scopes the pragma closer to its use site. Signed-off-by: Austin Seipp <aseipp@pobox.com>
Verilog 2001 attributes are supported by Vivado, Quartus, and other tools (like Yosys) in order to parallel/full case semantics. Usage of synopsys-specific synthesis comments can be done better this way, and it suppresses a real warning with Yosys. This takes us *out* of v95 territory, because Verilog attributes were added in Verilog 2001. Currently, no fallback is supported, though this could be fixed. It's unclear to me how much this harms "portability" of the output Verilog code, but such features can always be added back later on demand... Signed-off-by: Austin Seipp <aseipp@pobox.com>
Signed-off-by: Austin Seipp <aseipp@pobox.com>
9bf2bee
to
94da12c
Compare
@quark17 Sorry for the delay, but I think this should be ready now! (I've addressed the one nit by Ed) Let me know if anything else is needed. |
For the always-block issue: Rather than try to analyze the always-block to determine if it's a combinational always-block (which I think is going to be fragile), I would rather that this decision be specified by the place that creates the always-block. Specifically, I would change the If it helps, what's happening here is that BSC has generated an Note that BSC creates the combinational always-blocks in places where a continuous assignment is preferred, but Verilog does not allow writing the definition that way. For example, there is no case-expression, only case-statements, so any signal that is defined with a case-expression has to be written with an always-block. Further, BSC will declare that signal as For |
They are more than that. FPGA synthesis tools use initial blocks and assignments to establish the value held by the register or BRAM immediately after configuration. In fact, the initial value for a register doesn't even need to be the same as the "reset" value. If you remove initial blocks or disable them for synthesis, you would make it impossible for FPGA targeted designs to leverage this. |
Actually, I believe initial blocks do have another tangible advantage over resets on FPGAs in that the initial value can be encoded in the CRAM/power-on state, not using routed wires to enable a reset line. This can have the advantage that if your power on state is the same as reset (or you can activate some kind of "soft reset" through a reset controller), then you don't need any reset wires at all, which can help P&R since there will be less routing to handle, and thus less work to do. But this doesn't work on ASICs or even every FPGA I think (some Microsemi FPGAs lack initial CRAM values according to my memory) But I don't think that's quite relevant to the compiler output, which is my focus here. This problem seems much more like an API design question. For your proposed example where reset and initial are different, you'd almost certainly want a separate So I think there's definitely some API work that needs to be done for the FPGA families out there, but it's probably a wholly separate issue. There's definitely some stuff that could help that by being fixed in the compiler though... |
You are right: a discussion about the semantics the compiler should offer is of much broader scope than this change, which is just targeting how these particular semantics should be expressed. If we grant that the semantics of mkReg, mkRegU, and mkRegA are that they are "initialized" in simulation only and mkReg and mkRegA must be actively reset (not just powered-on configured) even on an FPGA, we can still usefully discuss the best Verilog text to express those semantics. To that end, your moving the "synopsys translate_" comments inside the ifdef BSV_NO_INITIAL_BLOCKS does seem like a reasonable hill-climb towards "better" to me. Not only that, but the src/Verilog/Reg.v versions all have the translate_* comments inside the ifdefs, so you could also argue that this change is just bringing the inline versions into alignment with their reference counterparts. |
@thoughtpolice, thank you again for pushing these improvements. I am about to tag a first release of BSC, and while I would really like to include these kinds of changes (to modernize the generated Verilog and Verilog primitives), I have decided to wait and make them a priority for the next release. (I will see about starting a "Discussions" page for what goes in the next release?) (1) The always-block commit here will need to change, according to my suggestions above. (Since I understand that code, I could just do that.) (2) Using attributes (instead of (3) Moving the In addition to your three commits: (4) I support replacing (5) Whether it's inside or outside, there's still the question of whether we need (6) I support removing the (7) And I would want to rename the macros starting with (8) And we should make sure that these changes are all applied to the primitives, as well, not just the generated code. I think all of these are something that we can do soon (right after tagging a first release), to be tested for when we tag a next release at the end of the year. (The plan is to tag releases in July and January; although I'm not opposed to tagging intermediate releases, if you need them.) Some of these are significant compatibility changes (and there will be others, like renaming the Verilog primitives, that you also suggested), so we will need to make this loudly apparent in the next release. But I also wonder if the release notes for the imminent release should warn users to prepare for upcoming changes. |
This fixes the Verilog output, as described in #118, and makes Yosys happy with the output from the
bsc
compiler. It basically movesbsc
into the realm of emitting Verilog 2001, which I think is an acceptable state of affairs.As explained in my comment in #118 located here, and basically: I think dropping psuedo Verilog 95 support and the
-v95
flag is probably the right thing to do (and more broadly I thinkbsc
shouldn't really try to please users of totally decrepit synthesis tools-that-only-accept-v95-but-probably-still-cost-10-billion-dollars-a-year, and alternative options like using Yosys to do this should be explored, but anyway...) However, this patch doesn't include that change or remove any of that code. I can add it if it seems reasonable, though.