Skip to content

Commit

Permalink
read_power_activities -scope
Browse files Browse the repository at this point in the history
Signed-off-by: James Cherry <[email protected]>
  • Loading branch information
jjcherry56 committed Oct 30, 2022
1 parent d5f1b28 commit ca29f41
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
Binary file modified doc/OpenSTA.odt
Binary file not shown.
5 changes: 3 additions & 2 deletions power/Power.i
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ set_power_pin_activity(const Pin *pin,
}

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
Expand Down
10 changes: 7 additions & 3 deletions power/Power.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 } {
parse_key_args "read_power_activities" args \
keys {} flags {-vcd}
keys {-scope} flags {-vcd}

check_argc_eq1 "set_power_activity" $args
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
}

################################################################
Expand Down
14 changes: 12 additions & 2 deletions power/ReadVcdActivities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using std::to_string;

static void
setVcdActivities(Vcd &vcd,
const char *scope,
Sta *sta);
static void
findVarActivity(const char *pin_name,
Expand All @@ -48,28 +49,37 @@ findVarActivity(const char *pin_name,

void
readVcdActivities(const char *filename,
const char *scope,
Sta *sta)
{
Vcd vcd = readVcdFile(filename, sta);
setVcdActivities(vcd, sta);
setVcdActivities(vcd, scope, sta);
}

static void
setVcdActivities(Vcd &vcd,
const char *scope,
Sta *sta)
{
Debug *debug = sta->debug();
Network *network = sta->network();
Power *power = sta->power();

float clk_period = INF;
size_t scope_length = strlen(scope);
for (Clock *clk : *sta->sdc()->clocks())
clk_period = min(clk->period(), clk_period);

for (VcdVar &var : vcd.vars()) {
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::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] == '\\')
var_name += ' ';
const char *sta_name = verilogToSta(var_name.c_str());
Expand Down
1 change: 1 addition & 0 deletions power/ReadVcdActivities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Sta;

void
readVcdActivities(const char *filename,
const char *scope,
Sta *sta);

} // namespace
11 changes: 2 additions & 9 deletions power/VcdReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,9 @@ VcdReader::parseVar()
string id = tokens[2];
string name;

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

0 comments on commit ca29f41

Please sign in to comment.