Add RTLIL::constpad, init by yosys_setup(); use for abc9
authorEddie Hung <eddie@fpgeh.com>
Tue, 7 Jan 2020 20:52:03 +0000 (12:52 -0800)
committerEddie Hung <eddie@fpgeh.com>
Wed, 8 Jan 2020 18:52:08 +0000 (10:52 -0800)
kernel/rtlil.cc
kernel/rtlil.h
kernel/yosys.cc
passes/cmds/scratchpad.cc
passes/techmap/abc9.cc

index ab4f4f377a84e4c30936fce7e0f4b7645b29256b..f286d139f92585fbf1a325d8e03ff73dd0310109 100644 (file)
@@ -46,6 +46,7 @@ IdString RTLIL::ID::Y;
 IdString RTLIL::ID::keep;
 IdString RTLIL::ID::whitebox;
 IdString RTLIL::ID::blackbox;
+dict<std::string, std::string> RTLIL::constpad;
 
 RTLIL::Const::Const()
 {
index e5b24cc02efb992e8199cf9468a72fa39fb25722..6251d265d486977f541d6e35baa11a3752b4b924 100644 (file)
@@ -377,6 +377,8 @@ namespace RTLIL
                extern IdString blackbox;
        };
 
+       extern dict<std::string, std::string> constpad;
+
        static inline std::string escape_id(std::string str) {
                if (str.size() > 0 && str[0] != '\\' && str[0] != '$')
                        return "\\" + str;
index 5018a48883f7c0768767811b6bba29ae8c246850..6c8427c19491480086e43637c3aee2d26c4ee97a 100644 (file)
@@ -524,6 +524,15 @@ void yosys_setup()
                PyRun_SimpleString("import sys");
        #endif
 
+       RTLIL::constpad["abc9.script.default"] = "&scorr; &sweep; &dc2; &dch -f; &ps; &if {C} {W} {D} -v; &mfs";
+       RTLIL::constpad["abc9.script.default.area"] = "&scorr; &sweep; &dc2; &dch -f; &ps; &if {C} {W} {D} -a -v; &mfs";
+       RTLIL::constpad["abc9.script.default.fast"] = "&if {W} {D}";
+       RTLIL::constpad["abc9.script.flow3"] = "&scorr; &sweep;" \
+               "&if {C} {W} {D}; &save; &st; &syn2; &if {C} {W} {D} -v; &save; &load; "\
+               "&st; &if {C} -g -K 6; &dch -f; &if {C} {W} {D} -v; &save; &load; "\
+               "&st; &if {C} -g -K 6; &synch2; &if {C} {W} {D} -v; &save; &load; "\
+               "&mfs";
+
        Pass::init_register();
        yosys_design = new RTLIL::Design;
        yosys_celltypes.setup();
index 7ec55b78ebe78eb1b956e6570e091733e754c295..34ec0863a490bb7ded0ba70cecf84e8fa0a8be70 100644 (file)
@@ -70,8 +70,10 @@ struct ScratchpadPass : public Pass {
                {
                        if (args[argidx] == "-get" && argidx+1 < args.size()) {
                                string identifier = args[++argidx];
-                               if (design->scratchpad.count(identifier)){
+                               if (design->scratchpad.count(identifier)) {
                                        log("%s\n", design->scratchpad_get_string(identifier).c_str());
+                               } else if (RTLIL::constpad.count(identifier)) {
+                                       log("%s\n", RTLIL::constpad.at(identifier).c_str());
                                } else {
                                        log("\"%s\" not set\n", identifier.c_str());
                                }
@@ -79,6 +81,8 @@ struct ScratchpadPass : public Pass {
                        }
                        if (args[argidx] == "-set" && argidx+2 < args.size()) {
                                string identifier = args[++argidx];
+                               if (RTLIL::constpad.count(identifier))
+                                       log_error("scratchpad entry \"%s\" is a global constant\n", identifier.c_str());
                                string value = args[++argidx];
                                if (value.front() == '\"' && value.back() == '\"') value = value.substr(1, value.size() - 2);
                                design->scratchpad_set_string(identifier, value);
@@ -92,8 +96,15 @@ struct ScratchpadPass : public Pass {
                        if (args[argidx] == "-copy" && argidx+2 < args.size()) {
                                string identifier_from = args[++argidx];
                                string identifier_to = args[++argidx];
-                               if (design->scratchpad.count(identifier_from) == 0) log_error("\"%s\" not set\n", identifier_from.c_str());
-                               string value = design->scratchpad_get_string(identifier_from);
+                               string value;
+                               if (design->scratchpad.count(identifier_from))
+                                       value = design->scratchpad_get_string(identifier_from);
+                               else if (RTLIL::constpad.count(identifier_from))
+                                       value = RTLIL::constpad.at(identifier_from);
+                               else
+                                       log_error("\"%s\" not set\n", identifier_from.c_str());
+                               if (RTLIL::constpad.count(identifier_to))
+                                       log_error("scratchpad entry \"%s\" is a global constant\n", identifier_to.c_str());
                                design->scratchpad_set_string(identifier_to, value);
                                continue;
                        }
@@ -102,10 +113,10 @@ struct ScratchpadPass : public Pass {
                                string expected = args[++argidx];
                                if (expected.front() == '\"' && expected.back() == '\"') expected = expected.substr(1, expected.size() - 2);
                                if (design->scratchpad.count(identifier) == 0)
-                                       log_error("Assertion failed: scratchpad entry '%s' is not defined\n", identifier.c_str());
+                                       log_error("scratchpad entry '%s' is not defined\n", identifier.c_str());
                                string value = design->scratchpad_get_string(identifier);
                                if (value != expected) {
-                                       log_error("Assertion failed: scratchpad entry '%s' is set to '%s' instead of the asserted '%s'\n",
+                                       log_error("scratchpad entry '%s' is set to '%s' instead of the asserted '%s'\n",
                                                   identifier.c_str(), value.c_str(), expected.c_str());
                                }
                                continue;
@@ -113,13 +124,13 @@ struct ScratchpadPass : public Pass {
                        if (args[argidx] == "-assert-set" && argidx+1 < args.size()) {
                                string identifier = args[++argidx];
                                if (design->scratchpad.count(identifier) == 0)
-                                       log_error("Assertion failed: scratchpad entry '%s' is not defined\n", identifier.c_str());
+                                       log_error("scratchpad entry '%s' is not defined\n", identifier.c_str());
                                continue;
                        }
                        if (args[argidx] == "-assert-unset" && argidx+1 < args.size()) {
                                string identifier = args[++argidx];
                                if (design->scratchpad.count(identifier) > 0)
-                                       log_error("Assertion failed: scratchpad entry '%s' is defined\n", identifier.c_str());
+                                       log_error("scratchpad entry '%s' is defined\n", identifier.c_str());
                                continue;
                        }
                        break;
index 8cb34e52313c0e18ef3c65ba284d2a39c8e58900..486b9313b0479db85fa05a2e90f5ab443559060d 100644 (file)
 // Berkeley Logic Synthesis and Verification Group, ABC: A System for Sequential Synthesis and Verification
 // http://www.eecs.berkeley.edu/~alanmi/abc/
 
-#if 0
-// Based on &flow3 - better QoR but more experimental
-#define ABC_COMMAND_LUT "&st; &ps -l; &sweep -v; &scorr; " \
-                                               "&st; &if {W}; &save; &st; &syn2; &if {W} -v; &save; &load; "\
-                                               "&st; &if -g -K 6; &dch -f; &if {W} -v; &save; &load; "\
-                                               "&st; &if -g -K 6; &synch2; &if {W} -v; &save; &load; "\
-                                               "&mfs; &ps -l"
-#else
-#define ABC_COMMAND_LUT "&st; &scorr; &sweep; &dc2; &st; &dch -f; &ps; &if {W} {D} -v; &mfs; &ps -l"
-#endif
-
-
-#define ABC_FAST_COMMAND_LUT "&st; &if {W} {D}"
-
 #include "kernel/register.h"
 #include "kernel/sigtools.h"
 #include "kernel/celltypes.h"
@@ -292,7 +278,8 @@ void abc9_module(RTLIL::Design *design, RTLIL::Module *module, std::string scrip
                } else
                        abc9_script += stringf("source %s", script_file.c_str());
        } else if (!lut_costs.empty() || !lut_file.empty()) {
-               abc9_script += fast_mode ? ABC_FAST_COMMAND_LUT : ABC_COMMAND_LUT;
+               abc9_script += fast_mode ? RTLIL::constpad.at("abc9.script.default.fast")
+                       : RTLIL::constpad.at("abc9.script.default");
        } else
                log_abort();
 
@@ -305,11 +292,14 @@ void abc9_module(RTLIL::Design *design, RTLIL::Module *module, std::string scrip
        for (size_t pos = abc9_script.find("{W}"); pos != std::string::npos; pos = abc9_script.find("{W}", pos))
                abc9_script = abc9_script.substr(0, pos) + wire_delay + abc9_script.substr(pos+3);
 
+       for (size_t pos = abc9_script.find("{C}"); pos != std::string::npos; pos = abc9_script.find("{C}", pos))
+               abc9_script = abc9_script.substr(0, pos) + design->scratchpad_get_string("abc9.if.C", "") + abc9_script.substr(pos+3);
+
        if (nomfs)
                for (size_t pos = abc9_script.find("&mfs"); pos != std::string::npos; pos = abc9_script.find("&mfs", pos))
                        abc9_script = abc9_script.erase(pos, strlen("&mfs"));
 
-       abc9_script += stringf("; &write -n %s/output.aig", tempdir_name.c_str());
+       abc9_script += stringf("&ps -l; &write -n %s/output.aig", tempdir_name.c_str());
        abc9_script = add_echos_to_abc9_cmd(abc9_script);
 
        for (size_t i = 0; i+1 < abc9_script.size(); i++)
@@ -758,18 +748,15 @@ struct Abc9Pass : public Pass {
                log("\n");
                log("        if no -script parameter is given, the following scripts are used:\n");
                log("\n");
-               log("        for -lut/-luts (only one LUT size):\n");
-               log("%s\n", fold_abc9_cmd(ABC_COMMAND_LUT).c_str());
-               log("\n");
-               log("        for -lut/-luts (different LUT sizes):\n");
-               log("%s\n", fold_abc9_cmd(ABC_COMMAND_LUT).c_str());
+               log("        for -lut/-luts:\n");
+               log("%s\n", fold_abc9_cmd(RTLIL::constpad.at("abc9.script.default")).c_str());
                log("\n");
                log("    -fast\n");
                log("        use different default scripts that are slightly faster (at the cost\n");
                log("        of output quality):\n");
                log("\n");
                log("        for -lut/-luts:\n");
-               log("%s\n", fold_abc9_cmd(ABC_FAST_COMMAND_LUT).c_str());
+               log("%s\n", fold_abc9_cmd(RTLIL::constpad.at("abc9.script.default.fast")).c_str());
                log("\n");
                log("    -D <picoseconds>\n");
                log("        set delay target. the string {D} in the default scripts above is\n");
@@ -883,9 +870,6 @@ struct Abc9Pass : public Pass {
                        }
                        if (arg == "-script" && argidx+1 < args.size()) {
                                script_file = args[++argidx];
-                               rewrite_filename(script_file);
-                               if (!script_file.empty() && !is_absolute_path(script_file) && script_file[0] != '+')
-                                       script_file = std::string(pwd) + "/" + script_file;
                                continue;
                        }
                        if (arg == "-D" && argidx+1 < args.size()) {