OpenSTA/liberty/InternalPower.cc

234 lines
5.6 KiB
C++
Raw Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
2020-03-07 03:50:37 +01:00
// Copyright (c) 2020, Parallax Software, Inc.
2018-09-28 17:54:21 +02:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2020-04-05 23:53:44 +02:00
#include "InternalPower.hh"
2020-04-05 20:35:51 +02:00
2020-04-05 23:53:44 +02:00
#include "FuncExpr.hh"
#include "TableModel.hh"
#include "Liberty.hh"
2018-09-28 17:54:21 +02:00
namespace sta {
InternalPowerAttrs::InternalPowerAttrs() :
2019-03-13 01:25:53 +01:00
when_(nullptr),
models_{nullptr, nullptr},
related_pg_pin_(nullptr)
2018-09-28 17:54:21 +02:00
{
2018-11-26 18:15:52 +01:00
}
InternalPowerAttrs::~InternalPowerAttrs()
{
2018-12-05 23:18:41 +01:00
}
void
InternalPowerAttrs::deleteContents()
{
2019-11-11 23:30:19 +01:00
for (auto tr_index : RiseFall::rangeIndex()) {
2018-12-05 23:18:41 +01:00
InternalPowerModel *model = models_[tr_index];
if (model)
delete model;
}
if (when_)
when_->deleteSubexprs();
2018-11-26 18:15:52 +01:00
stringDelete(related_pg_pin_);
2018-09-28 17:54:21 +02:00
}
InternalPowerModel *
2019-11-11 23:30:19 +01:00
InternalPowerAttrs::model(RiseFall *rf) const
2018-09-28 17:54:21 +02:00
{
2019-11-11 23:30:19 +01:00
return models_[rf->index()];
2018-09-28 17:54:21 +02:00
}
void
2019-11-11 23:30:19 +01:00
InternalPowerAttrs::setModel(RiseFall *rf,
2018-09-28 17:54:21 +02:00
InternalPowerModel *model)
{
2019-11-11 23:30:19 +01:00
models_[rf->index()] = model;
2018-09-28 17:54:21 +02:00
}
2018-11-26 18:15:52 +01:00
void
InternalPowerAttrs::setRelatedPgPin(const char *related_pg_pin)
{
stringDelete(related_pg_pin_);
related_pg_pin_ = stringCopy(related_pg_pin);
}
2018-09-28 17:54:21 +02:00
////////////////////////////////////////////////////////////////
InternalPower::InternalPower(LibertyCell *cell,
LibertyPort *port,
LibertyPort *related_port,
InternalPowerAttrs *attrs) :
port_(port),
related_port_(related_port),
2018-11-26 18:15:52 +01:00
when_(attrs->when()),
2018-12-05 23:18:41 +01:00
related_pg_pin_(attrs->relatedPgPin())
2018-09-28 17:54:21 +02:00
{
2019-11-11 23:30:19 +01:00
for (auto tr : RiseFall::range()) {
2018-09-28 17:54:21 +02:00
int tr_index = tr->index();
models_[tr_index] = attrs->model(tr);
}
cell->addInternalPower(this);
}
InternalPower::~InternalPower()
{
2018-12-05 23:18:41 +01:00
// models_, when_ and related_pg_pin_ are owned by InternalPowerAttrs.
2018-09-28 17:54:21 +02:00
}
LibertyCell *
InternalPower::libertyCell() const
{
return port_->libertyCell();
}
float
2019-11-11 23:30:19 +01:00
InternalPower::power(RiseFall *rf,
2018-09-28 17:54:21 +02:00
const Pvt *pvt,
float in_slew,
float load_cap)
{
2019-11-11 23:30:19 +01:00
InternalPowerModel *model = models_[rf->index()];
2018-09-28 17:54:21 +02:00
if (model)
return model->power(libertyCell(), pvt, in_slew, load_cap);
else
return 0.0;
}
////////////////////////////////////////////////////////////////
InternalPowerModel::InternalPowerModel(TableModel *model) :
model_(model)
{
}
InternalPowerModel::~InternalPowerModel()
{
delete model_;
}
float
InternalPowerModel::power(const LibertyCell *cell,
const Pvt *pvt,
float in_slew,
float load_cap) const
{
if (model_) {
float axis_value1, axis_value2, axis_value3;
findAxisValues(in_slew, load_cap,
axis_value1, axis_value2, axis_value3);
const LibertyLibrary *library = cell->libertyLibrary();
return model_->findValue(library, cell, pvt,
axis_value1, axis_value2, axis_value3);
}
else
return 0.0;
}
void
InternalPowerModel::reportPower(const LibertyCell *cell,
const Pvt *pvt,
float in_slew,
float load_cap,
int digits,
string *result) const
{
if (model_) {
float axis_value1, axis_value2, axis_value3;
findAxisValues(in_slew, load_cap,
axis_value1, axis_value2, axis_value3);
const LibertyLibrary *library = cell->libertyLibrary();
model_->reportValue("Power", library, cell, pvt,
2019-03-13 01:25:53 +01:00
axis_value1, nullptr, axis_value2, axis_value3, digits, result);
2018-09-28 17:54:21 +02:00
}
}
void
InternalPowerModel::findAxisValues(float in_slew,
float load_cap,
// Return values.
float &axis_value1,
float &axis_value2,
float &axis_value3) const
{
switch (model_->order()) {
case 0:
axis_value1 = 0.0;
axis_value2 = 0.0;
axis_value3 = 0.0;
break;
case 1:
axis_value1 = axisValue(model_->axis1(), in_slew, load_cap);
axis_value2 = 0.0;
axis_value3 = 0.0;
break;
case 2:
axis_value1 = axisValue(model_->axis1(), in_slew, load_cap);
axis_value2 = axisValue(model_->axis2(), in_slew, load_cap);
axis_value3 = 0.0;
break;
case 3:
axis_value1 = axisValue(model_->axis1(), in_slew, load_cap);
axis_value2 = axisValue(model_->axis2(), in_slew, load_cap);
axis_value3 = axisValue(model_->axis3(), in_slew, load_cap);
break;
default:
2020-12-14 02:21:35 +01:00
criticalError(229, "unsupported table order");
2018-09-28 17:54:21 +02:00
}
}
float
InternalPowerModel::axisValue(TableAxis *axis,
float in_slew,
float load_cap) const
{
TableAxisVariable var = axis->variable();
2019-03-13 01:25:53 +01:00
if (var == TableAxisVariable::input_transition_time)
2018-09-28 17:54:21 +02:00
return in_slew;
2019-03-13 01:25:53 +01:00
else if (var == TableAxisVariable::total_output_net_capacitance)
2018-09-28 17:54:21 +02:00
return load_cap;
else {
2020-12-14 02:21:35 +01:00
criticalError(230, "unsupported table axes");
2018-09-28 17:54:21 +02:00
return 0.0;
}
}
bool
InternalPowerModel::checkAxes(const TableModel *model)
{
TableAxis *axis1 = model->axis1();
TableAxis *axis2 = model->axis2();
TableAxis *axis3 = model->axis3();
bool axis_ok = true;
if (axis1)
axis_ok &= checkAxis(model->axis1());
if (axis2)
axis_ok &= checkAxis(model->axis2());
2019-03-13 01:25:53 +01:00
axis_ok &= (axis3 == nullptr);
2018-09-28 17:54:21 +02:00
return axis_ok;
}
bool
InternalPowerModel::checkAxis(TableAxis *axis)
{
TableAxisVariable var = axis->variable();
2019-03-13 01:25:53 +01:00
return var == TableAxisVariable::constrained_pin_transition
|| var == TableAxisVariable::related_pin_transition
|| var == TableAxisVariable::related_out_total_output_net_capacitance;
2018-09-28 17:54:21 +02:00
}
} // namespace