Fix missing check for thread bits width in ADDI

This commit is contained in:
steve 2007-01-31 22:28:55 +00:00
parent b2e1db6adb
commit 85ceea7358
2 changed files with 25 additions and 11 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.cc,v 1.50 2006/03/06 05:43:15 steve Exp $" #ident "$Id: vpi_priv.cc,v 1.51 2007/01/31 22:28:55 steve Exp $"
#endif #endif
# include "vpi_priv.h" # include "vpi_priv.h"
@ -574,6 +574,8 @@ vpiHandle vpi_put_value(vpiHandle obj, s_vpi_value*vp,
if (flags != vpiNoDelay) { if (flags != vpiNoDelay) {
vvp_time64_t dly; vvp_time64_t dly;
assert(when != 0);
switch (when->type) { switch (when->type) {
case vpiScaledRealTime: case vpiScaledRealTime:
dly = (vvp_time64_t)(when->real * dly = (vvp_time64_t)(when->real *
@ -846,6 +848,9 @@ extern "C" void vpi_control(PLI_INT32 operation, ...)
/* /*
* $Log: vpi_priv.cc,v $ * $Log: vpi_priv.cc,v $
* Revision 1.51 2007/01/31 22:28:55 steve
* Fix missing check for thread bits width in ADDI
*
* Revision 1.50 2006/03/06 05:43:15 steve * Revision 1.50 2006/03/06 05:43:15 steve
* Cleanup vpi_const to use vec4 values. * Cleanup vpi_const to use vec4 values.
* *

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: vthread.cc,v 1.158 2007/01/16 05:44:16 steve Exp $" #ident "$Id: vthread.cc,v 1.159 2007/01/31 22:28:55 steve Exp $"
#endif #endif
# include "config.h" # include "config.h"
@ -486,24 +486,29 @@ bool of_ADD_WR(vthread_t thr, vvp_code_t cp)
*/ */
bool of_ADDI(vthread_t thr, vvp_code_t cp) bool of_ADDI(vthread_t thr, vvp_code_t cp)
{ {
assert(cp->bit_idx[0] >= 4); // Collect arguments
unsigned bit_addr = cp->bit_idx[0];
unsigned long imm_value = cp->bit_idx[1];
unsigned bit_width = cp->number;
unsigned word_count = (cp->number+CPU_WORD_BITS-1)/CPU_WORD_BITS; assert(bit_addr >= 4);
unsigned long*lva = vector_to_array(thr, cp->bit_idx[0], cp->number); unsigned word_count = (bit_width+CPU_WORD_BITS-1)/CPU_WORD_BITS;
unsigned long*lva = vector_to_array(thr, bit_addr, bit_width);
unsigned long*lvb = 0; unsigned long*lvb = 0;
if (lva == 0) if (lva == 0)
goto x_out; goto x_out;
lvb = new unsigned long[word_count]; lvb = new unsigned long[word_count];
lvb[0] = cp->bit_idx[1]; lvb[0] = imm_value;
for (unsigned idx = 1 ; idx < word_count ; idx += 1) for (unsigned idx = 1 ; idx < word_count ; idx += 1)
lvb[idx] = 0; lvb[idx] = 0;
unsigned long carry; unsigned long carry;
carry = 0; carry = 0;
for (unsigned idx = 0 ; (idx*CPU_WORD_BITS) < cp->number ; idx += 1) { for (unsigned idx = 0 ; (idx*CPU_WORD_BITS) < bit_width ; idx += 1) {
unsigned long tmp = lvb[idx] + carry; unsigned long tmp = lvb[idx] + carry;
unsigned long sum = lva[idx] + tmp; unsigned long sum = lva[idx] + tmp;
@ -517,9 +522,10 @@ bool of_ADDI(vthread_t thr, vvp_code_t cp)
lva[idx] = sum; lva[idx] = sum;
} }
for (unsigned idx = 0 ; idx < cp->number ; idx += 1) { thr_check_addr(thr, bit_addr + bit_width - 1);
for (unsigned idx = 0 ; idx < bit_width ; idx += 1) {
unsigned long bit = lva[idx/CPU_WORD_BITS] >> (idx%CPU_WORD_BITS); unsigned long bit = lva[idx/CPU_WORD_BITS] >> (idx%CPU_WORD_BITS);
thr->bits4.set_bit(cp->bit_idx[0]+idx, (bit&1UL) ? BIT4_1:BIT4_0); thr->bits4.set_bit(bit_addr+idx, (bit&1UL) ? BIT4_1:BIT4_0);
} }
delete[]lva; delete[]lva;
@ -530,8 +536,8 @@ bool of_ADDI(vthread_t thr, vvp_code_t cp)
x_out: x_out:
delete[]lva; delete[]lva;
vvp_vector4_t tmp (cp->number, BIT4_X); vvp_vector4_t tmp (bit_width, BIT4_X);
thr->bits4.set_vec(cp->bit_idx[0], tmp); thr->bits4.set_vec(bit_addr, tmp);
return true; return true;
} }
@ -3372,6 +3378,9 @@ bool of_JOIN_UFUNC(vthread_t thr, vvp_code_t cp)
/* /*
* $Log: vthread.cc,v $ * $Log: vthread.cc,v $
* Revision 1.159 2007/01/31 22:28:55 steve
* Fix missing check for thread bits width in ADDI
*
* Revision 1.158 2007/01/16 05:44:16 steve * Revision 1.158 2007/01/16 05:44:16 steve
* Major rework of array handling. Memories are replaced with the * Major rework of array handling. Memories are replaced with the
* more general concept of arrays. The NetMemory and NetEMemory * more general concept of arrays. The NetMemory and NetEMemory