Skip to content

Commit

Permalink
for more complex channels
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Feb 9, 2023
1 parent ad6ce7d commit aee987a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
6 changes: 4 additions & 2 deletions channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,10 @@ act_channel_state::act_channel_state(expr_multires &vinit)
w = new WaitForOne(0);
probe = NULL;
fragmented = 0;
frag_st = 0;
ufrag_st = 0;
sfrag_st = 0;
sufrag_st = 0;
rfrag_st = 0;
rufrag_st = 0;
ct = NULL;
fH = NULL;
cm = NULL;
Expand Down
7 changes: 5 additions & 2 deletions channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ struct act_channel_state {



unsigned int frag_st:2; // send/recv, send_up/recv_up, or
unsigned int sfrag_st:2; // send/recv, send_up/recv_up, or
// send_rest/recv_rest
unsigned int ufrag_st:8; // micro-state within frag state
unsigned int rfrag_st:2; // send/recv, send_up/recv_up, or
// send_rest/recv_rest
unsigned int sufrag_st:8; // micro-state within frag state
unsigned int rufrag_st:8; // micro-state within frag state

unsigned int use_flavors:1; // 1 if !+/!- are in use
unsigned int send_flavor:1; // state of send flavor
Expand Down
89 changes: 63 additions & 26 deletions chpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1644,62 +1644,79 @@ int ChpSim::varSend (int pc, int wakeup, int id, int off, int flavor,
}

if (c->fragmented) {
#if 0
printf ("[send %p] fragmented; in-st: %d / %d; wake-up: %d\n", c,
c->sfrag_st, c->sufrag_st, wakeup);
#endif
*frag = 1;
if (c->frag_st == 0) {
if (c->sfrag_st == 0) {
c->data = v;
c->frag_st = 1;
c->ufrag_st = 0;
c->sfrag_st = 1;
c->sufrag_st = 0;
}

if (_sc->isResetMode()) {
list_iappend (_stalled_pc, pc);
sStall ();
#if 0
printf ("[send %p] stall\n", c);
#endif
return 1;
}

while (c->ufrag_st >= 0) {
while (c->sufrag_st >= 0) {
int idx;
if (c->frag_st == 1) {
if (c->sfrag_st == 1) {
idx = ACT_METHOD_SET;
}
else if (c->frag_st == 2) {
else if (c->sfrag_st == 2) {
idx = ACT_METHOD_SEND_UP;
}
else if (c->frag_st == 3) {
else if (c->sfrag_st == 3) {
idx = ACT_METHOD_SEND_REST;
}
else {
/* finished protocol */
c->frag_st = 0;
c->sfrag_st = 0;
if (bidir) {
*xchg = c->data2;
}
c->count++;
#if 0
printf ("[send %p] done\n", c);
#endif
return 0;
}
c->ufrag_st = c->cm->runMethod (_sc, c, idx, c->ufrag_st);
if (c->ufrag_st == 0xff) { /* -1 */
c->frag_st++;
c->ufrag_st = 0;
c->sufrag_st = c->cm->runMethod (_sc, c, idx, c->sufrag_st);
if (c->sufrag_st == 0xff) { /* -1 */
c->sfrag_st++;
c->sufrag_st = 0;

/* if flavors, then we are done half way as well */
if (c->use_flavors && c->send_flavor == 1) {
if (c->frag_st == 3) {
if (c->sfrag_st == 3) {
if (bidir) {
*xchg = c->data2;
}
c->count++;
#if 0
printf ("[send %p] done\n", c);
#endif
return 0;
}
}
}
else {
list_iappend (_stalled_pc, pc);
sStall ();
#if 0
printf ("[send %p] stall\n", c);
#endif
return 1;
}
}
}
Assert (!c->fragmented, "Hmm");
*frag = 0;

#ifdef DUMP_ALL
Expand Down Expand Up @@ -1831,44 +1848,60 @@ int ChpSim::varRecv (int pc, int wakeup, int id, int off, int flavor,


if (c->fragmented) {
#if 0
printf ("[recv %p] fragmented; in-st: %d / %d\n", c,
c->rfrag_st, c->rufrag_st);
#endif
*frag = 1;
if (c->frag_st == 0) {
if (c->rfrag_st == 0) {
if (bidir) {
c->data2 = xchg;
}
c->frag_st = 1;
c->ufrag_st = 0;
c->rfrag_st = 1;
c->rufrag_st = 0;
}

if (_sc->isResetMode()) {
list_iappend (_stalled_pc, pc);
sStall ();
#if 0
printf ("[recv %p] stall\n", c);
#endif
return 1;
}

while (c->ufrag_st >= 0) {
while (c->rufrag_st >= 0) {
int idx;
if (c->frag_st == 1) {
if (c->rfrag_st == 1) {
idx = ACT_METHOD_GET;
}
else if (c->frag_st == 2) {
else if (c->rfrag_st == 2) {
idx = ACT_METHOD_RECV_UP;
}
else if (c->frag_st == 3) {
else if (c->rfrag_st == 3) {
idx = ACT_METHOD_RECV_REST;
}
else {
/* finished protocol */
c->frag_st = 0;
#if 0
printf ("[recv %p] done\n", c);
#endif
c->rfrag_st = 0;
(*v) = c->data;
return 0;
}
c->ufrag_st = c->cm->runMethod (_sc, c, idx, c->ufrag_st);
if (c->ufrag_st == 0xff) { /* -1 */
c->frag_st++;
c->ufrag_st = 0;
#if 0
printf ("[recv %p] run method %d\n", c, idx);
#endif
c->rufrag_st = c->cm->runMethod (_sc, c, idx, c->rufrag_st);
if (c->rufrag_st == 0xff) { /* -1 */
c->rfrag_st++;
c->rufrag_st = 0;
if (c->use_flavors && c->recv_flavor == 1) {
if (c->frag_st == 3) {
if (c->rfrag_st == 3) {
#if 0
printf ("[recv %p] done\n", c);
#endif
(*v) = c->data;
return 0;
}
Expand All @@ -1877,10 +1910,14 @@ int ChpSim::varRecv (int pc, int wakeup, int id, int off, int flavor,
else {
list_iappend (_stalled_pc, pc);
sStall ();
#if 0
printf ("[recv %p] stall\n", c);
#endif
return 1;
}
}
}
Assert (!c->fragmented, "What?");

*frag = 0;

Expand Down
2 changes: 2 additions & 0 deletions prssim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ void PrsSimGraph::_add_one_gate (ActSimCore *sc, act_prs_lang_t *p)
struct prssim_stmt *s;
NEW (s, struct prssim_stmt);
s->next = NULL;
s->delay_up = 10;
s->delay_dn = 10;
if (p->u.p.g) {
if (p->u.p._g) {
s->type = PRSSIM_TGATE;
Expand Down

0 comments on commit aee987a

Please sign in to comment.