Skip to content

Commit 857efe6

Browse files
authored
Merge pull request #7996 from The-OpenROAD-Project/revert-7994-grt-fr-refactoring
Revert "Grt fr refactoring"
2 parents 2653a3e + bf9c911 commit 857efe6

File tree

4 files changed

+202
-69
lines changed

4 files changed

+202
-69
lines changed

src/grt/src/fastroute/include/DataType.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <string>
99
#include <vector>
1010

11-
#include "odb/geom.h"
1211
#include "utl/Logger.h"
1312

1413
namespace odb {
@@ -49,7 +48,7 @@ enum class EdgeDirection
4948
struct Segment // A Segment is a 2-pin connection
5049
{
5150
Segment(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int8_t cost)
52-
: x1(x1), y1(y1), x2(x2), y2(y2), cost(cost), xFirst(false), HVH(false)
51+
: x1(x1), y1(y1), x2(x2), y2(y2), cost(cost)
5352
{
5453
}
5554
const int16_t x1, y1, x2, y2; // coordinates of two endpoints (x1 <= x2)
@@ -79,7 +78,6 @@ struct FrNet // A Net is a set of connected MazePoints
7978
const std::vector<int>& getPinX() const { return pin_x_; }
8079
const std::vector<int>& getPinY() const { return pin_y_; }
8180
const std::vector<int>& getPinL() const { return pin_l_; }
82-
odb::Rect getPinBBox() const;
8381

8482
void addPin(int x, int y, int layer);
8583
void reset(odb::dbNet* db_net,

src/grt/src/fastroute/src/FastRoute.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,18 +1620,4 @@ void FrNet::reset(odb::dbNet* db_net,
16201620
pin_l_.clear();
16211621
}
16221622

1623-
odb::Rect FrNet::getPinBBox() const
1624-
{
1625-
odb::Rect rect;
1626-
rect.mergeInit();
1627-
1628-
const int deg = getNumPins();
1629-
for (int i = 0; i < deg; i++) {
1630-
const int x = getPinX(i);
1631-
const int y = getPinY(i);
1632-
rect.merge({x, y});
1633-
}
1634-
return rect;
1635-
}
1636-
16371623
} // namespace grt

src/grt/src/fastroute/src/RSMT.cpp

Lines changed: 197 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Pnt
1919
int o;
2020
};
2121

22-
static int orderx(const Pnt* a, const Pnt* b)
22+
int orderx(const Pnt* a, const Pnt* b)
2323
{
2424
return a->x < b->x;
2525
}
@@ -138,34 +138,79 @@ void FastRouteCore::fluteNormal(const int netID,
138138

139139
if (d == 2) {
140140
t.deg = 2;
141-
t.length = std::abs(x[0] - x[1]) + std::abs(y[0] - y[1]);
141+
t.length = abs(x[0] - x[1]) + abs(y[0] - y[1]);
142142
t.branch.resize(2);
143-
t.branch[0] = {x[0], y[0], 1};
144-
t.branch[1] = {x[1], y[1], 1};
143+
t.branch[0].x = x[0];
144+
t.branch[0].y = y[0];
145+
t.branch[0].n = 1;
146+
t.branch[1].x = x[1];
147+
t.branch[1].y = y[1];
148+
t.branch[1].n = 1;
145149
} else if (d == 3) {
146150
t.deg = 3;
147-
auto sort = [](const std::vector<int>& v) {
148-
std::array<int, 3> tmp{v[0], v[1], v[2]};
149-
std::sort(tmp.begin(), tmp.end());
150-
return tmp;
151-
};
152-
auto [x_min, x_mid, x_max] = sort(x);
153-
auto [y_min, y_mid, y_max] = sort(y);
151+
int x_max, x_min, x_mid;
152+
if (x[0] < x[1]) {
153+
if (x[0] < x[2]) {
154+
x_min = x[0];
155+
std::tie(x_mid, x_max) = std::minmax(x[1], x[2]);
156+
} else {
157+
x_min = x[2];
158+
x_mid = x[0];
159+
x_max = x[1];
160+
}
161+
} else {
162+
if (x[0] < x[2]) {
163+
x_min = x[1];
164+
x_mid = x[0];
165+
x_max = x[2];
166+
} else {
167+
std::tie(x_min, x_mid) = std::minmax(x[1], x[2]);
168+
x_max = x[0];
169+
}
170+
}
171+
int y_max, y_min, y_mid;
172+
if (y[0] < y[1]) {
173+
if (y[0] < y[2]) {
174+
y_min = y[0];
175+
std::tie(y_mid, y_max) = std::minmax(y[1], y[2]);
176+
} else {
177+
y_min = y[2];
178+
y_mid = y[0];
179+
y_max = y[1];
180+
}
181+
} else {
182+
if (y[0] < y[2]) {
183+
y_min = y[1];
184+
y_mid = y[0];
185+
y_max = y[2];
186+
} else {
187+
std::tie(y_min, y_mid) = std::minmax(y[1], y[2]);
188+
y_max = y[0];
189+
}
190+
}
154191

155192
t.length = abs(x_max - x_min) + abs(y_max - y_min);
156193
t.branch.resize(4);
157-
t.branch[0] = {x[0], y[0], 3};
158-
t.branch[1] = {x[1], y[1], 3};
159-
t.branch[2] = {x[2], y[2], 3};
160-
t.branch[3] = {x_mid, y_mid, 3};
194+
t.branch[0].x = x[0];
195+
t.branch[0].y = y[0];
196+
t.branch[0].n = 3;
197+
t.branch[1].x = x[1];
198+
t.branch[1].y = y[1];
199+
t.branch[1].n = 3;
200+
t.branch[2].x = x[2];
201+
t.branch[2].y = y[2];
202+
t.branch[2].n = 3;
203+
t.branch[3].x = x_mid;
204+
t.branch[3].y = y_mid;
205+
t.branch[3].n = 3;
161206
} else {
162207
std::vector<int> xs(d);
163208
std::vector<int> ys(d);
164209

165210
std::vector<int> tmp_xs(d);
166211
std::vector<int> tmp_ys(d);
167212
std::vector<int> s(d);
168-
std::vector<Pnt> pt(d);
213+
Pnt* pt = new Pnt[d];
169214
std::vector<Pnt*> ptp(d);
170215

171216
for (int i = 0; i < d; i++) {
@@ -239,6 +284,8 @@ void FastRouteCore::fluteNormal(const int netID,
239284
branch.x /= 100;
240285
branch.y /= ((int) (100 * coeffV));
241286
}
287+
288+
delete[] pt;
242289
}
243290
}
244291

@@ -256,24 +303,69 @@ void FastRouteCore::fluteCongest(const int netID,
256303
t.deg = 2;
257304
t.length = abs(x[0] - x[1]) + abs(y[0] - y[1]);
258305
t.branch.resize(2);
259-
t.branch[0] = {x[0], y[0], 1};
260-
t.branch[1] = {x[1], y[1], 1};
306+
t.branch[0].x = x[0];
307+
t.branch[0].y = y[0];
308+
t.branch[0].n = 1;
309+
t.branch[1].x = x[1];
310+
t.branch[1].y = y[1];
311+
t.branch[1].n = 1;
261312
} else if (d == 3) {
262313
t.deg = 3;
263-
auto sort = [](const std::vector<int>& v) {
264-
std::array<int, 3> tmp{v[0], v[1], v[2]};
265-
std::sort(tmp.begin(), tmp.end());
266-
return tmp;
267-
};
268-
auto [x_min, x_mid, x_max] = sort(x);
269-
auto [y_min, y_mid, y_max] = sort(y);
314+
int x_max, x_min, x_mid;
315+
if (x[0] < x[1]) {
316+
if (x[0] < x[2]) {
317+
x_min = x[0];
318+
std::tie(x_mid, x_max) = std::minmax(x[1], x[2]);
319+
} else {
320+
x_min = x[2];
321+
x_mid = x[0];
322+
x_max = x[1];
323+
}
324+
} else {
325+
if (x[0] < x[2]) {
326+
x_min = x[1];
327+
x_mid = x[0];
328+
x_max = x[2];
329+
} else {
330+
std::tie(x_min, x_mid) = std::minmax(x[1], x[2]);
331+
x_max = x[0];
332+
}
333+
}
334+
int y_max, y_min, y_mid;
335+
if (y[0] < y[1]) {
336+
if (y[0] < y[2]) {
337+
y_min = y[0];
338+
std::tie(y_mid, y_max) = std::minmax(y[1], y[2]);
339+
} else {
340+
y_min = y[2];
341+
y_mid = y[0];
342+
y_max = y[1];
343+
}
344+
} else {
345+
if (y[0] < y[2]) {
346+
y_min = y[1];
347+
y_mid = y[0];
348+
y_max = y[2];
349+
} else {
350+
std::tie(y_min, y_mid) = std::minmax(y[1], y[2]);
351+
y_max = y[0];
352+
}
353+
}
270354

271355
t.length = abs(x_max - x_min) + abs(y_max - y_min);
272356
t.branch.resize(4);
273-
t.branch[0] = {x[0], y[0], 3};
274-
t.branch[1] = {x[1], y[1], 3};
275-
t.branch[2] = {x[2], y[2], 3};
276-
t.branch[3] = {x_mid, y_mid, 3};
357+
t.branch[0].x = x[0];
358+
t.branch[0].y = y[0];
359+
t.branch[0].n = 3;
360+
t.branch[1].x = x[1];
361+
t.branch[1].y = y[1];
362+
t.branch[1].n = 3;
363+
t.branch[2].x = x[2];
364+
t.branch[2].y = y[2];
365+
t.branch[2].n = 3;
366+
t.branch[3].x = x_mid;
367+
t.branch[3].y = y_mid;
368+
t.branch[3].n = 3;
277369
} else {
278370
std::vector<int> xs(d);
279371
std::vector<int> ys(d);
@@ -386,48 +478,105 @@ bool FastRouteCore::netCongestion(const int netID)
386478

387479
bool FastRouteCore::VTreeSuite(const int netID)
388480
{
389-
const odb::Rect bbox = nets_[netID]->getPinBBox();
390-
return bbox.dy() > 3 * bbox.dx();
481+
int xmax = 0;
482+
int ymax = 0;
483+
int xmin = BIG_INT;
484+
int ymin = BIG_INT;
485+
486+
const int deg = nets_[netID]->getNumPins();
487+
for (int i = 0; i < deg; i++) {
488+
if (xmin > nets_[netID]->getPinX(i)) {
489+
xmin = nets_[netID]->getPinX(i);
490+
}
491+
if (xmax < nets_[netID]->getPinX(i)) {
492+
xmax = nets_[netID]->getPinX(i);
493+
}
494+
if (ymin > nets_[netID]->getPinY(i)) {
495+
ymin = nets_[netID]->getPinY(i);
496+
}
497+
if (ymax < nets_[netID]->getPinY(i)) {
498+
ymax = nets_[netID]->getPinY(i);
499+
}
500+
}
501+
502+
return (ymax - ymin) > 3 * (xmax - xmin);
391503
}
392504

393505
bool FastRouteCore::HTreeSuite(const int netID)
394506
{
395-
const odb::Rect bbox = nets_[netID]->getPinBBox();
396-
return 5 * bbox.dy() < bbox.dx();
507+
int xmax = 0;
508+
int ymax = 0;
509+
int xmin = BIG_INT;
510+
int ymin = BIG_INT;
511+
512+
const int deg = nets_[netID]->getNumPins();
513+
for (int i = 0; i < deg; i++) {
514+
if (xmin > nets_[netID]->getPinX(i)) {
515+
xmin = nets_[netID]->getPinX(i);
516+
}
517+
if (xmax < nets_[netID]->getPinX(i)) {
518+
xmax = nets_[netID]->getPinX(i);
519+
}
520+
if (ymin > nets_[netID]->getPinY(i)) {
521+
ymin = nets_[netID]->getPinY(i);
522+
}
523+
if (ymax < nets_[netID]->getPinY(i)) {
524+
ymax = nets_[netID]->getPinY(i);
525+
}
526+
}
527+
528+
return 5 * (ymax - ymin) < (xmax - xmin);
397529
}
398530

399531
float FastRouteCore::coeffADJ(const int netID)
400532
{
401-
const odb::Rect bbox = nets_[netID]->getPinBBox();
533+
const int deg = nets_[netID]->getNumPins();
534+
int xmax = 0;
535+
int ymax = 0;
536+
int xmin = BIG_INT;
537+
int ymin = BIG_INT;
538+
539+
for (int i = 0; i < deg; i++) {
540+
if (xmin > nets_[netID]->getPinX(i)) {
541+
xmin = nets_[netID]->getPinX(i);
542+
}
543+
if (xmax < nets_[netID]->getPinX(i)) {
544+
xmax = nets_[netID]->getPinX(i);
545+
}
546+
if (ymin > nets_[netID]->getPinY(i)) {
547+
ymin = nets_[netID]->getPinY(i);
548+
}
549+
if (ymax < nets_[netID]->getPinY(i)) {
550+
ymax = nets_[netID]->getPinY(i);
551+
}
552+
}
402553

403554
int Hcap = 0;
404555
int Vcap = 0;
405556
float Husage = 0;
406557
float Vusage = 0;
407558
float coef;
408-
if (bbox.dx() == 0) {
409-
for (int j = bbox.yMin(); j < bbox.yMax(); j++) {
410-
Vcap += getEdgeCapacity(
411-
nets_[netID], bbox.xMin(), j, EdgeDirection::Vertical);
412-
Vusage += graph2d_.getEstUsageV(bbox.xMin(), j);
559+
if (xmin == xmax) {
560+
for (int j = ymin; j < ymax; j++) {
561+
Vcap += getEdgeCapacity(nets_[netID], xmin, j, EdgeDirection::Vertical);
562+
Vusage += graph2d_.getEstUsageV(xmin, j);
413563
}
414564
coef = 1;
415-
} else if (bbox.dy() == 0) {
416-
for (int i = bbox.xMin(); i < bbox.xMax(); i++) {
417-
Hcap += getEdgeCapacity(
418-
nets_[netID], i, bbox.yMin(), EdgeDirection::Horizontal);
419-
Husage += graph2d_.getEstUsageH(i, bbox.yMin());
565+
} else if (ymin == ymax) {
566+
for (int i = xmin; i < xmax; i++) {
567+
Hcap += getEdgeCapacity(nets_[netID], i, ymin, EdgeDirection::Horizontal);
568+
Husage += graph2d_.getEstUsageH(i, ymin);
420569
}
421570
coef = 1;
422571
} else {
423-
for (int j = bbox.yMin(); j <= bbox.yMax(); j++) {
424-
for (int i = bbox.xMin(); i < bbox.xMax(); i++) {
572+
for (int j = ymin; j <= ymax; j++) {
573+
for (int i = xmin; i < xmax; i++) {
425574
Hcap += getEdgeCapacity(nets_[netID], i, j, EdgeDirection::Horizontal);
426575
Husage += graph2d_.getEstUsageH(i, j);
427576
}
428577
}
429-
for (int j = bbox.yMin(); j < bbox.yMax(); j++) {
430-
for (int i = bbox.xMin(); i <= bbox.xMax(); i++) {
578+
for (int j = ymin; j < ymax; j++) {
579+
for (int i = xmin; i <= xmax; i++) {
431580
Vcap += getEdgeCapacity(nets_[netID], i, j, EdgeDirection::Vertical);
432581
Vusage += graph2d_.getEstUsageV(i, j);
433582
}

src/grt/src/fastroute/src/RipUp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ bool FastRouteCore::newRipupCheck(const TreeEdge* treeedge,
191191
for (int i = 0; i < treeedge->route.routelen; i++) {
192192
if (grids[i].x == grids[i + 1].x) { // a vertical edge
193193
const int ymin = std::min(grids[i].y, grids[i + 1].y);
194-
if (graph2d_.getUsageRedV(grids[i].x, ymin) - v_capacity_
195-
< ripup_threshold) {
194+
if (graph2d_.getUsageRedV(grids[i].x, ymin)
195+
>= v_capacity_ - ripup_threshold) {
196196
needRipup = true;
197197
break;
198198
}
199199
} else if (grids[i].y == grids[i + 1].y) { // a horizontal edge
200200
const int xmin = std::min(grids[i].x, grids[i + 1].x);
201-
if (graph2d_.getUsageRedH(xmin, grids[i].y) - h_capacity_
202-
< ripup_threshold) {
201+
if (graph2d_.getUsageRedH(xmin, grids[i].y)
202+
>= h_capacity_ - ripup_threshold) {
203203
needRipup = true;
204204
break;
205205
}

0 commit comments

Comments
 (0)