3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-23 14:23:41 +00:00

More comments

This commit is contained in:
Alain Dargelas 2024-10-17 09:33:08 -07:00
parent 389518a8f0
commit f6d67ac21e
2 changed files with 19 additions and 6 deletions

View file

@ -28,6 +28,8 @@ struct ActivityProp {
Module *module; Module *module;
SigMap sigmap; 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<std::string> &result, bool skipEmpty) void tokenize(std::string_view str, std::string_view separator, std::vector<std::string> &result, bool skipEmpty)
{ {
std::string::size_type pos{0}; 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<std::string> tokenize(std::string_view str, std::string_view separator, bool skipEmpty) std::vector<std::string> tokenize(std::string_view str, std::string_view separator, bool skipEmpty)
{ {
std::vector<std::string> result; std::vector<std::string> result;
@ -63,10 +67,14 @@ struct ActivityProp {
// Build {signal bit - activity} map from the wire activities calculated in the sim pass // Build {signal bit - activity} map from the wire activities calculated in the sim pass
for (Wire *wire : module->wires()) { for (Wire *wire : module->wires()) {
SigSpec sig(sigmap(wire)); 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 act = wire->get_string_attribute("$ACKT");
std::string duty = wire->get_string_attribute("$DUTY"); std::string duty = wire->get_string_attribute("$DUTY");
// Split the activity lists
std::vector<std::string> activities = tokenize(act, " ", true); std::vector<std::string> activities = tokenize(act, " ", true);
std::vector<std::string> duties = tokenize(duty, " ", true); std::vector<std::string> duties = tokenize(duty, " ", true);
// Assign them to each SigBit (1 signal bit)
for (int i = 0; i < GetSize(sig); i++) { for (int i = 0; i < GetSize(sig); i++) {
SigBit bit(sig[i]); SigBit bit(sig[i]);
ActivityMap.emplace(bit, activities[i]); ActivityMap.emplace(bit, activities[i]);
@ -78,6 +86,7 @@ struct ActivityProp {
std::string cell_ports_activity; std::string cell_ports_activity;
std::string cell_ports_duty; std::string cell_ports_duty;
for (auto conn : cell->connections()) { 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++) { for (int i = 0; i < GetSize(conn.second); i++) {
SigBit bit(sigmap(conn.second[i])); SigBit bit(sigmap(conn.second[i]));
std::string port_name = std::string(conn.first.c_str()) + "[" + std::to_string(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("$ACKT:", cell_ports_activity);
cell->set_string_attribute("$DUTY:", cell_ports_duty); cell->set_string_attribute("$DUTY:", cell_ports_duty);
} }

View file

@ -2449,9 +2449,9 @@ struct AnnotateActivity : public OutputWriter {
continue; continue;
Const value = data.second; Const value = data.second;
SignalActivityDataMap::iterator itr = dataMap.find(sig); SignalActivityDataMap::iterator itr = dataMap.find(sig);
std::vector<uint32_t> &lastVals = (*itr).second.lastValues; std::vector<uint32_t> &lastVals = itr->second.lastValues;
std::vector<uint32_t> &toggleCounts = (*itr).second.toggleCounts; std::vector<uint32_t> &toggleCounts = itr->second.toggleCounts;
std::vector<uint32_t> &highTimes = (*itr).second.highTimes; std::vector<uint32_t> &highTimes = itr->second.highTimes;
for (int i = GetSize(value) - 1; i >= 0; i--) { for (int i = GetSize(value) - 1; i >= 0; i--) {
int val = '-'; int val = '-';
switch (value[i]) { switch (value[i]) {
@ -2467,6 +2467,7 @@ struct AnnotateActivity : public OutputWriter {
default: default:
val = 'z'; val = 'z';
} }
// If signal toggled
if (val != lastVals[i]) { if (val != lastVals[i]) {
toggleCounts[i]++; toggleCounts[i]++;
if (toggleCounts[i] > highest_toggle) { if (toggleCounts[i] > highest_toggle) {
@ -2492,11 +2493,12 @@ struct AnnotateActivity : public OutputWriter {
if (timescale == "fs") if (timescale == "fs")
real_timescale = 1e-15; real_timescale = 1e-15;
// TODO: remove all debug sections when dev is completed
bool debug = false; bool debug = false;
// Compute clock period, find the highest toggling signal and compute its average period // Compute clock period, find the highest toggling signal and compute its average period
SignalActivityDataMap::iterator itr = dataMap.find(clk); SignalActivityDataMap::iterator itr = dataMap.find(clk);
std::vector<uint32_t> &clktoggleCounts = (*itr).second.toggleCounts; std::vector<uint32_t> &clktoggleCounts = itr->second.toggleCounts;
double clk_period = real_timescale * (double)max_time / (clktoggleCounts[0] / 2); double clk_period = real_timescale * (double)max_time / (clktoggleCounts[0] / 2);
if (debug) { if (debug) {
std::cout << "Clock toggle count: " << clktoggleCounts[0] << "\n"; std::cout << "Clock toggle count: " << clktoggleCounts[0] << "\n";
@ -2518,8 +2520,8 @@ struct AnnotateActivity : public OutputWriter {
return; return;
std::string full_name = form_vcd_name(name, size, w); std::string full_name = form_vcd_name(name, size, w);
SignalActivityDataMap::const_iterator itr = dataMap.find(id); SignalActivityDataMap::const_iterator itr = dataMap.find(id);
const std::vector<uint32_t> &toggleCounts = (*itr).second.toggleCounts; const std::vector<uint32_t> &toggleCounts = itr->second.toggleCounts;
const std::vector<uint32_t> &highTimes = (*itr).second.highTimes; const std::vector<uint32_t> &highTimes = itr->second.highTimes;
if (debug) { if (debug) {
std::cout << full_name << ":\n"; std::cout << full_name << ":\n";
std::cout << " TC: "; std::cout << " TC: ";