Replace modules with internal cells, like $sr
#4662
Rodrigodd
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Some time ago, I asked on Slack how I could replace a module in a design with a
$sr
cell, but I never got a response. It took me a while to figure it out, so I thought it would be worth documenting that here.Basically, I have a Verilog module that simulates an SR-latch, but when this module is parsed by Yosys, it is translated into a combinatorial circuit driving a
$latch
cell. When translated back to Verilog and simulated, it would misbehave due to the order of signal evaluation.To avoid that, I needed to replace the entire module with a single
$sr
, which translates much better back to Verilog. Below is how I did that.For example, let's say the design has the following module:
One way to resolve this is to edit the module implementation to use a direct instance of the
$sr
cell and remember to pass the-icells
option to Yosys. However, if changing the original design is undesirable (since it would only work on Yosys), we can create a new module with the same signature as the original and automatically replace it in the design usingchtype
.So, you can create a module like this:
And then replace it in the original design:
You can do the same for any other internal cell. You only need to figure out the name of the output ports and parameters it requires. One way to figure this out is by checking
InternalCellChecker::check
inkernel/rtlil.cc
.In case the circuit you need to replace is not nicely contained in a module, you can use
extract
to isolate it into its own module and then later replace the module with one that uses the internal cell. I couldn't think of an illustrative example, but you can see it in action here.Beta Was this translation helpful? Give feedback.
All reactions