77#include " vpr_error.h"
88#include " globals.h"
99
10- static int get_expected_segs_to_target (RRNodeId inode, RRNodeId target_node, int * num_segs_ortho_dir_ptr);
10+ /* *
11+ * Assuming inode is CHANX or CHANY, this function calculates the number of required wires of the same type as inode
12+ * to arrive at target_noe.
13+ * @param inode The source node from which the cost to the target node is obtained.
14+ * @param target_node The target node to which the cost is obtained.
15+ * @return std::pait<int, int> The first element is the number of required wires in the same direction as inode,
16+ * while the second element determines the number of wires in the direction orthogonal to inode.
17+ */
18+ static std::pair<int , int > get_expected_segs_to_target (RRNodeId inode, RRNodeId target_node);
19+
1120static int round_up (float x);
1221
1322static std::unique_ptr<RouterLookahead> make_router_lookahead_object (const t_det_routing_arch& det_routing_arch,
@@ -31,8 +40,8 @@ static std::unique_ptr<RouterLookahead> make_router_lookahead_object(const t_det
3140
3241std::unique_ptr<RouterLookahead> make_router_lookahead (const t_det_routing_arch& det_routing_arch,
3342 e_router_lookahead router_lookahead_type,
34- std::string write_lookahead,
35- std::string read_lookahead,
43+ const std::string& write_lookahead,
44+ const std::string& read_lookahead,
3645 const std::vector<t_segment_inf>& segment_inf,
3746 bool is_flat) {
3847 std::unique_ptr<RouterLookahead> router_lookahead = make_router_lookahead_object (det_routing_arch,
@@ -53,8 +62,7 @@ std::unique_ptr<RouterLookahead> make_router_lookahead(const t_det_routing_arch&
5362}
5463
5564float ClassicLookahead::get_expected_cost (RRNodeId current_node, RRNodeId target_node, const t_conn_cost_params& params, float R_upstream) const {
56- float delay_cost, cong_cost;
57- std::tie (delay_cost, cong_cost) = get_expected_delay_and_cong (current_node, target_node, params, R_upstream);
65+ auto [delay_cost, cong_cost] = get_expected_delay_and_cong (current_node, target_node, params, R_upstream);
5866
5967 return delay_cost + cong_cost;
6068}
@@ -66,8 +74,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
6674 t_rr_type rr_type = rr_graph.node_type (node);
6775
6876 if (rr_type == CHANX || rr_type == CHANY) {
69- int num_segs_ortho_dir = 0 ;
70- int num_segs_same_dir = get_expected_segs_to_target (node, target_node, &num_segs_ortho_dir);
77+ auto [num_segs_same_dir, num_segs_ortho_dir] = get_expected_segs_to_target (node, target_node);
7178
7279 auto cost_index = rr_graph.node_cost_index (node);
7380 int ortho_cost_index = device_ctx.rr_indexed_data [cost_index].ortho_cost_index ;
@@ -112,28 +119,27 @@ static int round_up(float x) {
112119 return std::ceil (x - 0.001 );
113120}
114121
115- static int get_expected_segs_to_target (RRNodeId inode, RRNodeId target_node, int * num_segs_ortho_dir_ptr ) {
122+ static std::pair< int , int > get_expected_segs_to_target (RRNodeId inode, RRNodeId target_node) {
116123 /* Returns the number of segments the same type as inode that will be needed *
117124 * to reach target_node (not including inode) in each direction (the same *
118125 * direction (horizontal or vertical) as inode and the orthogonal direction).*/
119-
120126 auto & device_ctx = g_vpr_ctx.device ();
121127 const auto & rr_graph = device_ctx.rr_graph ;
122128
123- t_rr_type rr_type ;
124- int target_x, target_y, num_segs_same_dir, ortho_cost_index ;
125- RRIndexedDataId cost_index;
129+ int num_segs_ortho_dir ;
130+ int num_segs_same_dir;
131+
126132 int no_need_to_pass_by_clb;
127- float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;
133+ float ylow, yhigh, xlow, xhigh;
128134
129- target_x = rr_graph.node_xlow (target_node);
130- target_y = rr_graph.node_ylow (target_node);
135+ int target_x = rr_graph.node_xlow (target_node);
136+ int target_y = rr_graph.node_ylow (target_node);
131137
132- cost_index = rr_graph.node_cost_index (inode);
133- inv_length = device_ctx.rr_indexed_data [cost_index].inv_length ;
134- ortho_cost_index = device_ctx.rr_indexed_data [cost_index].ortho_cost_index ;
135- ortho_inv_length = device_ctx.rr_indexed_data [RRIndexedDataId (ortho_cost_index)].inv_length ;
136- rr_type = rr_graph.node_type (inode);
138+ RRIndexedDataId cost_index = rr_graph.node_cost_index (inode);
139+ float inv_length = device_ctx.rr_indexed_data [cost_index].inv_length ;
140+ int ortho_cost_index = device_ctx.rr_indexed_data [cost_index].ortho_cost_index ;
141+ float ortho_inv_length = device_ctx.rr_indexed_data [RRIndexedDataId (ortho_cost_index)].inv_length ;
142+ t_rr_type rr_type = rr_graph.node_type (inode);
137143
138144 if (rr_type == CHANX) {
139145 ylow = rr_graph.node_ylow (inode);
@@ -143,13 +149,13 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
143149 /* Count vertical (orthogonal to inode) segs first. */
144150
145151 if (ylow > target_y) { /* Coming from a row above target? */
146- *num_segs_ortho_dir_ptr = round_up ((ylow - target_y + 1 .) * ortho_inv_length);
152+ num_segs_ortho_dir = round_up ((ylow - target_y + 1 .) * ortho_inv_length);
147153 no_need_to_pass_by_clb = 1 ;
148154 } else if (ylow < target_y - 1 ) { /* Below the CLB bottom? */
149- *num_segs_ortho_dir_ptr = round_up ((target_y - ylow) * ortho_inv_length);
155+ num_segs_ortho_dir = round_up ((target_y - ylow) * ortho_inv_length);
150156 no_need_to_pass_by_clb = 1 ;
151157 } else { /* In a row that passes by target CLB */
152- *num_segs_ortho_dir_ptr = 0 ;
158+ num_segs_ortho_dir = 0 ;
153159 no_need_to_pass_by_clb = 0 ;
154160 }
155161
@@ -170,13 +176,13 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
170176 /* Count horizontal (orthogonal to inode) segs first. */
171177
172178 if (xlow > target_x) { /* Coming from a column right of target? */
173- *num_segs_ortho_dir_ptr = round_up ((xlow - target_x + 1 .) * ortho_inv_length);
179+ num_segs_ortho_dir = round_up ((xlow - target_x + 1 .) * ortho_inv_length);
174180 no_need_to_pass_by_clb = 1 ;
175181 } else if (xlow < target_x - 1 ) { /* Left of and not adjacent to the CLB? */
176- *num_segs_ortho_dir_ptr = round_up ((target_x - xlow) * ortho_inv_length);
182+ num_segs_ortho_dir = round_up ((target_x - xlow) * ortho_inv_length);
177183 no_need_to_pass_by_clb = 1 ;
178184 } else { /* In a column that passes by target CLB */
179- *num_segs_ortho_dir_ptr = 0 ;
185+ num_segs_ortho_dir = 0 ;
180186 no_need_to_pass_by_clb = 0 ;
181187 }
182188
@@ -191,7 +197,7 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
191197 }
192198 }
193199
194- return ( num_segs_same_dir) ;
200+ return { num_segs_same_dir, num_segs_ortho_dir} ;
195201}
196202
197203void invalidate_router_lookahead_cache () {
@@ -201,8 +207,8 @@ void invalidate_router_lookahead_cache() {
201207
202208const RouterLookahead* get_cached_router_lookahead (const t_det_routing_arch& det_routing_arch,
203209 e_router_lookahead router_lookahead_type,
204- std::string write_lookahead,
205- std::string read_lookahead,
210+ const std::string& write_lookahead,
211+ const std::string& read_lookahead,
206212 const std::vector<t_segment_inf>& segment_inf,
207213 bool is_flat) {
208214 auto & router_ctx = g_vpr_ctx.routing ();
0 commit comments