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];

vpr/src/route/DecompNetlistRouter.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void DecompNetlistRouter<HeapType>::route_partition_tree_node(tbb::task_group& g
128128
* nets use their own #fanouts. */
129129
std::vector<size_t> order(node.nets.size() + node.vnets.size());
130130
std::iota(order.begin(), order.end(), 0);
131-
std::sort(order.begin(), order.end(), [&](size_t i, size_t j) -> bool {
131+
std::stable_sort(order.begin(), order.end(), [&](size_t i, size_t j) -> bool {
132132
ParentNetId id1 = i < node.nets.size() ? node.nets[i] : node.vnets[i - node.nets.size()].net_id;
133133
ParentNetId id2 = j < node.nets.size() ? node.nets[j] : node.vnets[j - node.nets.size()].net_id;
134134
return _net_list.net_sinks(id1).size() > _net_list.net_sinks(id2).size();

vpr/src/route/ParallelNetlistRouter.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void ParallelNetlistRouter<HeapType>::route_partition_tree_node(tbb::task_group&
4242
auto& route_ctx = g_vpr_ctx.mutable_routing();
4343

4444
/* Sort so net with most sinks is routed first. */
45-
std::sort(node.nets.begin(), node.nets.end(), [&](ParentNetId id1, ParentNetId id2) -> bool {
45+
std::stable_sort(node.nets.begin(), node.nets.end(), [&](ParentNetId id1, ParentNetId id2) -> bool {
4646
return _net_list.net_sinks(id1).size() > _net_list.net_sinks(id2).size();
4747
});
4848

vpr/src/route/SerialNetlistRouter.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inline RouteIterResults SerialNetlistRouter<HeapType>::route_netlist(int itry, f
1212

1313
/* Sort so net with most sinks is routed first */
1414
auto sorted_nets = std::vector<ParentNetId>(_net_list.nets().begin(), _net_list.nets().end());
15-
std::sort(sorted_nets.begin(), sorted_nets.end(), [&](ParentNetId id1, ParentNetId id2) -> bool {
15+
std::stable_sort(sorted_nets.begin(), sorted_nets.end(), [&](ParentNetId id1, ParentNetId id2) -> bool {
1616
return _net_list.net_sinks(id1).size() > _net_list.net_sinks(id2).size();
1717
});
1818

vpr/src/route/cb_metrics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static void get_pin_locations(const t_physical_tile_type_ptr block_type, const e
611611
}
612612
}
613613
/* sort the vector at the current side in increasing order, for good measure */
614-
sort(pin_locations->at(iside).begin(), pin_locations->at(iside).end());
614+
std::stable_sort(pin_locations->at(iside).begin(), pin_locations->at(iside).end());
615615
}
616616
}
617617
/* now we have a vector of vectors [0..3][0..num_pins_on_this_side] specifying which pins are on which side */

vpr/src/route/route_net.tpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ inline NetResultFlags route_net(ConnectionRouter& router,
129129
}
130130

131131
// compare the criticality of different sink nodes
132-
sort(begin(remaining_targets), end(remaining_targets), [&](int a, int b) {
132+
std::stable_sort(begin(remaining_targets), end(remaining_targets), [&](int a, int b) {
133133
return pin_criticality[a] > pin_criticality[b];
134134
});
135135

vpr/src/route/router_lookahead_map_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ t_routing_cost_map get_routing_cost_map(int longest_seg_length,
671671

672672
//Uniquify the increments (avoid sampling the same locations repeatedly if they happen to
673673
//overlap)
674-
std::sort(ref_increments.begin(), ref_increments.end());
674+
std::stable_sort(ref_increments.begin(), ref_increments.end());
675675
ref_increments.erase(std::unique(ref_increments.begin(), ref_increments.end()), ref_increments.end());
676676

677677
//Upper right non-corner

vpr/src/route/router_lookahead_sampling.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static std::vector<SamplePoint> choose_points(const vtr::Matrix<int>& counts,
5959
vtr::Point<int> center = sample(window, 1, 1, 2);
6060

6161
// sort by distance from center
62-
std::sort(points.begin(), points.end(),
62+
std::stable_sort(points.begin(), points.end(),
6363
[&](const SamplePoint& a, const SamplePoint& b) {
6464
return manhattan_distance(a.location, center) < manhattan_distance(b.location, center);
6565
});
@@ -232,7 +232,7 @@ std::vector<SampleRegion> find_sample_regions(int num_segments) {
232232
compute_sample_regions(sample_regions, segment_counts, bounding_box_for_segment, num_segments);
233233

234234
// sort regions
235-
std::sort(sample_regions.begin(), sample_regions.end(),
235+
std::stable_sort(sample_regions.begin(), sample_regions.end(),
236236
[](const SampleRegion& a, const SampleRegion& b) {
237237
return a.order < b.order;
238238
});

vpr/src/route/rr_graph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,7 @@ static void build_rr_chan(RRGraphBuilder& rr_graph_builder,
32133213
}
32143214

32153215
void uniquify_edges(t_rr_edge_info_set& rr_edges_to_create) {
3216-
std::sort(rr_edges_to_create.begin(), rr_edges_to_create.end());
3216+
std::stable_sort(rr_edges_to_create.begin(), rr_edges_to_create.end());
32173217
rr_edges_to_create.erase(std::unique(rr_edges_to_create.begin(), rr_edges_to_create.end()), rr_edges_to_create.end());
32183218
}
32193219

0 commit comments

Comments
 (0)