Skip to content

Commit

Permalink
Merge pull request #4350 from jix/read_rtlil_performance
Browse files Browse the repository at this point in the history
rtlil: Add packed `extract` implementation for `SigSpec`
  • Loading branch information
povik authored Apr 24, 2024
2 parents cf02f86 + 178eceb commit cd1fb8b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4435,9 +4435,36 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
log_assert(offset >= 0);
log_assert(length >= 0);
log_assert(offset + length <= width_);
unpack();

cover("kernel.rtlil.sigspec.extract_pos");
return std::vector<RTLIL::SigBit>(bits_.begin() + offset, bits_.begin() + offset + length);

if (packed()) {
SigSpec extracted;
extracted.width_ = length;

auto it = chunks_.begin();
for (; offset; offset -= it->width, it++) {
if (offset < it->width) {
int chunk_length = min(it->width - offset, length);
extracted.chunks_.emplace_back(it->extract(offset, chunk_length));
length -= chunk_length;
it++;
break;
}
}
for (; length; length -= it->width, it++) {
if (length >= it->width) {
extracted.chunks_.emplace_back(*it);
} else {
extracted.chunks_.emplace_back(it->extract(0, length));
break;
}
}

return extracted;
} else {
return std::vector<RTLIL::SigBit>(bits_.begin() + offset, bits_.begin() + offset + length);
}
}

void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)
Expand Down

0 comments on commit cd1fb8b

Please sign in to comment.