Merge remote-tracking branch 'origin/eddie/submod_po' into xaig_dff
[yosys.git] / README.md
1 ```
2 yosys -- Yosys Open SYnthesis Suite
3
4 Copyright (C) 2012 - 2019 Clifford Wolf <clifford@clifford.at>
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 ```
18
19
20 yosys – Yosys Open SYnthesis Suite
21 ===================================
22
23 This is a framework for RTL synthesis tools. It currently has
24 extensive Verilog-2005 support and provides a basic set of
25 synthesis algorithms for various application domains.
26
27 Yosys can be adapted to perform any synthesis job by combining
28 the existing passes (algorithms) using synthesis scripts and
29 adding additional passes as needed by extending the yosys C++
30 code base.
31
32 Yosys is free software licensed under the ISC license (a GPL
33 compatible license that is similar in terms to the MIT license
34 or the 2-clause BSD license).
35
36
37 Web Site and Other Resources
38 ============================
39
40 More information and documentation can be found on the Yosys web site:
41 - http://www.clifford.at/yosys/
42
43 The "Documentation" page on the web site contains links to more resources,
44 including a manual that even describes some of the Yosys internals:
45 - http://www.clifford.at/yosys/documentation.html
46
47 The file `CodingReadme` in this directory contains additional information
48 for people interested in using the Yosys C++ APIs.
49
50 Users interested in formal verification might want to use the formal verification
51 front-end for Yosys, SymbiYosys:
52 - https://symbiyosys.readthedocs.io/en/latest/
53 - https://github.com/YosysHQ/SymbiYosys
54
55
56 Setup
57 ======
58
59 You need a C++ compiler with C++11 support (up-to-date CLANG or GCC is
60 recommended) and some standard tools such as GNU Flex, GNU Bison, and GNU Make.
61 TCL, readline and libffi are optional (see ``ENABLE_*`` settings in Makefile).
62 Xdot (graphviz) is used by the ``show`` command in yosys to display schematics.
63
64 For example on Ubuntu Linux 16.04 LTS the following commands will install all
65 prerequisites for building yosys:
66
67 $ sudo apt-get install build-essential clang bison flex \
68 libreadline-dev gawk tcl-dev libffi-dev git \
69 graphviz xdot pkg-config python3 libboost-system-dev \
70 libboost-python-dev libboost-filesystem-dev zlib1g-dev
71
72 Similarily, on Mac OS X Homebrew can be used to install dependencies:
73
74 $ brew tap Homebrew/bundle && brew bundle
75
76 or MacPorts:
77
78 $ sudo port install bison flex readline gawk libffi \
79 git graphviz pkgconfig python36 boost zlib tcl
80
81 On FreeBSD use the following command to install all prerequisites:
82
83 # pkg install bison flex readline gawk libffi\
84 git graphviz pkgconf python3 python36 tcl-wrapper boost-libs
85
86 On FreeBSD system use gmake instead of make. To run tests use:
87 % MAKE=gmake CC=cc gmake test
88
89 For Cygwin use the following command to install all prerequisites, or select these additional packages:
90
91 setup-x86_64.exe -q --packages=bison,flex,gcc-core,gcc-g++,git,libffi-devel,libreadline-devel,make,pkg-config,python3,tcl-devel,boost-build,zlib-devel
92
93 There are also pre-compiled Yosys binary packages for Ubuntu and Win32 as well
94 as a source distribution for Visual Studio. Visit the Yosys download page for
95 more information: http://www.clifford.at/yosys/download.html
96
97 To configure the build system to use a specific compiler, use one of
98
99 $ make config-clang
100 $ make config-gcc
101
102 For other compilers and build configurations it might be
103 necessary to make some changes to the config section of the
104 Makefile.
105
106 $ vi Makefile # ..or..
107 $ vi Makefile.conf
108
109 To build Yosys simply type 'make' in this directory.
110
111 $ make
112 $ sudo make install
113
114 Note that this also downloads, builds and installs ABC (using yosys-abc
115 as executable name).
116
117 Tests are located in the tests subdirectory and can be executed using the test target. Note that you need gawk as well as a recent version of iverilog (i.e. build from git). Then, execute tests via:
118
119 $ make test
120
121 Getting Started
122 ===============
123
124 Yosys can be used with the interactive command shell, with
125 synthesis scripts or with command line arguments. Let's perform
126 a simple synthesis job using the interactive command shell:
127
128 $ ./yosys
129 yosys>
130
131 the command ``help`` can be used to print a list of all available
132 commands and ``help <command>`` to print details on the specified command:
133
134 yosys> help help
135
136 reading and elaborating the design using the Verilog frontend:
137
138 yosys> read -sv tests/simple/fiedler-cooley.v
139 yosys> hierarchy -top up3down5
140
141 writing the design to the console in Yosys's internal format:
142
143 yosys> write_ilang
144
145 convert processes (``always`` blocks) to netlist elements and perform
146 some simple optimizations:
147
148 yosys> proc; opt
149
150 display design netlist using ``xdot``:
151
152 yosys> show
153
154 the same thing using ``gv`` as postscript viewer:
155
156 yosys> show -format ps -viewer gv
157
158 translating netlist to gate logic and perform some simple optimizations:
159
160 yosys> techmap; opt
161
162 write design netlist to a new Verilog file:
163
164 yosys> write_verilog synth.v
165
166 or using a simple synthesis script:
167
168 $ cat synth.ys
169 read -sv tests/simple/fiedler-cooley.v
170 hierarchy -top up3down5
171 proc; opt; techmap; opt
172 write_verilog synth.v
173
174 $ ./yosys synth.ys
175
176 If ABC is enabled in the Yosys build configuration and a cell library is given
177 in the liberty file ``mycells.lib``, the following synthesis script will
178 synthesize for the given cell library:
179
180 # read design
181 read -sv tests/simple/fiedler-cooley.v
182 hierarchy -top up3down5
183
184 # the high-level stuff
185 proc; fsm; opt; memory; opt
186
187 # mapping to internal cell library
188 techmap; opt
189
190 # mapping flip-flops to mycells.lib
191 dfflibmap -liberty mycells.lib
192
193 # mapping logic to mycells.lib
194 abc -liberty mycells.lib
195
196 # cleanup
197 clean
198
199 If you do not have a liberty file but want to test this synthesis script,
200 you can use the file ``examples/cmos/cmos_cells.lib`` from the yosys sources
201 as simple example.
202
203 Liberty file downloads for and information about free and open ASIC standard
204 cell libraries can be found here:
205
206 - http://www.vlsitechnology.org/html/libraries.html
207 - http://www.vlsitechnology.org/synopsys/vsclib013.lib
208
209 The command ``synth`` provides a good default synthesis script (see
210 ``help synth``):
211
212 read -sv tests/simple/fiedler-cooley.v
213 synth -top up3down5
214
215 # mapping to target cells
216 dfflibmap -liberty mycells.lib
217 abc -liberty mycells.lib
218 clean
219
220 The command ``prep`` provides a good default word-level synthesis script, as
221 used in SMT-based formal verification.
222
223
224 Unsupported Verilog-2005 Features
225 =================================
226
227 The following Verilog-2005 features are not supported by
228 Yosys and there are currently no plans to add support
229 for them:
230
231 - Non-synthesizable language features as defined in
232 IEC 62142(E):2005 / IEEE Std. 1364.1(E):2002
233
234 - The ``tri``, ``triand`` and ``trior`` net types
235
236 - The ``config`` and ``disable`` keywords and library map files
237
238
239 Verilog Attributes and non-standard features
240 ============================================
241
242 - The ``full_case`` attribute on case statements is supported
243 (also the non-standard ``// synopsys full_case`` directive)
244
245 - The ``parallel_case`` attribute on case statements is supported
246 (also the non-standard ``// synopsys parallel_case`` directive)
247
248 - The ``// synopsys translate_off`` and ``// synopsys translate_on``
249 directives are also supported (but the use of ``` `ifdef .. `endif ```
250 is strongly recommended instead).
251
252 - The ``nomem2reg`` attribute on modules or arrays prohibits the
253 automatic early conversion of arrays to separate registers. This
254 is potentially dangerous. Usually the front-end has good reasons
255 for converting an array to a list of registers. Prohibiting this
256 step will likely result in incorrect synthesis results.
257
258 - The ``mem2reg`` attribute on modules or arrays forces the early
259 conversion of arrays to separate registers.
260
261 - The ``nomeminit`` attribute on modules or arrays prohibits the
262 creation of initialized memories. This effectively puts ``mem2reg``
263 on all memories that are written to in an ``initial`` block and
264 are not ROMs.
265
266 - The ``nolatches`` attribute on modules or always-blocks
267 prohibits the generation of logic-loops for latches. Instead
268 all not explicitly assigned values default to x-bits. This does
269 not affect clocked storage elements such as flip-flops.
270
271 - The ``nosync`` attribute on registers prohibits the generation of a
272 storage element. The register itself will always have all bits set
273 to 'x' (undefined). The variable may only be used as blocking assigned
274 temporary variable within an always block. This is mostly used internally
275 by Yosys to synthesize Verilog functions and access arrays.
276
277 - The ``onehot`` attribute on wires mark them as one-hot state register. This
278 is used for example for memory port sharing and set by the fsm_map pass.
279
280 - The ``blackbox`` attribute on modules is used to mark empty stub modules
281 that have the same ports as the real thing but do not contain information
282 on the internal configuration. This modules are only used by the synthesis
283 passes to identify input and output ports of cells. The Verilog backend
284 also does not output blackbox modules on default. ``read_verilog``, unless
285 called with ``-noblackbox`` will automatically set the blackbox attribute
286 on any empty module it reads.
287
288 - The ``noblackbox`` attribute set on an empty module prevents ``read_verilog``
289 from automatically setting the blackbox attribute on the module.
290
291 - The ``whitebox`` attribute on modules triggers the same behavior as
292 ``blackbox``, but is for whitebox modules, i.e. library modules that
293 contain a behavioral model of the cell type.
294
295 - The ``lib_whitebox`` attribute overwrites ``whitebox`` when ``read_verilog``
296 is run in `-lib` mode. Otherwise it's automatically removed.
297
298 - The ``dynports`` attribute is used by the Verilog front-end to mark modules
299 that have ports with a width that depends on a parameter.
300
301 - The ``hdlname`` attribute is used by some passes to document the original
302 (HDL) name of a module when renaming a module.
303
304 - The ``keep`` attribute on cells and wires is used to mark objects that should
305 never be removed by the optimizer. This is used for example for cells that
306 have hidden connections that are not part of the netlist, such as IO pads.
307 Setting the ``keep`` attribute on a module has the same effect as setting it
308 on all instances of the module.
309
310 - The ``keep_hierarchy`` attribute on cells and modules keeps the ``flatten``
311 command from flattening the indicated cells and modules.
312
313 - The ``init`` attribute on wires is set by the frontend when a register is
314 initialized "FPGA-style" with ``reg foo = val``. It can be used during
315 synthesis to add the necessary reset logic.
316
317 - The ``top`` attribute on a module marks this module as the top of the
318 design hierarchy. The ``hierarchy`` command sets this attribute when called
319 with ``-top``. Other commands, such as ``flatten`` and various backends
320 use this attribute to determine the top module.
321
322 - The ``src`` attribute is set on cells and wires created by to the string
323 ``<hdl-file-name>:<line-number>`` by the HDL front-end and is then carried
324 through the synthesis. When entities are combined, a new |-separated
325 string is created that contains all the string from the original entities.
326
327 - The ``defaultvalue`` attribute is used to store default values for
328 module inputs. The attribute is attached to the input wire by the HDL
329 front-end when the input is declared with a default value.
330
331 - The ``parameter`` and ``localparam`` attributes are used to mark wires
332 that represent module parameters or localparams (when the HDL front-end
333 is run in ``-pwires`` mode).
334
335 - Wires marked with the ``hierconn`` attribute are connected to wires with the
336 same name (format ``cell_name.identifier``) when they are imported from
337 sub-modules by ``flatten``.
338
339 - The ``clkbuf_driver`` attribute can be set on an output port of a blackbox
340 module to mark it as a clock buffer output, and thus prevent ``clkbufmap``
341 from inserting another clock buffer on a net driven by such output.
342
343 - The ``clkbuf_sink`` attribute can be set on an input port of a module to
344 request clock buffer insertion by the ``clkbufmap`` pass.
345
346 - The ``clkbuf_inv`` attribute can be set on an output port of a module
347 with the value set to the name of an input port of that module. When
348 the ``clkbufmap`` would otherwise insert a clock buffer on this output,
349 it will instead try inserting the clock buffer on the input port (this
350 is used to implement clock inverter cells that clock buffer insertion
351 will "see through").
352
353 - The ``clkbuf_inhibit`` is the default attribute to set on a wire to prevent
354 automatic clock buffer insertion by ``clkbufmap``. This behaviour can be
355 overridden by providing a custom selection to ``clkbufmap``.
356
357 - The ``invertible_pin`` attribute can be set on a port to mark it as
358 invertible via a cell parameter. The name of the inversion parameter
359 is specified as the value of this attribute. The value of the inversion
360 parameter must be of the same width as the port, with 1 indicating
361 an inverted bit and 0 indicating a non-inverted bit.
362
363 - The ``iopad_external_pin`` attribute on a blackbox module's port marks
364 it as the external-facing pin of an I/O pad, and prevents ``iopadmap``
365 from inserting another pad cell on it.
366
367 - The module attribute ``abc_box_id`` specifies a positive integer linking a
368 blackbox or whitebox definition to a corresponding entry in a `abc9`
369 box-file.
370
371 - The port attribute ``abc_carry`` marks the carry-in (if an input port) and
372 carry-out (if output port) ports of a box. This information is necessary for
373 `abc9` to preserve the integrity of carry-chains. Specifying this attribute
374 onto a bus port will affect only its most significant bit.
375
376 - The port attribute ``abc_arrival`` specifies an integer (for output ports
377 only) to be used as the arrival time of this sequential port. It can be used,
378 for example, to specify the clk-to-Q delay of a flip-flop for consideration
379 during techmapping.
380
381 - The frontend sets attributes ``always_comb``, ``always_latch`` and
382 ``always_ff`` on processes derived from SystemVerilog style always blocks
383 according to the type of the always. These are checked for correctness in
384 ``proc_dlatch``.
385
386 - In addition to the ``(* ... *)`` attribute syntax, Yosys supports
387 the non-standard ``{* ... *}`` attribute syntax to set default attributes
388 for everything that comes after the ``{* ... *}`` statement. (Reset
389 by adding an empty ``{* *}`` statement.)
390
391 - In module parameter and port declarations, and cell port and parameter
392 lists, a trailing comma is ignored. This simplifies writing Verilog code
393 generators a bit in some cases.
394
395 - Modules can be declared with ``module mod_name(...);`` (with three dots
396 instead of a list of module ports). With this syntax it is sufficient
397 to simply declare a module port as 'input' or 'output' in the module
398 body.
399
400 - When defining a macro with `define, all text between triple double quotes
401 is interpreted as macro body, even if it contains unescaped newlines. The
402 triple double quotes are removed from the macro body. For example:
403
404 `define MY_MACRO(a, b) """
405 assign a = 23;
406 assign b = 42;
407 """
408
409 - The attribute ``via_celltype`` can be used to implement a Verilog task or
410 function by instantiating the specified cell type. The value is the name
411 of the cell type to use. For functions the name of the output port can
412 be specified by appending it to the cell type separated by a whitespace.
413 The body of the task or function is unused in this case and can be used
414 to specify a behavioral model of the cell type for simulation. For example:
415
416 module my_add3(A, B, C, Y);
417 parameter WIDTH = 8;
418 input [WIDTH-1:0] A, B, C;
419 output [WIDTH-1:0] Y;
420 ...
421 endmodule
422
423 module top;
424 ...
425 (* via_celltype = "my_add3 Y" *)
426 (* via_celltype_defparam_WIDTH = 32 *)
427 function [31:0] add3;
428 input [31:0] A, B, C;
429 begin
430 add3 = A + B + C;
431 end
432 endfunction
433 ...
434 endmodule
435
436 - A limited subset of DPI-C functions is supported. The plugin mechanism
437 (see ``help plugin``) can be used to load .so files with implementations
438 of DPI-C routines. As a non-standard extension it is possible to specify
439 a plugin alias using the ``<alias>:`` syntax. For example:
440
441 module dpitest;
442 import "DPI-C" function foo:round = real my_round (real);
443 parameter real r = my_round(12.345);
444 endmodule
445
446 $ yosys -p 'plugin -a foo -i /lib/libm.so; read_verilog dpitest.v'
447
448 - Sized constants (the syntax ``<size>'s?[bodh]<value>``) support constant
449 expressions as ``<size>``. If the expression is not a simple identifier, it
450 must be put in parentheses. Examples: ``WIDTH'd42``, ``(4+2)'b101010``
451
452 - The system tasks ``$finish``, ``$stop`` and ``$display`` are supported in
453 initial blocks in an unconditional context (only if/case statements on
454 expressions over parameters and constant values are allowed). The intended
455 use for this is synthesis-time DRC.
456
457 - There is limited support for converting specify .. endspecify statements to
458 special ``$specify2``, ``$specify3``, and ``$specrule`` cells, for use in
459 blackboxes and whiteboxes. Use ``read_verilog -specify`` to enable this
460 functionality. (By default specify .. endspecify blocks are ignored.)
461
462
463 Non-standard or SystemVerilog features for formal verification
464 ==============================================================
465
466 - Support for ``assert``, ``assume``, ``restrict``, and ``cover`` is enabled
467 when ``read_verilog`` is called with ``-formal``.
468
469 - The system task ``$initstate`` evaluates to 1 in the initial state and
470 to 0 otherwise.
471
472 - The system function ``$anyconst`` evaluates to any constant value. This is
473 equivalent to declaring a reg as ``rand const``, but also works outside
474 of checkers. (Yosys also supports ``rand const`` outside checkers.)
475
476 - The system function ``$anyseq`` evaluates to any value, possibly a different
477 value in each cycle. This is equivalent to declaring a reg as ``rand``,
478 but also works outside of checkers. (Yosys also supports ``rand``
479 variables outside checkers.)
480
481 - The system functions ``$allconst`` and ``$allseq`` can be used to construct
482 formal exist-forall problems. Assumptions only hold if the trace satisfies
483 the assumption for all ``$allconst/$allseq`` values. For assertions and cover
484 statements it is sufficient if just one ``$allconst/$allseq`` value triggers
485 the property (similar to ``$anyconst/$anyseq``).
486
487 - Wires/registers declared using the ``anyconst/anyseq/allconst/allseq`` attribute
488 (for example ``(* anyconst *) reg [7:0] foobar;``) will behave as if driven
489 by a ``$anyconst/$anyseq/$allconst/$allseq`` function.
490
491 - The SystemVerilog tasks ``$past``, ``$stable``, ``$rose`` and ``$fell`` are
492 supported in any clocked block.
493
494 - The syntax ``@($global_clock)`` can be used to create FFs that have no
495 explicit clock input (``$ff`` cells). The same can be achieved by using
496 ``@(posedge <netname>)`` or ``@(negedge <netname>)`` when ``<netname>``
497 is marked with the ``(* gclk *)`` Verilog attribute.
498
499
500 Supported features from SystemVerilog
501 =====================================
502
503 When ``read_verilog`` is called with ``-sv``, it accepts some language features
504 from SystemVerilog:
505
506 - The ``assert`` statement from SystemVerilog is supported in its most basic
507 form. In module context: ``assert property (<expression>);`` and within an
508 always block: ``assert(<expression>);``. It is transformed to an ``$assert`` cell.
509
510 - The ``assume``, ``restrict``, and ``cover`` statements from SystemVerilog are
511 also supported. The same limitations as with the ``assert`` statement apply.
512
513 - The keywords ``always_comb``, ``always_ff`` and ``always_latch``, ``logic``
514 and ``bit`` are supported.
515
516 - Declaring free variables with ``rand`` and ``rand const`` is supported.
517
518 - Checkers without a port list that do not need to be instantiated (but instead
519 behave like a named block) are supported.
520
521 - SystemVerilog packages are supported. Once a SystemVerilog file is read
522 into a design with ``read_verilog``, all its packages are available to
523 SystemVerilog files being read into the same design afterwards.
524
525 - typedefs are supported (including inside packages)
526
527 - SystemVerilog interfaces (SVIs) are supported. Modports for specifying whether
528 ports are inputs or outputs are supported.
529
530
531 Building the documentation
532 ==========================
533
534 Note that there is no need to build the manual if you just want to read it.
535 Simply download the PDF from http://www.clifford.at/yosys/documentation.html
536 instead.
537
538 On Ubuntu, texlive needs these packages to be able to build the manual:
539
540 sudo apt-get install texlive-binaries
541 sudo apt-get install texlive-science # install algorithm2e.sty
542 sudo apt-get install texlive-bibtex-extra # gets multibib.sty
543 sudo apt-get install texlive-fonts-extra # gets skull.sty and dsfont.sty
544 sudo apt-get install texlive-publishers # IEEEtran.cls
545
546 Also the non-free font luximono should be installed, there is unfortunately
547 no Ubuntu package for this so it should be installed separately using
548 `getnonfreefonts`:
549
550 wget https://tug.org/fonts/getnonfreefonts/install-getnonfreefonts
551 sudo texlua install-getnonfreefonts # will install to /usr/local by default, can be changed by editing BINDIR at MANDIR at the top of the script
552 getnonfreefonts luximono # installs to /home/user/texmf
553
554 Then execute, from the root of the repository:
555
556 make manual
557
558 Notes:
559
560 - To run `make manual` you need to have installed Yosys with `make install`,
561 otherwise it will fail on finding `kernel/yosys.h` while building
562 `PRESENTATION_Prog`.