OpenSTA/include/sta/MinMax.hh

130 lines
3.9 KiB
C++
Raw Normal View History

2018-09-28 17:54:21 +02:00
// OpenSTA, Static Timing Analyzer
// 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
// 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
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-09-28 17:54:21 +02:00
2020-02-16 01:13:16 +01:00
#pragma once
2018-09-28 17:54:21 +02:00
2019-07-18 15:19:00 +02:00
#include <array>
#include <vector>
2018-09-28 17:54:21 +02:00
#include "Iterator.hh"
namespace sta {
class MinMax;
class MinMaxAll;
2018-11-26 18:15:52 +01:00
// Use typedefs to make early/late functional equivalents to min/max.
2018-09-28 17:54:21 +02:00
typedef MinMax EarlyLate;
typedef MinMaxAll EarlyLateAll;
// Large value used for min/max initial values.
extern const float INF;
class MinMax
{
public:
static void init();
static void destroy();
// Singleton accessors.
2019-07-18 15:19:00 +02:00
static MinMax *min() { return &min_; }
static MinMax *max() { return &max_; }
static EarlyLate *early() { return &min_; }
static EarlyLate *late() { return &max_; }
static int minIndex() { return min_.index_; }
static int earlyIndex() { return min_.index_; }
static int maxIndex() { return max_.index_; }
static int lateIndex() { return max_.index_; }
2018-09-28 17:54:21 +02:00
const char *asString() const { return name_; }
int index() const { return index_; }
float initValue() const { return init_value_; }
// Max value1 > value2, Min value1 < value2.
bool compare(float value1,
float value2) const;
// min/max(value1, value2)
float minMax(float value1,
float value2) const;
2018-09-28 17:54:21 +02:00
MinMaxAll *asMinMaxAll() const;
MinMax *opposite() const;
2019-07-18 15:19:00 +02:00
// for range support.
// for (auto min_max : MinMax::range()) {}
static const std::array<MinMax*, 2> &range() { return range_; }
// for (auto mm_index : MinMax::rangeIndex()) {}
static const std::array<int, 2> &rangeIndex() { return range_index_; }
// Find MinMax from name.
2018-09-28 17:54:21 +02:00
static MinMax *find(const char *min_max);
// Find MinMax from index.
2018-09-28 17:54:21 +02:00
static MinMax *find(int index);
static const int index_max = 1;
static const int index_count = 2;
static const int index_bit_count = 1;
private:
MinMax(const char *name,
int index,
float init_value,
bool (*compare)(float value1,
float value2));
const char *name_;
int index_;
float init_value_;
bool (*compare_)(float value1,
float value2);
2019-07-18 15:19:00 +02:00
static MinMax min_;
static MinMax max_;
static const std::array<MinMax*, 2> range_;
static const std::array<int, 2> range_index_;
2018-09-28 17:54:21 +02:00
};
// Min/Max/All, where "All" means use both min and max.
class MinMaxAll
{
public:
// Singleton accessors.
2019-07-18 15:19:00 +02:00
static MinMaxAll *min() { return &min_; }
static MinMaxAll *early() { return &min_; }
static MinMaxAll *max() { return &max_; }
static MinMaxAll *late() { return &max_; }
static MinMaxAll *all() { return &all_; }
2018-09-28 17:54:21 +02:00
const char *asString() const { return name_; }
int index() const { return index_; }
MinMax *asMinMax() const;
bool matches(const MinMax *min_max) const;
bool matches(const MinMaxAll *min_max) const;
static MinMaxAll *find(const char *min_max);
2019-07-18 15:19:00 +02:00
// for (auto min_max : min_max->range()) {}
const std::vector<MinMax*> &range() const { return range_; }
// for (auto mm_index : min_max->rangeIndex()) {}
const std::vector<int> &rangeIndex() const { return range_index_; }
2018-09-28 17:54:21 +02:00
private:
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
const char *name_;
int index_;
2019-07-18 15:19:00 +02:00
const std::vector<MinMax*> range_;
const std::vector<int> range_index_;
2018-09-28 17:54:21 +02:00
2019-07-18 15:19:00 +02:00
static MinMaxAll min_;
static MinMaxAll max_;
static MinMaxAll all_;
2018-09-28 17:54:21 +02:00
};
} // namespace