Skip to content

Commit

Permalink
rtlil: handle all-zeros case in Const::compress
Browse files Browse the repository at this point in the history
  • Loading branch information
phsauter committed Sep 20, 2024
1 parent fafb73a commit 2880424
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,22 @@ void RTLIL::Const::compress(bool is_signed)

// back to front (MSB to LSB)
RTLIL::State leading_bit;
if(is_signed)
if (is_signed)
leading_bit = (bits.back() == RTLIL::State::Sx) ? RTLIL::State::S0 : bits.back();
else
leading_bit = RTLIL::State::S0;

size_t idx = bits.size();
while (idx > 0 && bits[idx -1] == leading_bit) {
--idx;
}
size_t idx = bits.size();
while (idx > 0 && bits[idx -1] == leading_bit) {
idx--;
}

// signed needs one leading bit
if (is_signed && idx < bits.size()) {
++idx;
}
idx++;
}
// must be at least one bit
idx = (idx == 0) ? 1 : idx;

bits.erase(bits.begin() + idx, bits.end());
}
Expand Down

0 comments on commit 2880424

Please sign in to comment.