forked from The-OpenROAD-Project/OpenSTA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWireload.cc
301 lines (272 loc) · 7.17 KB
/
Wireload.cc
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// 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/>.
#include "Wireload.hh"
#include <algorithm>
#include "StringUtil.hh"
#include "Liberty.hh"
namespace sta {
Wireload::Wireload(const char *name,
LibertyLibrary *library) :
name_(stringCopy(name)),
library_(library),
area_(0.0F),
resistance_(0.0F),
capacitance_(0.0F),
slope_(0.0F)
{
}
Wireload::Wireload(const char *name,
LibertyLibrary *library,
float area,
float resistance,
float capacitance,
float slope) :
name_(stringCopy(name)),
library_(library),
area_(area),
resistance_(resistance),
capacitance_(capacitance),
slope_(slope)
{
}
Wireload::~Wireload()
{
fanout_lengths_.deleteContents();
stringDelete(name_);
}
void
Wireload::setArea(float area)
{
area_ = area;
}
void
Wireload::setResistance(float res)
{
resistance_ = res;
}
void
Wireload::setCapacitance(float cap)
{
capacitance_ = cap;
}
void
Wireload::setSlope(float slope)
{
slope_ = slope;
}
struct FanoutLess
{
bool operator()(FanoutLength *fanout1,
FanoutLength *fanout2) const
{
return fanout1->first < fanout2->first;
}
};
void
Wireload::addFanoutLength(float fanout,
float length)
{
FanoutLength *fanout_length = new FanoutLength(fanout, length);
fanout_lengths_.push_back(fanout_length);
// Keep fanouts sorted for lookup.
if (fanout_lengths_.size() > 1
&& fanout < (fanout_lengths_[fanout_lengths_.size() - 2])->first)
sort(fanout_lengths_, FanoutLess());
}
void
Wireload::findWireload(float fanout,
const OperatingConditions *op_cond,
float &cap,
float &res) const
{
size_t size = fanout_lengths_.size();
float length;
if (size == 0)
length = 0;
else {
size_t max = size - 1;
float fanout0 = fanout_lengths_[0]->first;
float fanout_max = fanout_lengths_[max]->first;
if (fanout < fanout0) {
// Extrapolate from lowest fanout entry.
length = fanout_lengths_[0]->second - (fanout0 - fanout) * slope_;
if (length < 0)
length = 0;
}
else if (fanout == fanout0)
length = fanout_lengths_[0]->second;
else if (fanout >= fanout_max)
// Extrapolate from max fanout entry.
length = fanout_lengths_[max]->second + (fanout - fanout_max) * slope_;
else {
// Bisection search.
int lower = -1;
int upper = size;
while (upper - lower > 1) {
int mid = (upper + lower) >> 1;
if (fanout >= fanout_lengths_[mid]->first)
lower = mid;
else
upper = mid;
}
// Interpolate between lower and lower+1 entries.
float fanout1 = fanout_lengths_[lower]->first;
float fanout2 = fanout_lengths_[lower+1]->first;
float l1 = fanout_lengths_[lower]->second;
float l2 = fanout_lengths_[lower+1]->second;
length = l1 + (l2 - l1) * (fanout - fanout1) / (fanout2 - fanout1);
}
}
// Scale resistance and capacitance.
cap = length * capacitance_
* library_->scaleFactor(ScaleFactorType::wire_cap, op_cond);
res = length * resistance_
* library_->scaleFactor(ScaleFactorType::wire_res, op_cond);
}
////////////////////////////////////////////////////////////////
class WireloadForArea
{
public:
WireloadForArea(float min_area,
float max_area,
const Wireload *wireload);
float minArea() const { return min_area_; }
float maxArea() const { return max_area_; }
const Wireload *wireload() const { return wireload_; }
private:
float min_area_;
float max_area_;
const Wireload *wireload_;
};
WireloadForArea::WireloadForArea(float min_area,
float max_area,
const Wireload *wireload) :
min_area_(min_area),
max_area_(max_area),
wireload_(wireload)
{
}
WireloadSelection::WireloadSelection(const char *name) :
name_(stringCopy(name))
{
}
WireloadSelection::~WireloadSelection()
{
wireloads_.deleteContents();
stringDelete(name_);
}
struct WireloadForAreaMinLess
{
bool operator()(WireloadForArea *wireload1,
WireloadForArea *wireload2) const
{
return wireload1->minArea() < wireload2->minArea();
}
};
void
WireloadSelection::addWireloadFromArea(float min_area,
float max_area,
const Wireload *wireload)
{
WireloadForArea *wireload_area = new WireloadForArea(min_area, max_area,
wireload);
wireloads_.push_back(wireload_area);
// Keep wireloads sorted by area for lookup.
if (wireloads_.size() > 1
&& min_area < (wireloads_[wireloads_.size() - 2])->minArea())
sort(wireloads_, WireloadForAreaMinLess());
}
// Bisection search.
const Wireload *
WireloadSelection::findWireload(float area) const
{
int max = static_cast<int>(wireloads_.size()) - 1;
int lower = -1;
int upper = max + 1;
while (upper - lower > 1) {
int mid = (upper + lower) >> 1;
if (area >= wireloads_[mid]->minArea())
lower = mid;
else
upper = mid;
}
float area0 = wireloads_[0]->minArea();
float area_max = wireloads_[max]->minArea();
if (area <= area0)
return wireloads_[0]->wireload();
else if (area >= area_max)
return wireloads_[max]->wireload();
else
return wireloads_[lower]->wireload();
}
////////////////////////////////////////////////////////////////
const char *
wireloadTreeString(WireloadTree tree)
{
switch (tree) {
case WireloadTree::worst_case:
return "worst_case_tree";
case WireloadTree::best_case:
return "best_case_tree";
case WireloadTree::balanced:
return "balanced_tree";
case WireloadTree::unknown:
return "unknown";
}
// Prevent warnings from lame compilers.
return "?";
}
WireloadTree
stringWireloadTree(const char *wire_load_type)
{
if (stringEq(wire_load_type, "worst_case_tree"))
return WireloadTree::worst_case;
else if (stringEq(wire_load_type, "best_case_tree"))
return WireloadTree::best_case;
else if (stringEq(wire_load_type, "balanced_tree"))
return WireloadTree::balanced;
else
return WireloadTree::unknown;
}
const char *
wireloadModeString(WireloadMode wire_load_mode)
{
switch (wire_load_mode) {
case WireloadMode::top:
return "top";
case WireloadMode::enclosed:
return "enclosed";
case WireloadMode::segmented:
return "segmented";
case WireloadMode::unknown:
return "unknown";
}
// Prevent warnings from lame compilers.
return "?";
}
WireloadMode
stringWireloadMode(const char *wire_load_mode)
{
if (stringEq(wire_load_mode, "top"))
return WireloadMode::top;
else if (stringEq(wire_load_mode, "enclosed"))
return WireloadMode::enclosed;
else if (stringEq(wire_load_mode, "segmented"))
return WireloadMode::segmented;
else
return WireloadMode::unknown;
}
} // namespace