Right shift by constant.

This commit is contained in:
steve 2001-04-21 03:26:23 +00:00
parent 7c6f496765
commit 57b0d9691e
2 changed files with 91 additions and 8 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: eval_expr.c,v 1.18 2001/04/21 01:49:17 steve Exp $"
#ident "$Id: eval_expr.c,v 1.19 2001/04/21 03:26:23 steve Exp $"
#endif
# include "vvp_priv.h"
@ -314,13 +314,11 @@ static struct vector_info draw_binary_expr_ls(ivl_expr_t exp, unsigned wid)
ivl_expr_t le = ivl_expr_oper1(exp);
ivl_expr_t re = ivl_expr_oper2(exp);
unsigned shift;
unsigned shift = 0;
struct vector_info lv;
struct vector_info rs;
lv = draw_eval_expr_wid(le, wid);
/* XXXX support only constant right expressions. */
switch (ivl_expr_type(re)) {
case IVL_EX_NUMBER: {
@ -355,6 +353,8 @@ static struct vector_info draw_binary_expr_ls(ivl_expr_t exp, unsigned wid)
return rs;
}
lv = draw_eval_expr_wid(le, wid);
assert(lv.wid >= (wid - shift));
rs.base = allocate_vector(wid);
rs.wid = wid;
@ -367,6 +367,77 @@ static struct vector_info draw_binary_expr_ls(ivl_expr_t exp, unsigned wid)
return rs;
}
static struct vector_info draw_binary_expr_rs(ivl_expr_t exp, unsigned wid)
{
ivl_expr_t le = ivl_expr_oper1(exp);
ivl_expr_t re = ivl_expr_oper2(exp);
unsigned shift = 0;
struct vector_info lv;
struct vector_info rs;
/* XXXX support only constant right expressions. */
switch (ivl_expr_type(re)) {
case IVL_EX_NUMBER: {
unsigned idx, nbits = ivl_expr_width(re);
const char*bits = ivl_expr_bits(re);
for (idx = 0 ; idx < nbits ; idx += 1) switch (bits[idx]) {
case '0':
break;
case '1':
assert(idx < (8*sizeof shift));
shift |= 1 << idx;
break;
default:
assert(0);
}
break;
}
case IVL_EX_ULONG:
shift = ivl_expr_uvalue(re);
break;
default:
assert(0);
break;
}
if (shift >= wid) {
rs.base = 0;
rs.wid = wid;
return rs;
}
lv = draw_eval_expr_wid(le, wid);
switch (lv.base) {
case 0:
return lv;
case 1:
case 2:
case 3:
rs.base = allocate_vector(wid);
rs.wid = wid;
fprintf(vvp_out, " %%mov %u, %u, %u;\n", rs.base,
lv.base, wid-shift);
fprintf(vvp_out, " %%mov %u, 0, %u;\n",
rs.base+wid-shift, shift);
return rs;
default:
assert(lv.wid == wid);
fprintf(vvp_out, " %%mov %u, %u, %u;\n", lv.base,
lv.base+shift, wid-shift);
fprintf(vvp_out, " %%mov %u, 0, %u;\n",
lv.base+wid-shift, shift);
return lv;
}
}
static struct vector_info draw_binary_expr_plus(ivl_expr_t exp, unsigned wid)
{
ivl_expr_t le = ivl_expr_oper1(exp);
@ -416,10 +487,14 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid)
rv = draw_binary_expr_plus(exp, wid);
break;
case 'l':
case 'l': /* << */
rv = draw_binary_expr_ls(exp, wid);
break;
case 'r': /* >> */
rv = draw_binary_expr_rs(exp, wid);
break;
case '&':
case '|':
case '^':
@ -732,6 +807,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp)
/*
* $Log: eval_expr.c,v $
* Revision 1.19 2001/04/21 03:26:23 steve
* Right shift by constant.
*
* Revision 1.18 2001/04/21 01:49:17 steve
* Left shift by a constant amount.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vvp_process.c,v 1.29 2001/04/21 00:55:46 steve Exp $"
#ident "$Id: vvp_process.c,v 1.30 2001/04/21 03:26:23 steve Exp $"
#endif
# include "vvp_priv.h"
@ -141,8 +141,10 @@ static int show_stmt_assign(ivl_statement_t net)
if (ivl_lval_pins(lval) < wid)
wid = ivl_lval_pins(lval);
for (idx = 0 ; idx < wid ; idx += 1)
set_to_nexus(ivl_lval_pin(lval, idx), res.base+idx);
for (idx = 0 ; idx < wid ; idx += 1) {
unsigned bidx = res.base < 4? res.base : (res.base+idx);
set_to_nexus(ivl_lval_pin(lval, idx), bidx);
}
for (idx = wid ; idx < ivl_lval_pins(lval) ; idx += 1)
set_to_nexus(ivl_lval_pin(lval, idx), 0);
@ -749,6 +751,9 @@ int draw_func_definition(ivl_scope_t scope)
/*
* $Log: vvp_process.c,v $
* Revision 1.30 2001/04/21 03:26:23 steve
* Right shift by constant.
*
* Revision 1.29 2001/04/21 00:55:46 steve
* Generate code for disable.
*