From 4f75a2ca1b4a71ad335124b45d36eed9c8d619c8 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 28 Jan 2022 12:50:41 +0100 Subject: [PATCH] Do actual compare --- kernel/fstdata.cc | 106 ++++++++++++++++++---------------------------- kernel/fstdata.h | 13 +++--- passes/sat/sim.cc | 21 ++++++--- 3 files changed, 63 insertions(+), 77 deletions(-) diff --git a/kernel/fstdata.cc b/kernel/fstdata.cc index 466b8f19f..d700f61b6 100644 --- a/kernel/fstdata.cc +++ b/kernel/fstdata.cc @@ -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 &signal) +std::vector FstData::getAllEdges(std::vector &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 &signal, std::vector time) @@ -174,16 +177,17 @@ void FstData::reconstructAtTimes(std::vector &signal, std::vector 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 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 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 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; - } -} diff --git a/kernel/fstdata.h b/kernel/fstdata.h index 4c54a3f22..5d4899f47 100644 --- a/kernel/fstdata.h +++ b/kernel/fstdata.h @@ -45,18 +45,14 @@ class FstData std::vector& 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 &signal); - void reconstuctAll(); + void reconstruct_edges_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen); + std::vector getAllEdges(std::vector &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 &signal,std::vector time); void reconstructAllAtTimes(std::vector time); std::string valueAt(fstHandle signal, uint64_t time); - std::vector edges(fstHandle signal, bool positive, bool negative); - void recalc_time_offsets(fstHandle signal, std::vector time); - fstHandle getHandle(std::string name); double getTimescale() { return timescale; } private: @@ -68,12 +64,15 @@ private: std::map handle_to_var; std::map name_to_handle; std::map>> handle_to_data; + std::map last_data; std::map> time_to_index; std::map> index_to_time; std::vector sample_times; size_t sample_times_ndx; - std::map current; double timescale; + uint64_t start_time; + uint64_t end_time; + std::vector edges; }; YOSYS_NAMESPACE_END diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index d6f5f3a81..e9e114047 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -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); + } } }; -- 2.30.2