Skip to content

Commit 33f400e

Browse files
committed
grt: encapsulate Interval and unsigned->int
Signed-off-by: Matt Liberty <[email protected]>
1 parent 6f4b99d commit 33f400e

File tree

10 files changed

+217
-198
lines changed

10 files changed

+217
-198
lines changed

src/grt/src/cugr/src/CUGR.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ void CUGR::write(const std::string& guide_file)
170170
ss << net->getName() << '\n';
171171
ss << "(\n";
172172
for (const auto& guide : guides) {
173-
ss << grid_graph_->getGridline(0, guide.second.x.low) << " "
174-
<< grid_graph_->getGridline(1, guide.second.y.low) << " "
175-
<< grid_graph_->getGridline(0, guide.second.x.high + 1) << " "
176-
<< grid_graph_->getGridline(1, guide.second.y.high + 1) << " "
173+
ss << grid_graph_->getGridline(0, guide.second.x.low()) << " "
174+
<< grid_graph_->getGridline(1, guide.second.y.low()) << " "
175+
<< grid_graph_->getGridline(0, guide.second.x.high() + 1) << " "
176+
<< grid_graph_->getGridline(1, guide.second.y.high() + 1) << " "
177177
<< grid_graph_->getLayerName(guide.first) << "\n";
178178
}
179179
ss << ")\n";
@@ -285,7 +285,7 @@ void CUGR::getGuides(const GRNet* net,
285285

286286
auto getSpareResource = [&](const GRPoint& point) {
287287
double resource = std::numeric_limits<double>::max();
288-
unsigned direction = grid_graph_->getLayerDirection(point.getLayerIdx());
288+
int direction = grid_graph_->getLayerDirection(point.getLayerIdx());
289289
if (point[direction] + 1 < grid_graph_->getSize(direction)) {
290290
resource = std::min(
291291
resource,
@@ -337,8 +337,7 @@ void CUGR::getGuides(const GRNet* net,
337337
for (const auto& child : node->getChildren()) {
338338
if (node->getLayerIdx() == child->getLayerIdx()) {
339339
double wire_patch_threshold = constants_.wire_patch_threshold;
340-
unsigned direction
341-
= grid_graph_->getLayerDirection(node->getLayerIdx());
340+
int direction = grid_graph_->getLayerDirection(node->getLayerIdx());
342341
int l = std::min((*node)[direction], (*child)[direction]);
343342
int h = std::max((*node)[direction], (*child)[direction]);
344343
int r = (*node)[1 - direction];
@@ -391,7 +390,7 @@ void CUGR::printStatistics() const
391390
net->getRoutingTree(), [&](const std::shared_ptr<GRTreeNode>& node) {
392391
for (const auto& child : node->getChildren()) {
393392
if (node->getLayerIdx() == child->getLayerIdx()) {
394-
unsigned direction
393+
int direction
395394
= grid_graph_->getLayerDirection(node->getLayerIdx());
396395
int l = std::min((*node)[direction], (*child)[direction]);
397396
int h = std::max((*node)[direction], (*child)[direction]);
@@ -417,7 +416,7 @@ void CUGR::printStatistics() const
417416
for (int layerIndex = constants_.min_routing_layer;
418417
layerIndex < grid_graph_->getNumLayers();
419418
layerIndex++) {
420-
unsigned direction = grid_graph_->getLayerDirection(layerIndex);
419+
int direction = grid_graph_->getLayerDirection(layerIndex);
421420
for (int x = 0; x < grid_graph_->getSize(0) - 1 + direction; x++) {
422421
for (int y = 0; y < grid_graph_->getSize(1) - direction; y++) {
423422
CapacityT resource

src/grt/src/cugr/src/Design.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ int Design::readSpecialNetObstructions()
240240
void Design::computeGrid()
241241
{
242242
gridlines_.resize(2);
243-
for (unsigned dimension = 0; dimension < 2; dimension++) {
244-
const int low = die_region_[dimension].low;
245-
const int high = die_region_[dimension].high;
243+
for (int dimension = 0; dimension < 2; dimension++) {
244+
const int low = die_region_[dimension].low();
245+
const int high = die_region_[dimension].high();
246246
for (int i = low; i + default_gridline_spacing_ < high;
247247
i += default_gridline_spacing_) {
248248
gridlines_[dimension].push_back(i);

src/grt/src/cugr/src/GRNet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ GRNet::GRNet(const CUGRNet& baseNet, const GridGraph* gridGraph)
2323
std::unordered_set<uint64_t> included;
2424
for (const auto& pinShape : pinShapes) {
2525
const BoxT cells = gridGraph->rangeSearchCells(pinShape);
26-
for (int x = cells.x.low; x <= cells.x.high; x++) {
27-
for (int y = cells.y.low; y <= cells.y.high; y++) {
26+
for (int x = cells.x.low(); x <= cells.x.high(); x++) {
27+
for (int y = cells.y.low(); y <= cells.y.high(); y++) {
2828
const GRPoint point(pinShape.getLayerIdx(), x, y);
2929
const uint64_t hash = gridGraph->hashCell(point);
3030
if (included.find(hash) == included.end()) {

src/grt/src/cugr/src/GridGraph.cpp

Lines changed: 68 additions & 66 deletions
Large diffs are not rendered by default.

src/grt/src/cugr/src/GridGraph.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ class GridGraph
3535
GridGraph(const Design* design, const Constants& constants);
3636
int getLibDBU() const { return lib_dbu_; }
3737
int getM2Pitch() const { return m2_pitch_; }
38-
unsigned getNumLayers() const { return num_layers_; }
39-
unsigned getSize(unsigned dimension) const
40-
{
41-
return (dimension ? y_size_ : x_size_);
42-
}
38+
int getNumLayers() const { return num_layers_; }
39+
int getSize(int dimension) const { return (dimension ? y_size_ : x_size_); }
4340
std::string getLayerName(int layer_index) const
4441
{
4542
return layer_names_[layer_index];
4643
}
47-
unsigned getLayerDirection(int layer_index) const
44+
int getLayerDirection(int layer_index) const
4845
{
4946
return layer_directions_[layer_index];
5047
}
@@ -58,7 +55,7 @@ class GridGraph
5855
{
5956
return (uint64_t) x * y_size_ + y;
6057
}
61-
int getGridline(const unsigned dimension, const int index) const
58+
int getGridline(const int dimension, const int index) const
6259
{
6360
return gridlines_[dimension][index];
6461
}
@@ -70,7 +67,7 @@ class GridGraph
7067
}
7168

7269
// Costs
73-
int getEdgeLength(unsigned direction, unsigned edge_index) const;
70+
int getEdgeLength(int direction, int edge_index) const;
7471
CostT getWireCost(int layer_index, PointT u, PointT v) const;
7572
CostT getViaCost(int layer_index, PointT loc) const;
7673
CostT getUnitViaCost() const { return unit_via_cost_; }
@@ -114,13 +111,13 @@ class GridGraph
114111
const int lib_dbu_;
115112
int m2_pitch_;
116113

117-
unsigned num_layers_;
118-
unsigned x_size_;
119-
unsigned y_size_;
114+
int num_layers_;
115+
int x_size_;
116+
int y_size_;
120117
std::vector<std::vector<int>> gridlines_;
121118
std::vector<std::vector<int>> grid_centers_;
122119
std::vector<std::string> layer_names_;
123-
std::vector<unsigned> layer_directions_;
120+
std::vector<int> layer_directions_;
124121
std::vector<int> layer_min_lengths_;
125122

126123
// Unit costs
@@ -135,11 +132,10 @@ class GridGraph
135132
// (l, x, y+1)} depending on the routing direction of the layer
136133
Constants constants_;
137134

138-
IntervalT rangeSearchGridlines(unsigned dimension,
135+
IntervalT rangeSearchGridlines(int dimension,
139136
const IntervalT& loc_interval) const;
140137
// Find the gridlines_ within [locInterval.low, locInterval.high]
141-
IntervalT rangeSearchRows(unsigned dimension,
142-
const IntervalT& loc_interval) const;
138+
IntervalT rangeSearchRows(int dimension, const IntervalT& loc_interval) const;
143139
// Find the rows/columns overlapping with [locInterval.low, locInterval.high]
144140

145141
// Utility functions for cost calculation

src/grt/src/cugr/src/Layers.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,35 @@ int MetalLayer::getTrackLocation(const int track_index) const
8888
IntervalT MetalLayer::rangeSearchTracks(const IntervalT& loc_range,
8989
const bool include_bound) const
9090
{
91-
IntervalT track_range(
92-
ceil(double(std::max(loc_range.low, first_track_loc_) - first_track_loc_)
93-
/ double(pitch_)),
94-
floor(double(std::min(loc_range.high, last_track_loc_) - first_track_loc_)
95-
/ double(pitch_)));
91+
const int lo = std::max(loc_range.low(), first_track_loc_);
92+
const int hi = std::min(loc_range.high(), last_track_loc_);
93+
const double pitch = pitch_;
94+
IntervalT track_range(std::ceil((lo - first_track_loc_) / pitch),
95+
std::floor((hi - first_track_loc_) / pitch));
9696
if (!track_range.IsValid()) {
9797
return track_range;
9898
}
9999
if (!include_bound) {
100-
if (getTrackLocation(track_range.low) == loc_range.low) {
101-
++track_range.low;
100+
if (getTrackLocation(track_range.low()) == loc_range.low()) {
101+
track_range.addToLow(1);
102102
}
103-
if (getTrackLocation(track_range.high) == loc_range.high) {
104-
--track_range.high;
103+
if (getTrackLocation(track_range.high()) == loc_range.high()) {
104+
track_range.addToHigh(-1);
105105
}
106106
}
107107
return track_range;
108108
}
109109

110110
int MetalLayer::getParallelSpacing(const int width, const int length) const
111111
{
112-
unsigned w = parallel_width_.size() - 1;
112+
int w = parallel_width_.size() - 1;
113113
while (w > 0 && parallel_width_[w] >= width) {
114114
w--;
115115
}
116116
if (length == 0) {
117117
return parallel_spacing_[w][0];
118118
}
119-
unsigned l = parallel_length_.size() - 1;
119+
int l = parallel_length_.size() - 1;
120120
while (l > 0 && parallel_length_[l] >= length) {
121121
l--;
122122
}

src/grt/src/cugr/src/MazeRoute.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ void SparseGraph::init(const GridGraphView<CostT>& wire_cost_view,
8989
// 3. Add same-layer connections
9090
edges_.resize(vertices_.size(), {-1, -1, -1});
9191
costs_.resize(vertices_.size(), {-1, -1, -1});
92-
auto addSameLayerEdge
93-
= [&](const unsigned direction, const int xi, const int yi) {
94-
const int u = getVertexIndex(direction, xi, yi);
95-
const int v = direction == MetalLayer::H ? u + 1 : u + xs_.size();
96-
const PointT U(xs_[xi], ys_[yi]);
97-
const PointT V(xs_[xi + 1 - direction], ys_[yi + direction]);
92+
auto addSameLayerEdge = [&](const int direction, const int xi, const int yi) {
93+
const int u = getVertexIndex(direction, xi, yi);
94+
const int v = direction == MetalLayer::H ? u + 1 : u + xs_.size();
95+
const PointT U(xs_[xi], ys_[yi]);
96+
const PointT V(xs_[xi + 1 - direction], ys_[yi + direction]);
9897

99-
edges_[u][0] = v;
100-
edges_[v][1] = u;
101-
costs_[u][0] = costs_[v][1] = wire_cost_view.sum(U, V);
102-
};
98+
edges_[u][0] = v;
99+
edges_[v][1] = u;
100+
costs_[u][0] = costs_[v][1] = wire_cost_view.sum(U, V);
101+
};
103102

104103
for (int direction = 0; direction < 2; direction++) {
105104
if (direction == MetalLayer::H) {

src/grt/src/cugr/src/PatternRoute.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
250250
&& !node->getPaths()[0][0]->isOptional());
251251
auto& path = node->getPaths()[0][0];
252252
buildScaffolds(path);
253-
unsigned direction
253+
int direction
254254
= (node->y() == path->y() ? MetalLayer::H : MetalLayer::V);
255255
if (!scaffoldNodes[direction][path->getIndex()]
256256
&& congestion_view.check(*node, *path)) {
@@ -261,7 +261,7 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
261261
for (auto& childPaths : node->getPaths()) {
262262
for (auto& path : childPaths) {
263263
buildScaffolds(path);
264-
unsigned direction
264+
int direction
265265
= (node->y() == path->y() ? MetalLayer::H : MetalLayer::V);
266266
if (path->isOptional()) {
267267
if (!scaffoldNodes[direction][node->getIndex()]
@@ -289,7 +289,7 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
289289
}
290290
}
291291
for (auto& child : node->getChildren()) {
292-
for (unsigned direction = 0; direction < 2; direction++) {
292+
for (int direction = 0; direction < 2; direction++) {
293293
if (scaffoldNodes[direction][child->getIndex()]) {
294294
scaffolds[direction].emplace_back(
295295
std::make_shared<ScaffoldNode>(node));
@@ -304,7 +304,7 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
304304
};
305305

306306
buildScaffolds(routing_dag_);
307-
for (unsigned direction = 0; direction < 2; direction++) {
307+
for (int direction = 0; direction < 2; direction++) {
308308
if (scaffoldNodes[direction][routing_dag_->getIndex()]) {
309309
scaffolds[direction].emplace_back(
310310
std::make_shared<ScaffoldNode>(nullptr));
@@ -316,12 +316,12 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
316316
std::function<void(const std::shared_ptr<ScaffoldNode>&,
317317
IntervalT&,
318318
std::vector<int>&,
319-
unsigned,
319+
int,
320320
bool)>
321321
getTrunkAndStems = [&](const std::shared_ptr<ScaffoldNode>& scaffoldNode,
322322
IntervalT& trunk,
323323
std::vector<int>& stems,
324-
unsigned direction,
324+
int direction,
325325
bool starting) {
326326
if (starting) {
327327
if (scaffoldNode->node) {
@@ -362,9 +362,9 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
362362
};
363363

364364
std::function<std::shared_ptr<PatternRoutingNode>(
365-
std::shared_ptr<ScaffoldNode>, unsigned, int)>
365+
std::shared_ptr<ScaffoldNode>, int, int)>
366366
buildDetour = [&](const std::shared_ptr<ScaffoldNode>& scaffoldNode,
367-
unsigned direction,
367+
int direction,
368368
int shiftAmount) {
369369
std::shared_ptr<PatternRoutingNode> treeNode = scaffoldNode->node;
370370
if (treeNode->getFixedLayers().IsValid()) {
@@ -416,7 +416,7 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
416416
return shiftedTreeNode;
417417
};
418418

419-
for (unsigned direction = 0; direction < 2; direction++) {
419+
for (int direction = 0; direction < 2; direction++) {
420420
for (const std::shared_ptr<ScaffoldNode>& scaffold : scaffolds[direction]) {
421421
assert(scaffold->children.size() == 1);
422422

@@ -428,30 +428,29 @@ void PatternRoute::constructDetours(GridGraphView<bool>& congestion_view)
428428
int originalLength = getTotalStemLength(stems, trunkPos);
429429
IntervalT shiftInterval(trunkPos);
430430
int maxLengthIncrease = trunk.range() * constants_.max_detour_ratio;
431-
while (shiftInterval.low - 1 >= 0
432-
&& getTotalStemLength(stems, shiftInterval.low - 1)
431+
while (shiftInterval.low() - 1 >= 0
432+
&& getTotalStemLength(stems, shiftInterval.low() - 1)
433433
- originalLength
434434
<= maxLengthIncrease) {
435-
shiftInterval.low--;
435+
shiftInterval.addToLow(-1);
436436
}
437-
while (shiftInterval.high + 1 < grid_graph_->getSize(1 - direction)
438-
&& getTotalStemLength(stems, shiftInterval.high - 1)
437+
while (shiftInterval.high() + 1 < grid_graph_->getSize(1 - direction)
438+
&& getTotalStemLength(stems, shiftInterval.high() - 1)
439439
- originalLength
440440
<= maxLengthIncrease) {
441-
shiftInterval.high++;
441+
shiftInterval.addToHigh(1);
442442
}
443443
int step = 1;
444-
while ((trunkPos - shiftInterval.low) / (step + 1)
445-
+ (shiftInterval.high - trunkPos) / (step + 1)
444+
while ((trunkPos - shiftInterval.low()) / (step + 1)
445+
+ (shiftInterval.high() - trunkPos) / (step + 1)
446446
>= constants_.target_detour_count) {
447447
step++;
448448
}
449449

450-
shiftInterval.low
451-
= trunkPos - (trunkPos - shiftInterval.low) / step * step;
452-
shiftInterval.high
453-
= trunkPos + (shiftInterval.high - trunkPos) / step * step;
454-
for (int pos = shiftInterval.low; pos <= shiftInterval.high;
450+
shiftInterval.Set(
451+
trunkPos - (trunkPos - shiftInterval.low()) / step * step,
452+
trunkPos + (shiftInterval.high() - trunkPos) / step * step);
453+
for (int pos = shiftInterval.low(); pos <= shiftInterval.high();
455454
pos += step) {
456455
int shiftAmount = (pos - trunkPos);
457456
if (shiftAmount == 0) {
@@ -540,8 +539,7 @@ void PatternRoute::calculateRoutingCosts(
540539
for (int pathIndex = 0; pathIndex < childPaths.size(); pathIndex++) {
541540
std::shared_ptr<PatternRoutingNode>& path = childPaths[pathIndex];
542541
calculateRoutingCosts(path);
543-
unsigned direction
544-
= node->x() == path->x() ? MetalLayer::V : MetalLayer::H;
542+
int direction = node->x() == path->x() ? MetalLayer::V : MetalLayer::H;
545543
assert((*node)[1 - direction] == (*path)[1 - direction]);
546544
for (int layerIndex = constants_.min_routing_layer;
547545
layerIndex < grid_graph_->getNumLayers();
@@ -577,11 +575,11 @@ void PatternRoute::calculateRoutingCosts(
577575
+ grid_graph_->getViaCost(layerIndex - 1, *node);
578576
}
579577
IntervalT fixedLayers(node->getFixedLayers());
580-
fixedLayers.low = std::min(fixedLayers.low,
581-
static_cast<int>(grid_graph_->getNumLayers()) - 1);
582-
fixedLayers.high = std::max(fixedLayers.high, constants_.min_routing_layer);
578+
fixedLayers.Set(std::min(fixedLayers.low(),
579+
static_cast<int>(grid_graph_->getNumLayers()) - 1),
580+
std::max(fixedLayers.high(), constants_.min_routing_layer));
583581

584-
for (int lowLayerIndex = 0; lowLayerIndex <= fixedLayers.low;
582+
for (int lowLayerIndex = 0; lowLayerIndex <= fixedLayers.low();
585583
lowLayerIndex++) {
586584
std::vector<CostT> minChildCosts;
587585
std::vector<std::pair<int, int>> bestPaths;
@@ -603,7 +601,7 @@ void PatternRoute::calculateRoutingCosts(
603601
childCosts[child_index][layerIndex].second, layerIndex);
604602
}
605603
}
606-
if (layerIndex >= fixedLayers.high) {
604+
if (layerIndex >= fixedLayers.high()) {
607605
CostT cost = viaCosts[layerIndex] - viaCosts[lowLayerIndex];
608606
for (CostT childCost : minChildCosts) {
609607
cost += childCost;
@@ -682,13 +680,13 @@ std::shared_ptr<GRTreeNode> PatternRoute::getRoutingTree(
682680
}
683681
}
684682
}
685-
if (lowestRoutingNode->getLayerIdx() > node->getFixedLayers().low) {
683+
if (lowestRoutingNode->getLayerIdx() > node->getFixedLayers().low()) {
686684
lowestRoutingNode->addChild(std::make_shared<GRTreeNode>(
687-
node->getFixedLayers().low, node->x(), node->y()));
685+
node->getFixedLayers().low(), node->x(), node->y()));
688686
}
689-
if (highestRoutingNode->getLayerIdx() < node->getFixedLayers().high) {
687+
if (highestRoutingNode->getLayerIdx() < node->getFixedLayers().high()) {
690688
highestRoutingNode->addChild(std::make_shared<GRTreeNode>(
691-
node->getFixedLayers().high, node->x(), node->y()));
689+
node->getFixedLayers().high(), node->x(), node->y()));
692690
}
693691
return routingNode;
694692
}

0 commit comments

Comments
 (0)