3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-26 02:25:35 +00:00

Docs: working on opt page

Replace leftover `opt` example source/images with examples specific to the `opt_*` pass.
Currently has images for `opt_expr`, `opt_merge`, `opt_muxtree`, and `opt_share`.
Also includes some other TODO updates.
This commit is contained in:
Krystine Sherwin 2024-01-17 11:00:42 +13:00
parent 63a0f80996
commit 27ae093dba
No known key found for this signature in database
18 changed files with 140 additions and 105 deletions

View file

@ -81,6 +81,17 @@ The :cmd:ref:`opt_expr` pass is very conservative regarding optimizing ``$mux``
cells, as these cells are often used to model decision-trees and breaking these
trees can interfere with other optimizations.
.. literalinclude:: /code_examples/opt/opt_expr.ys
:language: Verilog
:start-after: read_verilog <<EOT
:end-before: EOT
:caption: example verilog for demonstrating :cmd:ref:`opt_expr`
.. figure:: /_images/code_examples/opt/opt_expr.*
:class: width-helper
Before and after :cmd:ref:`opt_expr`
Merging identical cells - :cmd:ref:`opt_merge`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -93,23 +104,38 @@ cells (``$mux`` and ``$pmux``.) This can be useful as it prevents multiplexer
trees to be merged, which might prevent :cmd:ref:`opt_muxtree` to identify
possible optimizations.
.. literalinclude:: /code_examples/opt/opt_merge.ys
:language: Verilog
:start-after: read_verilog <<EOT
:end-before: EOT
:caption: example verilog for demonstrating :cmd:ref:`opt_merge`
.. figure:: /_images/code_examples/opt/opt_merge.*
:class: width-helper
Before and after :cmd:ref:`opt_merge`
Removing never-active branches from multiplexer tree - :cmd:ref:`opt_muxtree`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This pass optimizes trees of multiplexer cells by analyzing the select inputs.
Consider the following simple example:
.. code:: verilog
.. literalinclude:: /code_examples/opt/opt_muxtree.ys
:language: Verilog
:start-after: read_verilog <<EOT
:end-before: EOT
:caption: example verilog for demonstrating :cmd:ref:`opt_muxtree`
module uut(a, y);
input a;
output [1:0] y = a ? (a ? 1 : 2) : 3;
endmodule
The output can never be 2, as this would require ``a`` to be 1 for the outer
The output can never be ``c``, as this would require ``a`` to be 1 for the outer
multiplexer and 0 for the inner multiplexer. The :cmd:ref:`opt_muxtree` pass
detects this contradiction and replaces the inner multiplexer with a constant 1,
yielding the logic for ``y = a ? 1 : 3``.
yielding the logic for ``y = a ? b : d``.
.. figure:: /_images/code_examples/opt/opt_muxtree.*
:class: width-helper
Before and after :cmd:ref:`opt_muxtree`
Simplifying large MUXes and AND/OR gates - :cmd:ref:`opt_reduce`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -139,8 +165,19 @@ This pass identifies mutually exclusive cells of the same type that:
allowing the cell to be merged and the multiplexer to be moved from
multiplexing its output to multiplexing the non-shared input signals.
.. todo:: more detailed description of :cmd:ref:`opt_share` (esp. why)
so that it's not just a copy-paste of the help output
.. literalinclude:: /code_examples/opt/opt_share.ys
:language: Verilog
:start-after: read_verilog <<EOT
:end-before: EOT
:caption: example verilog for demonstrating :cmd:ref:`opt_share`
.. figure:: /_images/code_examples/opt/opt_share.*
:class: width-helper
Before and after :cmd:ref:`opt_share`
When running :cmd:ref:`opt` in full, the original ``$mux`` (labeled ``$3``) is
optimized away by :cmd:ref:`opt_expr`.
Performing DFF optimizations - :cmd:ref:`opt_dff`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -160,58 +197,6 @@ This pass identifies unused signals and cells and removes them from the design.
It also creates an ``\unused_bits`` attribute on wires with unused bits. This
attribute can be used for debugging or by other optimization passes.
Example
~~~~~~~
.. todo:: describe ``opt`` images
and/or replace with an example image showing before/after of each ``opt_*``
command
.. figure:: /_images/code_examples/synth_flow/opt_01.*
:class: width-helper
.. literalinclude:: /code_examples/synth_flow/opt_01.ys
:language: yoscrypt
:caption: ``docs/source/code_examples/synth_flow/opt_01.ys``
.. literalinclude:: /code_examples/synth_flow/opt_01.v
:language: verilog
:caption: ``docs/source/code_examples/synth_flow/opt_01.v``
.. figure:: /_images/code_examples/synth_flow/opt_02.*
:class: width-helper
.. literalinclude:: /code_examples/synth_flow/opt_02.ys
:language: yoscrypt
:caption: ``docs/source/code_examples/synth_flow/opt_02.ys``
.. literalinclude:: /code_examples/synth_flow/opt_02.v
:language: verilog
:caption: ``docs/source/code_examples/synth_flow/opt_02.v``
.. figure:: /_images/code_examples/synth_flow/opt_03.*
:class: width-helper
.. literalinclude:: /code_examples/synth_flow/opt_03.ys
:language: yoscrypt
:caption: ``docs/source/code_examples/synth_flow/opt_03.ys``
.. literalinclude:: /code_examples/synth_flow/opt_03.v
:language: verilog
:caption: ``docs/source/code_examples/synth_flow/opt_03.v``
.. figure:: /_images/code_examples/synth_flow/opt_04.*
:class: width-helper
.. literalinclude:: /code_examples/synth_flow/opt_04.v
:language: verilog
:caption: ``docs/source/code_examples/synth_flow/opt_04.v``
.. literalinclude:: /code_examples/synth_flow/opt_04.ys
:language: yoscrypt
:caption: ``docs/source/code_examples/synth_flow/opt_04.ys``
When to use :cmd:ref:`opt` or :cmd:ref:`clean`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~