2023-08-06 19:58:40 -05:00
|
|
|
Techmap by example
|
|
|
|
------------------
|
|
|
|
|
2024-05-02 20:38:01 -05:00
|
|
|
As a quick recap, the `techmap` command replaces cells in the design with
|
|
|
|
implementations given as Verilog code (called "map files"). It can replace
|
2024-05-02 20:14:25 -05:00
|
|
|
Yosys' internal cell types (such as `$or`) as well as user-defined cell types.
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
- Verilog parameters are used extensively to customize the internal cell types.
|
|
|
|
- Additional special parameters are used by techmap to communicate meta-data to
|
|
|
|
the map files.
|
|
|
|
- Special wires are used to instruct techmap how to handle a module in the map
|
|
|
|
file.
|
|
|
|
- Generate blocks and recursion are powerful tools for writing map files.
|
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Code examples used in this document are included in the Yosys code base under
|
|
|
|
|code_examples/techmap|_.
|
|
|
|
|
|
|
|
.. |code_examples/techmap| replace:: :file:`docs/source/code_examples/techmap`
|
2024-03-23 23:41:40 -05:00
|
|
|
.. _code_examples/techmap: https://github.com/YosysHQ/yosys/tree/main/docs/source/code_examples/techmap
|
2024-01-29 18:31:00 -06:00
|
|
|
|
|
|
|
|
2023-08-06 19:58:40 -05:00
|
|
|
Mapping OR3X1
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
2023-09-18 18:21:15 -05:00
|
|
|
.. todo:: add/expand supporting text
|
|
|
|
|
2023-08-06 19:58:40 -05:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
This is a simple example for demonstration only. Techmap shouldn't be used
|
|
|
|
to implement basic logic optimization.
|
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/red_or3x1_map.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`red_or3x1_map.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/techmap/red_or3x1.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/red_or3x1_test.ys
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: yoscrypt
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`red_or3x1_test.ys`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/red_or3x1_test.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`red_or3x1_test.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Conditional techmap
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
- In some cases only cells with certain properties should be substituted.
|
2024-01-29 18:31:00 -06:00
|
|
|
- The special wire ``_TECHMAP_FAIL_`` can be used to disable a module in the map
|
|
|
|
file for a certain set of parameters.
|
|
|
|
- The wire ``_TECHMAP_FAIL_`` must be set to a constant value. If it is non-zero
|
|
|
|
then the module is disabled for this set of parameters.
|
2023-08-06 19:58:40 -05:00
|
|
|
- Example use-cases:
|
|
|
|
|
|
|
|
- coarse-grain cell types that only operate on certain bit widths
|
2024-01-29 18:31:00 -06:00
|
|
|
- memory resources for different memory geometries (width, depth, ports,
|
|
|
|
etc.)
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/techmap/sym_mul.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/sym_mul_map.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`sym_mul_map.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/sym_mul_test.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`sym_mul_test.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/sym_mul_test.ys
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: yoscrypt
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`sym_mul_test.ys`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
Scripting in map modules
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
- The special wires ``_TECHMAP_DO_*`` can be used to run Yosys scripts in the
|
|
|
|
context of the replacement module.
|
2023-08-06 19:58:40 -05:00
|
|
|
- The wire that comes first in alphabetical oder is interpreted as string (must
|
|
|
|
be connected to constants) that is executed as script. Then the wire is
|
|
|
|
removed. Repeat.
|
|
|
|
- You can even call techmap recursively!
|
|
|
|
- Example use-cases:
|
|
|
|
|
2024-05-02 20:16:48 -05:00
|
|
|
- Using always blocks in map module: call `proc`
|
|
|
|
- Perform expensive optimizations (such as `freduce`) on cells
|
2023-08-07 19:45:18 -05:00
|
|
|
where this is known to work well.
|
2023-08-06 19:58:40 -05:00
|
|
|
- Interacting with custom commands.
|
|
|
|
|
2023-08-07 19:45:18 -05:00
|
|
|
.. note:: PROTIP:
|
|
|
|
|
2024-05-02 20:38:01 -05:00
|
|
|
Commands such as `shell`, ``show -pause``, and `dump` can be used in the
|
|
|
|
``_TECHMAP_DO_*`` scripts for debugging map modules.
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/techmap/mymul.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mymul_map.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mymul_map.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mymul_test.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mymul_test.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mymul_test.ys
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: yoscrypt
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mymul_test.ys`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Handling constant inputs
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
- The special parameters ``_TECHMAP_CONSTMSK_<port-name>_`` and
|
|
|
|
``_TECHMAP_CONSTVAL_<port-name>_`` can be used to handle constant input values
|
|
|
|
to cells.
|
|
|
|
- The former contains 1-bits for all constant input bits on the port.
|
|
|
|
- The latter contains the constant bits or undef (x) for non-constant bits.
|
|
|
|
- Example use-cases:
|
|
|
|
|
|
|
|
- Converting arithmetic (for example multiply to shift).
|
|
|
|
- Identify constant addresses or enable bits in memory interfaces.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/techmap/mulshift.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mulshift_map.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mulshift_map.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mulshift_test.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mulshift_test.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/mulshift_test.ys
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: yoscrypt
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`mulshift_test.ys`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Handling shorted inputs
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
- The special parameters ``_TECHMAP_BITS_CONNMAP_`` and
|
|
|
|
``_TECHMAP_CONNMAP_<port-name>_`` can be used to handle shorted inputs.
|
|
|
|
- Each bit of the port correlates to an ``_TECHMAP_BITS_CONNMAP_`` bits wide
|
|
|
|
number in ``_TECHMAP_CONNMAP_<port-name>_``.
|
2024-01-29 18:31:00 -06:00
|
|
|
- Each unique signal bit is assigned its own number. Identical fields in the
|
|
|
|
``_TECHMAP_CONNMAP_<port-name>_`` parameters mean shorted signal bits.
|
2023-08-06 19:58:40 -05:00
|
|
|
- The numbers 0-3 are reserved for ``0``, ``1``, ``x``, and ``z`` respectively.
|
|
|
|
- Example use-cases:
|
|
|
|
|
|
|
|
- Detecting shared clock or control signals in memory interfaces.
|
|
|
|
- In some cases this can be used for for optimization.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/techmap/addshift.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/addshift_map.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`addshift_map.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/addshift_test.v
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`addshift_test.v`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/techmap/addshift_test.ys
|
2023-08-06 19:58:40 -05:00
|
|
|
:language: yoscrypt
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`addshift_test.ys`
|
2023-08-06 19:58:40 -05:00
|
|
|
|
|
|
|
Notes on using techmap
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
- Don't use positional cell parameters in map modules.
|
2023-12-04 16:22:00 -06:00
|
|
|
- You can use the ``$__``-prefix for internal cell types to avoid collisions
|
|
|
|
with the user-namespace. But always use two underscores or the internal
|
|
|
|
consistency checker will trigger on these cells.
|
2023-08-06 19:58:40 -05:00
|
|
|
- Techmap has two major use cases:
|
|
|
|
|
|
|
|
- Creating good logic-level representation of arithmetic functions. This
|
|
|
|
also means using dedicated hardware resources such as half- and full-adder
|
|
|
|
cells in ASICS or dedicated carry logic in FPGAs.
|
|
|
|
- Mapping of coarse-grain resources such as block memory or DSP cells.
|