2018-11-26 18:15:52 +01:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2020-03-07 03:50:37 +01:00
|
|
|
// Copyright (c) 2020, Parallax Software, Inc.
|
2018-11-26 18:15:52 +01: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-02-16 01:13:16 +01:00
|
|
|
#pragma once
|
2018-11-26 18:15:52 +01:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Sta.hh"
|
2018-11-26 18:15:52 +01:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
class PowerResult;
|
2019-04-29 17:39:05 +02:00
|
|
|
class PwrActivity;
|
|
|
|
|
class PropActivityVisitor;
|
|
|
|
|
class BfsFwdIterator;
|
|
|
|
|
|
|
|
|
|
typedef UnorderedMap<const Pin*,PwrActivity> PwrActivityMap;
|
|
|
|
|
|
|
|
|
|
enum class PwrActivityOrigin
|
|
|
|
|
{
|
|
|
|
|
global,
|
|
|
|
|
input,
|
|
|
|
|
user,
|
|
|
|
|
propagated,
|
|
|
|
|
clock,
|
|
|
|
|
constant,
|
2019-05-08 22:23:59 +02:00
|
|
|
defaulted,
|
2019-04-29 17:39:05 +02:00
|
|
|
unknown
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PwrActivity
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PwrActivity();
|
|
|
|
|
PwrActivity(float activity,
|
|
|
|
|
float duty,
|
|
|
|
|
PwrActivityOrigin origin);
|
|
|
|
|
float activity() const { return activity_; }
|
|
|
|
|
float duty() const { return duty_; }
|
|
|
|
|
PwrActivityOrigin origin() { return origin_; }
|
|
|
|
|
const char *originName() const;
|
|
|
|
|
void set(float activity,
|
|
|
|
|
float duty,
|
|
|
|
|
PwrActivityOrigin origin);
|
|
|
|
|
bool isSet() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// In general activity is per clock cycle, NOT per second.
|
|
|
|
|
float activity_;
|
|
|
|
|
float duty_;
|
|
|
|
|
PwrActivityOrigin origin_;
|
|
|
|
|
};
|
2018-11-26 18:15:52 +01:00
|
|
|
|
|
|
|
|
// The Power class has access to Sta components directly for
|
|
|
|
|
// convenience but also requires access to the Sta class member functions.
|
|
|
|
|
class Power : public StaState
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Power(Sta *sta);
|
|
|
|
|
void power(const Corner *corner,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &total,
|
|
|
|
|
PowerResult &sequential,
|
|
|
|
|
PowerResult &combinational,
|
|
|
|
|
PowerResult ¯o,
|
|
|
|
|
PowerResult &pad);
|
|
|
|
|
void power(const Instance *inst,
|
|
|
|
|
const Corner *corner,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
2019-04-29 17:39:05 +02:00
|
|
|
void setGlobalActivity(float activity,
|
|
|
|
|
float duty);
|
|
|
|
|
void setInputActivity(float activity,
|
|
|
|
|
float duty);
|
|
|
|
|
void setInputPortActivity(const Port *input_port,
|
|
|
|
|
float activity,
|
|
|
|
|
float duty);
|
|
|
|
|
PwrActivity &pinActivity(const Pin *pin);
|
2019-05-01 03:17:36 +02:00
|
|
|
bool hasPinActivity(const Pin *pin);
|
2019-05-08 22:23:59 +02:00
|
|
|
void setPinActivity(const Pin *pin,
|
|
|
|
|
PwrActivity &activity);
|
2019-04-29 17:39:05 +02:00
|
|
|
void setPinActivity(const Pin *pin,
|
|
|
|
|
float activity,
|
|
|
|
|
float duty,
|
|
|
|
|
PwrActivityOrigin origin);
|
|
|
|
|
// Activity is toggles per second.
|
2019-05-08 22:23:59 +02:00
|
|
|
PwrActivity findClkedActivity(const Pin *pin);
|
2018-11-26 18:15:52 +01:00
|
|
|
|
|
|
|
|
protected:
|
2019-04-29 17:39:05 +02:00
|
|
|
void preamble();
|
|
|
|
|
void ensureActivities();
|
|
|
|
|
|
2018-11-26 18:15:52 +01:00
|
|
|
void power(const Instance *inst,
|
|
|
|
|
LibertyCell *cell,
|
|
|
|
|
const Corner *corner,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
2020-04-29 05:32:59 +02:00
|
|
|
void findInputInternalPower(const Pin *to_pin,
|
|
|
|
|
const LibertyPort *to_port,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
LibertyCell *cell,
|
|
|
|
|
PwrActivity &to_activity,
|
|
|
|
|
float load_cap,
|
|
|
|
|
const DcalcAnalysisPt *dcalc_ap,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
|
|
|
|
void findOutputInternalPower(const Pin *to_pin,
|
|
|
|
|
const LibertyPort *to_port,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
LibertyCell *cell,
|
|
|
|
|
PwrActivity &to_activity,
|
|
|
|
|
float load_cap,
|
|
|
|
|
const DcalcAnalysisPt *dcalc_ap,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
2018-11-26 18:15:52 +01:00
|
|
|
void findLeakagePower(const Instance *inst,
|
|
|
|
|
LibertyCell *cell,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
2018-12-05 23:18:41 +01:00
|
|
|
void findSwitchingPower(LibertyCell *cell,
|
2018-11-26 18:15:52 +01:00
|
|
|
const LibertyPort *to_port,
|
2019-04-29 17:39:05 +02:00
|
|
|
PwrActivity &activity,
|
2018-11-26 18:15:52 +01:00
|
|
|
float load_cap,
|
|
|
|
|
const DcalcAnalysisPt *dcalc_ap,
|
|
|
|
|
// Return values.
|
|
|
|
|
PowerResult &result);
|
2019-04-20 23:07:00 +02:00
|
|
|
const Clock *findInstClk(const Instance *inst);
|
2019-04-29 17:39:05 +02:00
|
|
|
const Clock *findClk(const Pin *to_pin);
|
2019-05-08 22:23:59 +02:00
|
|
|
PwrActivity findClkedActivity(const Pin *pin,
|
|
|
|
|
const Clock *inst_clk);
|
|
|
|
|
PwrActivity findActivity(const Pin *pin);
|
|
|
|
|
float portVoltage(LibertyCell *cell,
|
|
|
|
|
const LibertyPort *port,
|
|
|
|
|
const DcalcAnalysisPt *dcalc_ap);
|
|
|
|
|
float pgNameVoltage(LibertyCell *cell,
|
|
|
|
|
const char *pg_port_name,
|
|
|
|
|
const DcalcAnalysisPt *dcalc_ap);
|
2019-04-29 17:39:05 +02:00
|
|
|
void seedActivities(BfsFwdIterator &bfs);
|
2019-05-01 03:17:36 +02:00
|
|
|
void seedRegOutputActivities(const Instance *reg,
|
2019-04-29 17:39:05 +02:00
|
|
|
Sequential *seq,
|
|
|
|
|
LibertyPort *output,
|
|
|
|
|
bool invert);
|
2019-05-01 03:17:36 +02:00
|
|
|
void seedRegOutputActivities(const Instance *inst,
|
|
|
|
|
BfsFwdIterator &bfs);
|
2019-04-29 17:39:05 +02:00
|
|
|
PwrActivity evalActivity(FuncExpr *expr,
|
|
|
|
|
const Instance *inst);
|
2019-05-08 22:23:59 +02:00
|
|
|
bool internalPowerMissingWhen(LibertyCell *cell,
|
|
|
|
|
const LibertyPort *to_port,
|
|
|
|
|
const char *related_pg_pin);
|
2019-05-20 01:06:06 +02:00
|
|
|
FuncExpr *inferedWhen(FuncExpr *expr,
|
|
|
|
|
const LibertyPort *from_port);
|
2018-11-26 18:15:52 +01:00
|
|
|
|
|
|
|
|
private:
|
2019-04-29 17:39:05 +02:00
|
|
|
PwrActivity global_activity_;
|
|
|
|
|
PwrActivity input_activity_;
|
|
|
|
|
PwrActivityMap activity_map_;
|
|
|
|
|
bool activities_valid_;
|
|
|
|
|
|
|
|
|
|
friend class PropActivityVisitor;
|
2018-11-26 18:15:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PowerResult
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PowerResult();
|
|
|
|
|
void clear();
|
|
|
|
|
float internal() const { return internal_; }
|
|
|
|
|
void setInternal(float internal);
|
|
|
|
|
float switching() const { return switching_; }
|
|
|
|
|
void setSwitching(float switching);
|
|
|
|
|
float leakage() const { return leakage_; }
|
|
|
|
|
void setLeakage(float leakage);
|
|
|
|
|
float total() const;
|
|
|
|
|
void incr(PowerResult &result);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
float internal_;
|
|
|
|
|
float switching_;
|
|
|
|
|
float leakage_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|