read_power_activities -scope

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2022-10-30 13:26:16 -07:00
parent d5f1b2888d
commit ca29f41613
6 changed files with 25 additions and 16 deletions

Binary file not shown.

View File

@ -110,9 +110,10 @@ set_power_pin_activity(const Pin *pin,
} }
void void
read_vcd_activities(const char *filename) read_vcd_activities(const char *filename,
const char *scope)
{ {
readVcdActivities(filename, Sta::sta()); readVcdActivities(filename, scope, Sta::sta());
} }
void void

View File

@ -251,15 +251,19 @@ proc set_power_activity { args } {
################################################################ ################################################################
define_cmd_args "read_power_activities" { -vcd filename } define_cmd_args "read_power_activities" { [-scope scope] -vcd filename }
proc read_power_activities { args } { proc read_power_activities { args } {
parse_key_args "read_power_activities" args \ parse_key_args "read_power_activities" args \
keys {} flags {-vcd} keys {-scope} flags {-vcd}
check_argc_eq1 "set_power_activity" $args check_argc_eq1 "set_power_activity" $args
set filename [file nativename [lindex $args 0]] set filename [file nativename [lindex $args 0]]
read_vcd_activities $filename set scope ""
if { [info exists keys(-scope)] } {
set scope $keys(-scope)
}
read_vcd_activities $filename $scope
} }
################################################################ ################################################################

View File

@ -33,6 +33,7 @@ using std::to_string;
static void static void
setVcdActivities(Vcd &vcd, setVcdActivities(Vcd &vcd,
const char *scope,
Sta *sta); Sta *sta);
static void static void
findVarActivity(const char *pin_name, findVarActivity(const char *pin_name,
@ -48,14 +49,16 @@ findVarActivity(const char *pin_name,
void void
readVcdActivities(const char *filename, readVcdActivities(const char *filename,
const char *scope,
Sta *sta) Sta *sta)
{ {
Vcd vcd = readVcdFile(filename, sta); Vcd vcd = readVcdFile(filename, sta);
setVcdActivities(vcd, sta); setVcdActivities(vcd, scope, sta);
} }
static void static void
setVcdActivities(Vcd &vcd, setVcdActivities(Vcd &vcd,
const char *scope,
Sta *sta) Sta *sta)
{ {
Debug *debug = sta->debug(); Debug *debug = sta->debug();
@ -63,13 +66,20 @@ setVcdActivities(Vcd &vcd,
Power *power = sta->power(); Power *power = sta->power();
float clk_period = INF; float clk_period = INF;
size_t scope_length = strlen(scope);
for (Clock *clk : *sta->sdc()->clocks()) for (Clock *clk : *sta->sdc()->clocks())
clk_period = min(clk->period(), clk_period); clk_period = min(clk->period(), clk_period);
for (VcdVar &var : vcd.vars()) { for (VcdVar &var : vcd.vars()) {
const VcdValues &var_values = vcd.values(var); const VcdValues &var_values = vcd.values(var);
if (!var_values.empty()) { if (!var_values.empty()
&& (var.type() == VcdVarType::wire
|| var.type() == VcdVarType::reg)) {
string var_name = var.name(); string var_name = var.name();
// string::starts_with in c++20
if (scope_length
&& var_name.substr(0, scope_length) == scope)
var_name = var_name.substr(scope_length + 1);
if (var_name[0] == '\\') if (var_name[0] == '\\')
var_name += ' '; var_name += ' ';
const char *sta_name = verilogToSta(var_name.c_str()); const char *sta_name = verilogToSta(var_name.c_str());

View File

@ -22,6 +22,7 @@ class Sta;
void void
readVcdActivities(const char *filename, readVcdActivities(const char *filename,
const char *scope,
Sta *sta); Sta *sta);
} // namespace } // namespace

View File

@ -183,16 +183,9 @@ VcdReader::parseVar()
string id = tokens[2]; string id = tokens[2];
string name; string name;
int level = 0;
for (string &context : scope_) { for (string &context : scope_) {
// Skip the first 2 levels of scope. name += context;
// -test bench module name += '/';
// -design instance
if (level > 1) {
name += context;
name += '/';
}
level++;
} }
name += tokens[3]; name += tokens[3];
// iverilog separates bus base name from bit range. // iverilog separates bus base name from bit range.