Skip to content

Commit

Permalink
Move DriveChunkWire 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 d5b7d50 commit 0a2a896
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 45 deletions.
46 changes: 46 additions & 0 deletions kernel/drivertools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,56 @@ DriveBitMultiple DriveChunkMultiple::operator[](int i) const
return result;
}

DriveChunkWire::DriveChunkWire(Wire *wire, int offset, int width)
: wire(wire), offset(offset), width(width) {}

DriveChunkWire::DriveChunkWire(DriveBitWire const &bit)
: wire(bit.wire), offset(bit.offset), width(1) {}

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

DriveBitWire DriveChunkWire::operator[](int i) const
{
log_assert(i >= 0 && i < width);
return DriveBitWire(wire, offset + i);
}

bool DriveChunkWire::is_whole() const
{
return offset == 0 && width == wire->width;
}

bool DriveChunkWire::operator==(const DriveChunkWire &other) const
{
return wire == other.wire && offset == other.offset && width == other.width;
}

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

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

DriveChunkWire::operator SigChunk() const
{
return SigChunk(wire, offset, width);
}

bool DriveChunkWire::can_append(DriveBitWire const &bit) const
{
return bit.wire == wire && bit.offset == offset + width;
}



bool DriveChunkWire::try_append(DriveBitWire const &bit)
{
if (!can_append(bit))
Expand All @@ -569,6 +613,8 @@ bool DriveChunkWire::try_append(DriveChunkWire const &chunk)
return true;
}



bool DriveChunkPort::can_append(DriveBitPort const &bit) const
{
return bit.cell == cell && bit.port == port && bit.offset == offset + width;
Expand Down
62 changes: 17 additions & 45 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,51 +201,23 @@ struct DriveBit

struct DriveChunkWire
{
Wire *wire;
int offset;
int width;

DriveChunkWire(Wire *wire, int offset, int width) : wire(wire), offset(offset), width(width) {}
DriveChunkWire(DriveBitWire const &bit) : wire(bit.wire), offset(bit.offset), width(1) {}

int size() const { return width; }

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

bool can_append(DriveBitWire const &bit) const;
bool try_append(DriveBitWire const &bit);
bool try_append(DriveChunkWire const &chunk);

// Whether this chunk is a whole wire
bool is_whole() const { return offset == 0 && width == wire->width; }

bool operator==(const DriveChunkWire &other) const
{
return wire == other.wire && offset == other.offset && width == other.width;
}

bool operator<(const DriveChunkWire &other) const
{
if (wire != other.wire)
return wire->name < other.wire->name;
if (width != other.width)
return width < other.width;
return offset < other.offset;
}

unsigned int hash() const
{
return mkhash_add(mkhash(wire->name.hash(), width), offset);
}

explicit operator SigChunk() const
{
return SigChunk(wire, offset, width);
}
Wire *wire;
int offset;
int width;

DriveChunkWire(Wire *wire, int offset, int width);
DriveChunkWire(DriveBitWire const &bit);

int size() const;
DriveBitWire operator[](int i) const;
bool can_append(DriveBitWire const &bit) const;
bool try_append(DriveBitWire const &bit);
bool try_append(DriveChunkWire const &chunk);
bool is_whole() const;
bool operator==(const DriveChunkWire &other) const;
bool operator<(const DriveChunkWire &other) const;
unsigned int hash() const;
explicit operator SigChunk() const;
};

struct DriveChunkPort
Expand Down

0 comments on commit 0a2a896

Please sign in to comment.