Harmonize BRAM/LUTRAM descriptions across all of Yosys.
[yosys.git] / techlibs / ecp5 / synth_ecp5.cc
index b1d3160bae95ed1d48613f5037642b2134e0b8e1..3985da57af12b478816ad76e51ccae3fe12e6449 100644 (file)
@@ -79,6 +79,9 @@ struct SynthEcp5Pass : public ScriptPass
                log("    -nowidelut\n");
                log("        do not use PFU muxes to implement LUTs larger than LUT4s\n");
                log("\n");
+               log("    -asyncprld\n");
+               log("        use async PRLD mode to implement DLATCH and DFFSR (EXPERIMENTAL)\n");
+               log("\n");
                log("    -abc2\n");
                log("        run two passes of 'abc' for slightly improved logic density\n");
                log("\n");
@@ -89,6 +92,9 @@ struct SynthEcp5Pass : public ScriptPass
                log("        generate an output netlist (and BLIF file) suitable for VPR\n");
                log("        (this feature is experimental and incomplete)\n");
                log("\n");
+               log("    -nodsp\n");
+               log("        do not map multipliers to MULT18X18D\n");
+               log("\n");
                log("\n");
                log("The following commands are executed by this synthesis command:\n");
                help_script();
@@ -96,7 +102,7 @@ struct SynthEcp5Pass : public ScriptPass
        }
 
        string top_opt, blif_file, edif_file, json_file;
-       bool noccu2, nodffe, nobram, nolutram, nowidelut, flatten, retime, abc2, abc9, vpr;
+       bool noccu2, nodffe, nobram, nolutram, nowidelut, asyncprld, flatten, retime, abc2, abc9, nodsp, vpr;
 
        void clear_flags() YS_OVERRIDE
        {
@@ -109,11 +115,13 @@ struct SynthEcp5Pass : public ScriptPass
                nobram = false;
                nolutram = false;
                nowidelut = false;
+               asyncprld = false;
                flatten = true;
                retime = false;
                abc2 = false;
                vpr = false;
                abc9 = false;
+               nodsp = false;
        }
 
        void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
@@ -172,6 +180,10 @@ struct SynthEcp5Pass : public ScriptPass
                                nobram = true;
                                continue;
                        }
+                       if (args[argidx] == "-asyncprld") {
+                               asyncprld = true;
+                               continue;
+                       }
                        if (args[argidx] == "-nolutram" || /*deprecated alias*/ args[argidx] == "-nodram") {
                                nolutram = true;
                                continue;
@@ -192,6 +204,10 @@ struct SynthEcp5Pass : public ScriptPass
                                abc9 = true;
                                continue;
                        }
+                       if (args[argidx] == "-nodsp") {
+                               nodsp = true;
+                               continue;
+                       }
                        break;
                }
                extra_args(args, argidx, design);
@@ -214,32 +230,49 @@ struct SynthEcp5Pass : public ScriptPass
        {
                if (check_label("begin"))
                {
-                       run("read_verilog -D_ABC -lib +/ecp5/cells_sim.v +/ecp5/cells_bb.v");
+                       run("read_verilog -lib +/ecp5/cells_sim.v +/ecp5/cells_bb.v");
                        run(stringf("hierarchy -check %s", help_mode ? "-top <top>" : top_opt.c_str()));
                }
 
-               if (flatten && check_label("flatten", "(unless -noflatten)"))
+               if (check_label("coarse"))
                {
                        run("proc");
-                       run("flatten");
+                       if (flatten || help_mode)
+                               run("flatten");
                        run("tribuf -logic");
                        run("deminout");
-               }
-
-               if (check_label("coarse"))
-               {
-                       run("synth -run coarse");
+                       run("opt_expr");
+                       run("opt_clean");
+                       run("check");
+                       run("opt");
+                       run("wreduce");
+                       run("peepopt");
+                       run("opt_clean");
+                       run("share");
+                       run("techmap -map +/cmp2lut.v -D LUT_WIDTH=4");
+                       run("opt_expr");
+                       run("opt_clean");
+                       if (!nodsp) {
+                               run("techmap -map +/mul2dsp.v -map +/ecp5/dsp_map.v -D DSP_A_MAXWIDTH=18 -D DSP_B_MAXWIDTH=18  -D DSP_A_MINWIDTH=2 -D DSP_B_MINWIDTH=2  -D DSP_NAME=$__MUL18X18", "(unless -nodsp)");
+                               run("chtype -set $mul t:$__soft_mul", "(unless -nodsp)");
+                       }
+                       run("alumacc");
+                       run("opt");
+                       run("fsm");
+                       run("opt -fast");
+                       run("memory -nomap");
+                       run("opt_clean");
                }
 
                if (!nobram && check_label("map_bram", "(skip if -nobram)"))
                {
-                       run("memory_bram -rules +/ecp5/bram.txt");
+                       run("memory_bram -rules +/ecp5/brams.txt");
                        run("techmap -map +/ecp5/brams_map.v");
                }
 
                if (!nolutram && check_label("map_lutram", "(skip if -nolutram)"))
                {
-                       run("memory_bram -rules +/ecp5/lutram.txt");
+                       run("memory_bram -rules +/ecp5/lutrams.txt");
                        run("techmap -map +/ecp5/lutrams_map.v");
                }
 
@@ -267,10 +300,13 @@ struct SynthEcp5Pass : public ScriptPass
                        run("opt_clean");
                        if (!nodffe)
                                run("dff2dffe -direct-match $_DFF_* -direct-match $__DFFS_*");
-                       run("techmap -D NO_LUT -map +/ecp5/cells_map.v");
+                       run(stringf("techmap -D NO_LUT %s -map +/ecp5/cells_map.v", help_mode ? "[-D ASYNC_PRLD]" : (asyncprld ? "-D ASYNC_PRLD" : "")));
                        run("opt_expr -undriven -mux_undef");
                        run("simplemap");
                        run("ecp5_ffinit");
+                       run("ecp5_gsr");
+                       run("attrmvcp -copy -attr syn_useioff");
+                       run("opt_clean");
                }
 
                if (check_label("map_luts"))
@@ -278,17 +314,19 @@ struct SynthEcp5Pass : public ScriptPass
                        if (abc2 || help_mode) {
                                run("abc", "      (only if -abc2)");
                        }
-                       std::string techmap_args = "-map +/ecp5/latches_map.v";
+                       std::string techmap_args = asyncprld ? "" : "-map +/ecp5/latches_map.v";
                        if (abc9)
-                               techmap_args += " -map +/ecp5/abc_map.v -max_iter 1";
-                       run("techmap " + techmap_args);
+                               techmap_args += " -map +/ecp5/abc9_map.v -max_iter 1";
+                       if (!asyncprld || abc9)
+                               run("techmap " + techmap_args);
 
                        if (abc9) {
+                               run("read_verilog -icells -lib +/ecp5/abc9_model.v");
                                if (nowidelut)
-                                       run("abc9 -lut +/ecp5/abc_5g_nowide.lut -box +/ecp5/abc_5g.box -W 200");
+                                       run("abc9 -lut +/ecp5/abc9_5g_nowide.lut -box +/ecp5/abc9_5g.box -W 200 -nomfs");
                                else
-                                       run("abc9 -lut +/ecp5/abc_5g.lut -box +/ecp5/abc_5g.box -W 200");
-                               run("techmap -map +/ecp5/abc_unmap.v");
+                                       run("abc9 -lut +/ecp5/abc9_5g.lut -box +/ecp5/abc9_5g.box -W 200 -nomfs");
+                               run("techmap -map +/ecp5/abc9_unmap.v");
                        } else {
                                if (nowidelut)
                                        run("abc -lut 4 -dress");
@@ -310,6 +348,7 @@ struct SynthEcp5Pass : public ScriptPass
 
                if (check_label("check"))
                {
+                       run("autoname");
                        run("hierarchy -check");
                        run("stat");
                        run("check -noinit");