From dfaed128c0d953ea681b165b9ba56fc2040b08e2 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 15 Jan 2014 16:30:34 -0800 Subject: [PATCH] Fix %store/vec4 overlap of vectors written with extreme indices. --- vvp/vthread.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 3910ed770..5648d54ee 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -1281,6 +1281,7 @@ bool of_ASSIGN_VEC4_OFF_D(vthread_t thr, vvp_code_t cp) unsigned off_index = cp->bit_idx[0]; unsigned del_index = cp->bit_idx[1]; vvp_vector4_t val = thr->pop_vec4(); + unsigned wid = val.size(); int off = thr->words[off_index].w_int; int del = thr->words[del_index].w_int; @@ -1300,6 +1301,9 @@ bool of_ASSIGN_VEC4_OFF_D(vthread_t thr, vvp_code_t cp) return true; assert(0); // XXXX Not implemented yet. } + if (off+wid > sig->value_size()) { + assert(0); // XXXX Not implemented yet. + } schedule_assign_vector(ptr, off, sig->value_size(), val, del); return true; @@ -5875,6 +5879,29 @@ bool of_STORE_VEC4(vthread_t thr, vvp_code_t cp) if (off_index!=0 && thr->flags[4] == BIT4_1) return true; + if (off <= -(int)wid) + return true; + if (off >= (int)sig->value_size()) + return true; + + // If the index is below the vector, then only assign the high + // bits that overlap with the target. + if (off < 0) { + int use_off = -off; + wid -= use_off; + val = val.subvalue(use_off, wid); + off = 0; + } + + // If the value is partly above the target, then only assign + // the bits that overlap. + if ((off+wid) > sig->value_size()) { + wid = sig->value_size()-off; + val = val.subvalue(0, wid); + val.resize(wid); + } + + if (off==0 && val.size()==sig->value_size()) vvp_send_vec4(ptr, val, thr->wt_context); else