2023-08-27 16:50:37 -05:00
|
|
|
The extract pass
|
2024-01-25 18:06:02 -06:00
|
|
|
----------------
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-05-02 20:38:01 -05:00
|
|
|
- Like the `techmap` pass, the `extract` pass is called with a map file. It
|
|
|
|
compares the circuits inside the modules of the map file with the design and
|
|
|
|
looks for sub-circuits in the design that match any of the modules in the map
|
|
|
|
file.
|
|
|
|
- If a match is found, the `extract` pass will replace the matching subcircuit
|
|
|
|
with an instance of the module from the map file.
|
2024-05-02 20:16:48 -05:00
|
|
|
- In a way the `extract` pass is the inverse of the techmap pass.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-12-07 14:46:02 -06:00
|
|
|
.. todo:: add/expand supporting text, also mention custom pattern matching and
|
|
|
|
pmgen
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Example code can be found in |code_examples/macc|_.
|
|
|
|
|
|
|
|
.. |code_examples/macc| replace:: :file:`docs/source/code_examples/macc`
|
2024-03-23 23:41:40 -05:00
|
|
|
.. _code_examples/macc: https://github.com/YosysHQ/yosys/tree/main/docs/source/code_examples/macc
|
2024-01-29 18:31:00 -06:00
|
|
|
|
2024-01-17 20:33:59 -06:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:lines: 1-2
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_00a.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-05-02 20:16:48 -05:00
|
|
|
before `extract`
|
2023-11-15 14:46:47 -06:00
|
|
|
|
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:lines: 6
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_00b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-05-02 20:16:48 -05:00
|
|
|
after `extract`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_test.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_simple_test.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_xmap.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_simple_xmap.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_test_01.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_simple_test_01.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_01a.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_01b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_simple_test_02.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_simple_test_02.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_02a.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_simple_test_02b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
The wrap-extract-unwrap method
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Often a coarse-grain element has a constant bit-width, but can be used to
|
2024-05-02 20:38:01 -05:00
|
|
|
implement operations with a smaller bit-width. For example, a 18x25-bit
|
|
|
|
multiplier can also be used to implement 16x20-bit multiplication.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-17 20:33:59 -06:00
|
|
|
A way of mapping such elements in coarse grain synthesis is the
|
|
|
|
wrap-extract-unwrap method:
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
wrap
|
|
|
|
Identify candidate-cells in the circuit and wrap them in a cell with a
|
2024-05-02 20:38:01 -05:00
|
|
|
constant wider bit-width using `techmap`. The wrappers use the same parameters
|
|
|
|
as the original cell, so the information about the original width of the ports
|
|
|
|
is preserved. Then use the `connwrappers` command to connect up the
|
|
|
|
bit-extended in- and outputs of the wrapper cells.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
extract
|
|
|
|
Now all operations are encoded using the same bit-width as the coarse grain
|
2024-05-02 20:38:01 -05:00
|
|
|
element. The `extract` command can be used to replace circuits with cells of
|
|
|
|
the target architecture.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
unwrap
|
2024-05-02 20:16:48 -05:00
|
|
|
The remaining wrapper cell can be unwrapped using `techmap`.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Example: DSP48_MACC
|
2023-08-02 16:20:29 -05:00
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
This section details an example that shows how to map MACC operations of
|
|
|
|
arbitrary size to MACC cells with a 18x25-bit multiplier and a 48-bit adder
|
2024-01-29 18:31:00 -06:00
|
|
|
(such as the Xilinx DSP48 cells).
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Preconditioning: :file:`macc_xilinx_swap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Make sure ``A`` is the smaller port on all multipliers
|
|
|
|
|
2023-09-18 18:21:15 -05:00
|
|
|
.. todo:: add/expand supporting text
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_swap_map.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_xilinx_swap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Wrapping multipliers: :file:`macc_xilinx_wrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_wrap_map.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 1-46
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_xilinx_wrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Wrapping adders: :file:`macc_xilinx_wrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_wrap_map.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 48-89
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_xilinx_wrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Extract: :file:`macc_xilinx_xmap.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_xmap.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: :file:`macc_xilinx_xmap.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
... simply use the same wrapping commands on this module as on the design to
|
2024-05-02 20:16:48 -05:00
|
|
|
create a template for the `extract` command.
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Unwrapping multipliers: :file:`macc_xilinx_unwrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_unwrap_map.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 1-30
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: ``$__mul_wrapper`` module in :file:`macc_xilinx_unwrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2024-01-29 18:31:00 -06:00
|
|
|
Unwrapping adders: :file:`macc_xilinx_unwrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_unwrap_map.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 32-61
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: ``$__add_wrapper`` module in :file:`macc_xilinx_unwrap_map.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 1-6
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: ``test1`` of :file:`macc_xilinx_test.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1a.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-13 17:55:39 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.v
|
2023-08-27 16:50:37 -05:00
|
|
|
:language: verilog
|
|
|
|
:lines: 8-13
|
2024-01-29 18:31:00 -06:00
|
|
|
:caption: ``test2`` of :file:`macc_xilinx_test.v`
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2a.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Wrapping in ``test1``:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:start-after: part c
|
|
|
|
:end-before: end part c
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1c.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Wrapping in ``test2``:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2b.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:start-after: part c
|
|
|
|
:end-before: end part c
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2c.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Extract in ``test1``:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1c.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:start-after: part d
|
|
|
|
:end-before: end part d
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test1d.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Extract in ``test2``:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2c.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:start-after: part d
|
|
|
|
:end-before: end part d
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2d.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
|
|
|
Unwrap in ``test2``:
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2d.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|
2023-08-27 16:50:37 -05:00
|
|
|
|
2023-11-15 14:46:47 -06:00
|
|
|
.. literalinclude:: /code_examples/macc/macc_xilinx_test.ys
|
|
|
|
:language: yoscrypt
|
|
|
|
:start-after: part e
|
|
|
|
:end-before: end part e
|
|
|
|
|
2023-11-14 22:39:37 -06:00
|
|
|
.. figure:: /_images/code_examples/macc/macc_xilinx_test2e.*
|
2024-05-10 17:40:54 -05:00
|
|
|
:class: width-helper invert-helper
|