File: MinMax.cc

package info (click to toggle)
opensta 0~20191111gitc018cb2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 5,116 kB
  • sloc: cpp: 99,117; tcl: 8,530; yacc: 1,435; lex: 894; makefile: 541; sh: 107
file content (177 lines) | stat: -rw-r--r-- 3,897 bytes parent folder | download
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
168
169
170
171
172
173
174
175
176
177
// OpenSTA, Static Timing Analyzer
// Copyright (c) 2019, 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/>.

#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_("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()};

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)
{
  if (stringEq(min_max, "min")
      || stringEq(min_max, "early"))
    return &min_;
  else if (stringEq(min_max, "max")
	   || stringEq(min_max, "late"))
    return &max_;
  else
    return nullptr;
}

MinMax *
MinMax::find(int index)
{
  if (index == min_.index())
    return &min_;
  else if (index == max_.index())
    return &max_;
  else
    return nullptr;
}

bool
MinMax::compare(float value1,
		float value2) const
{
  return compare_(value1, value2);
}

////////////////////////////////////////////////////////////////

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()});

MinMaxAll::MinMaxAll(const char *name,
		     int index,
		     std::vector<MinMax*> range,
		     std::vector<int> range_index) :
  name_(name),
  index_(index),
  range_(range),
  range_index_(range_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)
{
  if (stringEq(min_max, "min")
      || stringEq(min_max, "early"))
    return &min_;
  else if (stringEq(min_max, "max")
	   || stringEq(min_max, "late"))
    return &max_;
  else if (stringEq(min_max, "all")
	   || stringEq(min_max, "min_max")
	   || stringEq(min_max, "minmax"))
    return &all_;
  else
    return nullptr;
}

////////////////////////////////////////////////////////////////

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