Do actual compare
authorMiodrag Milanovic <mmicko@gmail.com>
Fri, 28 Jan 2022 11:50:41 +0000 (12:50 +0100)
committerMiodrag Milanovic <mmicko@gmail.com>
Fri, 28 Jan 2022 11:50:41 +0000 (12:50 +0100)
kernel/fstdata.cc
kernel/fstdata.h
passes/sat/sim.cc

index 466b8f19f147986140b7cba744fff8ff29588a05..d700f61b66b3daa2d3a7eb901a5ee27bd4221a49 100644 (file)
@@ -96,45 +96,47 @@ void FstData::extractVarNames()
        }
 }
 
-static void reconstruct_clb_varlen(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen)
+static void reconstruct_edges_varlen(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen)
 {
        FstData *ptr = (FstData*)user_data;
-       ptr->reconstruct_callback(pnt_time, pnt_facidx, pnt_value, plen);
+       ptr->reconstruct_edges_callback(pnt_time, pnt_facidx, pnt_value, plen);
 }
 
-static void reconstruct_clb(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value)
+static void reconstruct_edges(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value)
 {
        FstData *ptr = (FstData*)user_data;
        uint32_t plen = (pnt_value) ?  strlen((const char *)pnt_value) : 0;
-       ptr->reconstruct_callback(pnt_time, pnt_facidx, pnt_value, plen);
+       ptr->reconstruct_edges_callback(pnt_time, pnt_facidx, pnt_value, plen);
 }
 
-void FstData::reconstruct_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t /* plen */)
+void FstData::reconstruct_edges_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t /* plen */)
 {
-       handle_to_data[pnt_facidx].push_back(std::make_pair(pnt_time, std::string((const char *)pnt_value)));
-       size_t index = handle_to_data[pnt_facidx].size() - 1;
-       time_to_index[pnt_facidx][pnt_time] = index;
-       index_to_time[pnt_facidx][index] = pnt_time;
+       std::string val = std::string((const char *)pnt_value);
+       std::string prev = last_data[pnt_facidx];
+       if (pnt_time>=start_time) {
+               if (prev=="0" && val=="1")
+                       edges.push_back(pnt_time);
+               if (prev=="1" && val=="0")
+                       edges.push_back(pnt_time);
+       }
+       last_data[pnt_facidx] = val;
 }
 
-void FstData::reconstruct(std::vector<fstHandle> &signal)
+std::vector<uint64_t> FstData::getAllEdges(std::vector<fstHandle> &signal, uint64_t start, uint64_t end)
 {
-       handle_to_data.clear();
-       time_to_index.clear();
-       index_to_time.clear();
+       start_time = start;
+       end_time = end;
+       last_data.clear();
+       for(auto &s : signal) {
+               last_data[s] = "x";
+       }
+       edges.clear();
+       fstReaderSetLimitTimeRange(ctx, start_time, end_time);
        fstReaderClrFacProcessMaskAll(ctx);
        for(const auto sig : signal)
                fstReaderSetFacProcessMask(ctx,sig);
-       fstReaderIterBlocks2(ctx, reconstruct_clb, reconstruct_clb_varlen, this, nullptr);
-}
-
-void FstData::reconstuctAll()
-{
-       handle_to_data.clear();
-       time_to_index.clear();
-       index_to_time.clear();
-       fstReaderSetFacProcessMaskAll(ctx);
-       fstReaderIterBlocks2(ctx, reconstruct_clb, reconstruct_clb_varlen, this, nullptr);
+       fstReaderIterBlocks2(ctx, reconstruct_edges, reconstruct_edges_varlen, this, nullptr);
+       return edges;
 }
 
 static void reconstruct_clb_varlen_attimes(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen)
@@ -153,10 +155,11 @@ static void reconstruct_clb_attimes(void *user_data, uint64_t pnt_time, fstHandl
 void FstData::reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t /* plen */)
 {
        if (sample_times_ndx > sample_times.size()) return;
+
        uint64_t time = sample_times[sample_times_ndx];
        // if we are past the timestamp
        if (pnt_time > time) {
-               for (auto const& c : current)
+               for (auto const& c : last_data)
                {
                        handle_to_data[c.first].push_back(std::make_pair(time,c.second));
                        size_t index = handle_to_data[c.first].size() - 1;
@@ -165,8 +168,8 @@ void FstData::reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_faci
                }
                sample_times_ndx++;
        }
-       // always update current
-       current[pnt_facidx] =  std::string((const char *)pnt_value);
+       // always update last_data
+       last_data[pnt_facidx] =  std::string((const char *)pnt_value);
 }
 
 void FstData::reconstructAtTimes(std::vector<fstHandle> &signal, std::vector<uint64_t> time)
@@ -174,16 +177,17 @@ void FstData::reconstructAtTimes(std::vector<fstHandle> &signal, std::vector<uin
        handle_to_data.clear();
        time_to_index.clear();
        index_to_time.clear();
-       current.clear();
+       last_data.clear();
        sample_times_ndx = 0;
        sample_times = time;
+       fstReaderSetUnlimitedTimeRange(ctx);
        fstReaderClrFacProcessMaskAll(ctx);
        for(const auto sig : signal)
                fstReaderSetFacProcessMask(ctx,sig);
        fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr);
 
        if (time_to_index[signal.back()].count(time.back())==0) {
-               for (auto const& c : current)
+               for (auto const& c : last_data)
                {
                        handle_to_data[c.first].push_back(std::make_pair(time.back(),c.second));
                        size_t index = handle_to_data[c.first].size() - 1;
@@ -198,26 +202,29 @@ void FstData::reconstructAllAtTimes(std::vector<uint64_t> time)
        handle_to_data.clear();
        time_to_index.clear();
        index_to_time.clear();
-       current.clear();
+       last_data.clear();
        sample_times_ndx = 0;
        sample_times = time;
+
+       fstReaderSetUnlimitedTimeRange(ctx);
        fstReaderSetFacProcessMaskAll(ctx);
        fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr);
-/*
-       if (time_to_index[signal.back()].count(time.back())==0) {
-               for (auto const& c : current)
+
+       if (time_to_index[1].count(time.back())==0) {
+               for (auto const& c : last_data)
                {
                        handle_to_data[c.first].push_back(std::make_pair(time.back(),c.second));
                        size_t index = handle_to_data[c.first].size() - 1;
                        time_to_index[c.first][time.back()] = index;
                        index_to_time[c.first][index] = time.back();
                }
-       }*/
+       }
 }
 
 std::string FstData::valueAt(fstHandle signal, uint64_t time)
 {
-       // TODO: Check if signal exist
+       if (handle_to_data.find(signal) == handle_to_data.end())
+               log_error("Signal id %d not found\n", (int)signal);
        auto &data = handle_to_data[signal];
        if (time_to_index[signal].count(time)!=0) {
                size_t index = time_to_index[signal][time];
@@ -233,34 +240,3 @@ std::string FstData::valueAt(fstHandle signal, uint64_t time)
                return data.at(index).second;
        }
 }
-
-std::vector<uint64_t> FstData::edges(fstHandle signal, bool positive, bool negative)
-{
-       // TODO: Check if signal exist
-       auto &data = handle_to_data[signal];
-       std::string prev = "x";
-       std::vector<uint64_t> retVal;
-       for(auto &d : data) {
-               if (positive && prev=="0" && d.second=="1")
-                       retVal.push_back(d.first);
-               if (negative && prev=="1" && d.second=="0")
-                       retVal.push_back(d.first);
-               prev = d.second;
-       }
-       return retVal;
-}
-
-void FstData::recalc_time_offsets(fstHandle signal, std::vector<uint64_t> time)
-{
-       size_t index = 0;
-       auto &data = handle_to_data[signal];
-       for(auto curr : time) {
-               for(size_t i = index; i< data.size(); i++) {
-                       uint64_t t = index_to_time[signal][i];
-                       if (t > curr) 
-                               break;
-                       index = i;
-               }
-               time_to_index[signal][curr] = index;
-       }
-}
index 4c54a3f22127c750e744d5eab78df95c99318693..5d4899f47052b55ee01ad4161aa0431b6c9f54d1 100644 (file)
@@ -45,18 +45,14 @@ class FstData
 
        std::vector<FstVar>& getVars() { return vars; };
 
-       void reconstruct_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
-       void reconstruct(std::vector<fstHandle> &signal);
-       void reconstuctAll();
+       void reconstruct_edges_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
+       std::vector<uint64_t> getAllEdges(std::vector<fstHandle> &signal, uint64_t start_time, uint64_t end_time);
 
        void reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
        void reconstructAtTimes(std::vector<fstHandle> &signal,std::vector<uint64_t> time);
        void reconstructAllAtTimes(std::vector<uint64_t> time);
 
        std::string valueAt(fstHandle signal, uint64_t time);
-       std::vector<uint64_t> edges(fstHandle signal, bool positive, bool negative);
-       void recalc_time_offsets(fstHandle signal, std::vector<uint64_t> time);
-
        fstHandle getHandle(std::string name);
        double getTimescale() { return timescale; }
 private:
@@ -68,12 +64,15 @@ private:
        std::map<fstHandle, FstVar> handle_to_var;
        std::map<std::string, fstHandle> name_to_handle;
        std::map<fstHandle, std::vector<std::pair<uint64_t, std::string>>> handle_to_data;
+       std::map<fstHandle, std::string> last_data;
        std::map<fstHandle, std::map<uint64_t, size_t>> time_to_index;
        std::map<fstHandle, std::map<size_t, uint64_t>> index_to_time;
        std::vector<uint64_t> sample_times;
        size_t sample_times_ndx;
-       std::map<fstHandle, std::string> current;
        double timescale;
+       uint64_t start_time;
+       uint64_t end_time;
+       std::vector<uint64_t> edges;
 };
 
 YOSYS_NAMESPACE_END
index d6f5f3a81d1a79c34c2a515ee626400e3ec12cc9..e9e1140477f6c9201288d55ce6adb7a2be386956 100644 (file)
@@ -966,21 +966,32 @@ struct SimWorker : SimShared
                                log_warning("Stop time is after simulation file end time\n");
                        }
                }
-               fst->reconstruct(fst_clock);
-               auto edges = fst->edges(fst_clock.back(), true, true);
+               auto edges = fst->getAllEdges(fst_clock, startCount, stopCount);
                fst->reconstructAllAtTimes(edges);
-/*             for(auto &time : edges) {
+               for(auto &time : edges) {
                        for(auto &item : inputs) {
                                std::string v = fst->valueAt(item.second, time);
                                top->set_state(item.first, Const::from_string(v));
                        }
                        update();
+                       bool status = true;
                        for(auto &item : outputs) {
                                Const fst_val = Const::from_string(fst->valueAt(item.second, time));
                                Const sim_val = top->get_state(item.first);
-                               log("%s %s\n", log_signal(fst_val), log_signal(sim_val));
+                               if (sim_mode == SimulationMode::gate && !fst_val.is_fully_def()) { // FST data contains X
+                                       // TODO: check bit by bit
+                               } else if (sim_mode == SimulationMode::gold && !sim_val.is_fully_def()) { // sim data contains X
+                                       // TODO: check bit by bit
+                               } else {
+                                       if (fst_val!=sim_val) {
+                                               status = false;
+                                               log("signal: %s fst: %s  sim: %s\n", log_id(item.first), log_signal(fst_val), log_signal(sim_val));
+                                       }
+                               }
                        }
-               }*/
+                       if (!status)
+                               log_error("Signal difference at %zu\n", time);
+               }
        }
 };