Skip to content

Commit

Permalink
concat bitwidth issue corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Sep 29, 2024
1 parent 24dd329 commit 194f221
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
15 changes: 14 additions & 1 deletion chpgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,11 @@ static Expr *expr_to_chp_expr (Expr *e, ActSimCore *s, int *flags)
case E_COMPLEMENT:
ret->u.e.l = expr_to_chp_expr (e->u.e.l, s, flags);
{
phash_bucket_t *b;
int width;
act_type_expr (s->CurScope(), e->u.e.l, &width, 2);
ret->u.e.r = (Expr *) (long)width;
b = s->exprAddWidth (ret->u.e.l);
b->i = width;
}
break;

Expand All @@ -608,10 +610,21 @@ static Expr *expr_to_chp_expr (Expr *e, ActSimCore *s, int *flags)

case E_CONCAT:
{
/* this is interesting; we convert it to expr, bitwidth, expr,
bitwidth, ... pairs!
*/
Expr *tmp;
tmp = ret;
do {
phash_bucket_t *b;
tmp->u.e.l = expr_to_chp_expr (e->u.e.l, s, flags);
b = s->exprWidth (tmp->u.e.l);
if (!b) {
int width;
b = s->exprAddWidth (tmp->u.e.l);
act_type_expr (s->CurScope(), e->u.e.l, &width, 2);
b->i = width;
}
if (e->u.e.r) {
NEW (tmp->u.e.r, Expr);
tmp->u.e.r->type = e->u.e.r->type;
Expand Down
22 changes: 18 additions & 4 deletions chpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2717,16 +2717,24 @@ BigInt ChpSim::exprEval (Expr *e)
case E_NOT:
case E_COMPLEMENT:
l = exprEval (e->u.e.l);
if (l.getWidth() < ((long)e->u.e.r)) {
l.setWidth ((long)e->u.e.r);
{
phash_bucket_t *b;
b = _sc->exprWidth (e->u.e.l);
if (b) {
l.setWidth (b->i);
}
}
l = ~l;
break;

case E_UMINUS:
l = exprEval (e->u.e.l);
if (l.getWidth() < ((long)e->u.e.r)) {
l.setWidth ((long)e->u.e.r);
{
phash_bucket_t *b;
b = _sc->exprWidth (e->u.e.l);
if (b) {
l.setWidth (b->i);
}
}
l = -l;
l.toUnsigned ();
Expand Down Expand Up @@ -2756,7 +2764,13 @@ BigInt ChpSim::exprEval (Expr *e)
{
int first = 1;
do {
int width;
phash_bucket_t *b;
r = exprEval (e->u.e.l);
b = _sc->exprWidth (e->u.e.l);
if (b) {
r.setWidth (b->i);
}
if (first) {
l = r;
first = 0;
Expand Down
16 changes: 16 additions & 0 deletions test/107.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defproc test()
{
int<6> i, j;

int<12> k;

chp {
i := 1;
j := 7;
k := {j,i};
log ("%b got ", k);
k := {j,i+1};
log ("%b got ", k);
skip
}
}
1 change: 1 addition & 0 deletions test/runs/107.act.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WARNING: test<>: substituting chp model (requested prs, not found)
2 changes: 2 additions & 0 deletions test/runs/107.act.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ 30] <> got 000111000001
[ 40] <> got 001110000010

0 comments on commit 194f221

Please sign in to comment.