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.
This commit is contained in:
Stephen Williams 2008-08-30 15:30:22 -07:00
parent 49c4f2d106
commit fc476aa281
1 changed files with 13 additions and 2 deletions

View File

@ -1557,8 +1557,19 @@ vvp_vector2_t& vvp_vector2_t::operator >>= (unsigned shift)
} }
// Cleanup the tail bits. // Cleanup the tail bits.
unsigned long mask = -1UL >> (BITS_PER_WORD - wid_%BITS_PER_WORD); unsigned use_words = words;
vec_[words-1] &= mask; 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; return *this;