Do actual compare

This commit is contained in:
Miodrag Milanovic 2022-01-28 12:50:41 +01:00
parent 7101df62f8
commit 4f75a2ca1b
3 changed files with 63 additions and 77 deletions

View 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; 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; FstData *ptr = (FstData*)user_data;
uint32_t plen = (pnt_value) ? strlen((const char *)pnt_value) : 0; 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))); std::string val = std::string((const char *)pnt_value);
size_t index = handle_to_data[pnt_facidx].size() - 1; std::string prev = last_data[pnt_facidx];
time_to_index[pnt_facidx][pnt_time] = index; if (pnt_time>=start_time) {
index_to_time[pnt_facidx][index] = pnt_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(); start_time = start;
time_to_index.clear(); end_time = end;
index_to_time.clear(); last_data.clear();
for(auto &s : signal) {
last_data[s] = "x";
}
edges.clear();
fstReaderSetLimitTimeRange(ctx, start_time, end_time);
fstReaderClrFacProcessMaskAll(ctx); fstReaderClrFacProcessMaskAll(ctx);
for(const auto sig : signal) for(const auto sig : signal)
fstReaderSetFacProcessMask(ctx,sig); fstReaderSetFacProcessMask(ctx,sig);
fstReaderIterBlocks2(ctx, reconstruct_clb, reconstruct_clb_varlen, this, nullptr); fstReaderIterBlocks2(ctx, reconstruct_edges, reconstruct_edges_varlen, this, nullptr);
} return edges;
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);
} }
static void reconstruct_clb_varlen_attimes(void *user_data, uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen) 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 */) 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; if (sample_times_ndx > sample_times.size()) return;
uint64_t time = sample_times[sample_times_ndx]; uint64_t time = sample_times[sample_times_ndx];
// if we are past the timestamp // if we are past the timestamp
if (pnt_time > time) { 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)); handle_to_data[c.first].push_back(std::make_pair(time,c.second));
size_t index = handle_to_data[c.first].size() - 1; 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++; sample_times_ndx++;
} }
// always update current // always update last_data
current[pnt_facidx] = std::string((const char *)pnt_value); last_data[pnt_facidx] = std::string((const char *)pnt_value);
} }
void FstData::reconstructAtTimes(std::vector<fstHandle> &signal, std::vector<uint64_t> time) 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(); handle_to_data.clear();
time_to_index.clear(); time_to_index.clear();
index_to_time.clear(); index_to_time.clear();
current.clear(); last_data.clear();
sample_times_ndx = 0; sample_times_ndx = 0;
sample_times = time; sample_times = time;
fstReaderSetUnlimitedTimeRange(ctx);
fstReaderClrFacProcessMaskAll(ctx); fstReaderClrFacProcessMaskAll(ctx);
for(const auto sig : signal) for(const auto sig : signal)
fstReaderSetFacProcessMask(ctx,sig); fstReaderSetFacProcessMask(ctx,sig);
fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr); fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr);
if (time_to_index[signal.back()].count(time.back())==0) { 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)); handle_to_data[c.first].push_back(std::make_pair(time.back(),c.second));
size_t index = handle_to_data[c.first].size() - 1; 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(); handle_to_data.clear();
time_to_index.clear(); time_to_index.clear();
index_to_time.clear(); index_to_time.clear();
current.clear(); last_data.clear();
sample_times_ndx = 0; sample_times_ndx = 0;
sample_times = time; sample_times = time;
fstReaderSetUnlimitedTimeRange(ctx);
fstReaderSetFacProcessMaskAll(ctx); fstReaderSetFacProcessMaskAll(ctx);
fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr); fstReaderIterBlocks2(ctx, reconstruct_clb_attimes, reconstruct_clb_varlen_attimes, this, nullptr);
/*
if (time_to_index[signal.back()].count(time.back())==0) { if (time_to_index[1].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)); handle_to_data[c.first].push_back(std::make_pair(time.back(),c.second));
size_t index = handle_to_data[c.first].size() - 1; size_t index = handle_to_data[c.first].size() - 1;
time_to_index[c.first][time.back()] = index; time_to_index[c.first][time.back()] = index;
index_to_time[c.first][index] = time.back(); index_to_time[c.first][index] = time.back();
} }
}*/ }
} }
std::string FstData::valueAt(fstHandle signal, uint64_t time) 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]; auto &data = handle_to_data[signal];
if (time_to_index[signal].count(time)!=0) { if (time_to_index[signal].count(time)!=0) {
size_t index = time_to_index[signal][time]; 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; 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;
}
}

View File

@ -45,18 +45,14 @@ class FstData
std::vector<FstVar>& getVars() { return vars; }; 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_edges_callback(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen);
void reconstruct(std::vector<fstHandle> &signal); std::vector<uint64_t> getAllEdges(std::vector<fstHandle> &signal, uint64_t start_time, uint64_t end_time);
void reconstuctAll();
void reconstruct_callback_attimes(uint64_t pnt_time, fstHandle pnt_facidx, const unsigned char *pnt_value, uint32_t plen); 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 reconstructAtTimes(std::vector<fstHandle> &signal,std::vector<uint64_t> time);
void reconstructAllAtTimes(std::vector<uint64_t> time); void reconstructAllAtTimes(std::vector<uint64_t> time);
std::string valueAt(fstHandle signal, 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); fstHandle getHandle(std::string name);
double getTimescale() { return timescale; } double getTimescale() { return timescale; }
private: private:
@ -68,12 +64,15 @@ private:
std::map<fstHandle, FstVar> handle_to_var; std::map<fstHandle, FstVar> handle_to_var;
std::map<std::string, fstHandle> name_to_handle; 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::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<uint64_t, size_t>> time_to_index;
std::map<fstHandle, std::map<size_t, uint64_t>> index_to_time; std::map<fstHandle, std::map<size_t, uint64_t>> index_to_time;
std::vector<uint64_t> sample_times; std::vector<uint64_t> sample_times;
size_t sample_times_ndx; size_t sample_times_ndx;
std::map<fstHandle, std::string> current;
double timescale; double timescale;
uint64_t start_time;
uint64_t end_time;
std::vector<uint64_t> edges;
}; };
YOSYS_NAMESPACE_END YOSYS_NAMESPACE_END

View File

@ -966,21 +966,32 @@ struct SimWorker : SimShared
log_warning("Stop time is after simulation file end time\n"); log_warning("Stop time is after simulation file end time\n");
} }
} }
fst->reconstruct(fst_clock); auto edges = fst->getAllEdges(fst_clock, startCount, stopCount);
auto edges = fst->edges(fst_clock.back(), true, true);
fst->reconstructAllAtTimes(edges); fst->reconstructAllAtTimes(edges);
/* for(auto &time : edges) { for(auto &time : edges) {
for(auto &item : inputs) { for(auto &item : inputs) {
std::string v = fst->valueAt(item.second, time); std::string v = fst->valueAt(item.second, time);
top->set_state(item.first, Const::from_string(v)); top->set_state(item.first, Const::from_string(v));
} }
update(); update();
bool status = true;
for(auto &item : outputs) { for(auto &item : outputs) {
Const fst_val = Const::from_string(fst->valueAt(item.second, time)); Const fst_val = Const::from_string(fst->valueAt(item.second, time));
Const sim_val = top->get_state(item.first); 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);
}
} }
}; };