-
Notifications
You must be signed in to change notification settings - Fork 895
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
$print internal cell, for formatting tasks #3721
Conversation
First pass of docs are complete; they can be seen rendered here: https://kivikakk.github.io/yosys/CHAPTER_CellLib.html#debugging-cells |
These are really nice! |
I've now pushed a first pass at the CXXRTL implementation. Unordered notes:
edit: not translating all of |
Re: module top;
mid mid_uut ();
endmodule
module mid;
bot bot_uut ();
endmodule
module bot;
initial $display("%%l: %l\n%%m: %m");
endmodule Icarus Verilog gives:
Verilator gives:
We're currently showing |
Okay, I think I'm essentially done. I've opted not to reach for #2520 at this time, just so I don't bite off more than I can chew right now. Misc notes follow:
|
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.
please also add the new cell to techlibs/common/simlib.v
; preferably we'd have a working implementation that iverilog
can execute, but if that's infeasible (and it looks like it could be), at the very list it should have a blackbox with the right parameters and ports
Unless I'm missing something, I also think the lzero flag is redundant and the cell design can be easily simplified by removing it from the IR — AFAICS it can be simply lowered in the Verilog-to-cell conversion by setting padding to |
The cell in synchronous configuration seems quite reasonable to me (multiple triggers are a little weird though I see why it's done this way), but I think the async version semantics could use some discussion. The documentation mentions "printing at every step", which is ill-defined for many backends, and doesn't match the behavior of the source Verilog (which prints whenever any input to the containing comb process changes) nor Verilog backend output (which prints on any change of the format argument or the enable signal). While the documented semantics are implemented as-is in CXXRTL, this is rather suboptimal when one wants to watch a combinatorial signal that changes rarely. My proposal would be to define the cell to have the same behavior as what the Verilog backend currently emits: an async print cell prints whenever there's a change on An alternative would be to fully implement source Verilog behavior and track down all triggers of the containing process, but this doesn't seem that useful, and is rather unwieldy to implement. Also to be considered before the cell design is finalized: how about putting a |
👍 It's not hard to |
Yeah, having thought about it a bit, implemeting this cell here would be theoretically possible but incredibly unwieldy; let's just go with the blackbox and be done with it. |
Nice -- this keeps the logic for handling this case in one place, at parse time where it belongs. (96a766e) |
I agree! I wasn't quite sure what the behaviour of the Having played around with
Right, yes. For my curiosity and poking around, what's the most straightforward way to simulate source Verilog behaviour? Cursory testing shows that Verilator does indeed seem to by default --
This would at the very least simplify this test case a great deal! |
This is actually my original intent for the CXXRTL implementation.
No objection. |
I was thinking about the possibility of doing this in a pass (i.e. grouping by trigger and then concat format strings + args in priority order), to avoid complicating the backend, but this falls flat in the face of differing enable conditions. I'm also not sure if there are Verilog implementations with restrictions on system task arg counts to worry about. |
An alternative would be to create a print cell per process, have multiple enable inputs, and have some marker in the format string for "switch to the next enable in the list" (and presumably to a new line in the output); as a bonus, that'd ensure sane semantics in the async version. I'm not sure if I like this version, it's getting a bit complex; what do you think? |
I'm inclined to agree -- once the format string syntax starts getting stateful actions, it feels like it might grow a Common Lisp implementation when we're not looking. I don't think it's bad, but we can do well enough without the complexity imo. Having actually made the backend change (still local WIP), it's not so bad as I imagined, so I think we can leave the pass idea alone for now. |
OK!
It's also worth noting that Actions is triggering on my fork, so you can see early CI results: https://github.com/kivikakk/yosys/actions?query=branch%3Aprint-cell. |
(I gave this a spin in replacing a downstream solution for print cells I had, it works great, only thing I ran into is missing |
I'm interested in extending this in the future to support debug printing within SBY. This is what I'd eventually like to have:
It might be quite a while until I find time to work on this, (I also haven't gotten around to look at this PR in any detail yet), but I wanted to mention this now, in case anyone else is interested in working on this before I get to it or in case it's relevant for anything already in this PR. |
Ah, yep — seeing as the output stream now must be one of |
FYI I'm planning to give this a proper review sometime next week, hopefully Mon-Tue. |
See YosysHQ#3721 (comment) -- this reduces logic within the cell, and makes the rules that apply much more clear.
FWIW I pushed a rebase of this series below (there was slight conflict with #3722) |
Useful for error reporting of $display() arguments, etc.
"blk + chunks" is often an overrun, plus the fill is unnecessary; we throw blk away immediately.
Removing some signed checks and logic where we've already guaranteed the values to be positive. Indeed, in these cases, if a negative value got through (per my realisation in the signed fuzz harness), it would cause an infinite loop due to flooring division.
This is per fmt's (effective) use, as it turns out, so we're not losing any fidelity in the comparison.
It's possible to `generate` the appropriate always blocks per the triggers, but unlikely to be worth parsing the RTLIL \FORMAT parameter.
See #3721 (comment) -- this reduces logic within the cell, and makes the rules that apply much more clear.
Naming and use of statics to be possibly revised.
statics were obviously wrong -- may be multiple instantiations of any given module. Extend test to cover this.
Sort by PRIORITY, ensuring output order.
We add a new flow graph node type, PRINT_SYNC, as they don't get handled with regular CELL_EVALs. We could probably move this grouping out of the dump method.
See #3721 (comment) -- this reduces logic within the cell, and makes the rules that apply much more clear.
Absolutely fantastic work by everyone involved! This will be present in Yosys 0.33 release. |
Just in case this wasn't intentional let me point out this has gone in without the change to |
I suspect it wasn't intentional. @mwkmwkmwk could you take a look? |
Indeed, it has been removed in an earlier force-push on 13.05.2023; see the comparison linked above: https://github.com/YosysHQ/yosys/compare/2e16f9192401b5c83ce18e8651d57a4fd69c45c0..52a7bec44c23a3c6124ac1893705419308ba0c82 |
This seems to be the only commit that has been lost in that rebase. I've just cherry-picked it onto master. |
This is a rebase of @whitequark's #2459; so far this is back to the same stage it was at. I'll continue down the checklist from here.
Fmt::render
facility used by Yosys to print messages when it encountersinitial $display
statements and for$sformatf
.$print
cell.$print
cell and its format string mini-language.$print
cell handling in CXXRTL.%m
support that existed in the old$display
implementation (as an alias of%l
) but was removed because it is unclear whether this implementation is correct.$time
and%t
support to format strings.value
.