Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rsz/src/Resizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "sta/Units.hh"
#include "sta/Vector.hh"
#include "utl/Logger.h"
#include "utl/algorithms.h"
#include "utl/scope.h"

// http://vlsicad.eecs.umich.edu/BK/Slots/cache/dropzone.tamu.edu/~zhuoli/GSRC/fast_buffer_insertion.html
Expand Down Expand Up @@ -2968,7 +2969,11 @@ void Resizer::reportDontUse() const
if (dont_use_.empty()) {
logger_->report(" none");
} else {
for (auto* cell : dont_use_) {
std::vector<LibertyCell*> sorted_cells(dont_use_.begin(), dont_use_.end());
std::ranges::sort(sorted_cells, utl::natural_compare, [](auto* cell) {
return std::string_view(cell->name());
});
for (auto* cell : sorted_cells) {
if (!isLinkCell(cell)) {
continue;
}
Expand Down
3 changes: 0 additions & 3 deletions src/rsz/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,13 @@ BIG_TESTS = [
MANUAL_FOR_BAZEL_TESTS = [
"repair_tie11_hier",
"repair_tie12_hier",
"liberty_dont_use",
"pinswap_flat",
"pinswap_hier",
"repair_fanout1_hier",
"repair_fanout2_hier",
"repair_fanout3_hier",
"repair_setup4_flat",
"repair_setup4_hier",
"report_dont_use",
"report_dont_use_corners",
"split_load_hier",
]

Expand Down
40 changes: 40 additions & 0 deletions src/utl/include/utl/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
#pragma once

#include <algorithm>
#include <cctype>
#include <charconv>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <ios>
#include <sstream>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>

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

// Useful when you want to sort with embedded numbers compared
// numerically. For example FILL1 < FILL4 < FILL16.
inline bool natural_compare(std::string_view a, std::string_view b)
{
auto it_a = a.begin();
auto it_b = b.begin();

while (it_a != a.end() && it_b != b.end()) {
if (std::isdigit(*it_a) && std::isdigit(*it_b)) {
// Both are digits: extract and compare as numbers
uint64_t num_a = 0;
auto res_a = std::from_chars(&*it_a, a.data() + a.size(), num_a);
uint64_t num_b = 0;
auto res_b = std::from_chars(&*it_b, b.data() + b.size(), num_b);

if (num_a != num_b) {
return num_a < num_b;
}

// Move iterators forward by the number of digits consumed
it_a += (res_a.ptr - &*it_a);
it_b += (res_b.ptr - &*it_b);
} else {
// At least one is text: compare characters
if (*it_a != *it_b) {
return *it_a < *it_b;
}
++it_a;
++it_b;
}
}
// If one string is a prefix of the other, the shorter one comes first
return a.size() < b.size();
}

} // namespace utl