From f6d67ac21ef439e05df1f418b0ed361abd71b41a Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Thu, 17 Oct 2024 09:33:08 -0700 Subject: [PATCH] More comments --- passes/cmds/activity.cc | 11 +++++++++++ passes/sat/sim.cc | 14 ++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/passes/cmds/activity.cc b/passes/cmds/activity.cc index 527ab3270..efac64cb9 100644 --- a/passes/cmds/activity.cc +++ b/passes/cmds/activity.cc @@ -28,6 +28,8 @@ struct ActivityProp { Module *module; SigMap sigmap; + // Split a string based on separator, returns a vector of tokens as reference argument + // If skipEmpty is true, return "" for string " ", when separator is " " void tokenize(std::string_view str, std::string_view separator, std::vector &result, bool skipEmpty) { std::string::size_type pos{0}; @@ -49,6 +51,8 @@ struct ActivityProp { } } + // Split a string based on separator, returns a vector of tokens + // If skipEmpty is true, return "" for string " ", when separator is " " std::vector tokenize(std::string_view str, std::string_view separator, bool skipEmpty) { std::vector result; @@ -63,10 +67,14 @@ struct ActivityProp { // Build {signal bit - activity} map from the wire activities calculated in the sim pass for (Wire *wire : module->wires()) { SigSpec sig(sigmap(wire)); + // Retrieve the activity/dutycycle attributes created in the sim pass, attached to wires, in the form: + // $ACKT: 0.1 0.2 .... (Each bit in a bus has its own activity, index 0 of the bus is left most) std::string act = wire->get_string_attribute("$ACKT"); std::string duty = wire->get_string_attribute("$DUTY"); + // Split the activity lists std::vector activities = tokenize(act, " ", true); std::vector duties = tokenize(duty, " ", true); + // Assign them to each SigBit (1 signal bit) for (int i = 0; i < GetSize(sig); i++) { SigBit bit(sig[i]); ActivityMap.emplace(bit, activities[i]); @@ -78,6 +86,7 @@ struct ActivityProp { std::string cell_ports_activity; std::string cell_ports_duty; for (auto conn : cell->connections()) { + // Recombine individual bit activities for all cell ports into a list attached to the cell for (int i = 0; i < GetSize(conn.second); i++) { SigBit bit(sigmap(conn.second[i])); std::string port_name = std::string(conn.first.c_str()) + "[" + std::to_string(i) + "]"; @@ -109,6 +118,8 @@ struct ActivityProp { } } } + // Annotate on cells the complete list of ports activities and dutycycles in the form: + // $ACKT: \P1=0.1 \P2=0.2 .... cell->set_string_attribute("$ACKT:", cell_ports_activity); cell->set_string_attribute("$DUTY:", cell_ports_duty); } diff --git a/passes/sat/sim.cc b/passes/sat/sim.cc index 77591b35a..46614cd4f 100644 --- a/passes/sat/sim.cc +++ b/passes/sat/sim.cc @@ -2449,9 +2449,9 @@ struct AnnotateActivity : public OutputWriter { continue; Const value = data.second; SignalActivityDataMap::iterator itr = dataMap.find(sig); - std::vector &lastVals = (*itr).second.lastValues; - std::vector &toggleCounts = (*itr).second.toggleCounts; - std::vector &highTimes = (*itr).second.highTimes; + std::vector &lastVals = itr->second.lastValues; + std::vector &toggleCounts = itr->second.toggleCounts; + std::vector &highTimes = itr->second.highTimes; for (int i = GetSize(value) - 1; i >= 0; i--) { int val = '-'; switch (value[i]) { @@ -2467,6 +2467,7 @@ struct AnnotateActivity : public OutputWriter { default: val = 'z'; } + // If signal toggled if (val != lastVals[i]) { toggleCounts[i]++; if (toggleCounts[i] > highest_toggle) { @@ -2492,11 +2493,12 @@ struct AnnotateActivity : public OutputWriter { if (timescale == "fs") real_timescale = 1e-15; + // TODO: remove all debug sections when dev is completed bool debug = false; // Compute clock period, find the highest toggling signal and compute its average period SignalActivityDataMap::iterator itr = dataMap.find(clk); - std::vector &clktoggleCounts = (*itr).second.toggleCounts; + std::vector &clktoggleCounts = itr->second.toggleCounts; double clk_period = real_timescale * (double)max_time / (clktoggleCounts[0] / 2); if (debug) { std::cout << "Clock toggle count: " << clktoggleCounts[0] << "\n"; @@ -2518,8 +2520,8 @@ struct AnnotateActivity : public OutputWriter { return; std::string full_name = form_vcd_name(name, size, w); SignalActivityDataMap::const_iterator itr = dataMap.find(id); - const std::vector &toggleCounts = (*itr).second.toggleCounts; - const std::vector &highTimes = (*itr).second.highTimes; + const std::vector &toggleCounts = itr->second.toggleCounts; + const std::vector &highTimes = itr->second.highTimes; if (debug) { std::cout << full_name << ":\n"; std::cout << " TC: ";