Skip to content

Commit 2c45627

Browse files
acomodimtdudek
authored andcommitted
vpr: base: netlist: interchange: fix bus port generation
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 22e05d3 commit 2c45627

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

vpr/src/base/read_interchange_netlist.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ struct NetlistReader {
9090
std::string name = str_list[port.getName()];
9191
auto dir = port.getDir();
9292

93-
int bus_size, start_bit;
94-
std::tie(bus_size, start_bit) = get_bus_size(port);
93+
int start, end;
94+
std::tie(start, end) = get_bus_range(port);
95+
96+
int bus_size = std::abs(end - start) + 1;
97+
int start_bit = start < end ? start : end;
9598

9699
for (int bit = start_bit; bit < start_bit + bus_size; bit++) {
97100
auto port_name = name;
@@ -431,38 +434,40 @@ struct NetlistReader {
431434
return nullptr;
432435
}
433436

434-
std::pair<int, int> get_bus_size(LogicalNetlist::Netlist::Port::Reader port_reader) {
437+
std::pair<int, int> get_bus_range(LogicalNetlist::Netlist::Port::Reader port_reader) {
435438
if (port_reader.isBus()) {
436439
int s = port_reader.getBus().getBusStart();
437440
int e = port_reader.getBus().getBusEnd();
438441

439-
if (e < s)
440-
return std::make_pair(s - e + 1, e);
441-
else
442-
return std::make_pair(e - s + 1, s);
442+
return std::make_pair(s, e);
443443
}
444444

445-
return std::make_pair(1, 0);
445+
return std::make_pair(0, 0);
446446
}
447447

448448
unsigned int get_port_bit(LogicalNetlist::Netlist::PortInstance::Reader port_inst_reader) {
449+
unsigned int port_bit = 0;
449450
if (port_inst_reader.getBusIdx().which() == LogicalNetlist::Netlist::PortInstance::BusIdx::IDX)
450-
return port_inst_reader.getBusIdx().getIdx();
451+
port_bit = port_inst_reader.getBusIdx().getIdx();
451452

452-
return 0;
453+
return port_bit;
453454
}
454455

455456
std::unordered_map<std::pair<unsigned int, unsigned int>, std::string, vtr::hash_pair> get_port_net_map(unsigned int inst_idx) {
456457
auto inst_list = nr_.getInstList();
457458
auto decl_list = nr_.getCellDecls();
458459
auto str_list = nr_.getStrList();
460+
auto port_list = nr_.getPortList();
459461

460462
auto top_cell = nr_.getCellList()[nr_.getTopInst().getCell()];
461463
std::unordered_map<std::pair<unsigned int, unsigned int>, std::string, vtr::hash_pair> map;
462464
for (auto net : top_cell.getNets()) {
463465
std::string net_name = str_list[net.getName()];
464466

465467
for (auto port : net.getPortInsts()) {
468+
if (port.isExtPort())
469+
continue;
470+
466471
auto port_inst = port.getInst();
467472
auto cell = inst_list[port_inst].getCell();
468473
if (str_list[decl_list[cell].getName()] == arch_.gnd_cell.first)
@@ -477,7 +482,16 @@ struct NetlistReader {
477482
continue;
478483

479484
unsigned int port_bit = get_port_bit(port);
480-
auto pair = std::make_pair(port.getPort(), port_bit);
485+
486+
auto port_idx = port.getPort();
487+
int start, end;
488+
std::tie(start, end) = get_bus_range(port_list[port_idx]);
489+
490+
int bus_size = std::abs(end - start);
491+
492+
port_bit = start < end ? port_bit : bus_size - port_bit;
493+
494+
auto pair = std::make_pair(port_idx, port_bit);
481495
map.emplace(pair, net_name);
482496
}
483497
}

0 commit comments

Comments
 (0)