Skip to content

Commit d725472

Browse files
committed
rsz: sort the dont-use report for stability and enable test in bzl
Enable these three tests in bazel: - "liberty_dont_use" - "report_dont_use" - "report_dont_use_corners" A sort helper is introduced in utl. Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent c3bd3a2 commit d725472

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,39 @@ void sort_and_unique(Container& c, Comp comp = {}, Proj proj = {})
120120
c.erase(first, last);
121121
}
122122

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

0 commit comments

Comments
 (0)