Skip to content

Commit 3633e5f

Browse files
authored
Merge pull request #9168 from The-OpenROAD-Project-staging/rsz-sort-dont-use-reporting
rsz: sort the dont-use report for stability and enable test in bzl
2 parents fe6246a + e70a6e0 commit 3633e5f

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/rsz/src/Resizer.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "sta/Units.hh"
7777
#include "sta/Vector.hh"
7878
#include "utl/Logger.h"
79+
#include "utl/algorithms.h"
7980
#include "utl/scope.h"
8081

8182
// http://vlsicad.eecs.umich.edu/BK/Slots/cache/dropzone.tamu.edu/~zhuoli/GSRC/fast_buffer_insertion.html
@@ -2968,7 +2969,11 @@ void Resizer::reportDontUse() const
29682969
if (dont_use_.empty()) {
29692970
logger_->report(" none");
29702971
} else {
2971-
for (auto* cell : dont_use_) {
2972+
std::vector<LibertyCell*> sorted_cells(dont_use_.begin(), dont_use_.end());
2973+
std::ranges::sort(sorted_cells, utl::natural_compare, [](auto* cell) {
2974+
return std::string_view(cell->name());
2975+
});
2976+
for (auto* cell : sorted_cells) {
29722977
if (!isLinkCell(cell)) {
29732978
continue;
29742979
}

src/rsz/test/BUILD

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,13 @@ BIG_TESTS = [
232232
MANUAL_FOR_BAZEL_TESTS = [
233233
"repair_tie11_hier",
234234
"repair_tie12_hier",
235-
"liberty_dont_use",
236235
"pinswap_flat",
237236
"pinswap_hier",
238237
"repair_fanout1_hier",
239238
"repair_fanout2_hier",
240239
"repair_fanout3_hier",
241240
"repair_setup4_flat",
242241
"repair_setup4_hier",
243-
"report_dont_use",
244-
"report_dont_use_corners",
245242
"split_load_hier",
246243
]
247244

src/utl/include/utl/algorithms.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
#pragma once
55

66
#include <algorithm>
7+
#include <cctype>
8+
#include <charconv>
79
#include <cmath>
810
#include <cstddef>
11+
#include <cstdint>
12+
#include <cstdlib>
913
#include <functional>
1014
#include <iomanip>
1115
#include <ios>
1216
#include <sstream>
1317
#include <string>
18+
#include <string_view>
1419
#include <tuple>
1520
#include <type_traits>
1621

@@ -120,4 +125,39 @@ void sort_and_unique(Container& c, Comp comp = {}, Proj proj = {})
120125
c.erase(first, last);
121126
}
122127

128+
// Useful when you want to sort with embedded numbers compared
129+
// numerically. For example FILL1 < FILL4 < FILL16.
130+
inline bool natural_compare(std::string_view a, std::string_view b)
131+
{
132+
auto it_a = a.begin();
133+
auto it_b = b.begin();
134+
135+
while (it_a != a.end() && it_b != b.end()) {
136+
if (std::isdigit(*it_a) && std::isdigit(*it_b)) {
137+
// Both are digits: extract and compare as numbers
138+
uint64_t num_a = 0;
139+
auto res_a = std::from_chars(&*it_a, a.data() + a.size(), num_a);
140+
uint64_t num_b = 0;
141+
auto res_b = std::from_chars(&*it_b, b.data() + b.size(), num_b);
142+
143+
if (num_a != num_b) {
144+
return num_a < num_b;
145+
}
146+
147+
// Move iterators forward by the number of digits consumed
148+
it_a += (res_a.ptr - &*it_a);
149+
it_b += (res_b.ptr - &*it_b);
150+
} else {
151+
// At least one is text: compare characters
152+
if (*it_a != *it_b) {
153+
return *it_a < *it_b;
154+
}
155+
++it_a;
156+
++it_b;
157+
}
158+
}
159+
// If one string is a prefix of the other, the shorter one comes first
160+
return a.size() < b.size();
161+
}
162+
123163
} // namespace utl

0 commit comments

Comments
 (0)