mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-28 03:15:50 +00:00
Converting a number of inline commands to refs
Also reflowing text for line width. Maybe look into supporting commands with options?
This commit is contained in:
parent
f8333e52f7
commit
685da6a2e5
17 changed files with 398 additions and 384 deletions
|
@ -6,9 +6,9 @@ Installation and prerequisites
|
|||
==============================
|
||||
|
||||
This Application Note is based on the `Yosys GIT`_ `Rev. 2b90ba1`_ from
|
||||
2013-12-08. The README file covers how to install Yosys. The ``show`` command
|
||||
requires a working installation of `GraphViz`_ and `xdot` for generating the
|
||||
actual circuit diagrams.
|
||||
2013-12-08. The README file covers how to install Yosys. The :cmd:ref:`show`
|
||||
command requires a working installation of `GraphViz`_ and `xdot` for generating
|
||||
the actual circuit diagrams.
|
||||
|
||||
.. _Yosys GIT: https://github.com/YosysHQ/yosys
|
||||
|
||||
|
@ -23,8 +23,8 @@ Overview
|
|||
|
||||
This application note is structured as follows:
|
||||
|
||||
:ref:`intro_show` introduces the ``show`` command and explains the symbols used
|
||||
in the circuit diagrams generated by it.
|
||||
:ref:`intro_show` introduces the :cmd:ref:`show` command and explains the
|
||||
symbols used in the circuit diagrams generated by it.
|
||||
|
||||
:ref:`navigate` introduces additional commands used to navigate in the design,
|
||||
select portions of the design, and print additional information on the elements
|
||||
|
@ -41,7 +41,7 @@ Introduction to the show command
|
|||
================================
|
||||
|
||||
.. code-block:: console
|
||||
:caption: Yosys script with ``show`` commands and example design
|
||||
:caption: Yosys script with :cmd:ref:`show` commands and example design
|
||||
:name: example_src
|
||||
|
||||
$ cat example.ys
|
||||
|
@ -64,24 +64,24 @@ Introduction to the show command
|
|||
:class: width-helper
|
||||
:name: example_out
|
||||
|
||||
Output of the three ``show`` commands from :numref:`example_src`
|
||||
Output of the three :cmd:ref:`show` commands from :numref:`example_src`
|
||||
|
||||
The ``show`` command generates a circuit diagram for the design in its current
|
||||
state. Various options can be used to change the appearance of the circuit
|
||||
diagram, set the name and format for the output file, and so forth. When called
|
||||
without any special options, it saves the circuit diagram in a temporary file
|
||||
and launches ``xdot`` to display the diagram. Subsequent calls to show re-use the
|
||||
``xdot`` instance (if still running).
|
||||
The :cmd:ref:`show` command generates a circuit diagram for the design in its
|
||||
current state. Various options can be used to change the appearance of the
|
||||
circuit diagram, set the name and format for the output file, and so forth. When
|
||||
called without any special options, it saves the circuit diagram in a temporary
|
||||
file and launches ``xdot`` to display the diagram. Subsequent calls to show
|
||||
re-use the ``xdot`` instance (if still running).
|
||||
|
||||
A simple circuit
|
||||
----------------
|
||||
|
||||
:numref:`example_src` shows a simple synthesis script and a Verilog file that
|
||||
demonstrate the usage of show in a simple setting. Note that ``show`` is called with
|
||||
the ``-pause`` option, that halts execution of the Yosys script until the user
|
||||
presses the Enter key. The ``show -pause`` command also allows the user to enter
|
||||
an interactive shell to further investigate the circuit before continuing
|
||||
synthesis.
|
||||
demonstrate the usage of show in a simple setting. Note that :cmd:ref:`show` is
|
||||
called with the :cmd:ref:`-pause` option, that halts execution of the Yosys
|
||||
script until the user presses the Enter key. The ``show -pause`` command also
|
||||
allows the user to enter an interactive shell to further investigate the circuit
|
||||
before continuing synthesis.
|
||||
|
||||
So this script, when executed, will show the design after each of the three
|
||||
synthesis commands. The generated circuit diagrams are shown in
|
||||
|
@ -111,28 +111,28 @@ original ``always``-block in the 2nd line. Note how the multiplexer from the
|
|||
``?:``-expression is represented as a ``$mux`` cell but the multiplexer from the
|
||||
``if``-statement is yet still hidden within the process.
|
||||
|
||||
The ``proc`` command transforms the process from the first diagram into a
|
||||
The :cmd:ref:`proc` command transforms the process from the first diagram into a
|
||||
multiplexer and a d-type flip-flip, which brings us to the 2nd diagram.
|
||||
|
||||
The Rhombus shape to the right is a dangling wire. (Wire nodes are only shown if
|
||||
they are dangling or have "public" names, for example names assigned from the
|
||||
Verilog input.) Also note that the design now contains two instances of a
|
||||
``BUF``-node. This are artefacts left behind by the ``proc``-command. It is
|
||||
quite usual to see such artefacts after calling commands that perform changes in
|
||||
the design, as most commands only care about doing the transformation in the
|
||||
``BUF``-node. This are artefacts left behind by the :cmd:ref:`proc` command. It
|
||||
is quite usual to see such artefacts after calling commands that perform changes
|
||||
in the design, as most commands only care about doing the transformation in the
|
||||
least complicated way, not about cleaning up after them. The next call to
|
||||
``clean`` (or ``opt``, which includes ``clean`` as one of its operations) will
|
||||
clean up this artefacts. This operation is so common in Yosys scripts that it
|
||||
can simply be abbreviated with the ``;;`` token, which doubles as separator for
|
||||
commands. Unless one wants to specifically analyze this artefacts left behind
|
||||
some operations, it is therefore recommended to always call ``clean`` before
|
||||
calling ``show``.
|
||||
:cmd:ref:`clean` (or :cmd:ref:`proc`, which includes :cmd:ref:`clean` as one of
|
||||
its operations) will clean up this artefacts. This operation is so common in
|
||||
Yosys scripts that it can simply be abbreviated with the ``;;`` token, which
|
||||
doubles as separator for commands. Unless one wants to specifically analyze this
|
||||
artefacts left behind some operations, it is therefore recommended to always
|
||||
call :cmd:ref:`clean` before calling :cmd:ref:`show`.
|
||||
|
||||
In this script we directly call ``opt`` as next step, which finally leads us to
|
||||
the 3rd diagram in :numref:`example_out`. Here we see that the ``opt`` command
|
||||
not only has removed the artifacts left behind by ``proc``, but also determined
|
||||
correctly that it can remove the first ``$mux`` cell without changing the
|
||||
behavior of the circuit.
|
||||
In this script we directly call :cmd:ref:`proc` as next step, which finally
|
||||
leads us to the 3rd diagram in :numref:`example_out`. Here we see that the
|
||||
:cmd:ref:`proc` command not only has removed the artifacts left behind by
|
||||
:cmd:ref:`proc`, but also determined correctly that it can remove the first
|
||||
``$mux`` cell without changing the behavior of the circuit.
|
||||
|
||||
.. figure:: ../../images/011/splice.*
|
||||
:class: width-helper
|
||||
|
@ -148,7 +148,7 @@ behavior of the circuit.
|
|||
:class: width-helper
|
||||
:name: splitnets_libfile
|
||||
|
||||
Effects of ``splitnets`` command and of providing a cell library. (The
|
||||
Effects of :cmd:ref:`splitnets` command and of providing a cell library. (The
|
||||
circuit is a half-adder built from simple CMOS gates.)
|
||||
|
||||
Break-out boxes for signal vectors
|
||||
|
@ -158,8 +158,8 @@ As has been indicated by the last example, Yosys is can manage signal vectors
|
|||
(aka. multi-bit wires or buses) as native objects. This provides great
|
||||
advantages when analyzing circuits that operate on wide integers. But it also
|
||||
introduces some additional complexity when the individual bits of of a signal
|
||||
vector are accessed. The example ``show`` in :numref:`splice_src` demonstrates
|
||||
how such circuits are visualized by the ``show`` command.
|
||||
vector are accessed. The example :cmd:ref:`show` in :numref:`splice_src`
|
||||
demonstrates how such circuits are visualized by the :cmd:ref:`show` command.
|
||||
|
||||
The key elements in understanding this circuit diagram are of course the boxes
|
||||
with round corners and rows labeled ``<MSB_LEFT>:<LSB_LEFT> -
|
||||
|
@ -191,11 +191,11 @@ bits, resulting in an unnecessary complex diagram.
|
|||
For the 2nd diagram Yosys has been given a description of the cell library as
|
||||
Verilog file containing blackbox modules. There are two ways to load cell
|
||||
descriptions into Yosys: First the Verilog file for the cell library can be
|
||||
passed directly to the ``show`` command using the ``-lib <filename>`` option.
|
||||
Secondly it is possible to load cell libraries into the design with the
|
||||
passed directly to the :cmd:ref:`show` command using the ``-lib <filename>``
|
||||
option. Secondly it is possible to load cell libraries into the design with the
|
||||
``read_verilog -lib <filename>`` command. The 2nd method has the great advantage
|
||||
that the library only needs to be loaded once and can then be used in all
|
||||
subsequent calls to the ``show`` command.
|
||||
subsequent calls to the :cmd:ref:`show` command.
|
||||
|
||||
In addition to that, the 2nd diagram was generated after ``splitnet -ports`` was
|
||||
run on the design. This command splits all signal vectors into individual signal
|
||||
|
@ -206,21 +206,21 @@ command only operates on interior signals.
|
|||
Miscellaneous notes
|
||||
-------------------
|
||||
|
||||
Per default the ``show`` command outputs a temporary dot file and launches
|
||||
``xdot`` to display it. The options ``-format``, ``-viewer`` and ``-prefix`` can
|
||||
be used to change format, viewer and filename prefix. Note that the ``pdf`` and
|
||||
``ps`` format are the only formats that support plotting multiple modules in one
|
||||
run.
|
||||
Per default the :cmd:ref:`show` command outputs a temporary dot file and
|
||||
launches ``xdot`` to display it. The options ``-format``, ``-viewer`` and
|
||||
``-prefix`` can be used to change format, viewer and filename prefix. Note that
|
||||
the ``pdf`` and ``ps`` format are the only formats that support plotting
|
||||
multiple modules in one run.
|
||||
|
||||
In densely connected circuits it is sometimes hard to keep track of the
|
||||
individual signal wires. For this cases it can be useful to call ``show`` with
|
||||
the ``-colors <integer>`` argument, which randomly assigns colors to the nets.
|
||||
The integer (> 0) is used as seed value for the random color assignments.
|
||||
individual signal wires. For this cases it can be useful to call :cmd:ref:`show`
|
||||
with the ``-colors <integer>`` argument, which randomly assigns colors to the
|
||||
nets. The integer (> 0) is used as seed value for the random color assignments.
|
||||
Sometimes it is necessary it try some values to find an assignment of colors
|
||||
that looks good.
|
||||
|
||||
The command ``help show`` prints a complete listing of all options supported by
|
||||
the ``show`` command.
|
||||
the :cmd:ref:`show` command.
|
||||
|
||||
.. _navigate:
|
||||
|
||||
|
@ -232,13 +232,13 @@ only helps in simple cases. For complex modules the generated circuit
|
|||
diagrams are just stupidly big and are no help at all. In such cases one
|
||||
first has to select the relevant portions of the circuit.
|
||||
|
||||
In addition to *what* to display one also needs to carefully decide *when*
|
||||
to display it, with respect to the synthesis flow. In general it is a
|
||||
good idea to troubleshoot a circuit in the earliest state in which a
|
||||
problem can be reproduced. So if, for example, the internal state before
|
||||
calling the ``techmap`` command already fails to verify, it is better to
|
||||
troubleshoot the coarse-grain version of the circuit before ``techmap`` than
|
||||
the gate-level circuit after ``techmap``.
|
||||
In addition to *what* to display one also needs to carefully decide *when* to
|
||||
display it, with respect to the synthesis flow. In general it is a good idea to
|
||||
troubleshoot a circuit in the earliest state in which a problem can be
|
||||
reproduced. So if, for example, the internal state before calling the
|
||||
:cmd:ref:`techmap` command already fails to verify, it is better to troubleshoot
|
||||
the coarse-grain version of the circuit before :cmd:ref:`techmap` than the
|
||||
gate-level circuit after :cmd:ref:`techmap`.
|
||||
|
||||
.. Note:: It is generally recommended to verify the internal state of a
|
||||
design by writing it to a Verilog file using ``write_verilog -noexpr``
|
||||
|
@ -249,7 +249,7 @@ Interactive navigation
|
|||
----------------------
|
||||
|
||||
.. code-block:: none
|
||||
:caption: Demonstration of ``ls`` and ``cd`` using ``example.v`` from :numref:`example_src`
|
||||
:caption: Demonstration of :cmd:ref:`ls` and :cmd:ref:`cd` using ``example.v`` from :numref:`example_src`
|
||||
:name: lscd
|
||||
|
||||
yosys> ls
|
||||
|
@ -293,17 +293,17 @@ Interactive navigation
|
|||
end
|
||||
|
||||
Once the right state within the synthesis flow for debugging the circuit has
|
||||
been identified, it is recommended to simply add the ``shell`` command to the
|
||||
matching place in the synthesis script. This command will stop the synthesis at
|
||||
the specified moment and go to shell mode, where the user can interactively
|
||||
been identified, it is recommended to simply add the :cmd:ref:`shell` command to
|
||||
the matching place in the synthesis script. This command will stop the synthesis
|
||||
at the specified moment and go to shell mode, where the user can interactively
|
||||
enter commands.
|
||||
|
||||
For most cases, the shell will start with the whole design selected (i.e. when
|
||||
the synthesis script does not already narrow the selection). The command ``ls``
|
||||
can now be used to create a list of all modules. The command ``cd`` can be used
|
||||
to switch to one of the modules (type ``cd ..`` to switch back). Now the `ls`
|
||||
command lists the objects within that module. :numref:`lscd` demonstrates this
|
||||
using the design from :numref:`example_src`.
|
||||
the synthesis script does not already narrow the selection). The command
|
||||
:cmd:ref:`ls` can now be used to create a list of all modules. The command
|
||||
:cmd:ref:`cd` can be used to switch to one of the modules (type ``cd ..`` to
|
||||
switch back). Now the `ls` command lists the objects within that module.
|
||||
:numref:`lscd` demonstrates this using the design from :numref:`example_src`.
|
||||
|
||||
There is a thing to note in :numref:`lscd`: We can see that the cell names from
|
||||
:numref:`example_out` are just abbreviations of the actual cell names, namely
|
||||
|
@ -312,16 +312,16 @@ starting with a dollar sign) are rather long and contains some additional
|
|||
information on the origin of the named object. But in most cases those names can
|
||||
simply be abbreviated using the last part.
|
||||
|
||||
Usually all interactive work is done with one module selected using the ``cd``
|
||||
command. But it is also possible to work from the design-context (``cd ..``). In
|
||||
this case all object names must be prefixed with ``<module_name>/``. For example
|
||||
``a*/b*`` would refer to all objects whose names start with ``b`` from all
|
||||
modules whose names start with ``a``.
|
||||
Usually all interactive work is done with one module selected using the
|
||||
:cmd:ref:`cd` command. But it is also possible to work from the design-context
|
||||
(``cd ..``). In this case all object names must be prefixed with
|
||||
``<module_name>/``. For example ``a*/b*`` would refer to all objects whose names
|
||||
start with ``b`` from all modules whose names start with ``a``.
|
||||
|
||||
The ``dump`` command can be used to print all information about an object. For
|
||||
example ``dump $2`` will print :numref:`dump2`. This can for example be useful
|
||||
to determine the names of nets connected to cells, as the net-names are usually
|
||||
suppressed in the circuit diagram if they are auto-generated.
|
||||
The :cmd:ref:`dump` command can be used to print all information about an
|
||||
object. For example ``dump $2`` will print :numref:`dump2`. This can for example
|
||||
be useful to determine the names of nets connected to cells, as the net-names
|
||||
are usually suppressed in the circuit diagram if they are auto-generated.
|
||||
|
||||
For the remainder of this document we will assume that the commands are
|
||||
run from module-context and not design-context.
|
||||
|
@ -333,23 +333,24 @@ Working with selections
|
|||
:class: width-helper
|
||||
:name: seladd
|
||||
|
||||
Output of ``show`` after ``select $2`` or ``select t:$add`` (see also
|
||||
Output of :cmd:ref:`show` after ``select $2`` or ``select t:$add`` (see also
|
||||
:numref:`example_out`)
|
||||
|
||||
When a module is selected using the ``cd`` command, all commands (with a few
|
||||
exceptions, such as the ``read_`` and ``write_`` commands) operate only on the
|
||||
selected module. This can also be useful for synthesis scripts where different
|
||||
synthesis strategies should be applied to different modules in the design.
|
||||
When a module is selected using the :cmd:ref:`cd` command, all commands (with a
|
||||
few exceptions, such as the ``read_`` and ``write_`` commands) operate only on
|
||||
the selected module. This can also be useful for synthesis scripts where
|
||||
different synthesis strategies should be applied to different modules in the
|
||||
design.
|
||||
|
||||
But for most interactive work we want to further narrow the set of
|
||||
selected objects. This can be done using the ``select`` command.
|
||||
But for most interactive work we want to further narrow the set of selected
|
||||
objects. This can be done using the :cmd:ref:`select` command.
|
||||
|
||||
For example, if the command ``select $2`` is executed, a subsequent ``show``
|
||||
command will yield the diagram shown in :numref:`seladd`. Note that the nets are
|
||||
now displayed in ellipses. This indicates that they are not selected, but only
|
||||
shown because the diagram contains a cell that is connected to the net. This of
|
||||
course makes no difference for the circuit that is shown, but it can be a useful
|
||||
information when manipulating selections.
|
||||
For example, if the command ``select $2`` is executed, a subsequent
|
||||
:cmd:ref:`show` command will yield the diagram shown in :numref:`seladd`. Note
|
||||
that the nets are now displayed in ellipses. This indicates that they are not
|
||||
selected, but only shown because the diagram contains a cell that is connected
|
||||
to the net. This of course makes no difference for the circuit that is shown,
|
||||
but it can be a useful information when manipulating selections.
|
||||
|
||||
Objects can not only be selected by their name but also by other properties. For
|
||||
example ``select t:$add`` will select all cells of type ``$add``. In this case
|
||||
|
@ -366,13 +367,13 @@ matching different properties.
|
|||
Many commands can operate on explicit selections. For example the command ``dump
|
||||
t:$add`` will print information on all ``$add`` cells in the active module.
|
||||
Whenever a command has ``[selection]`` as last argument in its usage help, this
|
||||
means that it will use the engine behind the ``select`` command to evaluate
|
||||
additional arguments and use the resulting selection instead of the selection
|
||||
created by the last ``select`` command.
|
||||
means that it will use the engine behind the :cmd:ref:`select` command to
|
||||
evaluate additional arguments and use the resulting selection instead of the
|
||||
selection created by the last :cmd:ref:`select` command.
|
||||
|
||||
Normally the ``select`` command overwrites a previous selection. The commands
|
||||
``select -add`` and ``select -del`` can be used to add or remove objects from
|
||||
the current selection.
|
||||
Normally the :cmd:ref:`select` command overwrites a previous selection. The
|
||||
commands ``select -add`` and ``select -del`` can be used to add or remove
|
||||
objects from the current selection.
|
||||
|
||||
The command ``select -clear`` can be used to reset the selection to the default,
|
||||
which is a complete selection of everything in the current module.
|
||||
|
@ -391,9 +392,9 @@ Operations on selections
|
|||
|
||||
Output of ``show a:sumstuff`` on :numref:`sumprod`
|
||||
|
||||
The ``select`` command is actually much more powerful than it might seem on the
|
||||
first glimpse. When it is called with multiple arguments, each argument is
|
||||
evaluated and pushed separately on a stack. After all arguments have been
|
||||
The :cmd:ref:`select` command is actually much more powerful than it might seem
|
||||
on the first glimpse. When it is called with multiple arguments, each argument
|
||||
is evaluated and pushed separately on a stack. After all arguments have been
|
||||
processed it simply creates the union of all elements on the stack. So the
|
||||
following command will select all ``$add`` cells and all objects with the
|
||||
``foo`` attribute set:
|
||||
|
@ -445,7 +446,7 @@ Selecting logic cones
|
|||
:numref:`sumprod_01` shows what is called the ``input cone`` of ``sum``, i.e.
|
||||
all cells and signals that are used to generate the signal ``sum``. The ``%ci``
|
||||
action can be used to select the input cones of all object in the top selection
|
||||
in the stack maintained by the ``select`` command.
|
||||
in the stack maintained by the :cmd:ref:`select` command.
|
||||
|
||||
As the ``%x`` action, this commands broadens the selection by one "step".
|
||||
But this time the operation only works against the direction of data
|
||||
|
@ -484,8 +485,8 @@ appended to the ``%ci`` action.
|
|||
Lets consider the design from :numref:`memdemo_src`. It serves no purpose other
|
||||
than being a non-trivial circuit for demonstrating some of the advanced Yosys
|
||||
features. We synthesize the circuit using ``proc; opt; memory; opt`` and change
|
||||
to the ``memdemo`` module with ``cd memdemo``. If we type ``show`` now we see
|
||||
the diagram shown in :numref:`memdemo_00`.
|
||||
to the ``memdemo`` module with ``cd memdemo``. If we type :cmd:ref:`show` now we
|
||||
see the diagram shown in :numref:`memdemo_00`.
|
||||
|
||||
.. literalinclude:: ../APPNOTE_011_Design_Investigation/memdemo.v
|
||||
:caption: Demo circuit for demonstrating some advanced Yosys features
|
||||
|
@ -580,7 +581,7 @@ Storing and recalling selections
|
|||
The current selection can be stored in memory with the command ``select -set
|
||||
<name>``. It can later be recalled using ``select @<name>``. In fact, the
|
||||
``@<name>`` expression pushes the stored selection on the stack maintained by
|
||||
the ``select`` command. So for example
|
||||
the :cmd:ref:`select` command. So for example
|
||||
|
||||
.. code-block:: yoscrypt
|
||||
|
||||
|
@ -593,9 +594,9 @@ script that sets up relevant selections, so they can easily be recalled,
|
|||
for example when Yosys needs to be re-run after a design or source code
|
||||
change.
|
||||
|
||||
The ``history`` command can be used to list all recent interactive commands.
|
||||
This feature can be useful for creating such a script from the commands
|
||||
used in an interactive session.
|
||||
The :cmd:ref:`history` command can be used to list all recent interactive
|
||||
commands. This feature can be useful for creating such a script from the
|
||||
commands used in an interactive session.
|
||||
|
||||
.. _poke:
|
||||
|
||||
|
@ -610,10 +611,10 @@ of the module and wants to carefully read all the debug output created by the
|
|||
commands in order to spot a problem. This kind of troubleshooting is much easier
|
||||
if the circuit under investigation is encapsulated in a separate module.
|
||||
|
||||
:numref:`submod` shows how the ``submod`` command can be used to split the
|
||||
circuit from :numref:`memdemo_src` and :numref:`memdemo_00` into its components.
|
||||
The ``-name`` option is used to specify the name of the new module and also the
|
||||
name of the new cell in the current module.
|
||||
:numref:`submod` shows how the :cmd:ref:`submod` command can be used to split
|
||||
the circuit from :numref:`memdemo_src` and :numref:`memdemo_00` into its
|
||||
components. The ``-name`` option is used to specify the name of the new module
|
||||
and also the name of the new cell in the current module.
|
||||
|
||||
.. figure:: ../../images/011/submod_dots.*
|
||||
:class: width-helper
|
||||
|
@ -621,7 +622,7 @@ name of the new cell in the current module.
|
|||
|
||||
.. code-block:: yoscrypt
|
||||
:caption: The circuit from :numref:`memdemo_src` and :numref:`memdemo_00`
|
||||
broken up using ``submod``
|
||||
broken up using :cmd:ref:`submod`
|
||||
:name: submod
|
||||
|
||||
select -set outstage y %ci2:+$dff[Q,D] %ci*:-$mux[S]:-$dff
|
||||
|
@ -634,8 +635,8 @@ name of the new cell in the current module.
|
|||
Evaluation of combinatorial circuits
|
||||
------------------------------------
|
||||
|
||||
The ``eval`` command can be used to evaluate combinatorial circuits. For example
|
||||
(see :numref:`submod` for the circuit diagram of ``selstage``):
|
||||
The :cmd:ref:`eval` command can be used to evaluate combinatorial circuits. For
|
||||
example (see :numref:`submod` for the circuit diagram of ``selstage``):
|
||||
|
||||
::
|
||||
|
||||
|
@ -676,11 +677,11 @@ The ``-table`` option can be used to create a truth table. For example:
|
|||
|
||||
Assumed undef (x) value for the following signals: \s2
|
||||
|
||||
Note that the ``eval`` command (as well as the ``sat`` command discussed in the
|
||||
next sections) does only operate on flattened modules. It can not analyze
|
||||
signals that are passed through design hierarchy levels. So the ``flatten``
|
||||
command must be used on modules that instantiate other modules before this
|
||||
commands can be applied.
|
||||
Note that the :cmd:ref:`eval` command (as well as the :cmd:ref:`sat` command
|
||||
discussed in the next sections) does only operate on flattened modules. It can
|
||||
not analyze signals that are passed through design hierarchy levels. So the
|
||||
:cmd:ref:`flatten` command must be used on modules that instantiate other
|
||||
modules before this commands can be applied.
|
||||
|
||||
Solving combinatorial SAT problems
|
||||
----------------------------------
|
||||
|
@ -754,18 +755,18 @@ Solving combinatorial SAT problems
|
|||
\____ $$$|__/|________/|__/|_______/|__/
|
||||
\__/
|
||||
|
||||
Often the opposite of the ``eval`` command is needed, i.e. the circuits output
|
||||
is given and we want to find the matching input signals. For small circuits with
|
||||
only a few input bits this can be accomplished by trying all possible input
|
||||
combinations, as it is done by the ``eval -table`` command. For larger circuits
|
||||
however, Yosys provides the ``sat`` command that uses a `SAT`_ solver,
|
||||
`MiniSAT`_, to solve this kind of problems.
|
||||
Often the opposite of the :cmd:ref:`eval` command is needed, i.e. the circuits
|
||||
output is given and we want to find the matching input signals. For small
|
||||
circuits with only a few input bits this can be accomplished by trying all
|
||||
possible input combinations, as it is done by the ``eval -table`` command. For
|
||||
larger circuits however, Yosys provides the :cmd:ref:`sat` command that uses a
|
||||
`SAT`_ solver, `MiniSAT`_, to solve this kind of problems.
|
||||
|
||||
.. _SAT: http://en.wikipedia.org/wiki/Circuit_satisfiability
|
||||
|
||||
.. _MiniSAT: http://minisat.se/
|
||||
|
||||
The ``sat`` command works very similar to the ``eval`` command. The main
|
||||
The :cmd:ref:`sat` command works very similar to the :cmd:ref:`eval` command. The main
|
||||
difference is that it is now also possible to set output values and find the
|
||||
corresponding input values. For Example:
|
||||
|
||||
|
@ -792,8 +793,8 @@ corresponding input values. For Example:
|
|||
\s1 0 0 00
|
||||
\s2 0 0 00
|
||||
|
||||
Note that the ``sat`` command supports signal names in both arguments to the
|
||||
``-set`` option. In the above example we used ``-set s1 s2`` to constraint
|
||||
Note that the :cmd:ref:`sat` command supports signal names in both arguments to
|
||||
the ``-set`` option. In the above example we used ``-set s1 s2`` to constraint
|
||||
``s1`` and ``s2`` to be equal. When more complex constraints are needed, a
|
||||
wrapper circuit must be constructed that checks the constraints and signals if
|
||||
the constraint was met using an extra output port, which then can be forced to a
|
||||
|
@ -812,8 +813,8 @@ of course be to perform the test in 32 bits, for example by replacing ``p !=
|
|||
a*b`` in the miter with ``p != {16'd0,a}b``, or by using a temporary variable
|
||||
for the 32 bit product ``a*b``. But as 31 fits well into 8 bits (and as the
|
||||
purpose of this document is to show off Yosys features) we can also simply force
|
||||
the upper 8 bits of ``a`` and ``b`` to zero for the ``sat`` call, as is done in
|
||||
the second command in :numref:`primesat` (line 31).
|
||||
the upper 8 bits of ``a`` and ``b`` to zero for the :cmd:ref:`sat` call, as is
|
||||
done in the second command in :numref:`primesat` (line 31).
|
||||
|
||||
The ``-prove`` option used in this example works similar to ``-set``, but tries
|
||||
to find a case in which the two arguments are not equal. If such a case is not
|
||||
|
@ -917,18 +918,18 @@ to this question, as produced by the following command:
|
|||
sat -seq 6 -show y -show d -set-init-undef \
|
||||
-max_undef -set-at 4 y 1 -set-at 5 y 2 -set-at 6 y 3
|
||||
|
||||
The ``-seq 6`` option instructs the ``sat`` command to solve a sequential
|
||||
The ``-seq 6`` option instructs the :cmd:ref:`sat` command to solve a sequential
|
||||
problem in 6 time steps. (Experiments with lower number of steps have show that
|
||||
at least 3 cycles are necessary to bring the circuit in a state from which the
|
||||
sequence 1, 2, 3 can be produced.)
|
||||
|
||||
The ``-set-init-undef`` option tells the ``sat`` command to initialize all
|
||||
registers to the undef (``x``) state. The way the ``x`` state is treated in
|
||||
The ``-set-init-undef`` option tells the :cmd:ref:`sat` command to initialize
|
||||
all registers to the undef (``x``) state. The way the ``x`` state is treated in
|
||||
Verilog will ensure that the solution will work for any initial state.
|
||||
|
||||
The ``-max_undef`` option instructs the ``sat`` command to find a solution with
|
||||
a maximum number of undefs. This way we can see clearly which inputs bits are
|
||||
relevant to the solution.
|
||||
The ``-max_undef`` option instructs the :cmd:ref:`sat` command to find a
|
||||
solution with a maximum number of undefs. This way we can see clearly which
|
||||
inputs bits are relevant to the solution.
|
||||
|
||||
Finally the three ``-set-at`` options add constraints for the ``y`` signal to
|
||||
play the 1, 2, 3 sequence, starting with time step 4.
|
||||
|
@ -938,27 +939,27 @@ is the only way of setting the ``s1`` and ``s2`` registers to a known value. The
|
|||
input values for the other steps are a bit harder to work out manually, but the
|
||||
SAT solver finds the correct solution in an instant.
|
||||
|
||||
There is much more to write about the ``sat`` command. For example, there is a
|
||||
set of options that can be used to performs sequential proofs using temporal
|
||||
induction :cite:p:`een2003temporal`. The command ``help sat`` can be used to
|
||||
print a list of all options with short descriptions of their functions.
|
||||
There is much more to write about the :cmd:ref:`sat` command. For example, there
|
||||
is a set of options that can be used to performs sequential proofs using
|
||||
temporal induction :cite:p:`een2003temporal`. The command ``help sat`` can be
|
||||
used to print a list of all options with short descriptions of their functions.
|
||||
|
||||
.. _conclusion:
|
||||
|
||||
Conclusion
|
||||
==========
|
||||
|
||||
Yosys provides a wide range of functions to analyze and investigate
|
||||
designs. For many cases it is sufficient to simply display circuit
|
||||
diagrams, maybe use some additional commands to narrow the scope of the
|
||||
circuit diagrams to the interesting parts of the circuit. But some cases
|
||||
require more than that. For this applications Yosys provides commands
|
||||
that can be used to further inspect the behavior of the circuit, either
|
||||
by evaluating which output values are generated from certain input
|
||||
values (``eval``) or by evaluation which input values and initial conditions
|
||||
can result in a certain behavior at the outputs (``sat``). The SAT command
|
||||
can even be used to prove (or disprove) theorems regarding the circuit,
|
||||
in more advanced cases with the additional help of a miter circuit.
|
||||
Yosys provides a wide range of functions to analyze and investigate designs. For
|
||||
many cases it is sufficient to simply display circuit diagrams, maybe use some
|
||||
additional commands to narrow the scope of the circuit diagrams to the
|
||||
interesting parts of the circuit. But some cases require more than that. For
|
||||
this applications Yosys provides commands that can be used to further inspect
|
||||
the behavior of the circuit, either by evaluating which output values are
|
||||
generated from certain input values (:cmd:ref:`eval`) or by evaluation which
|
||||
input values and initial conditions can result in a certain behavior at the
|
||||
outputs (:cmd:ref:`sat`). The SAT command can even be used to prove (or
|
||||
disprove) theorems regarding the circuit, in more advanced cases with the
|
||||
additional help of a miter circuit.
|
||||
|
||||
This features can be powerful tools for the circuit designer using Yosys
|
||||
as a utility for building circuits and the software developer using
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue