From 8e30bc9f9e68940b32e0639711f2e7ec990e2e42 Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 22 Nov 2002 00:01:50 +0000 Subject: [PATCH] Careful of left operands to shift that are constant. --- tgt-vvp/eval_expr.c | 31 ++++++++++++++++++++++++++++++- vvp/vthread.cc | 7 ++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index d382596e5..caf75fc40 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: eval_expr.c,v 1.85 2002/11/21 22:42:48 steve Exp $" +#ident "$Id: eval_expr.c,v 1.86 2002/11/22 00:01:50 steve Exp $" #endif # include "vvp_priv.h" @@ -666,6 +666,19 @@ static struct vector_info draw_binary_expr_lrs(ivl_expr_t exp, unsigned wid) case 'l': /* << (left shift) */ lv = draw_eval_expr_wid(le, wid, 0); + + /* shifting 0 gets 0. */ + if (lv.base == 0) + break; + + if (lv.base < 4) { + struct vector_info tmp; + tmp.base = allocate_vector(lv.wid); + tmp.wid = lv.wid; + fprintf(vvp_out, " %%mov %u, %u, %u;\n", + tmp.base, lv.base, lv.wid); + lv = tmp; + } fprintf(vvp_out, " %%shiftl/i0 %u, %u;\n", lv.base, lv.wid); break; @@ -680,6 +693,19 @@ static struct vector_info draw_binary_expr_lrs(ivl_expr_t exp, unsigned wid) } else { lv = draw_eval_expr_wid(le, ivl_expr_width(le), 0); } + + /* shifting 0 gets 0. */ + if (lv.base == 0) + break; + + if (lv.base < 4) { + struct vector_info tmp; + tmp.base = allocate_vector(lv.wid); + tmp.wid = lv.wid; + fprintf(vvp_out, " %%mov %u, %u, %u;\n", + tmp.base, lv.base, lv.wid); + lv = tmp; + } fprintf(vvp_out, " %%shiftr/i0 %u, %u;\n", lv.base, lv.wid); break; @@ -1937,6 +1963,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp, int stuff_ok_flag) /* * $Log: eval_expr.c,v $ + * Revision 1.86 2002/11/22 00:01:50 steve + * Careful of left operands to shift that are constant. + * * Revision 1.85 2002/11/21 22:42:48 steve * Allow right values of right shift to shift in. * diff --git a/vvp/vthread.cc b/vvp/vthread.cc index a58c4eccd..91e24e6ed 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: vthread.cc,v 1.94 2002/11/21 22:43:14 steve Exp $" +#ident "$Id: vthread.cc,v 1.95 2002/11/22 00:01:50 steve Exp $" #endif # include "vthread.h" @@ -2221,6 +2221,8 @@ bool of_SHIFTL_I0(vthread_t thr, vvp_code_t cp) unsigned wid = cp->number; unsigned long shift = thr->index[0]; + assert(base >= 4); + if (shift >= wid) { for (unsigned idx = 0 ; idx < wid ; idx += 1) thr_put_bit(thr, base+idx, 0); @@ -2494,6 +2496,9 @@ bool of_CALL_UFUNC(vthread_t thr, vvp_code_t cp) /* * $Log: vthread.cc,v $ + * Revision 1.95 2002/11/22 00:01:50 steve + * Careful of left operands to shift that are constant. + * * Revision 1.94 2002/11/21 22:43:14 steve * %set/x0 instruction to support bounds checking. *