mirror of
https://github.com/YosysHQ/yosys
synced 2026-05-21 17:39:41 +00:00
Merge pull request #5832 from YosysHQ/emil/simple-extract
rtlil: rewrite SigSpec::extract for perf and packing
This commit is contained in:
commit
ec0a102302
5 changed files with 198 additions and 30 deletions
|
|
@ -5272,26 +5272,32 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
|
|||
log_assert(length >= 0);
|
||||
log_assert(offset + length <= size());
|
||||
|
||||
SigSpec extracted;
|
||||
Chunks cs = chunks();
|
||||
auto it = cs.begin();
|
||||
for (; offset; offset -= it->width, ++it) {
|
||||
if (offset < it->width) {
|
||||
int chunk_length = min(it->width - offset, length);
|
||||
extracted.append(it->extract(offset, chunk_length));
|
||||
length -= chunk_length;
|
||||
++it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; length; length -= it->width, ++it) {
|
||||
if (length >= it->width) {
|
||||
extracted.append(*it);
|
||||
std::vector<SigBit> extracted;
|
||||
SigBit first;
|
||||
bool is_packing = true;
|
||||
for (int i = offset; i < offset + length; i++) {
|
||||
bool was_packing_before = is_packing;
|
||||
SigBit bit = (*this)[i];
|
||||
if (i == offset) {
|
||||
first = bit;
|
||||
if (!bit.wire)
|
||||
is_packing = false;
|
||||
} else {
|
||||
extracted.append(it->extract(0, length));
|
||||
break;
|
||||
if (bit.wire != first.wire)
|
||||
is_packing = false;
|
||||
if (bit.wire)
|
||||
if (bit.offset != first.offset + (i - offset))
|
||||
is_packing = false;
|
||||
}
|
||||
if (was_packing_before && !is_packing)
|
||||
for (int j = offset; j < i; j++)
|
||||
extracted.push_back((*this)[j]);
|
||||
if (!is_packing)
|
||||
extracted.push_back((*this)[i]);
|
||||
}
|
||||
if (is_packing)
|
||||
return SigChunk(first.wire, first.offset, length);
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1400,6 +1400,8 @@ struct RTLIL::SigSpecConstIterator
|
|||
struct RTLIL::SigSpec
|
||||
{
|
||||
private:
|
||||
friend class SigSpecRepTest;
|
||||
FRIEND_TEST(SigSpecRepTest, Extract);
|
||||
enum Representation : char {
|
||||
CHUNK,
|
||||
BITS,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue