This commit is contained in:
Stan Lee 2026-02-26 16:00:27 -08:00
parent 0b46d8b201
commit b11eef4fe1
1 changed files with 9 additions and 5 deletions

View File

@ -2524,22 +2524,26 @@ struct AnnotateActivity : public OutputWriter {
double real_timescale = worker->fst->getTimescale();
if (worker->debug) {
log_debug("Timescale %e seconds extracted from converted VCD file", real_timescale);
log_flush();
}
// Compute clock period, find the highest toggling signal and compute its average period
double clk_period;
SignalActivityDataMap::iterator itr = dataMap.find(clk);
std::vector<double_t> &clktoggleCounts = itr->second.toggleCounts;
double clk_period = real_timescale * (double)max_time / (clktoggleCounts[0] / 2.0);
if (itr == dataMap.end()) { // if clock signal can't be identified, set frequency to 1GHz
log_warning("Clock signal not found, setting frequency to 1GHz...\n");
clk_period = 1.0 / 1.0e9;
} else {
std::vector<double_t> &clktoggleCounts = itr->second.toggleCounts;
clk_period = real_timescale * (double)max_time / (clktoggleCounts[0] / 2.0);
}
double frequency = 1.0 / clk_period;
double density = clktoggleCounts[0] / (real_timescale * (double)max_time);
worker->top->module->set_string_attribute("$DENSITY", std::to_string(density));
worker->top->module->set_string_attribute("$FREQUENCY", std::to_string(frequency));
worker->top->module->set_string_attribute("$DURATION", std::to_string(max_time));
std::stringstream ss;
ss << std::setprecision(4) << real_timescale;
worker->top->module->set_string_attribute("$TIMESCALE", ss.str());
if (worker->debug) {
log_debug("Clock toggle count: %f", clktoggleCounts[0]);
log_debug("Max time: %d", max_time);
log_debug("Clock period: %f", clk_period);
log_debug("Frequency: %f", frequency);