Revert "Merge remote-tracking branch 'origin/eddie/shregmap_improve' into xc7mux"
[yosys.git] / kernel / yosys.cc
index a12355f1d509453bf54bc6b4414f019e90fcee73..377572fc2984243a2ede59d2e35af34a7fa27b8d 100644 (file)
@@ -151,14 +151,16 @@ void yosys_banner()
 
 int ceil_log2(int x)
 {
+#if defined(__GNUC__)
+        return x > 1 ? (8*sizeof(int)) - __builtin_clz(x-1) : 0;
+#else
        if (x <= 0)
                return 0;
-
        for (int i = 0; i < 32; i++)
                if (((x-1) >> i) == 0)
                        return i;
-
        log_abort();
+#endif
 }
 
 std::string stringf(const char *fmt, ...)
@@ -482,6 +484,20 @@ void remove_directory(std::string dirname)
 #endif
 }
 
+std::string escape_filename_spaces(const std::string& filename)
+{
+       std::string out;
+       out.reserve(filename.size());
+       for (auto c : filename)
+       {
+               if (c == ' ')
+                       out += "\\ ";
+               else
+                       out.push_back(c);
+       }
+       return out;
+}
+
 int GetSize(RTLIL::Wire *wire)
 {
        return wire->width;