Merge remote-tracking branch 'origin/clifford/pmux2shiftx' into xc7srl
[yosys.git] / README.md
1 ```
2 yosys -- Yosys Open SYnthesis Suite
3
4 Copyright (C) 2012 - 2018 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
70
71 Similarily, on Mac OS X MacPorts or Homebrew can be used to install dependencies:
72
73 $ brew tap Homebrew/bundle && brew bundle
74 $ sudo port install bison flex readline gawk libffi \
75 git graphviz pkgconfig python36
76
77 On FreeBSD use the following command to install all prerequisites:
78
79 # pkg install bison flex readline gawk libffi\
80 git graphviz pkgconfig python3 python36 tcl-wrapper
81
82 On FreeBSD system use gmake instead of make. To run tests use:
83 % MAKE=gmake CC=cc gmake test
84
85 For Cygwin use the following command to install all prerequisites, or select these additional packages:
86
87 setup-x86_64.exe -q --packages=bison,flex,gcc-core,gcc-g++,git,libffi-devel,libreadline-devel,make,pkg-config,python3,tcl-devel
88
89 There are also pre-compiled Yosys binary packages for Ubuntu and Win32 as well
90 as a source distribution for Visual Studio. Visit the Yosys download page for
91 more information: http://www.clifford.at/yosys/download.html
92
93 To configure the build system to use a specific compiler, use one of
94
95 $ make config-clang
96 $ make config-gcc
97
98 For other compilers and build configurations it might be
99 necessary to make some changes to the config section of the
100 Makefile.
101
102 $ vi Makefile # ..or..
103 $ vi Makefile.conf
104
105 To build Yosys simply type 'make' in this directory.
106
107 $ make
108 $ sudo make install
109
110 Note that this also downloads, builds and installs ABC (using yosys-abc
111 as executable name).
112
113 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:
114
115 $ make test
116
117 Getting Started
118 ===============
119
120 Yosys can be used with the interactive command shell, with
121 synthesis scripts or with command line arguments. Let's perform
122 a simple synthesis job using the interactive command shell:
123
124 $ ./yosys
125 yosys>
126
127 the command ``help`` can be used to print a list of all available
128 commands and ``help <command>`` to print details on the specified command:
129
130 yosys> help help
131
132 reading the design using the Verilog frontend:
133
134 yosys> read_verilog tests/simple/fiedler-cooley.v
135
136 writing the design to the console in Yosys's internal format:
137
138 yosys> write_ilang
139
140 elaborate design hierarchy:
141
142 yosys> hierarchy
143
144 convert processes (``always`` blocks) to netlist elements and perform
145 some simple optimizations:
146
147 yosys> proc; opt
148
149 display design netlist using ``xdot``:
150
151 yosys> show
152
153 the same thing using ``gv`` as postscript viewer:
154
155 yosys> show -format ps -viewer gv
156
157 translating netlist to gate logic and perform some simple optimizations:
158
159 yosys> techmap; opt
160
161 write design netlist to a new Verilog file:
162
163 yosys> write_verilog synth.v
164
165 a similar synthesis can be performed using yosys command line options only:
166
167 $ ./yosys -o synth.v -p hierarchy -p proc -p opt \
168 -p techmap -p opt tests/simple/fiedler-cooley.v
169
170 or using a simple synthesis script:
171
172 $ cat synth.ys
173 read_verilog tests/simple/fiedler-cooley.v
174 hierarchy; proc; opt; techmap; opt
175 write_verilog synth.v
176
177 $ ./yosys synth.ys
178
179 It is also possible to only have the synthesis commands but not the read/write
180 commands in the synthesis script:
181
182 $ cat synth.ys
183 hierarchy; proc; opt; techmap; opt
184
185 $ ./yosys -o synth.v tests/simple/fiedler-cooley.v synth.ys
186
187 The following very basic synthesis script should work well with all designs:
188
189 # check design hierarchy
190 hierarchy
191
192 # translate processes (always blocks)
193 proc; opt
194
195 # detect and optimize FSM encodings
196 fsm; opt
197
198 # implement memories (arrays)
199 memory; opt
200
201 # convert to gate logic
202 techmap; opt
203
204 If ABC is enabled in the Yosys build configuration and a cell library is given
205 in the liberty file ``mycells.lib``, the following synthesis script will
206 synthesize for the given cell library:
207
208 # the high-level stuff
209 hierarchy; proc; fsm; opt; memory; opt
210
211 # mapping to internal cell library
212 techmap; opt
213
214 # mapping flip-flops to mycells.lib
215 dfflibmap -liberty mycells.lib
216
217 # mapping logic to mycells.lib
218 abc -liberty mycells.lib
219
220 # cleanup
221 clean
222
223 If you do not have a liberty file but want to test this synthesis script,
224 you can use the file ``examples/cmos/cmos_cells.lib`` from the yosys sources.
225
226 Liberty file downloads for and information about free and open ASIC standard
227 cell libraries can be found here:
228
229 - http://www.vlsitechnology.org/html/libraries.html
230 - http://www.vlsitechnology.org/synopsys/vsclib013.lib
231
232 The command ``synth`` provides a good default synthesis script (see
233 ``help synth``). If possible a synthesis script should borrow from ``synth``.
234 For example:
235
236 # the high-level stuff
237 hierarchy
238 synth -run coarse
239
240 # mapping to internal cells
241 techmap; opt -fast
242 dfflibmap -liberty mycells.lib
243 abc -liberty mycells.lib
244 clean
245
246 Yosys is under construction. A more detailed documentation will follow.
247
248
249 Unsupported Verilog-2005 Features
250 =================================
251
252 The following Verilog-2005 features are not supported by
253 Yosys and there are currently no plans to add support
254 for them:
255
256 - Non-synthesizable language features as defined in
257 IEC 62142(E):2005 / IEEE Std. 1364.1(E):2002
258
259 - The ``tri``, ``triand``, ``trior``, ``wand`` and ``wor`` net types
260
261 - The ``config`` keyword and library map files
262
263 - The ``disable``, ``primitive`` and ``specify`` statements
264
265 - Latched logic (is synthesized as logic with feedback loops)
266
267
268 Verilog Attributes and non-standard features
269 ============================================
270
271 - The ``full_case`` attribute on case statements is supported
272 (also the non-standard ``// synopsys full_case`` directive)
273
274 - The ``parallel_case`` attribute on case statements is supported
275 (also the non-standard ``// synopsys parallel_case`` directive)
276
277 - The ``// synopsys translate_off`` and ``// synopsys translate_on``
278 directives are also supported (but the use of ``` `ifdef .. `endif ```
279 is strongly recommended instead).
280
281 - The ``nomem2reg`` attribute on modules or arrays prohibits the
282 automatic early conversion of arrays to separate registers. This
283 is potentially dangerous. Usually the front-end has good reasons
284 for converting an array to a list of registers. Prohibiting this
285 step will likely result in incorrect synthesis results.
286
287 - The ``mem2reg`` attribute on modules or arrays forces the early
288 conversion of arrays to separate registers.
289
290 - The ``nomeminit`` attribute on modules or arrays prohibits the
291 creation of initialized memories. This effectively puts ``mem2reg``
292 on all memories that are written to in an ``initial`` block and
293 are not ROMs.
294
295 - The ``nolatches`` attribute on modules or always-blocks
296 prohibits the generation of logic-loops for latches. Instead
297 all not explicitly assigned values default to x-bits. This does
298 not affect clocked storage elements such as flip-flops.
299
300 - The ``nosync`` attribute on registers prohibits the generation of a
301 storage element. The register itself will always have all bits set
302 to 'x' (undefined). The variable may only be used as blocking assigned
303 temporary variable within an always block. This is mostly used internally
304 by Yosys to synthesize Verilog functions and access arrays.
305
306 - The ``onehot`` attribute on wires mark them as one-hot state register. This
307 is used for example for memory port sharing and set by the fsm_map pass.
308
309 - The ``blackbox`` attribute on modules is used to mark empty stub modules
310 that have the same ports as the real thing but do not contain information
311 on the internal configuration. This modules are only used by the synthesis
312 passes to identify input and output ports of cells. The Verilog backend
313 also does not output blackbox modules on default.
314
315 - The ``whitebox`` attribute on modules triggers the same behavior as
316 ``blackbox``, but is for whitebox modules, i.e. library modules that
317 contain a behavioral model of the cell type.
318
319 - The ``dynports`` attribute is used by the Verilog front-end to mark modules
320 that have ports with a width that depends on a parameter.
321
322 - The ``hdlname`` attribute is used by some passes to document the original
323 (HDL) name of a module when renaming a module.
324
325 - The ``keep`` attribute on cells and wires is used to mark objects that should
326 never be removed by the optimizer. This is used for example for cells that
327 have hidden connections that are not part of the netlist, such as IO pads.
328 Setting the ``keep`` attribute on a module has the same effect as setting it
329 on all instances of the module.
330
331 - The ``keep_hierarchy`` attribute on cells and modules keeps the ``flatten``
332 command from flattening the indicated cells and modules.
333
334 - The ``init`` attribute on wires is set by the frontend when a register is
335 initialized "FPGA-style" with ``reg foo = val``. It can be used during
336 synthesis to add the necessary reset logic.
337
338 - The ``top`` attribute on a module marks this module as the top of the
339 design hierarchy. The ``hierarchy`` command sets this attribute when called
340 with ``-top``. Other commands, such as ``flatten`` and various backends
341 use this attribute to determine the top module.
342
343 - The ``src`` attribute is set on cells and wires created by to the string
344 ``<hdl-file-name>:<line-number>`` by the HDL front-end and is then carried
345 through the synthesis. When entities are combined, a new |-separated
346 string is created that contains all the string from the original entities.
347
348 - In addition to the ``(* ... *)`` attribute syntax, Yosys supports
349 the non-standard ``{* ... *}`` attribute syntax to set default attributes
350 for everything that comes after the ``{* ... *}`` statement. (Reset
351 by adding an empty ``{* *}`` statement.)
352
353 - In module parameter and port declarations, and cell port and parameter
354 lists, a trailing comma is ignored. This simplifies writing Verilog code
355 generators a bit in some cases.
356
357 - Modules can be declared with ``module mod_name(...);`` (with three dots
358 instead of a list of module ports). With this syntax it is sufficient
359 to simply declare a module port as 'input' or 'output' in the module
360 body.
361
362 - When defining a macro with `define, all text between triple double quotes
363 is interpreted as macro body, even if it contains unescaped newlines. The
364 tipple double quotes are removed from the macro body. For example:
365
366 `define MY_MACRO(a, b) """
367 assign a = 23;
368 assign b = 42;
369 """
370
371 - The attribute ``via_celltype`` can be used to implement a Verilog task or
372 function by instantiating the specified cell type. The value is the name
373 of the cell type to use. For functions the name of the output port can
374 be specified by appending it to the cell type separated by a whitespace.
375 The body of the task or function is unused in this case and can be used
376 to specify a behavioral model of the cell type for simulation. For example:
377
378 module my_add3(A, B, C, Y);
379 parameter WIDTH = 8;
380 input [WIDTH-1:0] A, B, C;
381 output [WIDTH-1:0] Y;
382 ...
383 endmodule
384
385 module top;
386 ...
387 (* via_celltype = "my_add3 Y" *)
388 (* via_celltype_defparam_WIDTH = 32 *)
389 function [31:0] add3;
390 input [31:0] A, B, C;
391 begin
392 add3 = A + B + C;
393 end
394 endfunction
395 ...
396 endmodule
397
398 - A limited subset of DPI-C functions is supported. The plugin mechanism
399 (see ``help plugin``) can be used to load .so files with implementations
400 of DPI-C routines. As a non-standard extension it is possible to specify
401 a plugin alias using the ``<alias>:`` syntax. For example:
402
403 module dpitest;
404 import "DPI-C" function foo:round = real my_round (real);
405 parameter real r = my_round(12.345);
406 endmodule
407
408 $ yosys -p 'plugin -a foo -i /lib/libm.so; read_verilog dpitest.v'
409
410 - Sized constants (the syntax ``<size>'s?[bodh]<value>``) support constant
411 expressions as <size>. If the expression is not a simple identifier, it
412 must be put in parentheses. Examples: ``WIDTH'd42``, ``(4+2)'b101010``
413
414 - The system tasks ``$finish`` and ``$display`` are supported in initial blocks
415 in an unconditional context (only if/case statements on parameters
416 and constant values). The intended use for this is synthesis-time DRC.
417
418
419 Non-standard or SystemVerilog features for formal verification
420 ==============================================================
421
422 - Support for ``assert``, ``assume``, ``restrict``, and ``cover`` is enabled
423 when ``read_verilog`` is called with ``-formal``.
424
425 - The system task ``$initstate`` evaluates to 1 in the initial state and
426 to 0 otherwise.
427
428 - The system function ``$anyconst`` evaluates to any constant value. This is
429 equivalent to declaring a reg as ``rand const``, but also works outside
430 of checkers. (Yosys also supports ``rand const`` outside checkers.)
431
432 - The system function ``$anyseq`` evaluates to any value, possibly a different
433 value in each cycle. This is equivalent to declaring a reg as ``rand``,
434 but also works outside of checkers. (Yosys also supports ``rand``
435 variables outside checkers.)
436
437 - The system functions ``$allconst`` and ``$allseq`` can be used to construct
438 formal exist-forall problems. Assumptions only hold if the trace satisfies
439 the assumption for all ``$allconst/$allseq`` values. For assertions and cover
440 statements it is sufficient if just one ``$allconst/$allseq`` value triggers
441 the property (similar to ``$anyconst/$anyseq``).
442
443 - Wires/registers declared using the ``anyconst/anyseq/allconst/allseq`` attribute
444 (for example ``(* anyconst *) reg [7:0] foobar;``) will behave as if driven
445 by a ``$anyconst/$anyseq/$allconst/$allseq`` function.
446
447 - The SystemVerilog tasks ``$past``, ``$stable``, ``$rose`` and ``$fell`` are
448 supported in any clocked block.
449
450 - The syntax ``@($global_clock)`` can be used to create FFs that have no
451 explicit clock input ($ff cells). The same can be achieved by using
452 ``@(posedge <netname>)`` or ``@(negedge <netname>)`` when ``<netname>``
453 is marked with the ``(* gclk *)`` Verilog attribute.
454
455
456 Supported features from SystemVerilog
457 =====================================
458
459 When ``read_verilog`` is called with ``-sv``, it accepts some language features
460 from SystemVerilog:
461
462 - The ``assert`` statement from SystemVerilog is supported in its most basic
463 form. In module context: ``assert property (<expression>);`` and within an
464 always block: ``assert(<expression>);``. It is transformed to a $assert cell.
465
466 - The ``assume``, ``restrict``, and ``cover`` statements from SystemVerilog are
467 also supported. The same limitations as with the ``assert`` statement apply.
468
469 - The keywords ``always_comb``, ``always_ff`` and ``always_latch``, ``logic``
470 and ``bit`` are supported.
471
472 - Declaring free variables with ``rand`` and ``rand const`` is supported.
473
474 - Checkers without a port list that do not need to be instantiated (but instead
475 behave like a named block) are supported.
476
477 - SystemVerilog packages are supported. Once a SystemVerilog file is read
478 into a design with ``read_verilog``, all its packages are available to
479 SystemVerilog files being read into the same design afterwards.
480
481 - SystemVerilog interfaces (SVIs) are supported. Modports for specifying whether
482 ports are inputs or outputs are supported.
483
484
485 Building the documentation
486 ==========================
487
488 Note that there is no need to build the manual if you just want to read it.
489 Simply download the PDF from http://www.clifford.at/yosys/documentation.html
490 instead.
491
492 On Ubuntu, texlive needs these packages to be able to build the manual:
493
494 sudo apt-get install texlive-binaries
495 sudo apt-get install texlive-science # install algorithm2e.sty
496 sudo apt-get install texlive-bibtex-extra # gets multibib.sty
497 sudo apt-get install texlive-fonts-extra # gets skull.sty and dsfont.sty
498 sudo apt-get install texlive-publishers # IEEEtran.cls
499
500 Also the non-free font luximono should be installed, there is unfortunately
501 no Ubuntu package for this so it should be installed separately using
502 `getnonfreefonts`:
503
504 wget https://tug.org/fonts/getnonfreefonts/install-getnonfreefonts
505 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
506 getnonfreefonts luximono # installs to /home/user/texmf
507
508 Then execute, from the root of the repository:
509
510 make manual
511
512 Notes:
513
514 - To run `make manual` you need to have installed Yosys with `make install`,
515 otherwise it will fail on finding `kernel/yosys.h` while building
516 `PRESENTATION_Prog`.