Use `netrange_width()` helper where appropriate

The `netrange_width()` helper function computes the total width of a set of
ranges. There are a few places where this is currently open-coded and
`netrange_width()` can be used. This removes a bit of duplicated code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-05-15 22:41:47 +02:00
parent 4269388878
commit bdbe74252c
3 changed files with 5 additions and 17 deletions

View File

@ -1965,9 +1965,8 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,
use_width = 1; use_width = 1;
while (const netuarray_t *utype = while (const netuarray_t *utype =
dynamic_cast<const netuarray_t*>(data_type)) { dynamic_cast<const netuarray_t*>(data_type)) {
const vector<netrange_t> &dims = utype->static_dimensions(); use_width = netrange_width(utype->static_dimensions(),
for (size_t i = 0; i < dims.size(); i++) use_width);
use_width *= dims[i].width();
data_type = utype->element_type(); data_type = utype->element_type();
} }
if (!data_type->packed()) { if (!data_type->packed()) {

View File

@ -819,12 +819,7 @@ bool NetNet::sb_to_slice(const list<long>&indices, long sb, long&loff, unsigned
unsigned NetNet::unpacked_count() const unsigned NetNet::unpacked_count() const
{ {
unsigned c = 1; return netrange_width(unpacked_dims_);
for (size_t idx = 0 ; idx < unpacked_dims_.size() ; idx += 1) {
c *= unpacked_dims_[idx].width();
}
return c;
} }
void NetNet::incr_eref() void NetNet::incr_eref()

View File

@ -42,14 +42,8 @@ bool netparray_t::packed(void) const
long netparray_t::packed_width(void) const long netparray_t::packed_width(void) const
{ {
long cur_width = element_type()->packed_width(); return netrange_width(static_dimensions(),
element_type()->packed_width());
for (vector<netrange_t>::const_iterator cur = static_dimensions().begin()
; cur != static_dimensions().end() ; ++cur) {
cur_width *= cur->width();
}
return cur_width;
} }
vector<netrange_t> netparray_t::slice_dimensions() const vector<netrange_t> netparray_t::slice_dimensions() const