From 80598b1080591d523d5fa496bf221969d959e8de Mon Sep 17 00:00:00 2001 From: Rajit Manohar Date: Fri, 2 Jun 2023 11:32:51 -0400 Subject: [PATCH] thread vs array size fix --- chpsim.cc | 40 ++++++++++++++++++++++------------------ test/99.act | 7 +++++++ test/runs/99.act.stderr | 1 + test/runs/99.act.stdout | 1 + 4 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 test/99.act create mode 100644 test/runs/99.act.stderr create mode 100644 test/runs/99.act.stdout diff --git a/chpsim.cc b/chpsim.cc index d08298c..1bdcd15 100644 --- a/chpsim.cc +++ b/chpsim.cc @@ -1154,28 +1154,23 @@ int ChpSim::Step (Event *ev) int idx; ChpSimGraph *g = _pc[pc]; for (int i=0; i < stmt->u.fork; i++) { - if (first) { - idx = pc; - first = 0; - } - else { - Assert (_pcused < _npc, "What?"); - idx = _holes[_pcused++]; - _holes[_pcused-1] = -1; - count++; - } - _pc[idx] = g->all[i]; if (g->all[i]) { -#if 0 + if (first) { + idx = pc; + first = 0; + } + else { + Assert (_pcused < _npc, "What?"); + idx = _holes[_pcused++]; + _holes[_pcused-1] = -1; + count++; + } + _pc[idx] = g->all[i]; +#if 0 printf (" idx:%d", idx); #endif _nextEvent (idx, bw_cost); } - else { - Assert (_pcused > 0, "What?"); - _holes[_pcused-1] = idx; - _pcused--; - } } //_pcused += stmt->u.fork - 1; #ifdef DUMP_ALL @@ -4627,6 +4622,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc, int tmp; int width; int used_slots = 0; + ChpSimGraph *ostop; if (!c) return NULL; @@ -4666,6 +4662,7 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc, (act_chp_lang_t *)list_value (list_first (c->u.semi_comma.cmd)), stop); } ret = new ChpSimGraph (sc); + ostop = *stop; *stop = new ChpSimGraph (sc); tmp = cur_pending_count++; if (cur_pending_count > max_pending_count) { @@ -4694,10 +4691,17 @@ ChpSimGraph *ChpSimGraph::_buildChpSimGraph (ActSimCore *sc, ret->stmt->energy_cost = 0; ret->stmt->bw_cost = 0; ret->stmt->type = CHPSIM_FORK; - ret->stmt->u.fork = count; + ret->stmt->u.fork = i; (*stop)->wait = count; (*stop)->totidx = tmp; } + else { + FREE (ret->all); + FREE (ret); + FREE (*stop); + *stop = ostop; + ret = NULL; + } break; case ACT_CHP_SELECT: diff --git a/test/99.act b/test/99.act new file mode 100644 index 0000000..e9ee7dd --- /dev/null +++ b/test/99.act @@ -0,0 +1,7 @@ +defproc test() +{ + int x, y; + chp { + (x := 1, skip, y:= 2); log ("got hi") + } +} diff --git a/test/runs/99.act.stderr b/test/runs/99.act.stderr new file mode 100644 index 0000000..78d54cb --- /dev/null +++ b/test/runs/99.act.stderr @@ -0,0 +1 @@ +WARNING: test<>: substituting chp model (requested prs, not found) diff --git a/test/runs/99.act.stdout b/test/runs/99.act.stdout new file mode 100644 index 0000000..8dcf1dd --- /dev/null +++ b/test/runs/99.act.stdout @@ -0,0 +1 @@ +[ 10] <> got hi