2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
20 #include "kernel/register.h"
21 #include "kernel/celltypes.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct SynthIce40Pass
: public ScriptPass
30 SynthIce40Pass() : ScriptPass("synth_ice40", "synthesis for iCE40 FPGAs") { }
32 void on_register() YS_OVERRIDE
34 RTLIL::constpad
["synth_ice40.abc9.hx.W"] = "250";
35 RTLIL::constpad
["synth_ice40.abc9.lp.W"] = "400";
36 RTLIL::constpad
["synth_ice40.abc9.u.W"] = "750";
39 void help() YS_OVERRIDE
41 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
43 log(" synth_ice40 [options]\n");
45 log("This command runs synthesis for iCE40 FPGAs.\n");
47 log(" -device < hx | lp | u >\n");
48 log(" relevant only for '-abc9' flow, optimise timing for the specified device.\n");
49 log(" default: hx\n");
51 log(" -top <module>\n");
52 log(" use the specified module as top module\n");
54 log(" -blif <file>\n");
55 log(" write the design to the specified BLIF file. writing of an output file\n");
56 log(" is omitted if this parameter is not specified.\n");
58 log(" -edif <file>\n");
59 log(" write the design to the specified EDIF file. writing of an output file\n");
60 log(" is omitted if this parameter is not specified.\n");
62 log(" -json <file>\n");
63 log(" write the design to the specified JSON file. writing of an output file\n");
64 log(" is omitted if this parameter is not specified.\n");
66 log(" -run <from_label>:<to_label>\n");
67 log(" only run the commands between the labels (see below). an empty\n");
68 log(" from label is synonymous to 'begin', and empty to label is\n");
69 log(" synonymous to the end of the command list.\n");
72 log(" do not flatten design before synthesis\n");
75 log(" run 'abc'/'abc9' with -dff option\n");
78 log(" run 'abc' with '-dff -D 1' options\n");
81 log(" do not use SB_CARRY cells in output netlist\n");
84 log(" do not use SB_DFFE* cells in output netlist\n");
86 log(" -dffe_min_ce_use <min_ce_use>\n");
87 log(" do not use SB_DFFE* cells if the resulting CE line would go to less\n");
88 log(" than min_ce_use SB_DFFE* in output netlist\n");
91 log(" do not use SB_RAM40_4K* cells in output netlist\n");
94 log(" use iCE40 UltraPlus DSP cells for large arithmetic\n");
97 log(" use built-in Yosys LUT techmapping instead of abc\n");
100 log(" run two passes of 'abc' for slightly improved logic density\n");
103 log(" generate an output netlist (and BLIF file) suitable for VPR\n");
104 log(" (this feature is experimental and incomplete)\n");
107 log(" use new ABC9 flow (EXPERIMENTAL)\n");
110 log(" use FlowMap LUT techmapping instead of abc (EXPERIMENTAL)\n");
113 log("The following commands are executed by this synthesis command:\n");
118 string top_opt
, blif_file
, edif_file
, json_file
, device_opt
;
119 bool nocarry
, nodffe
, nobram
, dsp
, flatten
, retime
, noabc
, abc2
, vpr
, abc9
, dff
, flowmap
;
122 void clear_flags() YS_OVERRIDE
124 top_opt
= "-auto-top";
143 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
145 string run_from
, run_to
;
149 for (argidx
= 1; argidx
< args
.size(); argidx
++)
151 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
152 top_opt
= "-top " + args
[++argidx
];
155 if (args
[argidx
] == "-blif" && argidx
+1 < args
.size()) {
156 blif_file
= args
[++argidx
];
159 if (args
[argidx
] == "-edif" && argidx
+1 < args
.size()) {
160 edif_file
= args
[++argidx
];
163 if (args
[argidx
] == "-json" && argidx
+1 < args
.size()) {
164 json_file
= args
[++argidx
];
167 if (args
[argidx
] == "-run" && argidx
+1 < args
.size()) {
168 size_t pos
= args
[argidx
+1].find(':');
169 if (pos
== std::string::npos
)
171 run_from
= args
[++argidx
].substr(0, pos
);
172 run_to
= args
[argidx
].substr(pos
+1);
175 if (args
[argidx
] == "-flatten") {
179 if (args
[argidx
] == "-noflatten") {
183 if (args
[argidx
] == "-retime") {
187 if (args
[argidx
] == "-relut") {
188 // removed, opt_lut is always run
191 if (args
[argidx
] == "-nocarry") {
195 if (args
[argidx
] == "-nodffe") {
199 if (args
[argidx
] == "-dffe_min_ce_use" && argidx
+1 < args
.size()) {
200 min_ce_use
= atoi(args
[++argidx
].c_str());
203 if (args
[argidx
] == "-nobram") {
207 if (args
[argidx
] == "-dsp") {
211 if (args
[argidx
] == "-noabc") {
215 if (args
[argidx
] == "-abc2") {
219 if (args
[argidx
] == "-vpr") {
223 if (args
[argidx
] == "-abc9") {
227 if (args
[argidx
] == "-dff") {
231 if (args
[argidx
] == "-device" && argidx
+1 < args
.size()) {
232 device_opt
= args
[++argidx
];
235 if (args
[argidx
] == "-flowmap") {
241 extra_args(args
, argidx
, design
);
243 if (!design
->full_selection())
244 log_cmd_error("This command only operates on fully selected designs!\n");
245 if (device_opt
!= "hx" && device_opt
!= "lp" && device_opt
!="u")
246 log_cmd_error("Invalid or no device specified: '%s'\n", device_opt
.c_str());
249 log_cmd_error("-retime option not currently compatible with -abc9!\n");
251 log_cmd_error("-abc9 is incompatible with -noabc!\n");
253 log_cmd_error("-abc9 is incompatible with -flowmap!\n");
254 if (flowmap
&& noabc
)
255 log_cmd_error("-flowmap is incompatible with -noabc!\n");
257 log_header(design
, "Executing SYNTH_ICE40 pass.\n");
260 run_script(design
, run_from
, run_to
);
265 void script() YS_OVERRIDE
268 if (device_opt
== "lp")
269 define
= "-D ICE40_LP";
270 else if (device_opt
== "u")
271 define
= "-D ICE40_U";
273 define
= "-D ICE40_HX";
274 if (check_label("begin"))
276 run("read_verilog " + define
+ " -lib -specify +/ice40/cells_sim.v");
277 run(stringf("hierarchy -check %s", help_mode
? "-top <top>" : top_opt
.c_str()));
281 if (check_label("flatten", "(unless -noflatten)"))
285 run("tribuf -logic");
290 if (check_label("coarse"))
300 run("techmap -map +/cmp2lut.v -D LUT_WIDTH=4");
303 if (help_mode
|| dsp
) {
304 run("memory_dff"); // ice40_dsp will merge registers, reserve memory port registers first
305 run("wreduce t:$mul");
306 run("techmap -map +/mul2dsp.v -map +/ice40/dsp_map.v -D DSP_A_MAXWIDTH=16 -D DSP_B_MAXWIDTH=16 "
307 "-D DSP_A_MINWIDTH=2 -D DSP_B_MINWIDTH=2 -D DSP_Y_MINWIDTH=11 "
308 "-D DSP_NAME=$__MUL16X16", "(if -dsp)");
309 run("select a:mul2dsp", " (if -dsp)");
310 run("setattr -unset mul2dsp", " (if -dsp)");
311 run("opt_expr -fine", " (if -dsp)");
312 run("wreduce", " (if -dsp)");
313 run("select -clear", " (if -dsp)");
314 run("ice40_dsp", " (if -dsp)");
315 run("chtype -set $mul t:$__soft_mul", "(if -dsp)");
321 run("memory -nomap");
325 if (!nobram
&& check_label("map_bram", "(skip if -nobram)"))
327 run("memory_bram -rules +/ice40/brams.txt");
328 run("techmap -map +/ice40/brams_map.v");
329 run("ice40_braminit");
332 if (check_label("map_ffram"))
334 run("opt -fast -mux_undef -undriven -fine");
335 run("memory_map -iattr -attr !ram_block -attr !rom_block -attr logic_block "
336 "-attr syn_ramstyle=auto -attr syn_ramstyle=registers "
337 "-attr syn_romstyle=auto -attr syn_romstyle=logic");
338 run("opt -undriven -fine");
341 if (check_label("map_gates"))
346 run("ice40_wrapcarry");
347 run("techmap -map +/techmap.v -map +/ice40/arith_map.v");
350 if (retime
|| help_mode
)
351 run("abc -dff -D 1", "(only if -retime)");
355 if (check_label("map_ffs"))
358 run("dff2dffe -direct-match $_DFF_*");
359 if (min_ce_use
>= 0) {
361 run(stringf("dff2dffe -unmap-mince %d", min_ce_use
));
362 run("simplemap t:$dff");
364 if ((abc9
&& dff
) || help_mode
)
365 run("zinit -all", "(-abc9 and -dff only)");
366 run("techmap -map +/ice40/ff_map.v");
367 run("opt_expr -mux_undef");
371 run("ice40_opt -full");
374 if (check_label("map_luts"))
376 if (abc2
|| help_mode
) {
377 run("abc", " (only if -abc2)");
378 run("ice40_opt", "(only if -abc2)");
380 run("techmap -map +/ice40/latches_map.v");
381 if (noabc
|| flowmap
|| help_mode
) {
382 run("simplemap", " (if -noabc or -flowmap)");
383 if (noabc
|| help_mode
)
384 run("techmap -map +/gate2lut.v -D LUT_WIDTH=4", "(only if -noabc)");
385 if (flowmap
|| help_mode
)
386 run("flowmap -maxlut 4", "(only if -flowmap)");
390 run("read_verilog " + define
+ " -icells -lib -specify +/abc9_model.v +/ice40/abc9_model.v");
391 std::string abc9_opts
;
392 std::string k
= "synth_ice40.abc9.W";
393 if (active_design
&& active_design
->scratchpad
.count(k
))
394 abc9_opts
+= stringf(" -W %s", active_design
->scratchpad_get_string(k
).c_str());
396 k
= stringf("synth_ice40.abc9.%s.W", device_opt
.c_str());
397 abc9_opts
+= stringf(" -W %s", RTLIL::constpad
.at(k
).c_str());
400 abc9_opts
+= " -dff";
401 run("abc9 " + abc9_opts
);
404 run(stringf("abc -dress -lut 4 %s", dff
? "-dff" : ""), "(skip if -noabc)");
406 run("ice40_wrapcarry -unwrap");
407 run("techmap -map +/ice40/ff_map.v");
409 run("opt_lut -dlogic SB_CARRY:I0=2:I1=1:CI=0");
412 if (check_label("map_cells"))
415 run("techmap -map +/ice40/cells_map.v", "(skip if -vpr)");
417 run("techmap -map +/ice40/cells_map.v");
421 if (check_label("check"))
424 run("hierarchy -check");
426 run("check -noinit");
429 if (check_label("blif"))
431 if (!blif_file
.empty() || help_mode
) {
432 if (vpr
|| help_mode
) {
433 run(stringf("opt_clean -purge"),
435 run(stringf("write_blif -attr -cname -conn -param %s",
436 help_mode
? "<file-name>" : blif_file
.c_str()),
440 run(stringf("write_blif -gates -attr -param %s",
441 help_mode
? "<file-name>" : blif_file
.c_str()),
446 if (check_label("edif"))
448 if (!edif_file
.empty() || help_mode
)
449 run(stringf("write_edif %s", help_mode
? "<file-name>" : edif_file
.c_str()));
452 if (check_label("json"))
454 if (!json_file
.empty() || help_mode
)
455 run(stringf("write_json %s", help_mode
? "<file-name>" : json_file
.c_str()));
460 PRIVATE_NAMESPACE_END