Skip to content

Commit

Permalink
Move DriveChunkPort implementation to drivertools.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed May 22, 2024
1 parent 0a2a896 commit 021423a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
46 changes: 46 additions & 0 deletions kernel/drivertools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,52 @@ bool DriveChunkPort::try_append(DriveChunkPort const &chunk)
return true;
}

DriveChunkPort::DriveChunkPort(Cell *cell, IdString port, int offset, int width)
: cell(cell), port(port), offset(offset), width(width) {}

DriveChunkPort::DriveChunkPort(Cell *cell, IdString port)
: cell(cell), port(port), offset(0), width(GetSize(cell->connections().at(port))) {}

DriveChunkPort::DriveChunkPort(Cell *cell, std::pair<IdString, SigSpec> const &conn)
: cell(cell), port(conn.first), offset(0), width(GetSize(conn.second)) {}

DriveChunkPort::DriveChunkPort(DriveBitPort const &bit)
: cell(bit.cell), port(bit.port), offset(bit.offset), width(1) {}

int DriveChunkPort::size() const { return width; }

DriveBitPort DriveChunkPort::operator[](int i) const
{
log_assert(i >= 0 && i < width);
return DriveBitPort(cell, port, offset + i);
}

bool DriveChunkPort::is_whole() const
{
return offset == 0 && width == cell->connections().at(port).size();
}

bool DriveChunkPort::operator==(const DriveChunkPort &other) const
{
return cell == other.cell && port == other.port && offset == other.offset && width == other.width;
}

bool DriveChunkPort::operator<(const DriveChunkPort &other) const
{
if (cell != other.cell)
return cell->name < other.cell->name;
if (port != other.port)
return port < other.port;
if (width != other.width)
return width < other.width;
return offset < other.offset;
}

unsigned int DriveChunkPort::hash() const
{
return mkhash_add(mkhash(mkhash(cell->name.hash(), port.hash()), width), offset);
}

bool DriveChunkMarker::can_append(DriveBitMarker const &bit) const
{
return bit.marker == marker && bit.offset == offset + width;
Expand Down
68 changes: 17 additions & 51 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,61 +222,27 @@ struct DriveChunkWire

struct DriveChunkPort
{
Cell *cell;
IdString port;
int offset;
int width;

DriveChunkPort(Cell *cell, IdString port, int offset, int width) :
cell(cell), port(port), offset(offset), width(width) { }
DriveChunkPort(Cell *cell, IdString port) :
cell(cell), port(port), offset(0), width(GetSize(cell->connections().at(port))) { }
DriveChunkPort(Cell *cell, std::pair<IdString, SigSpec> const &conn) :
cell(cell), port(conn.first), offset(0), width(GetSize(conn.second)) { }
DriveChunkPort(DriveBitPort const &bit) :
cell(bit.cell), port(bit.port), offset(bit.offset), width(1) { }

int size() const { return width; }

DriveBitPort operator[](int i) const
{
log_assert(i >= 0 && i < width);
return DriveBitPort(cell, port, offset + i);
}

bool can_append(DriveBitPort const &bit) const;
bool try_append(DriveBitPort const &bit);
bool try_append(DriveChunkPort const &chunk);

// Whether this chunk is a whole port
bool is_whole() const
{
return offset == 0 && width == cell->connections().at(port).size();
}

bool operator==(const DriveChunkPort &other) const
{
return cell == other.cell && port == other.port && offset == other.offset && width == other.width;
}
Cell *cell;
IdString port;
int offset;
int width;

bool operator<(const DriveChunkPort &other) const
{
if (cell != other.cell)
return cell->name < other.cell->name;
if (port != other.port)
return port < other.port;
if (width != other.width)
return width < other.width;
return offset < other.offset;
}
DriveChunkPort(Cell *cell, IdString port, int offset, int width);
DriveChunkPort(Cell *cell, IdString port);
DriveChunkPort(Cell *cell, std::pair<IdString, SigSpec> const &conn);
DriveChunkPort(DriveBitPort const &bit);

unsigned int hash() const
{
return mkhash_add(mkhash(mkhash(cell->name.hash(), port.hash()), width), offset);
}
int size() const;
DriveBitPort operator[](int i) const;
bool can_append(DriveBitPort const &bit) const;
bool try_append(DriveBitPort const &bit);
bool try_append(DriveChunkPort const &chunk);
bool is_whole() const;
bool operator==(const DriveChunkPort &other) const;
bool operator<(const DriveChunkPort &other) const;
unsigned int hash() const;
};


struct DriveChunkMarker
{
int marker;
Expand Down

0 comments on commit 021423a

Please sign in to comment.