3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-05 22:06:04 +00:00

Make SigSpecConstIterator iterate over SigSpec without unpacking

To make this efficient, the iterator keeps `chunk_index_hint` pointing to
the current chunk. This is only a hint, since it is not possible to maintain
its validity if the `SigSpec` representation is temporarily changed to unpacked.
In that case we have to resync using binary search.
This commit is contained in:
Robert O'Callahan 2025-09-01 04:49:29 +00:00
parent acee6db361
commit e49f9765a2
3 changed files with 105 additions and 10 deletions

View file

@ -4447,6 +4447,23 @@ bool RTLIL::SigChunk::operator !=(const RTLIL::SigChunk &other) const
return true;
}
const RTLIL::SigChunk &RTLIL::SigSpecConstIterator::find_chunk()
{
int low = 0;
int high = GetSize(sig_p->chunks_);
while (high - low >= 2) {
int mid = (low + high) / 2;
if (sig_p->chunks_[mid].offset_in_sigspec <= bit_index)
low = mid;
else
high = mid;
}
chunk_index_hint = low;
const RTLIL::SigChunk &chunk = sig_p->chunks_[chunk_index_hint];
log_assert(chunk.offset_in_sigspec <= bit_index && bit_index < chunk.offset_in_sigspec + chunk.width);
return chunk;
}
RTLIL::SigSpec::SigSpec(std::initializer_list<RTLIL::SigSpec> parts)
{
cover("kernel.rtlil.sigspec.init.list");