From d7814ed7678beede211508287bce4b3c56d18134 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 11 Jun 2008 14:38:35 -0700 Subject: [PATCH] Better handle some vector size matters for %load/v The %load/v instruction was doing some spurious resizes of the vector that comes from the signal. Eliminate those resizes that can be removed, and optimize some that remain. --- vvp/vthread.cc | 12 +++++++----- vvp/vvp_net.cc | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index b20131ea1..8c0b9cd46 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -2461,7 +2461,6 @@ static vvp_vector4_t load_base(vthread_t thr, vvp_code_t cp) assert(cp->bit_idx[0] >= 4); assert(cp->bit_idx[1] > 0); - unsigned wid = cp->bit_idx[1]; vvp_net_t*net = cp->net; /* For the %load to work, the functor must actually be a @@ -2473,10 +2472,7 @@ static vvp_vector4_t load_base(vthread_t thr, vvp_code_t cp) assert(sig); } - vvp_vector4_t sig_value = sig->vec4_value(); - sig_value.resize(wid); - - return sig_value; + return sig->vec4_value(); } bool of_LOAD_VEC(vthread_t thr, vvp_code_t cp) @@ -2489,10 +2485,16 @@ bool of_LOAD_VEC(vthread_t thr, vvp_code_t cp) /* Check the address once, before we scan the vector. */ thr_check_addr(thr, bit+wid-1); + if (sig_value.size() > wid) + sig_value.resize(wid); + /* Copy the vector bits into the bits4 vector. Do the copy directly to skip the excess calls to thr_check_addr. */ thr->bits4.set_vec(bit, sig_value); + for (unsigned idx = sig_value.size() ; idx < wid ; idx += 1) + thr->bits4.set_bit(bit+idx, BIT4_X); + return true; } diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index f0fc896d6..7ad426bca 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -404,6 +404,13 @@ void vvp_vector4_t::resize(unsigned newsize) if (newsize > BITS_PER_WORD) { unsigned newcnt = (newsize + BITS_PER_WORD - 1) / BITS_PER_WORD; + if (newcnt == cnt) { + // If the word count doesn't change, then there is + // no need for re-allocation so we are done now. + size_ = newsize; + return; + } + unsigned long*newbits = new unsigned long[2*newcnt]; if (cnt > 1) {