@@ -74,6 +74,59 @@ RRNodeId RRSpatialLookup::find_node(int x,
74
74
return RRNodeId (rr_node_indices_[type][node_x][node_y][node_side][ptc]);
75
75
}
76
76
77
+ std::vector<RRNodeId> RRSpatialLookup::find_channel_nodes (int x,
78
+ int y,
79
+ t_rr_type type) const {
80
+ std::vector<RRNodeId> channel_nodes;
81
+
82
+ /* Pre-check: the x, y, type are valid! Otherwise, return an empty vector */
83
+ if ((0 > x || 0 > y) && (CHANX == type || CHANY == type)) {
84
+ return channel_nodes;
85
+ }
86
+
87
+ /* Currently need to swap x and y for CHANX because of chan, seg convention
88
+ * This is due to that the fast look-up builders uses (y, x) coordinate when
89
+ * registering a CHANX node in the look-up
90
+ * TODO: Once the builders is reworked for use consistent (x, y) convention,
91
+ * the following swapping can be removed
92
+ */
93
+ size_t node_x = x;
94
+ size_t node_y = y;
95
+ if (CHANX == type) {
96
+ std::swap (node_x, node_y);
97
+ }
98
+
99
+ VTR_ASSERT_SAFE (3 == rr_node_indices_[type].ndims ());
100
+
101
+ /* Sanity check to ensure the x, y, side are in range
102
+ * - Return a list of valid ids by searching in look-up when all the parameters are in range
103
+ * - Return an empty list if any out-of-range is detected
104
+ */
105
+ if (size_t (type) >= rr_node_indices_.size ()) {
106
+ return channel_nodes;
107
+ }
108
+
109
+ if (node_x >= rr_node_indices_[type].dim_size (0 )) {
110
+ return channel_nodes;
111
+ }
112
+
113
+ if (node_y >= rr_node_indices_[type].dim_size (1 )) {
114
+ return channel_nodes;
115
+ }
116
+
117
+ /* By default, we always added the channel nodes to the TOP side (to save memory) */
118
+ e_side node_side = TOP;
119
+ if (node_side >= rr_node_indices_[type].dim_size (2 )) {
120
+ return channel_nodes;
121
+ }
122
+
123
+ for (const auto & node : rr_node_indices_[type][node_x][node_y][node_side]) {
124
+ channel_nodes.push_back (RRNodeId (node));
125
+ }
126
+
127
+ return channel_nodes;
128
+ }
129
+
77
130
void RRSpatialLookup::add_node (RRNodeId node,
78
131
int x,
79
132
int y,
0 commit comments