Any tip or example for traversing the design to find all physical path from a source-bit to a destination-bit? #3539
-
Now I am writing a recursive function to find all physical paths (the mux on path) from one sigbit to another sigbit using DFS algorithm. SigMap sigmap(top_module);
std::map<RTLIL::SigBit, std::vector<RTLIL::Cell*>> bit_users;
std::map<RTLIL::SigBit, bool> visited;
std::map<RTLIL::SigBit, bool> hasPath; // cut off some useless bits
bool find_paths(RTLIL::SigBit curr_bit, RTLIL::SigBit dest_bit) {
// reach destination
if (sigmap(curr_bit) == sigmap(dest_bit)) {
// do something to save path
return false;
}
// curr_bit has been visited, avoid loop
RTLIL::SigBit mapped_bit = sigmap(curr_bit);
if (visited.count(mapped_bit) && visted[mapped_bit]) {
return false;
}
// no path can reach dest_bit from curr_bit
if (hasPath.count(mapped_bit))
if (!hasPath[mapped_bit]) {
return false;
}
} else {
hasPath[mapped_bit] = false;
}
// avoid loop
visited[mapped_bit] = true;
std::vector<RTLIL::Cell *> user_cells = bit_users[sigmap(curr_bit)]
for (auto cell : user_cells) {
if ( cell is a mux ) {
// mux could has more than two data inputs
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
RTLIL::SigSpec sig_b = cell->getPort(ID::B);
......
RTLIL::SigSpec sig_v = cell->getPort(ID::V);
RTLIL::SigSpec sig_out = cell->getPort(ID::Y);
// do something to check which signal contains curr_bit,
// then determine the curr_bit offset in that signal
int offset = ?;
bool path_exists = find_paths(sig_out[offset], RTLIL::SigBit dest_bit);
hasPath[mapped_bit] = hasPath[mapped_bit] || path_exists;
} else {
for (auto conn : cell.connections()) {
RTLIL::IdString port_name = conn.first;
RTLIL::SigSpec port_sig = conn.second;
// just simply iterate every bits of port_sig might cause
// search-state space explosion
// and also would get the path that not actually connected from source to destination
if (cell->output(port_name)) {
for (int offset = 0; offset < GetSize(port_sig); ++offset) {
bool path_exists = find_paths(port_sig[offset], RTLIL::SigBit dest_bit);
hasPath[mapped_bit] = hasPath[mapped_bit] || path_exists;
}
}
}
}
}
visited[mapped_bit] = false;
return hasPath[mapped_bit];
} My questions is: There are many kind of RTL cells (maybe the width of all inputs are equal to output or not, maybe the cell has more than 2 inputs). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
You can use
select
to select the intersection of the output cone of the starting signal and the input cone of the target signal, and then iterate only over selected cells and wires.