2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2025-01-22 02:54:33 +01:00
|
|
|
// Copyright (c) 2025, 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
|
2022-01-04 18:17:08 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-28 17:54:21 +02:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2022-01-04 18:17:08 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2025-01-22 02:54:33 +01:00
|
|
|
//
|
|
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
|
|
|
|
//
|
|
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
|
|
|
|
//
|
|
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Sim.hh"
|
2020-04-05 20:35:51 +02:00
|
|
|
|
2024-07-17 23:19:49 +02:00
|
|
|
// https://davidkebo.com/cudd
|
|
|
|
|
#include "cudd.h"
|
|
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Error.hh"
|
|
|
|
|
#include "Mutex.hh"
|
|
|
|
|
#include "Debug.hh"
|
|
|
|
|
#include "Report.hh"
|
|
|
|
|
#include "Stats.hh"
|
|
|
|
|
#include "FuncExpr.hh"
|
|
|
|
|
#include "TimingRole.hh"
|
|
|
|
|
#include "TimingArc.hh"
|
|
|
|
|
#include "Liberty.hh"
|
|
|
|
|
#include "PortDirection.hh"
|
2021-06-22 02:49:46 +02:00
|
|
|
#include "Sequential.hh"
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "Network.hh"
|
|
|
|
|
#include "Sdc.hh"
|
|
|
|
|
#include "Graph.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
2021-08-23 02:01:46 +02:00
|
|
|
static LogicValue
|
|
|
|
|
logicNot(LogicValue value);
|
2023-01-19 19:23:45 +01:00
|
|
|
static const Pin *
|
2018-09-28 17:54:21 +02:00
|
|
|
findDrvrPin(const Pin *pin,
|
|
|
|
|
Network *network);
|
|
|
|
|
|
|
|
|
|
Sim::Sim(StaState *sta) :
|
|
|
|
|
StaState(sta),
|
2019-03-13 01:25:53 +01:00
|
|
|
observer_(nullptr),
|
2018-09-28 17:54:21 +02:00
|
|
|
valid_(false),
|
|
|
|
|
incremental_(false),
|
2023-01-19 19:23:45 +01:00
|
|
|
const_func_pins_(network_),
|
2018-09-28 17:54:21 +02:00
|
|
|
const_func_pins_valid_(false),
|
2023-01-19 19:23:45 +01:00
|
|
|
invalid_insts_(network_),
|
|
|
|
|
invalid_drvr_pins_(network_),
|
|
|
|
|
invalid_load_pins_(network_),
|
|
|
|
|
instances_with_const_pins_(network_),
|
|
|
|
|
instances_to_annotate_(network_),
|
2024-02-27 18:00:48 +01:00
|
|
|
bdd_(sta)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Sim::~Sim()
|
|
|
|
|
{
|
|
|
|
|
delete observer_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimingSense
|
|
|
|
|
Sim::functionSense(const FuncExpr *expr,
|
|
|
|
|
const Pin *input_pin,
|
|
|
|
|
const Instance *inst)
|
|
|
|
|
{
|
2021-01-04 18:12:27 +01:00
|
|
|
debugPrint(debug_, "sim", 4, "find sense pin %s %s",
|
|
|
|
|
network_->pathName(input_pin),
|
2025-03-31 00:27:53 +02:00
|
|
|
expr->to_string().c_str());
|
2019-03-13 01:25:53 +01:00
|
|
|
bool increasing, decreasing;
|
|
|
|
|
{
|
2024-06-03 23:09:30 +02:00
|
|
|
LockGuard lock(bdd_lock_);
|
2024-02-27 18:00:48 +01:00
|
|
|
DdNode *bdd = funcBddSim(expr, inst);
|
|
|
|
|
DdManager *cudd_mgr = bdd_.cuddMgr();
|
2019-03-13 01:25:53 +01:00
|
|
|
LibertyPort *input_port = network_->libertyPort(input_pin);
|
2024-02-27 18:00:48 +01:00
|
|
|
DdNode *input_node = bdd_.ensureNode(input_port);
|
2019-03-13 01:25:53 +01:00
|
|
|
unsigned int input_index = Cudd_NodeReadIndex(input_node);
|
2024-02-27 18:00:48 +01:00
|
|
|
increasing = (Cudd_Increasing(cudd_mgr, bdd, input_index)
|
|
|
|
|
== Cudd_ReadOne(cudd_mgr));
|
|
|
|
|
decreasing = (Cudd_Decreasing(cudd_mgr, bdd, input_index)
|
|
|
|
|
== Cudd_ReadOne(cudd_mgr));
|
|
|
|
|
Cudd_RecursiveDeref(cudd_mgr, bdd);
|
|
|
|
|
bdd_.clearVarMap();
|
2019-03-13 01:25:53 +01:00
|
|
|
}
|
2018-09-28 17:54:21 +02:00
|
|
|
TimingSense sense;
|
|
|
|
|
if (increasing && decreasing)
|
2019-03-13 01:25:53 +01:00
|
|
|
sense = TimingSense::none;
|
2018-09-28 17:54:21 +02:00
|
|
|
else if (increasing)
|
2019-03-13 01:25:53 +01:00
|
|
|
sense = TimingSense::positive_unate;
|
2018-09-28 17:54:21 +02:00
|
|
|
else if (decreasing)
|
2019-03-13 01:25:53 +01:00
|
|
|
sense = TimingSense::negative_unate;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
sense = TimingSense::non_unate;
|
2025-03-31 00:27:53 +02:00
|
|
|
debugPrint(debug_, "sim", 4, " %s", to_string(sense));
|
2018-09-28 17:54:21 +02:00
|
|
|
return sense;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicValue
|
|
|
|
|
Sim::evalExpr(const FuncExpr *expr,
|
2024-02-27 18:00:48 +01:00
|
|
|
const Instance *inst)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2024-06-03 23:09:30 +02:00
|
|
|
LockGuard lock(bdd_lock_);
|
2024-02-27 18:00:48 +01:00
|
|
|
DdNode *bdd = funcBddSim(expr, inst);
|
2019-03-13 01:25:53 +01:00
|
|
|
LogicValue value = LogicValue::unknown;
|
2024-02-27 18:00:48 +01:00
|
|
|
DdManager *cudd_mgr = bdd_.cuddMgr();
|
|
|
|
|
if (bdd == Cudd_ReadLogicZero(cudd_mgr))
|
2019-03-13 01:25:53 +01:00
|
|
|
value = LogicValue::zero;
|
2024-02-27 18:00:48 +01:00
|
|
|
else if (bdd == Cudd_ReadOne(cudd_mgr))
|
2019-03-13 01:25:53 +01:00
|
|
|
value = LogicValue::one;
|
2024-02-27 18:00:48 +01:00
|
|
|
|
2019-02-16 21:07:59 +01:00
|
|
|
if (bdd) {
|
2024-02-27 18:00:48 +01:00
|
|
|
Cudd_RecursiveDeref(bdd_.cuddMgr(), bdd);
|
|
|
|
|
bdd_.clearVarMap();
|
2019-02-16 21:07:59 +01:00
|
|
|
}
|
2018-09-28 17:54:21 +02:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 18:00:48 +01:00
|
|
|
// BDD with instance pin values substituted.
|
2018-09-28 17:54:21 +02:00
|
|
|
DdNode *
|
2024-02-27 18:00:48 +01:00
|
|
|
Sim::funcBddSim(const FuncExpr *expr,
|
|
|
|
|
const Instance *inst)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2024-02-27 18:00:48 +01:00
|
|
|
DdNode *bdd = bdd_.funcBdd(expr);
|
|
|
|
|
DdManager *cudd_mgr = bdd_.cuddMgr();
|
|
|
|
|
InstancePinIterator *pin_iter = network_->pinIterator(inst);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
|
|
|
|
const Pin *pin = pin_iter->next();
|
|
|
|
|
const LibertyPort *port = network_->libertyPort(pin);
|
|
|
|
|
DdNode *port_node = bdd_.findNode(port);
|
|
|
|
|
if (port_node) {
|
2018-09-28 17:54:21 +02:00
|
|
|
LogicValue value = logicValue(pin);
|
2024-02-27 18:00:48 +01:00
|
|
|
int var_index = Cudd_NodeReadIndex(port_node);
|
2018-09-28 17:54:21 +02:00
|
|
|
switch (value) {
|
2019-03-13 01:25:53 +01:00
|
|
|
case LogicValue::zero:
|
2024-02-27 18:00:48 +01:00
|
|
|
bdd = Cudd_bddCompose(cudd_mgr, bdd, Cudd_ReadLogicZero(cudd_mgr), var_index);
|
|
|
|
|
Cudd_Ref(bdd);
|
|
|
|
|
break;
|
2019-03-13 01:25:53 +01:00
|
|
|
case LogicValue::one:
|
2024-02-27 18:00:48 +01:00
|
|
|
bdd = Cudd_bddCompose(cudd_mgr, bdd, Cudd_ReadOne(cudd_mgr), var_index);
|
|
|
|
|
Cudd_Ref(bdd);
|
|
|
|
|
break;
|
2018-09-28 17:54:21 +02:00
|
|
|
default:
|
2024-02-27 18:00:48 +01:00
|
|
|
break;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-29 07:53:27 +02:00
|
|
|
delete pin_iter;
|
2024-02-27 18:00:48 +01:00
|
|
|
return bdd;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 02:01:46 +02:00
|
|
|
static LogicValue
|
|
|
|
|
logicNot(LogicValue value)
|
|
|
|
|
{
|
|
|
|
|
static LogicValue logic_not[5] = {LogicValue::one, LogicValue::zero,
|
|
|
|
|
LogicValue::unknown, LogicValue::unknown,
|
|
|
|
|
LogicValue::unknown};
|
|
|
|
|
return logic_not[int(value)];
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
void
|
|
|
|
|
Sim::clear()
|
|
|
|
|
{
|
|
|
|
|
valid_ = false;
|
|
|
|
|
incremental_ = false;
|
|
|
|
|
const_func_pins_.clear();
|
|
|
|
|
const_func_pins_valid_ = false;
|
|
|
|
|
instances_with_const_pins_.clear();
|
|
|
|
|
instances_to_annotate_.clear();
|
|
|
|
|
invalid_insts_.clear();
|
|
|
|
|
invalid_drvr_pins_.clear();
|
|
|
|
|
invalid_load_pins_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::setObserver(SimObserver *observer)
|
|
|
|
|
{
|
|
|
|
|
delete observer_;
|
|
|
|
|
observer_ = observer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::ensureConstantsPropagated()
|
|
|
|
|
{
|
|
|
|
|
if (!valid_) {
|
2020-12-29 19:33:22 +01:00
|
|
|
Stats stats(debug_, report_);
|
2018-09-28 17:54:21 +02:00
|
|
|
ensureConstantFuncPins();
|
|
|
|
|
instances_to_annotate_.clear();
|
|
|
|
|
if (incremental_) {
|
|
|
|
|
seedInvalidConstants();
|
|
|
|
|
propagateToInvalidLoads();
|
|
|
|
|
propagateFromInvalidDrvrsToLoads();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clearSimValues();
|
|
|
|
|
seedConstants();
|
|
|
|
|
}
|
|
|
|
|
invalid_insts_.clear();
|
2021-06-22 02:49:46 +02:00
|
|
|
propagateConstants(false);
|
2018-09-28 17:54:21 +02:00
|
|
|
annotateGraphEdges();
|
|
|
|
|
valid_ = true;
|
|
|
|
|
incremental_ = true;
|
|
|
|
|
|
|
|
|
|
stats.report("Propagate constants");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 02:49:46 +02:00
|
|
|
void
|
|
|
|
|
Sim::findLogicConstants()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
2021-07-08 19:42:56 +02:00
|
|
|
ensureConstantFuncPins();
|
2021-06-22 02:49:46 +02:00
|
|
|
setConstFuncPins();
|
2021-07-08 19:42:56 +02:00
|
|
|
enqueueConstantPinInputs();
|
2021-06-22 02:49:46 +02:00
|
|
|
propagateConstants(true);
|
2021-06-22 03:35:34 +02:00
|
|
|
valid_ = true;
|
2021-06-22 02:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
void
|
|
|
|
|
Sim::seedInvalidConstants()
|
|
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Instance *inst : invalid_insts_)
|
2018-09-28 17:54:21 +02:00
|
|
|
eval_queue_.push(inst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::propagateToInvalidLoads()
|
|
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Pin *load_pin : invalid_load_pins_) {
|
|
|
|
|
const Net *net = network_->net(load_pin);
|
2019-11-05 15:51:54 +01:00
|
|
|
if (net && network_->isGround(net))
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(load_pin, LogicValue::zero);
|
2019-11-05 15:51:54 +01:00
|
|
|
else if (net && network_->isPower(net))
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(load_pin, LogicValue::one);
|
2018-09-28 17:54:21 +02:00
|
|
|
else {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *drvr_pin = findDrvrPin(load_pin, network_);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (drvr_pin)
|
|
|
|
|
propagateDrvrToLoad(drvr_pin, load_pin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
invalid_load_pins_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::propagateFromInvalidDrvrsToLoads()
|
|
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Pin *drvr_pin : invalid_drvr_pins_) {
|
2021-03-27 02:09:35 +01:00
|
|
|
LogicValue value = const_func_pins_.hasKey(drvr_pin)
|
|
|
|
|
? pinConstFuncValue(drvr_pin)
|
|
|
|
|
: logicValue(drvr_pin);
|
2018-09-28 17:54:21 +02:00
|
|
|
PinConnectedPinIterator *load_iter=network_->connectedPinIterator(drvr_pin);
|
|
|
|
|
while (load_iter->hasNext()) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *load_pin = load_iter->next();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (load_pin != drvr_pin
|
|
|
|
|
&& network_->isLoad(load_pin))
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(load_pin, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
delete load_iter;
|
|
|
|
|
}
|
|
|
|
|
invalid_drvr_pins_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::propagateDrvrToLoad(const Pin *drvr_pin,
|
|
|
|
|
const Pin *load_pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
LogicValue value = logicValue(drvr_pin);
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(load_pin, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::constantsInvalid()
|
|
|
|
|
{
|
|
|
|
|
valid_ = false;
|
|
|
|
|
incremental_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::ensureConstantFuncPins()
|
|
|
|
|
{
|
|
|
|
|
if (!const_func_pins_valid_) {
|
|
|
|
|
LeafInstanceIterator *inst_iter = network_->leafInstanceIterator();
|
|
|
|
|
while (inst_iter->hasNext()) {
|
|
|
|
|
Instance *inst = inst_iter->next();
|
|
|
|
|
InstancePinIterator *pin_iter = network_->pinIterator(inst);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *pin = pin_iter->next();
|
2018-09-28 17:54:21 +02:00
|
|
|
recordConstPinFunc(pin);
|
|
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
}
|
|
|
|
|
delete inst_iter;
|
|
|
|
|
const_func_pins_valid_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::recordConstPinFunc(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
LibertyPort *port = network_->libertyPort(pin);
|
|
|
|
|
if (port) {
|
|
|
|
|
FuncExpr *expr = port->function();
|
|
|
|
|
if (expr
|
|
|
|
|
// Tristate outputs do not force the output to be constant.
|
2019-03-13 01:25:53 +01:00
|
|
|
&& port->tristateEnable() == nullptr
|
2018-09-28 17:54:21 +02:00
|
|
|
&& (expr->op() == FuncExpr::op_zero
|
|
|
|
|
|| expr->op() == FuncExpr::op_one))
|
|
|
|
|
const_func_pins_.insert(pin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::deleteInstanceBefore(const Instance *inst)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2019-04-11 05:36:48 +02:00
|
|
|
instances_with_const_pins_.erase(inst);
|
|
|
|
|
invalid_insts_.erase(inst);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::makePinAfter(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
// Incrementally update const_func_pins_.
|
|
|
|
|
recordConstPinFunc(pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::deletePinBefore(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
// Incrementally update const_func_pins_.
|
2019-04-11 05:36:48 +02:00
|
|
|
const_func_pins_.erase(pin);
|
|
|
|
|
invalid_load_pins_.erase(pin);
|
|
|
|
|
invalid_drvr_pins_.erase(pin);
|
2018-09-28 17:54:21 +02:00
|
|
|
invalid_insts_.insert(network_->instance(pin));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::connectPinAfter(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (incremental_) {
|
2020-11-14 18:34:26 +01:00
|
|
|
recordConstPinFunc(pin);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (network_->isLoad(pin))
|
|
|
|
|
invalid_load_pins_.insert(pin);
|
|
|
|
|
if (network_->isDriver(pin))
|
|
|
|
|
invalid_drvr_pins_.insert(pin);
|
|
|
|
|
valid_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::disconnectPinBefore(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2019-11-05 15:51:54 +01:00
|
|
|
if (incremental_) {
|
|
|
|
|
if (network_->isLoad(pin)) {
|
|
|
|
|
invalid_load_pins_.insert(pin);
|
|
|
|
|
removePropagatedValue(pin);
|
|
|
|
|
}
|
|
|
|
|
if (network_->isDriver(pin))
|
|
|
|
|
invalid_drvr_pins_.insert(pin);
|
|
|
|
|
}
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::pinSetFuncAfter(const Pin *pin)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
if (incremental_) {
|
|
|
|
|
Instance *inst = network_->instance(pin);
|
|
|
|
|
if (instances_with_const_pins_.hasKey(inst))
|
|
|
|
|
invalid_insts_.insert(inst);
|
|
|
|
|
valid_ = false;
|
|
|
|
|
}
|
|
|
|
|
// Incrementally update const_func_pins_.
|
2019-04-11 05:36:48 +02:00
|
|
|
const_func_pins_.erase(pin);
|
2018-09-28 17:54:21 +02:00
|
|
|
recordConstPinFunc(pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::seedConstants()
|
|
|
|
|
{
|
|
|
|
|
// Propagate constants from inputs tied hi/low in the network.
|
2021-06-22 02:49:46 +02:00
|
|
|
enqueueConstantPinInputs();
|
2019-03-13 01:25:53 +01:00
|
|
|
// Propagate set_LogicValue::zero, set_LogicValue::one, set_logic_dc constants.
|
2021-06-22 02:49:46 +02:00
|
|
|
setConstraintConstPins(sdc_->logicValues());
|
2018-09-28 17:54:21 +02:00
|
|
|
// Propagate set_case_analysis constants.
|
2021-06-22 02:49:46 +02:00
|
|
|
setConstraintConstPins(sdc_->caseLogicValues());
|
2018-09-28 17:54:21 +02:00
|
|
|
// Propagate 0/1 constant functions.
|
2021-06-22 02:49:46 +02:00
|
|
|
setConstFuncPins();
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-22 02:49:46 +02:00
|
|
|
Sim::propagateConstants(bool thru_sequentials)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
while (!eval_queue_.empty()) {
|
|
|
|
|
const Instance *inst = eval_queue_.front();
|
|
|
|
|
eval_queue_.pop();
|
2021-06-22 02:49:46 +02:00
|
|
|
evalInstance(inst, thru_sequentials);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::setConstraintConstPins(LogicValueMap &value_map)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2024-06-27 22:57:58 +02:00
|
|
|
for (const auto [pin, value] : value_map) {
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, "case pin %s = %c",
|
|
|
|
|
network_->pathName(pin),
|
|
|
|
|
logicValueString(value));
|
2018-09-28 17:54:21 +02:00
|
|
|
if (network_->isHierarchical(pin)) {
|
|
|
|
|
// Set the logic value on pins inside the instance of a hierarchical pin.
|
|
|
|
|
bool pin_is_output = network_->direction(pin)->isAnyOutput();
|
|
|
|
|
PinConnectedPinIterator *pin_iter=network_->connectedPinIterator(pin);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *pin1 = pin_iter->next();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (network_->isLeaf(pin1)
|
|
|
|
|
&& network_->direction(pin1)->isAnyInput()
|
|
|
|
|
&& ((pin_is_output && !network_->isInside(pin1, pin))
|
|
|
|
|
|| (!pin_is_output && network_->isInside(pin1, pin))))
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(pin1, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(pin, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Propagate constants from outputs with constant functions
|
|
|
|
|
// (tie high and tie low cell instances).
|
|
|
|
|
void
|
2021-06-22 02:49:46 +02:00
|
|
|
Sim::setConstFuncPins()
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Pin *pin : const_func_pins_) {
|
2021-03-27 02:09:35 +01:00
|
|
|
LogicValue value = pinConstFuncValue(pin);
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(pin, value);
|
2021-03-27 02:09:35 +01:00
|
|
|
debugPrint(debug_, "sim", 2, "func pin %s = %c",
|
|
|
|
|
network_->pathName(pin),
|
|
|
|
|
logicValueString(value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicValue
|
2023-01-19 19:23:45 +01:00
|
|
|
Sim::pinConstFuncValue(const Pin *pin)
|
2021-03-27 02:09:35 +01:00
|
|
|
{
|
|
|
|
|
LibertyPort *port = network_->libertyPort(pin);
|
|
|
|
|
if (port) {
|
|
|
|
|
FuncExpr *expr = port->function();
|
|
|
|
|
if (expr->op() == FuncExpr::op_zero)
|
|
|
|
|
return LogicValue::zero;
|
|
|
|
|
else if (expr->op() == FuncExpr::op_one)
|
|
|
|
|
return LogicValue::one;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
2021-03-27 02:09:35 +01:00
|
|
|
return LogicValue::unknown;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-22 02:49:46 +02:00
|
|
|
Sim::enqueueConstantPinInputs()
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
ConstantPinIterator *const_iter = network_->constantPinIterator();
|
|
|
|
|
while (const_iter->hasNext()) {
|
|
|
|
|
LogicValue value;
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *pin;
|
2018-09-28 17:54:21 +02:00
|
|
|
const_iter->next(pin, value);
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, "network constant pin %s = %c",
|
|
|
|
|
network_->pathName(pin),
|
|
|
|
|
logicValueString(value));
|
2021-06-22 02:49:46 +02:00
|
|
|
setPinValue(pin, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
delete const_iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::removePropagatedValue(const Pin *pin)
|
|
|
|
|
{
|
|
|
|
|
Instance *inst = network_->instance(pin);
|
|
|
|
|
if (instances_with_const_pins_.hasKey(inst)) {
|
|
|
|
|
invalid_insts_.insert(inst);
|
|
|
|
|
valid_ = false;
|
|
|
|
|
|
|
|
|
|
LogicValue constraint_value;
|
|
|
|
|
bool exists;
|
|
|
|
|
sdc_->caseLogicValue(pin, constraint_value, exists);
|
|
|
|
|
if (!exists) {
|
|
|
|
|
sdc_->logicValue(pin, constraint_value, exists);
|
|
|
|
|
if (!exists) {
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, "pin %s remove prop constant",
|
|
|
|
|
network_->pathName(pin));
|
2020-06-16 18:23:19 +02:00
|
|
|
Vertex *vertex, *bidirect_drvr_vertex;
|
|
|
|
|
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
|
|
|
|
|
if (vertex)
|
|
|
|
|
setSimValue(vertex, LogicValue::unknown);
|
|
|
|
|
if (bidirect_drvr_vertex)
|
|
|
|
|
setSimValue(bidirect_drvr_vertex, LogicValue::unknown);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::setPinValue(const Pin *pin,
|
2021-06-22 02:49:46 +02:00
|
|
|
LogicValue value)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
LogicValue constraint_value;
|
|
|
|
|
bool exists;
|
|
|
|
|
sdc_->caseLogicValue(pin, constraint_value, exists);
|
|
|
|
|
if (!exists)
|
|
|
|
|
sdc_->logicValue(pin, constraint_value, exists);
|
|
|
|
|
if (exists
|
|
|
|
|
&& value != constraint_value) {
|
2019-03-13 01:25:53 +01:00
|
|
|
if (value != LogicValue::unknown)
|
2024-01-08 03:23:53 +01:00
|
|
|
report_->warn(1521, "propagated logic value %c differs from constraint value of %c on pin %s.",
|
2018-09-28 17:54:21 +02:00
|
|
|
logicValueString(value),
|
|
|
|
|
logicValueString(constraint_value),
|
|
|
|
|
sdc_network_->pathName(pin));
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 3, "pin %s = %c",
|
|
|
|
|
network_->pathName(pin),
|
|
|
|
|
logicValueString(value));
|
2018-09-28 17:54:21 +02:00
|
|
|
Vertex *vertex, *bidirect_drvr_vertex;
|
|
|
|
|
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
|
|
|
|
|
// Set vertex constant flags.
|
2024-05-28 04:33:08 +02:00
|
|
|
bool value_changed = false;
|
|
|
|
|
if (vertex) {
|
|
|
|
|
value_changed |= value != vertex->simValue();
|
2018-09-28 17:54:21 +02:00
|
|
|
setSimValue(vertex, value);
|
2024-05-28 04:33:08 +02:00
|
|
|
}
|
|
|
|
|
if (bidirect_drvr_vertex) {
|
|
|
|
|
value_changed |= value != bidirect_drvr_vertex->simValue();
|
2018-09-28 17:54:21 +02:00
|
|
|
setSimValue(bidirect_drvr_vertex, value);
|
2024-05-28 04:33:08 +02:00
|
|
|
}
|
|
|
|
|
if (value_changed) {
|
|
|
|
|
Instance *inst = network_->instance(pin);
|
|
|
|
|
if (logicValueZeroOne(value))
|
|
|
|
|
instances_with_const_pins_.insert(inst);
|
|
|
|
|
instances_to_annotate_.insert(inst);
|
|
|
|
|
|
|
|
|
|
if (network_->isLeaf(inst)
|
|
|
|
|
&& network_->direction(pin)->isAnyInput()) {
|
|
|
|
|
if (eval_queue_.empty()
|
|
|
|
|
|| (eval_queue_.back() != inst))
|
|
|
|
|
eval_queue_.push(inst);
|
|
|
|
|
}
|
|
|
|
|
else if (network_->isDriver(pin)) {
|
|
|
|
|
// Enqueue instances with input pins connected to net.
|
|
|
|
|
PinConnectedPinIterator *pin_iter=network_->connectedPinIterator(pin);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
|
|
|
|
const Pin *pin1 = pin_iter->next();
|
|
|
|
|
if (pin1 != pin
|
|
|
|
|
&& network_->isLoad(pin1))
|
|
|
|
|
setPinValue(pin1, value);
|
|
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2021-06-22 02:49:46 +02:00
|
|
|
Sim::evalInstance(const Instance *inst,
|
|
|
|
|
bool thru_sequentials)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, "eval %s", network_->pathName(inst));
|
2018-09-28 17:54:21 +02:00
|
|
|
InstancePinIterator *pin_iter = network_->pinIterator(inst);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
|
|
|
|
Pin *pin = pin_iter->next();
|
2021-06-22 02:49:46 +02:00
|
|
|
LibertyPort *port = network_->libertyPort(pin);
|
|
|
|
|
if (port) {
|
|
|
|
|
PortDirection *dir = port->direction();
|
|
|
|
|
if (dir->isAnyOutput()) {
|
2020-11-17 18:59:19 +01:00
|
|
|
LogicValue value = LogicValue::unknown;
|
2018-09-28 17:54:21 +02:00
|
|
|
FuncExpr *expr = port->function();
|
2021-06-22 02:49:46 +02:00
|
|
|
LibertyCell *cell = port->libertyCell();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (expr) {
|
2020-11-17 18:59:19 +01:00
|
|
|
FuncExpr *tri_en_expr = port->tristateEnable();
|
|
|
|
|
if (tri_en_expr) {
|
|
|
|
|
if (evalExpr(tri_en_expr, inst) == LogicValue::one) {
|
|
|
|
|
value = evalExpr(expr, inst);
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, " %s tri_en=1 %s = %c",
|
|
|
|
|
port->name(),
|
2025-03-31 00:27:53 +02:00
|
|
|
expr->to_string().c_str(),
|
2021-01-01 20:46:51 +01:00
|
|
|
logicValueString(value));
|
2020-11-17 18:59:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-07-08 19:42:56 +02:00
|
|
|
LibertyPort *expr_port = expr->port();
|
|
|
|
|
Sequential *sequential = (thru_sequentials && expr_port)
|
2021-07-12 20:15:36 +02:00
|
|
|
? cell->outputPortSequential(expr_port)
|
2021-07-08 19:42:56 +02:00
|
|
|
: nullptr;
|
2021-06-22 02:49:46 +02:00
|
|
|
if (sequential) {
|
|
|
|
|
value = evalExpr(sequential->data(), inst);
|
2021-07-08 19:42:56 +02:00
|
|
|
if (expr_port == sequential->outputInv())
|
|
|
|
|
value = logicNot(value);
|
2021-06-22 02:49:46 +02:00
|
|
|
debugPrint(debug_, "sim", 2, " %s seq %s = %c",
|
|
|
|
|
port->name(),
|
2025-03-31 00:27:53 +02:00
|
|
|
expr->to_string().c_str(),
|
2021-06-22 02:49:46 +02:00
|
|
|
logicValueString(value));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
value = evalExpr(expr, inst);
|
|
|
|
|
debugPrint(debug_, "sim", 2, " %s %s = %c",
|
|
|
|
|
port->name(),
|
2025-03-31 00:27:53 +02:00
|
|
|
expr->to_string().c_str(),
|
2021-06-22 02:49:46 +02:00
|
|
|
logicValueString(value));
|
|
|
|
|
}
|
2020-11-17 18:59:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-27 23:47:12 +01:00
|
|
|
else if (port->isClockGateOut()) {
|
2020-11-17 18:59:19 +01:00
|
|
|
value = clockGateOutValue(inst);
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 2, " %s gated_clk = %c",
|
|
|
|
|
port->name(),
|
|
|
|
|
logicValueString(value));
|
2020-11-17 18:59:19 +01:00
|
|
|
}
|
2021-06-22 02:49:46 +02:00
|
|
|
if (value != logicValue(pin))
|
|
|
|
|
setPinValue(pin, value);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 18:59:19 +01:00
|
|
|
LogicValue
|
|
|
|
|
Sim::clockGateOutValue(const Instance *inst)
|
|
|
|
|
{
|
|
|
|
|
LibertyCell *cell = network_->libertyCell(inst);
|
|
|
|
|
LibertyCellPortIterator port_iter(cell);
|
|
|
|
|
while (port_iter.hasNext()) {
|
|
|
|
|
LibertyPort *port = port_iter.next();
|
2022-11-27 23:47:12 +01:00
|
|
|
if (port->isClockGateClock()
|
|
|
|
|
|| port->isClockGateEnable()) {
|
2020-11-17 18:59:19 +01:00
|
|
|
Pin *gclk_pin = network_->findPin(inst, port);
|
|
|
|
|
if (gclk_pin) {
|
|
|
|
|
Vertex *gclk_vertex = graph_->pinLoadVertex(gclk_pin);
|
|
|
|
|
if (gclk_vertex->simValue() == LogicValue::zero)
|
|
|
|
|
return LogicValue::zero;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return LogicValue::unknown;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
void
|
|
|
|
|
Sim::setSimValue(Vertex *vertex,
|
|
|
|
|
LogicValue value)
|
|
|
|
|
{
|
|
|
|
|
if (value != vertex->simValue()) {
|
|
|
|
|
vertex->setSimValue(value);
|
|
|
|
|
if (observer_)
|
|
|
|
|
observer_->valueChangeAfter(vertex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TimingSense
|
|
|
|
|
Sim::functionSense(const Instance *inst,
|
|
|
|
|
const Pin *from_pin,
|
|
|
|
|
const Pin *to_pin)
|
|
|
|
|
{
|
|
|
|
|
if (logicZeroOne(from_pin))
|
2019-03-13 01:25:53 +01:00
|
|
|
return TimingSense::none;
|
2018-09-28 17:54:21 +02:00
|
|
|
else {
|
|
|
|
|
LibertyPort *from_port = network_->libertyPort(from_pin);
|
|
|
|
|
LibertyPort *to_port = network_->libertyPort(to_pin);
|
|
|
|
|
if (to_port) {
|
|
|
|
|
const FuncExpr *func = to_port->function();
|
|
|
|
|
if (func) {
|
|
|
|
|
PortDirection *to_dir = to_port->direction();
|
|
|
|
|
if (to_dir->isAnyTristate()) {
|
|
|
|
|
FuncExpr *tri_func = to_port->tristateEnable();
|
|
|
|
|
if (tri_func) {
|
|
|
|
|
if (func->hasPort(from_port)) {
|
|
|
|
|
// from_pin is an input to the to_pin function.
|
|
|
|
|
LogicValue tri_enable = evalExpr(tri_func, inst);
|
2019-03-13 01:25:53 +01:00
|
|
|
if (tri_enable == LogicValue::zero)
|
2018-09-28 17:54:21 +02:00
|
|
|
// Tristate is disabled.
|
2019-03-13 01:25:53 +01:00
|
|
|
return TimingSense::none;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
|
|
|
|
return functionSense(func, from_pin, inst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Missing tristate enable function.
|
|
|
|
|
if (func->hasPort(from_port))
|
|
|
|
|
// from_pin is an input to the to_pin function.
|
|
|
|
|
return functionSense(func, from_pin, inst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (func->hasPort(from_port))
|
|
|
|
|
// from_pin is an input to the to_pin function.
|
|
|
|
|
return functionSense(func, from_pin, inst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-13 01:25:53 +01:00
|
|
|
return TimingSense::unknown;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogicValue
|
|
|
|
|
Sim::logicValue(const Pin *pin) const
|
|
|
|
|
{
|
|
|
|
|
Vertex *vertex = graph_->pinLoadVertex(pin);
|
|
|
|
|
if (vertex)
|
|
|
|
|
return vertex->simValue();
|
|
|
|
|
else {
|
|
|
|
|
if (network_->isHierarchical(pin)) {
|
2023-01-19 19:23:45 +01:00
|
|
|
const Pin *drvr_pin = findDrvrPin(pin, network_);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (drvr_pin)
|
|
|
|
|
return logicValue(drvr_pin);
|
|
|
|
|
}
|
2019-03-13 01:25:53 +01:00
|
|
|
return LogicValue::unknown;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 19:23:45 +01:00
|
|
|
static const Pin *
|
2018-09-28 17:54:21 +02:00
|
|
|
findDrvrPin(const Pin *pin,
|
|
|
|
|
Network *network)
|
|
|
|
|
{
|
|
|
|
|
PinSet *drvrs = network->drivers(pin);
|
|
|
|
|
if (drvrs) {
|
|
|
|
|
PinSet::Iterator drvr_iter(drvrs);
|
|
|
|
|
if (drvr_iter.hasNext())
|
|
|
|
|
return drvr_iter.next();
|
|
|
|
|
}
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
logicValueZeroOne(LogicValue value)
|
|
|
|
|
{
|
2019-03-13 01:25:53 +01:00
|
|
|
return value == LogicValue::zero || value == LogicValue::one;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Sim::logicZeroOne(const Pin *pin) const
|
|
|
|
|
{
|
|
|
|
|
return logicValueZeroOne(logicValue(pin));
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 07:56:32 +02:00
|
|
|
bool
|
|
|
|
|
Sim::logicZeroOne(const Vertex *vertex) const
|
|
|
|
|
{
|
|
|
|
|
return logicValueZeroOne(vertex->simValue());
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
void
|
|
|
|
|
Sim::clearSimValues()
|
|
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Instance *inst : instances_with_const_pins_) {
|
2018-09-28 17:54:21 +02:00
|
|
|
// Clear sim values on all pins before evaling functions.
|
|
|
|
|
clearInstSimValues(inst);
|
|
|
|
|
annotateVertexEdges(inst, false);
|
|
|
|
|
}
|
|
|
|
|
instances_with_const_pins_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::clearInstSimValues(const Instance *inst)
|
|
|
|
|
{
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 4, "clear %s",
|
|
|
|
|
network_->pathName(inst));
|
2018-09-28 17:54:21 +02:00
|
|
|
InstancePinIterator *pin_iter = network_->pinIterator(inst);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
|
|
|
|
Pin *pin = pin_iter->next();
|
|
|
|
|
Vertex *vertex, *bidirect_drvr_vertex;
|
|
|
|
|
graph_->pinVertices(pin, vertex, bidirect_drvr_vertex);
|
|
|
|
|
if (vertex)
|
2019-03-13 01:25:53 +01:00
|
|
|
setSimValue(vertex, LogicValue::unknown);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (bidirect_drvr_vertex)
|
2019-03-13 01:25:53 +01:00
|
|
|
setSimValue(bidirect_drvr_vertex, LogicValue::unknown);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Annotate graph edges disabled by constant values.
|
|
|
|
|
void
|
|
|
|
|
Sim::annotateGraphEdges()
|
|
|
|
|
{
|
2023-01-19 19:23:45 +01:00
|
|
|
for (const Instance *inst : instances_to_annotate_)
|
2018-09-28 17:54:21 +02:00
|
|
|
annotateVertexEdges(inst, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::annotateVertexEdges(const Instance *inst,
|
|
|
|
|
bool annotate)
|
|
|
|
|
{
|
2021-01-01 20:46:51 +01:00
|
|
|
debugPrint(debug_, "sim", 4, "annotate %s %s",
|
|
|
|
|
network_->pathName(inst),
|
|
|
|
|
annotate ? "true" : "false");
|
2018-09-28 17:54:21 +02:00
|
|
|
InstancePinIterator *pin_iter = network_->pinIterator(inst);
|
|
|
|
|
while (pin_iter->hasNext()) {
|
|
|
|
|
Pin *pin = pin_iter->next();
|
2019-09-07 21:37:05 +02:00
|
|
|
Vertex *vertex = graph_->pinDrvrVertex(pin);
|
2018-09-28 17:54:21 +02:00
|
|
|
if (vertex)
|
|
|
|
|
annotateVertexEdges(inst, pin, vertex, annotate);
|
|
|
|
|
}
|
|
|
|
|
delete pin_iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Sim::annotateVertexEdges(const Instance *inst,
|
|
|
|
|
const Pin *pin,
|
|
|
|
|
Vertex *vertex,
|
|
|
|
|
bool annotate)
|
|
|
|
|
{
|
|
|
|
|
bool fanin_disables_changed = false;
|
|
|
|
|
VertexInEdgeIterator edge_iter(vertex, graph_);
|
|
|
|
|
while (edge_iter.hasNext()) {
|
|
|
|
|
Edge *edge = edge_iter.next();
|
|
|
|
|
if (!edge->role()->isWire()) {
|
|
|
|
|
Vertex *from_vertex = edge->from(graph_);
|
|
|
|
|
Pin *from_pin = from_vertex->pin();
|
2019-03-13 01:25:53 +01:00
|
|
|
TimingSense sense = TimingSense::unknown;
|
2018-09-28 17:54:21 +02:00
|
|
|
bool is_disabled_cond = false;
|
|
|
|
|
if (annotate) {
|
|
|
|
|
// Set timing sense on edges in instances that have constant pins.
|
2019-08-13 07:56:32 +02:00
|
|
|
if (logicZeroOne(from_vertex))
|
2019-03-13 01:25:53 +01:00
|
|
|
sense = TimingSense::none;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
|
|
|
|
sense = functionSense(inst, from_pin, pin);
|
|
|
|
|
|
2019-03-13 01:25:53 +01:00
|
|
|
if (sense != TimingSense::none)
|
2018-09-28 17:54:21 +02:00
|
|
|
// Disable conditional timing edges based on constant pins.
|
|
|
|
|
is_disabled_cond = isCondDisabled(edge, inst, from_pin,
|
|
|
|
|
pin, network_,sim_)
|
|
|
|
|
// Disable mode conditional timing
|
|
|
|
|
// edges based on constant pins.
|
2024-10-24 20:37:07 +02:00
|
|
|
|| isModeDisabled(edge,inst,network_,sim_);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
bool disables_changed = false;
|
|
|
|
|
if (sense != edge->simTimingSense()) {
|
|
|
|
|
edge->setSimTimingSense(sense);
|
|
|
|
|
disables_changed = true;
|
|
|
|
|
fanin_disables_changed = true;
|
|
|
|
|
}
|
|
|
|
|
if (is_disabled_cond != edge->isDisabledCond()) {
|
|
|
|
|
edge->setIsDisabledCond(is_disabled_cond);
|
|
|
|
|
disables_changed = true;
|
|
|
|
|
fanin_disables_changed = true;
|
|
|
|
|
}
|
|
|
|
|
if (observer_ && disables_changed)
|
|
|
|
|
observer_->fanoutEdgesChangeAfter(from_vertex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (observer_ && fanin_disables_changed)
|
|
|
|
|
observer_->faninEdgesChangeAfter(vertex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
isCondDisabled(Edge *edge,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
const Pin *from_pin,
|
|
|
|
|
const Pin *to_pin,
|
|
|
|
|
const Network *network,
|
2024-02-27 18:00:48 +01:00
|
|
|
Sim *sim)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
bool is_disabled;
|
|
|
|
|
FuncExpr *disable_cond;
|
|
|
|
|
isCondDisabled(edge, inst, from_pin, to_pin, network, sim,
|
|
|
|
|
is_disabled, disable_cond);
|
|
|
|
|
return is_disabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
isCondDisabled(Edge *edge,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
const Pin *from_pin,
|
|
|
|
|
const Pin *to_pin,
|
|
|
|
|
const Network *network,
|
2024-02-27 18:00:48 +01:00
|
|
|
Sim *sim,
|
2018-09-28 17:54:21 +02:00
|
|
|
bool &is_disabled,
|
|
|
|
|
FuncExpr *&disable_cond)
|
|
|
|
|
{
|
|
|
|
|
TimingArcSet *arc_set = edge->timingArcSet();
|
|
|
|
|
FuncExpr *cond = arc_set->cond();
|
|
|
|
|
if (cond) {
|
|
|
|
|
LogicValue cond_value = sim->evalExpr(cond, inst);
|
|
|
|
|
disable_cond = cond;
|
2019-03-13 01:25:53 +01:00
|
|
|
is_disabled = (cond_value == LogicValue::zero);
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Unconditional "default" arc set is disabled if another
|
|
|
|
|
// conditional arc from/to the same pins is enabled (condition
|
|
|
|
|
// evals to logic one).
|
|
|
|
|
LibertyCell *cell = network->libertyCell(inst);
|
|
|
|
|
LibertyPort *from_port = network->libertyPort(from_pin);
|
|
|
|
|
LibertyPort *to_port = network->libertyPort(to_pin);
|
|
|
|
|
is_disabled = false;
|
2022-06-12 17:21:34 +02:00
|
|
|
for (TimingArcSet *cond_set : cell->timingArcSets(from_port, to_port)) {
|
2018-09-28 17:54:21 +02:00
|
|
|
FuncExpr *cond = cond_set->cond();
|
2019-03-13 01:25:53 +01:00
|
|
|
if (cond && sim->evalExpr(cond, inst) == LogicValue::one) {
|
2018-09-28 17:54:21 +02:00
|
|
|
disable_cond = cond;
|
|
|
|
|
is_disabled = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
isModeDisabled(Edge *edge,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
const Network *network,
|
2024-02-27 18:00:48 +01:00
|
|
|
Sim *sim)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
bool is_disabled;
|
|
|
|
|
FuncExpr *disable_cond;
|
|
|
|
|
isModeDisabled(edge, inst, network, sim,
|
|
|
|
|
is_disabled, disable_cond);
|
|
|
|
|
return is_disabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
isModeDisabled(Edge *edge,
|
|
|
|
|
const Instance *inst,
|
|
|
|
|
const Network *network,
|
2024-02-27 18:00:48 +01:00
|
|
|
Sim *sim,
|
2018-09-28 17:54:21 +02:00
|
|
|
bool &is_disabled,
|
|
|
|
|
FuncExpr *&disable_cond)
|
|
|
|
|
{
|
|
|
|
|
// Default values.
|
|
|
|
|
is_disabled = false;
|
|
|
|
|
disable_cond = 0;
|
|
|
|
|
TimingArcSet *arc_set = edge->timingArcSet();
|
|
|
|
|
const char *mode_name = arc_set->modeName();
|
|
|
|
|
const char *mode_value = arc_set->modeValue();
|
|
|
|
|
if (mode_name && mode_value) {
|
|
|
|
|
LibertyCell *cell = network->libertyCell(inst);
|
|
|
|
|
ModeDef *mode_def = cell->findModeDef(mode_name);
|
|
|
|
|
if (mode_def) {
|
|
|
|
|
ModeValueDef *value_def = mode_def->findValueDef(mode_value);
|
|
|
|
|
if (value_def) {
|
|
|
|
|
FuncExpr *cond = value_def->cond();
|
|
|
|
|
if (cond) {
|
|
|
|
|
LogicValue cond_value = sim->evalExpr(cond, inst);
|
2019-03-13 01:25:53 +01:00
|
|
|
if (cond_value == LogicValue::zero) {
|
2018-09-28 17:54:21 +02:00
|
|
|
// For a mode value to be disabled by having a value of
|
|
|
|
|
// logic zero one mode value must logic one.
|
2024-06-27 22:57:58 +02:00
|
|
|
for (const auto [name, value_def] : *mode_def->values()) {
|
|
|
|
|
if (value_def) {
|
|
|
|
|
FuncExpr *cond1 = value_def->cond();
|
2018-09-28 17:54:21 +02:00
|
|
|
if (cond1) {
|
|
|
|
|
LogicValue cond_value1 = sim->evalExpr(cond1, inst);
|
2019-03-13 01:25:53 +01:00
|
|
|
if (cond_value1 == LogicValue::one) {
|
2018-09-28 17:54:21 +02:00
|
|
|
disable_cond = cond;
|
|
|
|
|
is_disabled = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|