Files
OpenSTA/include/sta/MinMax.hh
T

144 lines
4.7 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2026-03-10 13:21:17 -07:00
// Copyright (c) 2026, Parallax Software, Inc.
2018-09-28 08:54:21 -07: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 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2025-01-21 18:54:33 -07: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 08:54:21 -07:00
2020-02-15 17:13:16 -07:00
#pragma once
2018-09-28 08:54:21 -07:00
2019-07-18 06:19:00 -07:00
#include <array>
2025-03-30 15:27:53 -07:00
#include <string>
2026-04-15 09:38:10 -07:00
#include <vector>
2025-03-30 15:27:53 -07:00
2018-09-28 08:54:21 -07:00
#include "Iterator.hh"
namespace sta {
class MinMax;
class MinMaxAll;
2018-11-26 09:15:52 -08:00
// Use typedefs to make early/late functional equivalents to min/max.
2026-01-03 16:59:35 -08:00
using EarlyLate = MinMax;
using EarlyLateAll = MinMaxAll;
2018-09-28 08:54:21 -07:00
// Large value used for min/max initial values.
extern const float INF;
class MinMax
{
public:
static void init();
static void destroy();
// Singleton accessors.
2025-03-30 15:27:53 -07:00
static const MinMax *min() { return &min_; }
static const MinMax *max() { return &max_; }
static const EarlyLate *early() { return &min_; }
static const EarlyLate *late() { return &max_; }
2026-04-13 14:58:16 -07:00
static size_t minIndex() { return min_.index_; }
static size_t earlyIndex() { return min_.index_; }
static size_t maxIndex() { return max_.index_; }
static size_t lateIndex() { return max_.index_; }
2025-04-11 16:59:48 -07:00
const std::string &to_string() const { return name_; }
2026-04-13 14:58:16 -07:00
size_t index() const { return index_; }
2018-09-28 08:54:21 -07:00
float initValue() const { return init_value_; }
2024-03-20 12:29:58 -07:00
int initValueInt() const { return init_value_int_; }
2018-09-28 08:54:21 -07:00
// Max value1 > value2, Min value1 < value2.
bool compare(float value1,
2026-01-03 16:59:35 -08:00
float value2) const;
// min/max(value1, value2)
float minMax(float value1,
2026-01-03 16:59:35 -08:00
float value2) const;
2025-03-30 15:27:53 -07:00
const MinMaxAll *asMinMaxAll() const;
const MinMax *opposite() const;
2019-07-18 06:19:00 -07:00
// for range support.
// for (auto min_max : MinMax::range()) {}
2025-03-30 15:27:53 -07:00
static const std::array<const MinMax*, 2> &range() { return range_; }
2019-07-18 06:19:00 -07:00
// for (auto mm_index : MinMax::rangeIndex()) {}
2026-04-13 14:58:16 -07:00
static const std::array<size_t, 2> &rangeIndex() { return range_index_; }
// Find MinMax from name.
2026-04-13 14:58:16 -07:00
static const MinMax *find(std::string_view min_max);
// Find MinMax from index.
2026-04-13 14:58:16 -07:00
static const MinMax *find(size_t index);
static const size_t index_max = 1;
static const size_t index_count = 2;
static const size_t index_bit_count = 1;
2018-09-28 08:54:21 -07:00
private:
2026-04-13 14:58:16 -07:00
MinMax(std::string_view name,
size_t index,
2026-01-03 16:59:35 -08:00
float init_value,
2024-03-20 12:29:58 -07:00
int init_value_int,
2026-01-03 16:59:35 -08:00
bool (*compare)(float value1,
float value2));
2018-09-28 08:54:21 -07:00
2025-04-11 16:59:48 -07:00
const std::string name_;
2018-09-28 08:54:21 -07:00
int index_;
float init_value_;
2024-03-20 12:29:58 -07:00
int init_value_int_;
2018-09-28 08:54:21 -07:00
bool (*compare_)(float value1,
2026-01-03 16:59:35 -08:00
float value2);
2018-09-28 08:54:21 -07:00
2025-03-30 15:27:53 -07:00
static const MinMax min_;
static const MinMax max_;
static const std::array<const MinMax*, 2> range_;
2026-04-13 14:58:16 -07:00
static const std::array<size_t, 2> range_index_;
2018-09-28 08:54:21 -07:00
};
// Min/Max/All, where "All" means use both min and max.
class MinMaxAll
{
public:
// Singleton accessors.
2025-03-30 15:27:53 -07:00
static const MinMaxAll *min() { return &min_; }
static const MinMaxAll *early() { return &min_; }
static const MinMaxAll *max() { return &max_; }
static const MinMaxAll *late() { return &max_; }
static const MinMaxAll *all() { return &all_; }
2026-01-03 16:59:35 -08:00
static const MinMaxAll *minMax() { return &all_; }
2025-04-11 16:59:48 -07:00
const std::string &to_string() const { return name_; }
2026-04-13 14:58:16 -07:00
size_t index() const { return index_; }
2025-03-30 15:27:53 -07:00
const MinMax *asMinMax() const;
2018-09-28 08:54:21 -07:00
bool matches(const MinMax *min_max) const;
bool matches(const MinMaxAll *min_max) const;
2025-03-30 15:27:53 -07:00
static const MinMaxAll *find(const char *min_max);
2024-06-27 13:57:58 -07:00
// for (const auto min_max : min_max->range()) {}
2025-03-30 15:27:53 -07:00
const std::vector<const MinMax*> &range() const { return range_; }
2024-06-27 13:57:58 -07:00
// for (const auto mm_index : min_max->rangeIndex()) {}
2026-04-13 14:58:16 -07:00
const std::vector<size_t> &rangeIndex() const { return range_index_; }
2018-09-28 08:54:21 -07:00
private:
2026-04-13 14:58:16 -07:00
MinMaxAll(std::string_view name,
size_t index,
const std::vector<const MinMax*> &range,
const std::vector<size_t> &range_index);
2018-09-28 08:54:21 -07:00
2025-04-11 16:59:48 -07:00
const std::string name_;
2026-04-13 14:58:16 -07:00
size_t index_;
2025-03-30 15:27:53 -07:00
const std::vector<const MinMax*> range_;
2026-04-13 14:58:16 -07:00
const std::vector<size_t> range_index_;
2018-09-28 08:54:21 -07:00
2025-03-30 15:27:53 -07:00
static const MinMaxAll min_;
static const MinMaxAll max_;
static const MinMaxAll all_;
2018-09-28 08:54:21 -07:00
};
2026-04-13 14:58:16 -07:00
} // namespace sta