sv: More tests for wildcard port connections
[yosys.git] / manual / CHAPTER_StateOfTheArt.tex
1
2 \chapter{Evaluation of other OSS Verilog Synthesis Tools}
3 \label{chapter:sota}
4
5 In this appendix\footnote{This appendix is an updated version of an
6 unpublished student research paper. \cite{VerilogFossEval}}
7 the existing FOSS Verilog synthesis tools\footnote{To the
8 author's best knowledge, all relevant tools that existed at the time of this
9 writing are included. But as there is no formal channel through which such
10 tools are published it is hard to give any guarantees in that matter.} are
11 evaluated. Extremely limited or application specific tools (e.g.~pure Verilog
12 Netlist parsers) as well as Verilog simulators are not included. These existing
13 solutions are tested using a set of representative Verilog code snippets. It is
14 shown that no existing FOSS tool implements even close to a sufficient subset
15 of Verilog to be usable as synthesis tool for a wide range existing Verilog code.
16
17 The packages evaluated are:
18
19 \begin{itemize}
20 \item Icarus Verilog \citeweblink{Icarus}\footnote{Icarus Verilog is mainly a simulation
21 tool but also supported synthesis up to version 0.8. Therefore version 0.8.7 is used
22 for this evaluation.)}
23 \item Verilog-to-Routing (VTR) / Odin-II \cite{vtr2012}\cite{Odin}\citeweblink{VTR}
24 \item HDL Analyzer and Netlist Architect (HANA) \citeweblink{HANA}
25 \item Verilog front-end to VIS (vl2mv) \cite{Cheng93vl2mv:a}\citeweblink{VIS}
26 \end{itemize}
27
28 In each of the following sections Verilog modules that test a certain Verilog
29 language feature are presented and the support for these features is tested in all
30 the tools mentioned above. It is evaluated whether the tools under test
31 successfully generate netlists for the Verilog input and whether these netlists
32 match the simulation behavior of the designs using testbenches.
33
34 All test cases are verified to be synthesizeable using Xilinx XST from the Xilinx
35 WebPACK \citeweblink{XilinxWebPACK} suite.
36
37 Trivial features such as support for simple structural Verilog are not explicitly tested.
38
39 Vl2mv and Odin-II generate output in the BLIF (Berkeley Logic Interchange
40 Format) and BLIF-MV (an extended version of BLIF) formats respectively.
41 ABC \citeweblink{ABC} is used to convert this output to Verilog for verification
42 using testbenches.
43
44 Icarus Verilog generates EDIF (Electronic Design Interchange Format) output
45 utilizing LPM (Library of Parameterized Modules) cells. The EDIF files are
46 converted to Verilog using edif2ngd and netgen from Xilinx WebPACK. A
47 hand-written implementation of the LPM cells utilized by the generated netlists
48 is used for verification.
49
50 Following these functional tests, a quick analysis of the extensibility of the tools
51 under test is provided in a separate section.
52
53 The last section of this chapter finally concludes these series of evaluations
54 with a summary of the results.
55
56 \begin{figure}[t!]
57 \begin{minipage}{7.7cm}
58 \lstinputlisting[numbers=left,frame=single,language=Verilog]{CHAPTER_StateOfTheArt/always01_pub.v}
59 \end{minipage}
60 \hfill
61 \begin{minipage}{7.7cm}
62 \lstinputlisting[frame=single,language=Verilog]{CHAPTER_StateOfTheArt/always02_pub.v}
63 \end{minipage}
64 \caption{1st and 2nd Verilog always examples}
65 \label{fig:StateOfTheArt_always12}
66 \end{figure}
67
68 \begin{figure}[!]
69 \lstinputlisting[numbers=left,frame=single,language=Verilog]{CHAPTER_StateOfTheArt/always03.v}
70 \caption{3rd Verilog always example}
71 \label{fig:StateOfTheArt_always3}
72 \end{figure}
73
74 \section{Always blocks and blocking vs.~nonblocking assignments}
75 \label{sec:blocking_nonblocking}
76
77 The ``always''-block is one of the most fundamental non-trivial Verilog
78 language features. It can be used to model a combinatorial path (with optional
79 registers on the outputs) in a way that mimics a regular programming language.
80
81 Within an always block, if- and case-statements can be used to model multiplexers.
82 Blocking assignments ($=$) and nonblocking assignments ($<=$) are used to populate the
83 leaf-nodes of these multiplexer trees. Unassigned leaf-nodes default to feedback
84 paths that cause the output register to hold the previous value. More advanced
85 synthesis tools often convert these feedback paths to register enable signals or
86 even generate circuits with clock gating.
87
88 Registers assigned with nonblocking assignments ($<=$) behave differently from
89 variables in regular programming languages: In a simulation they are not
90 updated immediately after being assigned. Instead the right-hand sides are
91 evaluated and the results stored in temporary memory locations. After all
92 pending updates have been prepared in this way they are executed, thus yielding
93 semi-parallel execution of all nonblocking assignments.
94
95 For synthesis this means that every occurrence of that register in an expression
96 addresses the output port of the corresponding register regardless of the question whether the register
97 has been assigned a new value in an earlier command in the same always block.
98 Therefore with nonblocking assignments the order of the assignments has no effect
99 on the resulting circuit as long as the left-hand sides of the assignments are
100 unique.
101
102 The three example codes in Fig.~\ref{fig:StateOfTheArt_always12} and
103 Fig.~\ref{fig:StateOfTheArt_always3} use all these features and can thus be used
104 to test the synthesis tools capabilities to synthesize always blocks correctly.
105
106 The first example is only using the most fundamental Verilog features. All
107 tools under test were able to successfully synthesize this design.
108
109 \begin{figure}[b!]
110 \lstinputlisting[numbers=left,frame=single,language=Verilog]{CHAPTER_StateOfTheArt/arrays01.v}
111 \caption{Verilog array example}
112 \label{fig:StateOfTheArt_arrays}
113 \end{figure}
114
115 The 2nd example is functionally identical to the 1st one but is using an
116 if-statement inside the always block. Odin-II fails to synthesize it and
117 instead produces the following error message:
118
119 \begin{verbatim}
120 ERROR: (File: always02.v) (Line number: 13)
121 You've defined the driver "count~0" twice
122 \end{verbatim}
123
124 Vl2mv does not produce an error message but outputs an invalid synthesis result
125 that is not using the reset input at all.
126
127 Icarus Verilog also doesn't produce an error message but generates an invalid output
128 for this 2nd example. The code generated by Icarus Verilog only implements the reset
129 path for the count register, effectively setting the output to constant 0.
130
131 So of all tools under test only HANA was able to create correct synthesis results
132 for the 2nd example.
133
134 The 3rd example is using blocking and nonblocking assignments and many if statements.
135 Odin also fails to synthesize this example:
136
137 \begin{verbatim}
138 ERROR: (File: always03.v) (Line number: 8)
139 ODIN doesn't handle blocking statements in Sequential blocks
140 \end{verbatim}
141
142 HANA, Icarus Verilog and vl2mv create invalid synthesis results for the 3rd example.
143
144 So unfortunately none of the tools under test provide a complete and correct
145 implementation of blocking and nonblocking assignments.
146
147 \section{Arrays for memory modelling}
148
149 Verilog arrays are part of the synthesizeable subset of Verilog and are
150 commonly used to model addressable memory. The Verilog code in
151 Fig.~\ref{fig:StateOfTheArt_arrays} demonstrates this by implementing a single
152 port memory.
153
154 For this design HANA, vl2m and ODIN-II generate error messages indicating that
155 arrays are not supported.
156
157 \begin{figure}[t!]
158 \lstinputlisting[numbers=left,frame=single,language=Verilog]{CHAPTER_StateOfTheArt/forgen01.v}
159 \caption{Verilog for loop example}
160 \label{fig:StateOfTheArt_for}
161 \end{figure}
162
163 Icarus Verilog produces an invalid output that is using the address only for
164 reads. Instead of using the address input for writes, the generated design
165 simply loads the data to all memory locations whenever the write-enable input
166 is active, effectively turning the design into a single 4-bit D-Flip-Flop with
167 enable input.
168
169 As all tools under test already fail this simple test, there is nothing to gain
170 by continuing tests on this aspect of Verilog synthesis such as synthesis of dual port
171 memories, correct handling of write collisions, and so forth.
172
173 \begin{figure}[t!]
174 \lstinputlisting[numbers=left,frame=single,language=Verilog]{CHAPTER_StateOfTheArt/forgen02.v}
175 \caption{Verilog generate example}
176 \label{fig:StateOfTheArt_gen}
177 \end{figure}
178
179 \section{For-loops and generate blocks}
180
181 For-loops and generate blocks are more advanced Verilog features. These features
182 allow the circuit designer to add program code to her design that is evaluated
183 during synthesis to generate (parts of) the circuits description; something that
184 could only be done using a code generator otherwise.
185
186 For-loops are only allowed in synthesizeable Verilog if they can be completely
187 unrolled. Then they can be a powerful tool to generate array logic or static
188 lookup tables. The code in Fig.~\ref{fig:StateOfTheArt_for} generates a circuit that
189 tests a 5 bit value for being a prime number using a static lookup table.
190
191 Generate blocks can be used to model array logic in complex parametric designs. The
192 code in Fig.~\ref{fig:StateOfTheArt_gen} implements a ripple-carry adder with
193 parametric width from simple assign-statements and logic operations using a Verilog
194 generate block.
195
196 All tools under test failed to synthesize both test cases. HANA creates invalid
197 output in both cases. Icarus Verilog creates invalid output for the first
198 test and fails with an error for the second case. The other two tools fail with
199 error messages for both tests.
200
201 \section{Extensibility}
202
203 This section briefly discusses the extensibility of the tools under test and
204 their internal data- and control-flow. As all tools under test already failed
205 to synthesize simple Verilog always-blocks correctly, not much resources have
206 been spent on evaluating the extensibility of these tools and therefore only a
207 very brief discussion of the topic is provided here.
208
209 HANA synthesizes for a built-in library of standard cells using two passes over
210 an AST representation of the Verilog input. This approach executes fast but
211 limits the extensibility as everything happens in only two comparable complex
212 AST walks and there is no universal intermediate representation that is flexible
213 enough to be used in arbitrary optimizations.
214
215 Odin-II and vl2m are both front ends to existing synthesis flows. As such they
216 only try to quickly convert the Verilog input into the internal representation
217 of their respective flows (BLIF). So extensibility is less of an issue here as
218 potential extensions would likely be implemented in other components of the
219 flow.
220
221 Icarus Verilog is clearly designed to be a simulation tool rather than a
222 synthesis tool. The synthesis part of Icarus Verilog is an ad-hoc add-on to
223 Icarus Verilog that aims at converting an internal representation that is meant
224 for generation of a virtual machine based simulation code to netlists.
225
226 \section{Summary and Outlook}
227
228 Table~\ref{tab:StateOfTheArt_sum} summarizes the tests performed. Clearly none
229 of the tools under test make a serious attempt at providing a feature-complete
230 implementation of Verilog. It can be argued that Odin-II performed best in the
231 test as it never generated incorrect code but instead produced error messages
232 indicating that unsupported Verilog features where used in the Verilog input.
233
234 In conclusion, to the best knowledge of the author, there is no FOSS Verilog
235 synthesis tool other than Yosys that is anywhere near feature completeness and
236 therefore there is no other candidate for a generic Verilog front end and/or
237 synthesis framework to be used as a basis for custom synthesis tools.
238
239 Yosys could also replace vl2m and/or Odin-II in their respective flows or
240 function as a pre-compiler that can translate full-featured Verilog code to the
241 simple subset of Verilog that is understood by vl2m and Odin-II.
242
243 Yosys is designed for extensibility. It can be used as-is to synthesize Verilog
244 code to netlists, but its main purpose is to be used as basis for custom tools.
245 Yosys is structured in a language dependent Verilog front end and language
246 independent synthesis code (which is in itself structured in independent
247 passes). This architecture will simplify implementing additional HDL front
248 ends and/or additional synthesis passes.
249
250 Chapter~\ref{chapter:eval} contains a more detailed evaluation of Yosys using real-world
251 designs that are far out of reach for any of the other tools discussed in this appendix.
252
253 \vskip2cm
254 \begin{table}[h]
255 % yosys hana vis icarus odin
256 % always01 ok ok ok ok ok
257 % always02 ok ok failed failed error
258 % always03 ok failed failed missing error
259 % arrays01 ok error error failed error
260 % forgen01 ok failed error failed error
261 % forgen02 ok failed error error error
262 \def\ok{\ding{52}}
263 \def\error{\ding{56}}
264 \def\failed{$\skull$}
265 \def\missing{$\skull$}
266 \rowcolors{2}{gray!25}{white}
267 \centerline{
268 \begin{tabular}{|l|cccc|c|}
269 \hline
270 & \bf HANA & \bf VIS / vl2m & \bf Icarus Verilog & \bf Odin-II & \bf Yosys \\
271 \hline
272 \tt always01 & \ok & \ok & \ok & \ok & \ok \\
273 \tt always02 & \ok & \failed & \failed & \error & \ok \\
274 \tt always03 & \failed & \failed & \missing & \error & \ok \\
275 \tt arrays01 & \error & \error & \failed & \error & \ok \\
276 \tt forgen01 & \failed & \error & \failed & \error & \ok \\
277 \tt forgen02 & \failed & \error & \error & \error & \ok \\
278 \hline
279 \end{tabular}
280 }
281 \centerline{
282 \ding{52} \dots passed \hskip2em
283 \ding{56} \dots produced error \hskip2em
284 $\skull$ \dots incorrect output
285 }
286 \caption{Summary of all test results}
287 \label{tab:StateOfTheArt_sum}
288 \end{table}
289