Merge pull request #112 from Silimate/sim

Fix activity annotation bug
This commit is contained in:
Akash Levy 2026-03-03 22:46:32 -08:00 committed by GitHub
commit b9dcda8ca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 5 deletions

View File

@ -2533,19 +2533,24 @@ struct AnnotateActivity : public OutputWriter {
}
// 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);
}
log_flush();
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);