Skip to content

Commit f31fc95

Browse files
authored
Merge pull request #2525 from verilog-to-routing/stable_sort
Replace all sort functions with stable sort
2 parents a2e91dc + 6eb4b26 commit f31fc95

File tree

24 files changed

+2338
-2338
lines changed

24 files changed

+2338
-2338
lines changed

libs/librrgraph/src/base/rr_graph_obj.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ void RRGraph::set_node_segment(const RRNodeId& node, const RRSegmentId& segment_
10411041
*/
10421042
void RRGraph::partition_node_in_edges(const RRNodeId& node) {
10431043
//Partition the edges so the first set of edges are all configurable, and the later are not
1044-
auto first_non_config_edge = std::partition(node_in_edges_[node].begin(), node_in_edges_[node].end(),
1044+
auto first_non_config_edge = std::stable_partition(node_in_edges_[node].begin(), node_in_edges_[node].end(),
10451045
[&](const RREdgeId edge) { return edge_is_configurable(edge); }); /* Condition to partition edges */
10461046

10471047
size_t num_conf_edges = std::distance(node_in_edges_[node].begin(), first_non_config_edge);
@@ -1060,7 +1060,7 @@ void RRGraph::partition_node_in_edges(const RRNodeId& node) {
10601060
*/
10611061
void RRGraph::partition_node_out_edges(const RRNodeId& node) {
10621062
//Partition the edges so the first set of edges are all configurable, and the later are not
1063-
auto first_non_config_edge = std::partition(node_out_edges_[node].begin(), node_out_edges_[node].end(),
1063+
auto first_non_config_edge = std::stable_partition(node_out_edges_[node].begin(), node_out_edges_[node].end(),
10641064
[&](const RREdgeId edge) { return edge_is_configurable(edge); }); /* Condition to partition edges */
10651065

10661066
size_t num_conf_edges = std::distance(node_out_edges_[node].begin(), first_non_config_edge);

vpr/src/draw/draw_basic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void draw_congestion(ezgl::renderer* g) {
339339

340340
return lhs_cong_ratio < rhs_cong_ratio;
341341
};
342-
std::sort(congested_rr_nodes.begin(), congested_rr_nodes.end(), cmp_ascending_acc_cost);
342+
std::stable_sort(congested_rr_nodes.begin(), congested_rr_nodes.end(), cmp_ascending_acc_cost);
343343

344344
if (draw_state->show_congestion == DRAW_CONGESTED_WITH_NETS) {
345345
auto rr_node_nets = collect_rr_node_nets();

vpr/src/draw/draw_rr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ void draw_rr_costs(ezgl::renderer* g, const vtr::vector<RRNodeId, float>& rr_cos
816816
}
817817
return rr_costs[lhs_node] < rr_costs[rhs_node];
818818
};
819-
std::sort(nodes.begin(), nodes.end(), cmp_ascending_cost);
819+
std::stable_sort(nodes.begin(), nodes.end(), cmp_ascending_cost);
820820

821821
for (RRNodeId inode : nodes) {
822822
float cost = rr_costs[inode];

vpr/src/place/compressed_grid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ t_compressed_block_grid create_compressed_block_grid(const std::vector<std::vect
8484
}
8585

8686
//Uniquify x/y locations
87-
std::sort(layer_x_locs.begin(), layer_x_locs.end());
87+
std::stable_sort(layer_x_locs.begin(), layer_x_locs.end());
8888
layer_x_locs.erase(unique(layer_x_locs.begin(), layer_x_locs.end()), layer_x_locs.end());
8989

90-
std::sort(layer_y_locs.begin(), layer_y_locs.end());
90+
std::stable_sort(layer_y_locs.begin(), layer_y_locs.end());
9191
layer_y_locs.erase(unique(layer_y_locs.begin(), layer_y_locs.end()), layer_y_locs.end());
9292

9393
//The index of an x-position in x_locs corresponds to it's compressed

vpr/src/place/cut_spreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ std::pair<int, int> CutSpreader::cut_region(SpreaderRegion& r, bool dir) {
446446
}
447447

448448
// sort blks based on raw location
449-
std::sort(cut_blks.begin(), cut_blks.end(), [&](const ClusterBlockId a, const ClusterBlockId b) {
449+
std::stable_sort(cut_blks.begin(), cut_blks.end(), [&](const ClusterBlockId a, const ClusterBlockId b) {
450450
return dir ? (ap->blk_locs[a].rawy < ap->blk_locs[b].rawy) : (ap->blk_locs[a].rawx < ap->blk_locs[b].rawx);
451451
});
452452

vpr/src/place/median_move_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ e_create_move MedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks_
131131
}
132132

133133
//calculate the median region
134-
std::sort(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end());
135-
std::sort(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end());
134+
std::stable_sort(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end());
135+
std::stable_sort(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end());
136136

137137
limit_coords.xmin = place_move_ctx.X_coord[floor((place_move_ctx.X_coord.size() - 1) / 2)];
138138
limit_coords.xmax = place_move_ctx.X_coord[floor((place_move_ctx.X_coord.size() - 1) / 2) + 1];

vpr/src/place/noc_place_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ bool noc_routing_has_cycle() {
883883
static std::vector<NocLinkId> find_affected_links_by_flow_reroute(std::vector<NocLinkId>& prev_links,
884884
std::vector<NocLinkId>& curr_links) {
885885
// Sort both link containers
886-
std::sort(prev_links.begin(), prev_links.end());
887-
std::sort(curr_links.begin(), curr_links.end());
886+
std::stable_sort(prev_links.begin(), prev_links.end());
887+
std::stable_sort(curr_links.begin(), curr_links.end());
888888

889889
// stores links that appear either in prev_links or curr_links but not both of them
890890
std::vector<NocLinkId> unique_links;

vpr/src/place/place.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,8 +2393,8 @@ static float analyze_setup_slack_cost(const PlacerSetupSlacks* setup_slacks) {
23932393
}
23942394

23952395
//Sort in ascending order, from the worse slack value to the best
2396-
std::sort(original_setup_slacks.begin(), original_setup_slacks.end());
2397-
std::sort(proposed_setup_slacks.begin(), proposed_setup_slacks.end());
2396+
std::stable_sort(original_setup_slacks.begin(), original_setup_slacks.end());
2397+
std::stable_sort(proposed_setup_slacks.begin(), proposed_setup_slacks.end());
23982398

23992399
//Check the first pair of slack values that are different
24002400
//If found, return their difference

vpr/src/place/timing_place_lookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ float delay_reduce(std::vector<float>& delays, e_reducer reducer) {
871871
auto itr = std::max_element(delays.begin(), delays.end());
872872
delay = *itr;
873873
} else if (reducer == e_reducer::MEDIAN) {
874-
std::sort(delays.begin(), delays.end());
874+
std::stable_sort(delays.begin(), delays.end());
875875
delay = vtr::median(delays.begin(), delays.end());
876876
} else if (reducer == e_reducer::ARITHMEAN) {
877877
delay = vtr::arithmean(delays.begin(), delays.end());

vpr/src/place/weighted_median_move_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ e_create_move WeightedMedianMoveGenerator::propose_move(t_pl_blocks_to_be_moved&
9595
}
9696

9797
//calculate the weighted median region
98-
std::sort(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end());
99-
std::sort(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end());
98+
std::stable_sort(place_move_ctx.X_coord.begin(), place_move_ctx.X_coord.end());
99+
std::stable_sort(place_move_ctx.Y_coord.begin(), place_move_ctx.Y_coord.end());
100100

101101
if (place_move_ctx.X_coord.size() == 1) {
102102
limit_coords.xmin = place_move_ctx.X_coord[0];

0 commit comments

Comments
 (0)