diff --git a/elab_expr.cc b/elab_expr.cc index 46e98f8db..1f5ac0f33 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -3981,6 +3981,7 @@ NetExpr* PEIdent::elaborate_expr_net_part_(Design*des, NetScope*scope, ivl_assert(*this, lrc); lrc = net->sig()->sb_to_slice(prefix_indices, msv, moff, mwid); ivl_assert(*this, lrc); + ivl_assert(*this, lwid == mwid); if (moff > loff) { sb_lsb = loff; @@ -3989,6 +3990,7 @@ NetExpr* PEIdent::elaborate_expr_net_part_(Design*des, NetScope*scope, sb_lsb = moff; sb_msb = loff + lwid - 1; } + wid = sb_msb - sb_lsb + 1; } else { // This case, the prefix indices are enough to index // down to a single bit/slice. diff --git a/nettypes.cc b/nettypes.cc index 6b5797146..301f28603 100644 --- a/nettypes.cc +++ b/nettypes.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2012-2013 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -98,7 +98,7 @@ bool prefix_to_slice(const std::vector&dims, if (pcur->get_msb() >= pcur->get_lsb()) acc_off += (sb - pcur->get_lsb()) * acc_wid; else - acc_off += (sb - pcur->get_msb()) * acc_wid; + acc_off += (pcur->get_lsb() - sb) * acc_wid; if (prefix.empty()) { loff = acc_off; @@ -115,7 +115,7 @@ bool prefix_to_slice(const std::vector&dims, if (pcur->get_msb() >= pcur->get_lsb()) acc_off += (*icur - pcur->get_lsb()) * acc_wid; else - acc_off += (*icur - pcur->get_msb()) * acc_wid; + acc_off += (pcur->get_lsb() - *icur) * acc_wid; } while (icur != prefix.begin());