presentation progress
[yosys.git] / manual / PRESENTATION_ExSyn.tex
1
2 \section{Yosys by example -- Synthesis}
3
4 \begin{frame}
5 \sectionpage
6 \end{frame}
7
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9
10 \subsection{Typical Phases of a Synthesis Flow}
11
12 \begin{frame}{\subsecname}
13 \begin{itemize}
14 \item Reading and elaborating the design
15 \item High-level synthesis and optimization
16 \begin{itemize}
17 \item Converting {\tt always}-blocks to logic and registers
18 \item Perform coarse-grain optimizations (resource sharing, const folding, ...)
19 \item Handling of memories and other coarse-grain blocks
20 \item Extracting and optimizing finite state machines
21 \end{itemize}
22 \item Convert remaining logic to bit-level logic functions
23 \item Perform optimizations on bit-level logic functions
24 \item Map bit-level logic and register to gates from cell library
25 \item Write results to output file
26 \end{itemize}
27 \end{frame}
28
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30
31 \subsection{Reading the design}
32
33 \begin{frame}[fragile]{\subsecname}
34 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
35 read_verilog file1.v
36 read_verilog -I include_dir -D enable_foo -D WIDTH=12 file2.v
37 read_verilog -lib cell_library.v
38
39 verilog_defaults -add -I include_dir
40 read_verilog file3.v
41 read_verilog file4.v
42 verilog_defaults -clear
43
44 verilog_defaults -push
45 verilog_defaults -add -I include_dir
46 read_verilog file5.v
47 read_verilog file6.v
48 verilog_defaults -pop
49 \end{lstlisting}
50 \end{frame}
51
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 \subsection{Design elaboration}
55
56 \begin{frame}[fragile]{\subsecname}
57 During design elaboration Yosys figures out how the modules are hierarchically
58 connected. It also re-runs the AST parts of the Verilog frontend to create
59 all needed variations of parametric modules.
60
61 \bigskip
62 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
63 # simplest form. at least this version should be used after reading all input files
64 #
65 hierarchy
66
67 # recommended form. fail if parts of the design hierarchy are missing. remove
68 # everything that is unreachable by the top module. mark the top module.
69 #
70 hierarchy -check -top top_module
71 \end{lstlisting}
72 \end{frame}
73
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76 \subsection{The ``proc'' commands}
77
78 \begin{frame}[fragile]{\subsecname}
79 The Verilog frontend converts {\tt always}-blocks to RTL netlists for the
80 expressions and ``processes'' for the control- and memory elements.
81
82 \medskip
83 The {\tt proc} command transforms this ``processes'' to netlists of RTL
84 multiplexer and register cells.
85
86 \medskip
87 The {\tt proc} command is actually a macro-command that calls the following
88 other commands:
89
90 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
91 proc_clean # remove empty branches and processes
92 proc_rmdead # remove unreachable branches
93 proc_init # special handling of "initial" blocks
94 proc_arst # identify modeling of async resets
95 proc_mux # convert decision trees to multiplexer networks
96 proc_dff # extract registers from processes
97 proc_clean # if all went fine, this should remove all the processes
98 \end{lstlisting}
99
100 \medskip
101 Many commands can not operate on modules with ``processes'' in them. Usually
102 a call to {\tt proc} is the first command in the actual synthesis procedure
103 after design elaboration.
104 \end{frame}
105
106 \begin{frame}[fragile]{\subsecname{} -- Example 1/3}
107 \begin{columns}
108 \column[t]{5cm}
109 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/proc_01.v}
110 \column[t]{5cm}
111 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/proc_01.ys}
112 \end{columns}
113 \hfil\includegraphics[width=8cm,trim=0 0cm 0 0cm]{PRESENTATION_ExSyn/proc_01.pdf}
114 \end{frame}
115
116 \begin{frame}[t, fragile]{\subsecname{} -- Example 2/3}
117 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm -2.5cm]{PRESENTATION_ExSyn/proc_02.pdf}\vss}
118 \vskip-1cm
119 \begin{columns}
120 \column[t]{5cm}
121 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/proc_02.v}
122 \column[t]{5cm}
123 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/proc_02.ys}
124 \end{columns}
125 \end{frame}
126
127 \begin{frame}[t, fragile]{\subsecname{} -- Example 3/3}
128 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm -1.5cm]{PRESENTATION_ExSyn/proc_03.pdf}\vss}
129 \vskip-1cm
130 \begin{columns}
131 \column[t]{5cm}
132 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/proc_03.ys}
133 \column[t]{5cm}
134 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/proc_03.v}
135 \end{columns}
136 \end{frame}
137
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139
140 \subsection{The ``opt'' commands}
141
142 \begin{frame}[fragile]{\subsecname}
143 The {\tt opt} command implements a series of simple optimizations. It also
144 is a macro command that calls other commands:
145
146 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
147 opt_const # const folding
148 opt_share -nomux # merging identical cells
149
150 do
151 opt_muxtree # remove never-active branches from multiplexer tree
152 opt_reduce # consolidate trees of boolean ops to reduce functions
153 opt_share # merging identical cells
154 opt_rmdff # remove/simplify registers with constant inputs
155 opt_clean # remove unused objects (cells, wires) from design
156 opt_const # const folding
157 while [changed design]
158 \end{lstlisting}
159
160 The command {\tt clean} can be used as alias for {\tt opt\_clean}. And {\tt ;;}
161 can be used as shortcut for {\tt clean}. For example:
162
163 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
164 proc; opt; memory; opt_const;; fsm;;
165 \end{lstlisting}
166 \end{frame}
167
168 \begin{frame}[t, fragile]{\subsecname{} -- Example 1/4}
169 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm -0.5cm]{PRESENTATION_ExSyn/opt_01.pdf}\vss}
170 \vskip-1cm
171 \begin{columns}
172 \column[t]{5cm}
173 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/opt_01.ys}
174 \column[t]{5cm}
175 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/opt_01.v}
176 \end{columns}
177 \end{frame}
178
179 \begin{frame}[t, fragile]{\subsecname{} -- Example 2/4}
180 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm 0cm]{PRESENTATION_ExSyn/opt_02.pdf}\vss}
181 \vskip-1cm
182 \begin{columns}
183 \column[t]{5cm}
184 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/opt_02.ys}
185 \column[t]{5cm}
186 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/opt_02.v}
187 \end{columns}
188 \end{frame}
189
190 \begin{frame}[t, fragile]{\subsecname{} -- Example 3/4}
191 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm -2cm]{PRESENTATION_ExSyn/opt_03.pdf}\vss}
192 \vskip-1cm
193 \begin{columns}
194 \column[t]{5cm}
195 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/opt_03.ys}
196 \column[t]{5cm}
197 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/opt_03.v}
198 \end{columns}
199 \end{frame}
200
201 \begin{frame}[t, fragile]{\subsecname{} -- Example 4/4}
202 \vbox to 0cm{\hskip6cm\includegraphics[width=6cm,trim=0cm 0cm 0cm -3cm]{PRESENTATION_ExSyn/opt_04.pdf}\vss}
203 \vskip-1cm
204 \begin{columns}
205 \column[t]{5cm}
206 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/opt_04.v}
207 \column[t]{5cm}
208 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/opt_04.ys}
209 \end{columns}
210 \end{frame}
211
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214 \subsection{When to use ``opt'' or ``clean''}
215
216 \begin{frame}{\subsecname}
217 Usually it does not hurt to call {\tt opt} after each regular command in the
218 synthesis script. But it increases the synthesis time, so it is favourable
219 to only call {\tt opt} when an improvement can be archieved.
220
221 \bigskip
222 The designs in {\tt yosys-bigsim} are a good playground for experimenting with
223 the effects of calling {\tt opt} in various places of the flow.
224
225 \bigskip
226 It generally is a good idea us call {\tt opt} before inherently expensive
227 commands such as {\tt sat} or {\tt freduce}, as the possible gain is much
228 higher in this cases as the possible loss.
229
230 \bigskip
231 The {\tt clean} command on the other hand is very fast and many commands leave
232 a mess (dangling signal wires, etc). For example, most commands do not remove
233 any wires or cells. They just change the connections and depend on a later
234 call to clean to get rid of the now unused objects. So the occasional {\tt ;;}
235 is a good idea in every synthesis script.
236 \end{frame}
237
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239
240 \subsection{The ``memory'' commands}
241
242 \begin{frame}[fragile]{\subsecname}
243 In the RTL netlist, memory reads and writes are individual cells. This makes
244 consolidating the number of ports for a memory easier. The {\tt memory}
245 transforms memories to an implementation. Per default that is logic for address
246 decoders and registers. It also is a macro command that calls other commands:
247
248 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
249 # this merges registers into the memory read- and write cells.
250 memory_dff
251
252 # this collects all read and write cells for a memory and transforms them
253 # into one multi-port memory cell.
254 memory_collect
255
256 # this takes the multi-port memory cells and transforms it to address decoder
257 # logic and registers. This step is skipped if "memory" is called with -nomap.
258 memory_map
259 \end{lstlisting}
260
261 \bigskip
262 Usually it is preferred to use architecture-specific RAM resources for memory.
263 For example:
264
265 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
266 memory -nomap; techmap -map my_memory_map.v; memory_map
267 \end{lstlisting}
268 \end{frame}
269
270 \begin{frame}[t, fragile]{\subsecname{} -- Example 1/2}
271 \vbox to 0cm{\includegraphics[width=\linewidth,trim=0cm 0cm 0cm -10cm]{PRESENTATION_ExSyn/memory_01.pdf}\vss}
272 \vskip-1cm
273 \begin{columns}
274 \column[t]{5cm}
275 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/memory_01.ys}
276 \column[t]{5cm}
277 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/memory_01.v}
278 \end{columns}
279 \end{frame}
280
281 \begin{frame}[t, fragile]{\subsecname{} -- Example 2/2}
282 \vbox to 0cm{\hfill\includegraphics[width=7.5cm,trim=0cm 0cm 0cm -6cm]{PRESENTATION_ExSyn/memory_02.pdf}\vss}
283 \vskip-1cm
284 \begin{columns}
285 \column[t]{5cm}
286 \lstinputlisting[basicstyle=\ttfamily\fontsize{6pt}{8pt}\selectfont, language=verilog]{PRESENTATION_ExSyn/memory_02.v}
287 \column[t]{5cm}
288 \lstinputlisting[basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont, frame=single]{PRESENTATION_ExSyn/memory_02.ys}
289 \end{columns}
290 \end{frame}
291
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293
294 \subsection{The ``fsm'' commands}
295
296 \begin{frame}[fragile]{\subsecname{}}
297 The {\tt fsm} command identifies, extracts, optimizes (re-encodes), and
298 re-synthesizes finite state machines. It again is a macro that calls
299 a series of other commands:
300
301 \begin{lstlisting}[xleftmargin=0.5cm, basicstyle=\ttfamily\fontsize{8pt}{10pt}\selectfont]
302 fsm_detect # unless got option -nodetect
303 fsm_extract
304
305 fsm_opt
306 opt_clean
307 fsm_opt
308
309 fsm_expand # if got option -expand
310 opt_clean # if got option -expand
311 fsm_opt # if got option -expand
312
313 fsm_recode # unless got option -norecode
314
315 fsm_info
316
317 fsm_export # if got option -export
318 fsm_map # unless got option -nomap
319 \end{lstlisting}
320 \end{frame}
321
322 \begin{frame}{\subsecname{} -- details}
323 Some details on the most importand commands from the {\tt fsm\_*} group:
324
325 \bigskip
326 The {\tt fsm\_detect} command identifies FSM state registers and marks them
327 with the {\tt (* fsm\_encoding = "auto" *)} attribute, if they do not have the
328 {\tt fsm\_encoding} set already. Mark registers with {\tt (* fsm\_encoding =
329 "none" *)} to disable FSM optimization for a register.
330
331 \bigskip
332 The {\tt fsm\_extract} command replaces the entire FSM (logic and state
333 registers) with a {\tt \$fsm} cell.
334
335 \bigskip
336 The commands {\tt fsm\_opt} and {\tt fsm\_recode} can be used to optimize the
337 FSM.
338
339 \bigskip
340 Finally the {\tt fsm\_map} command can be used to convert the (optimized) {\tt
341 \$fsm} cell back to logic and registers.
342 \end{frame}
343
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345
346 \subsection{The ``techmap'' command}
347
348 \begin{frame}{\subsecname}
349 TBD
350 \end{frame}
351
352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353
354 \subsection{The ``abc'' command}
355
356 \begin{frame}{\subsecname}
357 TBD
358 \end{frame}
359
360 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361
362 \subsection{Other special-purpose mapping commands}
363
364 \begin{frame}{\subsecname}
365 TBD
366 \end{frame}
367
368 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369