2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2019-01-01 21:26:11 +01:00
|
|
|
// Copyright (c) 2019, 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/>.
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include "Machine.hh"
|
|
|
|
|
#include "StringUtil.hh"
|
|
|
|
|
#include "MinMax.hh"
|
|
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
const float INF = 1E+30F;
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
compareMin(float value1,
|
|
|
|
|
float value2)
|
|
|
|
|
{
|
|
|
|
|
return value1 < value2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
compareMax(float value1,
|
|
|
|
|
float value2)
|
|
|
|
|
{
|
|
|
|
|
return value1 > value2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
MinMax *MinMax::min_;
|
|
|
|
|
MinMax *MinMax::max_;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MinMax::init()
|
|
|
|
|
{
|
|
|
|
|
min_ = new MinMax("min", 0, INF, compareMin);
|
|
|
|
|
max_ = new MinMax("max", 1, -INF, compareMax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MinMax::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete min_;
|
2019-03-13 01:25:53 +01:00
|
|
|
min_ = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
delete max_;
|
2019-03-13 01:25:53 +01:00
|
|
|
max_ = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax::MinMax(const char *name,
|
|
|
|
|
int index,
|
|
|
|
|
float init_value,
|
|
|
|
|
bool (*compare)(float value1, float value2)) :
|
|
|
|
|
name_(name),
|
|
|
|
|
index_(index),
|
|
|
|
|
init_value_(init_value),
|
|
|
|
|
compare_(compare)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMaxAll *
|
|
|
|
|
MinMax::asMinMaxAll() const
|
|
|
|
|
{
|
|
|
|
|
if (this == min_)
|
|
|
|
|
return MinMaxAll::min();
|
|
|
|
|
else
|
|
|
|
|
return MinMaxAll::max();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::opposite() const
|
|
|
|
|
{
|
|
|
|
|
if (this == max_)
|
|
|
|
|
return min_;
|
|
|
|
|
else
|
|
|
|
|
return max_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::find(const char *min_max)
|
|
|
|
|
{
|
2018-11-26 18:15:52 +01:00
|
|
|
if (stringEq(min_max, "min")
|
|
|
|
|
|| stringEq(min_max, "early"))
|
2018-09-28 17:54:21 +02:00
|
|
|
return min();
|
2018-11-26 18:15:52 +01:00
|
|
|
else if (stringEq(min_max, "max")
|
|
|
|
|
|| stringEq(min_max, "late"))
|
2018-09-28 17:54:21 +02:00
|
|
|
return max();
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::find(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index == min_->index())
|
|
|
|
|
return min();
|
|
|
|
|
else if (index == max_->index())
|
|
|
|
|
return max();
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MinMax::compare(float value1,
|
|
|
|
|
float value2) const
|
|
|
|
|
{
|
|
|
|
|
return compare_(value1, value2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
MinMaxAll *MinMaxAll::min_;
|
|
|
|
|
MinMaxAll *MinMaxAll::max_;
|
|
|
|
|
MinMaxAll *MinMaxAll::all_;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MinMaxAll::init()
|
|
|
|
|
{
|
|
|
|
|
min_ = new MinMaxAll("min", 0);
|
|
|
|
|
max_ = new MinMaxAll("max", 1);
|
|
|
|
|
all_ = new MinMaxAll("all", 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MinMaxAll::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete min_;
|
2019-03-13 01:25:53 +01:00
|
|
|
min_ = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
delete max_;
|
2019-03-13 01:25:53 +01:00
|
|
|
max_ = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
delete all_;
|
2019-03-13 01:25:53 +01:00
|
|
|
all_ = nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMaxAll::MinMaxAll(const char *name,
|
|
|
|
|
int index) :
|
|
|
|
|
name_(name),
|
|
|
|
|
index_(index)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMaxAll::asMinMax() const
|
|
|
|
|
{
|
|
|
|
|
if (this == min_)
|
|
|
|
|
return MinMax::min();
|
|
|
|
|
else
|
|
|
|
|
return MinMax::max();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MinMaxAll::matches(const MinMax *min_max) const
|
|
|
|
|
{
|
|
|
|
|
return this == all_ || asMinMax() == min_max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MinMaxAll::matches(const MinMaxAll *min_max) const
|
|
|
|
|
{
|
|
|
|
|
return this == all_ || this == min_max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMaxAll *
|
|
|
|
|
MinMaxAll::find(const char *min_max)
|
|
|
|
|
{
|
2018-11-26 18:15:52 +01:00
|
|
|
if (stringEq(min_max, "min")
|
|
|
|
|
|| stringEq(min_max, "early"))
|
2018-09-28 17:54:21 +02:00
|
|
|
return min();
|
2018-11-26 18:15:52 +01:00
|
|
|
else if (stringEq(min_max, "max")
|
|
|
|
|
|| stringEq(min_max, "late"))
|
2018-09-28 17:54:21 +02:00
|
|
|
return max();
|
|
|
|
|
else if (stringEq(min_max, "all")
|
|
|
|
|
|| stringEq(min_max, "min_max")
|
|
|
|
|
|| stringEq(min_max, "minmax"))
|
|
|
|
|
return all_;
|
|
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
MinMaxIterator::MinMaxIterator(const MinMaxAll *min_max)
|
|
|
|
|
{
|
|
|
|
|
if (min_max == MinMaxAll::all()) {
|
|
|
|
|
index_ = 0;
|
|
|
|
|
index_max_ = MinMax::index_max;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
index_ = min_max->asMinMax()->index();
|
|
|
|
|
index_max_ = index_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|