From: Eddie Hung Date: Mon, 22 Jul 2019 23:10:21 +0000 (-0700) Subject: SigSpec::extract() to return as many bits as poss if out of bounds X-Git-Tag: working-ls180~1039^2~306 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8c31441ba066ea246ff1ef55c3dd6ceb4ee8d6e3;p=yosys.git SigSpec::extract() to return as many bits as poss if out of bounds --- diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 5d992ef2d..fd98ab4bd 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -3354,7 +3354,13 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const { unpack(); cover("kernel.rtlil.sigspec.extract_pos"); - return std::vector(bits_.begin() + offset, length >= 0 ? bits_.begin() + offset + length : bits_.end() + length + 1); + auto it = bits_.begin() + std::min(offset, width_); + decltype(it) ie; + if (length >= 0) + ie = bits_.begin() + std::min(offset + length, width_); + else + ie = bits_.end() + std::max(length + 1, offset - width_); + return std::vector(it, ie); } void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)