forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinMaxValues.hh
167 lines (145 loc) · 3.67 KB
/
MinMaxValues.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2023, Parallax Software, Inc.
//
// 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/>.
#pragma once
#include "MinMax.hh"
#include "Error.hh"
namespace sta {
template <class TYPE>
class MinMaxValues
{
public:
MinMaxValues()
{
clear();
}
MinMaxValues(TYPE init_value)
{
int mm_index;
mm_index = MinMax::minIndex();
values_[mm_index] = init_value;
exists_[mm_index] = true;
mm_index = MinMax::maxIndex();
values_[mm_index] = init_value;
exists_[mm_index] = true;
}
void
clear()
{
exists_[MinMax::minIndex()] = false;
exists_[MinMax::maxIndex()] = false;
}
void
clear(const MinMaxAll *min_max)
{
exists_[min_max->index()] = false;
}
bool
empty()
{
return !exists_[MinMax::minIndex()]
&& !exists_[MinMax::maxIndex()];
}
void
setValue(TYPE value)
{
for (auto mm_index : MinMax::rangeIndex()) {
values_[mm_index] = value;
exists_[mm_index] = true;
}
}
void
setValue(const MinMaxAll *min_max,
TYPE value)
{
for (auto mm_index : min_max->rangeIndex()) {
values_[mm_index] = value;
exists_[mm_index] = true;
}
}
void
setValue(const MinMax *min_max,
TYPE value)
{
int mm_index = min_max->index();
values_[mm_index] = value;
exists_[mm_index] = true;
}
void
mergeValue(const MinMax *min_max,
TYPE value)
{
int mm_index = min_max->index();
if (!exists_[mm_index]
|| min_max->compare(value, values_[mm_index])) {
values_[mm_index] = value;
exists_[mm_index] = true;
}
}
TYPE
value(const MinMax *min_max) const
{
int mm_index = min_max->index();
bool exists = exists_[mm_index];
if (exists)
return values_[mm_index];
else
criticalError(226, "uninitialized value reference");
}
void
value(const MinMax *min_max,
// Return values.
TYPE &value,
bool &exists) const
{
int mm_index = min_max->index();
exists = exists_[mm_index];
value = values_[mm_index];
}
bool
hasValue(const MinMax *min_max) const
{
int mm_index = min_max->index();
return exists_[mm_index];
}
void
removeValue(const MinMaxAll *min_max)
{
for (auto mm_index : min_max->rangeIndex())
exists_[mm_index] = false;
}
static bool equal(MinMaxValues *values1,
MinMaxValues *values2)
{
return ((!values1->exists_[MinMax::minIndex()]
&& !values2->exists_[MinMax::minIndex()])
|| (values1->exists_[MinMax::minIndex()]
&& values2->exists_[MinMax::minIndex()]
&& values1->values_[MinMax::minIndex()]
== values2->values_[MinMax::minIndex()]))
&& ((!values1->exists_[MinMax::maxIndex()]
&& !values2->exists_[MinMax::maxIndex()])
|| (values1->exists_[MinMax::maxIndex()]
&& values2->exists_[MinMax::maxIndex()]
&& values1->values_[MinMax::maxIndex()]
== values2->values_[MinMax::maxIndex()]));
}
private:
TYPE values_[MinMax::index_count];
bool exists_[MinMax::index_count];
};
typedef MinMaxValues<float> MinMaxFloatValues;
typedef MinMaxValues<int> MinMaxIntValues;
} // namespace