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