2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2024-01-12 01:34:49 +01:00
|
|
|
// Copyright (c) 2024, 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/>.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "MinMax.hh"
|
2020-04-05 20:35:51 +02:00
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
#include <algorithm>
|
2020-04-05 20:35:51 +02:00
|
|
|
|
2020-04-05 23:53:44 +02:00
|
|
|
#include "StringUtil.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2019-07-18 15:19:00 +02:00
|
|
|
MinMax MinMax::min_("min", 0, INF, compareMin);
|
|
|
|
|
MinMax MinMax::max_("max", 1, -INF, compareMax);
|
|
|
|
|
const std::array<MinMax*, 2> MinMax::range_{&min_, &max_};
|
|
|
|
|
const std::array<int, 2> MinMax::range_index_{min_.index(), max_.index()};
|
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
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
if (this == &min_)
|
2018-09-28 17:54:21 +02:00
|
|
|
return MinMaxAll::min();
|
|
|
|
|
else
|
|
|
|
|
return MinMaxAll::max();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::opposite() const
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
if (this == &max_)
|
|
|
|
|
return &min_;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-07-18 15:19:00 +02:00
|
|
|
return &max_;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::find(const char *min_max)
|
|
|
|
|
{
|
2018-11-26 18:15:52 +01:00
|
|
|
if (stringEq(min_max, "min")
|
|
|
|
|
|| stringEq(min_max, "early"))
|
2019-07-18 15:19:00 +02:00
|
|
|
return &min_;
|
2018-11-26 18:15:52 +01:00
|
|
|
else if (stringEq(min_max, "max")
|
|
|
|
|
|| stringEq(min_max, "late"))
|
2019-07-18 15:19:00 +02:00
|
|
|
return &max_;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMax::find(int index)
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
if (index == min_.index())
|
|
|
|
|
return &min_;
|
|
|
|
|
else if (index == max_.index())
|
|
|
|
|
return &max_;
|
2018-09-28 17:54:21 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 23:46:30 +02:00
|
|
|
float
|
|
|
|
|
MinMax::minMax(float value1,
|
|
|
|
|
float value2) const
|
|
|
|
|
{
|
|
|
|
|
if (compare_(value1, value2))
|
|
|
|
|
return value1;
|
|
|
|
|
else
|
|
|
|
|
return value2;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2019-07-18 15:19:00 +02:00
|
|
|
MinMaxAll MinMaxAll::min_("min", 0, {MinMax::min()}, {MinMax::min()->index()});
|
|
|
|
|
MinMaxAll MinMaxAll::max_("max", 1, {MinMax::max()}, {MinMax::max()->index()});
|
|
|
|
|
MinMaxAll MinMaxAll::all_("all", 2, {MinMax::min(), MinMax::max()},
|
|
|
|
|
{MinMax::min()->index(), MinMax::max()->index()});
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
MinMaxAll::MinMaxAll(const char *name,
|
2019-07-18 15:19:00 +02:00
|
|
|
int index,
|
|
|
|
|
std::vector<MinMax*> range,
|
|
|
|
|
std::vector<int> range_index) :
|
2018-09-28 17:54:21 +02:00
|
|
|
name_(name),
|
2019-07-18 15:19:00 +02:00
|
|
|
index_(index),
|
|
|
|
|
range_(range),
|
|
|
|
|
range_index_(range_index)
|
2018-09-28 17:54:21 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMax *
|
|
|
|
|
MinMaxAll::asMinMax() const
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
if (this == &min_)
|
2018-09-28 17:54:21 +02:00
|
|
|
return MinMax::min();
|
|
|
|
|
else
|
|
|
|
|
return MinMax::max();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MinMaxAll::matches(const MinMax *min_max) const
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
return this == &all_ || asMinMax() == min_max;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
MinMaxAll::matches(const MinMaxAll *min_max) const
|
|
|
|
|
{
|
2019-07-18 15:19:00 +02:00
|
|
|
return this == &all_ || this == min_max;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MinMaxAll *
|
|
|
|
|
MinMaxAll::find(const char *min_max)
|
|
|
|
|
{
|
2018-11-26 18:15:52 +01:00
|
|
|
if (stringEq(min_max, "min")
|
|
|
|
|
|| stringEq(min_max, "early"))
|
2019-07-18 15:19:00 +02:00
|
|
|
return &min_;
|
2018-11-26 18:15:52 +01:00
|
|
|
else if (stringEq(min_max, "max")
|
|
|
|
|
|| stringEq(min_max, "late"))
|
2019-07-18 15:19:00 +02:00
|
|
|
return &max_;
|
2018-09-28 17:54:21 +02:00
|
|
|
else if (stringEq(min_max, "all")
|
|
|
|
|
|| stringEq(min_max, "min_max")
|
|
|
|
|
|| stringEq(min_max, "minmax"))
|
2019-07-18 15:19:00 +02:00
|
|
|
return &all_;
|
2018-09-28 17:54:21 +02:00
|
|
|
else
|
2019-03-13 01:25:53 +01:00
|
|
|
return nullptr;
|
2018-09-28 17:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|