Display simulation time data
authorMiodrag Milanovic <mmicko@gmail.com>
Mon, 31 Jan 2022 09:52:47 +0000 (10:52 +0100)
committerMiodrag Milanovic <mmicko@gmail.com>
Mon, 31 Jan 2022 09:52:47 +0000 (10:52 +0100)
kernel/fstdata.cc
kernel/fstdata.h
passes/sat/sim.cc

index 5d6d85ed8c5ee6f0cd92231a3026c9331e748502..a7a2c80f7f4aba0e250c782bc3c7f3000f750306 100644 (file)
 
 USING_YOSYS_NAMESPACE
 
+
 FstData::FstData(std::string filename) : ctx(nullptr)
 {
+       const std::vector<std::string> g_units = { "s", "ms", "us", "ns", "ps", "fs", "as", "zs" };
        ctx = (fstReaderContext *)fstReaderOpen(filename.c_str());
-       timescale = pow(10.0, (int)fstReaderGetTimescale(ctx));
+       int scale = (int)fstReaderGetTimescale(ctx);    
+       timescale = pow(10.0, scale);
+       timescale_str = "";
+       int unit = 0;
+       int zeros = 0;
+       if (scale > 0)  {
+               zeros = scale;
+       } else {
+               if ((scale % 3) == 0) {
+                       zeros = (-scale % 3);
+                       unit = (-scale / 3);
+               } else {
+                       zeros = 3 - (-scale % 3);
+                       unit = (-scale / 3) + 1;
+               }
+       }
+       for (int i=0;i<zeros; i++) timescale_str += "0";
+       if (zeros>0)timescale_str += " ";
+       timescale_str += g_units[unit];
        extractVarNames();
 }
 
index 8095981a295379b4f35e472bdee7866c279886e1..c069ff5e5b8b418c3e3e078fcb4f69ac6b5a72dc 100644 (file)
@@ -55,6 +55,7 @@ class FstData
        std::string valueAt(fstHandle signal, uint64_t time);
        fstHandle getHandle(std::string name);
        double getTimescale() { return timescale; }
+       const char *getTimescaleString() { return timescale_str.c_str(); }
 private:
        void extractVarNames();
 
@@ -69,6 +70,7 @@ private:
        std::vector<uint64_t> sample_times;
        size_t sample_times_ndx;
        double timescale;
+       std::string timescale_str;
        uint64_t start_time;
        uint64_t end_time;
        std::vector<uint64_t> edges;
index ff815b69a7ef1f0b3b36dbaf44688c9e7b3bbc00..05fe112012d959fa78160f9a6c975a5e35ee22b1 100644 (file)
@@ -1033,7 +1033,9 @@ struct SimWorker : SimShared
                                log_error("No clock edges found in given time range\n");
                        fst->reconstructAllAtTimes(edges);
                        bool initial = false;
+                       int cycle = 0;
                        for(auto &time : edges) {
+                               log("Simulating cycle %d [%zu %s].\n", cycle+1, time, fst->getTimescaleString());
                                for(auto &item : inputs) {
                                        std::string v = fst->valueAt(item.second, time);
                                        top->set_state(item.first, Const::from_string(v));
@@ -1046,7 +1048,8 @@ struct SimWorker : SimShared
 
                                bool status = top->checkSignals(time);
                                if (status)
-                                       log_error("Signal difference at %zu\n", time);
+                                       log_error("Signal difference\n");
+                               cycle++;
                        }
                }
        }