From fc476aa281b266396a93b4e04092b75e96c7fe0f Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 30 Aug 2008 15:30:22 -0700 Subject: [PATCH] Fix right shift of vvp_vector2_t. The right shift of vvp_vector2_t needs to account for and mask off shifted bits. Otherwise there will be unexpected results after a vvp_vector2_t::trim method. --- vvp/vvp_net.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index f921e014c..a3bd2ee19 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -1557,8 +1557,19 @@ vvp_vector2_t& vvp_vector2_t::operator >>= (unsigned shift) } // Cleanup the tail bits. - unsigned long mask = -1UL >> (BITS_PER_WORD - wid_%BITS_PER_WORD); - vec_[words-1] &= mask; + unsigned use_words = words; + unsigned long mask_shift = BITS_PER_WORD - wid_%BITS_PER_WORD; + mask_shift += oshift; + while (mask_shift >= BITS_PER_WORD) { + vec_[use_words-1] = 0; + use_words -= 1; + mask_shift -= BITS_PER_WORD; + } + if (mask_shift > 0) { + assert(use_words > 0); + unsigned long mask = -1UL >> mask_shift; + vec_[use_words-1] &= mask; + } } return *this;