Skip to content

Commit

Permalink
groupBusPorts callback for endedness
Browse files Browse the repository at this point in the history
Signed-off-by: James Cherry <[email protected]>
  • Loading branch information
jjcherry56 committed Aug 12, 2021
1 parent 598842f commit 0c2255b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/sta/ConcreteLibrary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public:
ConcretePortSeq *members);
// Group previously defined bus bit ports together.
void groupBusPorts(const char bus_brkt_left,
const char bus_brkt_right);
const char bus_brkt_right,
std::function<bool(const char*)> port_big_endian_pred);
size_t portCount() const;
void setName(const char *name);
void addPort(ConcretePort *port);
Expand Down
3 changes: 2 additions & 1 deletion include/sta/ConcreteNetwork.hh
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public:
const char *name,
int from_index,
int to_index);
virtual void groupBusPorts(Cell *cell);
virtual void groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_is_big_endian);
virtual Port *makeBundlePort(Cell *cell,
const char *name,
PortSeq *members);
Expand Down
3 changes: 2 additions & 1 deletion include/sta/Network.hh
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ public:
const char *name,
int from_index,
int to_index) = 0;
virtual void groupBusPorts(Cell *cell) = 0;
virtual void groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_is_big_endian) = 0;
virtual Port *makeBundlePort(Cell *cell,
const char *name,
PortSeq *members) = 0;
Expand Down
27 changes: 18 additions & 9 deletions network/ConcreteLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ typedef Map<const char*, BusPort*, CharPtrLess> BusPortMap;

void
ConcreteCell::groupBusPorts(const char bus_brkt_left,
const char bus_brkt_right)
const char bus_brkt_right,
std::function<bool(const char*)> port_is_big_endian)
{
const char bus_brkts_left[2]{bus_brkt_left, '\0'};
const char bus_brkts_right[2]{bus_brkt_right, '\0'};
Expand All @@ -395,12 +396,8 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
if (bus_name) {
if (!port->isBusBit()) {
BusPort *bus_port = port_map.findKey(bus_name);
if (bus_port) {
// Treat it as [max:min]/[from:to], ie downto.
bus_port->setFrom(std::max(index, bus_port->from()));
bus_port->setTo(std::min(index, bus_port->to()));
if (bus_port)
stringDelete(bus_name);
}
else {
bus_port = new BusPort(bus_name, index, port->direction());
port_map[bus_name] = bus_port;
Expand All @@ -419,6 +416,7 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
while (bus_iter.hasNext()) {
BusPort *bus_port = bus_iter.next();
const char *bus_name = bus_port->name();
bool is_big_endian = port_is_big_endian(bus_name);
ConcretePortSeq *members = bus_port->members();
sort(members, [&](ConcretePort *port1,
ConcretePort *port2) {
Expand All @@ -430,10 +428,21 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
parseBusName(port2->name(), bus_brkts_left, bus_brkts_right, escape_,
bus_name, index2);
stringDelete(bus_name);
return index1 > index2;
return is_big_endian ? index1 > index2 : index1 < index2;
});
ConcretePort *port = makeBusPort(bus_name, bus_port->from(),
bus_port->to(), members);

char *bus_name1;
int from_index, to_index;
parseBusName((*members)[0]->name(),
bus_brkts_left, bus_brkts_right, escape_,
bus_name1, from_index);
stringDelete(bus_name1);
parseBusName((*members)[members->size() - 1]->name(),
bus_brkts_left, bus_brkts_right, escape_,
bus_name1, to_index);
stringDelete(bus_name1);

ConcretePort *port = makeBusPort(bus_name, from_index, to_index, members);
port->setDirection(bus_port->direction());
delete bus_port;

Expand Down
5 changes: 3 additions & 2 deletions network/ConcreteNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,13 @@ ConcreteNetwork::makeBusPort(Cell *cell,
}

void
ConcreteNetwork::groupBusPorts(Cell *cell)
ConcreteNetwork::groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_is_big_endian)
{
Library *lib = library(cell);
ConcreteLibrary *clib = reinterpret_cast<ConcreteLibrary*>(lib);
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight());
ccell->groupBusPorts(clib->busBrktLeft(), clib->busBrktRight(), port_is_big_endian);
}

Port *
Expand Down

0 comments on commit 0c2255b

Please sign in to comment.