Skip to content

Commit

Permalink
started work on cause ids
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanohar committed Aug 5, 2024
1 parent 1ad5ad6 commit be18acb
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
2 changes: 1 addition & 1 deletion actsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class ActSimDES : public SimDES {
virtual void sPrintCause (char *buf, int sz) {
buf[0] = '\0';
}

virtual int causeGlobalIdx() { return -1; }
};

class ActSimObj;
Expand Down
22 changes: 20 additions & 2 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,27 @@ static void usage (char *name)
exit (1);
}

class DummyObject : public ActSimDES {
public:
DummyObject() { gid = -1; };
~DummyObject() { };

int Step (Event *ev) { return 1; }
void computeFanout() { }
int causeGlobalIdx() { return gid; }
void setGid(int id) { gid = id; }
void sPrintCause(char *buf, int sz) { snprintf (buf, sz, "-cmd-"); }

private:
int gid;
};


static ActStatePass *glob_sp;
ActSim *glob_sim;
static Act *glob_act;
static Process *glob_top;
DummyObject *glob_dummy;

int is_rand_excl()
{
Expand Down Expand Up @@ -696,7 +713,6 @@ static int id_to_siminfo_glob_raw (char *s,
}



int process_set (int argc, char **argv)
{
if (argc != 3) {
Expand Down Expand Up @@ -785,10 +801,11 @@ int process_set (int argc, char **argv)

SimDES **arr;
arr = glob_sim->getFO (offset, type);
glob_dummy->setGid (offset);
for (int i=0; i < glob_sim->numFanout (offset, type); i++) {
ActSimDES *p = dynamic_cast <ActSimDES *> (arr[i]);
Assert (p, "Hmm?");
p->propagate ();
p->propagate (glob_dummy);
}
return LISP_RET_TRUE;
}
Expand Down Expand Up @@ -1690,6 +1707,7 @@ int main (int argc, char **argv)
glob_sp->run (p);

glob_sim = new ActSim (p);
glob_dummy = new DummyObject ();
glob_sim->runInit ();
ActExclConstraint::_sc = glob_sim;

Expand Down
49 changes: 38 additions & 11 deletions prssim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,30 +572,37 @@ static const int _or_table[3][3] = { { 0, 1, 2 },
#define PENDING_1 (1+1)
#define PENDING_X (1+2)

int OnePrsSim::eval (prssim_expr *x)
int OnePrsSim::eval (prssim_expr *x, int cause, int *lid)
{
int a, b;
if (!x) { return 0; }
switch (x->type) {
case PRSSIM_EXPR_AND:
a = eval (x->l);
b = eval (x->r);
a = eval (x->l, cause, lid);
b = eval (x->r, cause, lid);
return _and_table[a][b];
break;

case PRSSIM_EXPR_OR:
a = eval (x->l);
b = eval (x->r);
a = eval (x->l, cause, lid);
b = eval (x->r, cause, lid);
return _or_table[a][b];
break;

case PRSSIM_EXPR_NOT:
a = eval (x->l);
a = eval (x->l, cause, lid);
return _not_table[a];
break;

case PRSSIM_EXPR_VAR:
return _proc->getBool (x->vid);
{
int gid;
int ret = _proc->getBool (x->vid, &gid);
if (gid == cause) {
*lid = x->vid;
}
return ret;
}
break;

case PRSSIM_EXPR_TRUE:
Expand Down Expand Up @@ -668,6 +675,8 @@ int OnePrsSim::Step (Event *ev)
*/
if (t == 2 /* X */ && flags == PENDING_NONE) {
int u_state, d_state, u_weak, d_weak;
u_weak = 0;
d_weak = 0;
u_state = eval (_me->up[PRSSIM_NORM]);
if (u_state == 0) {
u_state = eval (_me->up[PRSSIM_WEAK]);
Expand Down Expand Up @@ -780,6 +789,16 @@ void OnePrsSim::propagate (void *cause)
{
int u_state, d_state;
int u_weak = 0, d_weak = 0;
int lid = -1;
int causeid;

if (cause) {
ActSimDES *xx = (ActSimDES *) cause;
causeid = xx->causeGlobalIdx ();
}
else {
causeid = -1;
}

/*-- fire rule --*/
switch (_me->type) {
Expand Down Expand Up @@ -853,17 +872,20 @@ void OnePrsSim::propagate (void *cause)

case PRSSIM_RULE:
/* evaluate up, up-weak and dn, dn-weak */
u_state = eval (_me->up[PRSSIM_NORM]);
u_state = eval (_me->up[PRSSIM_NORM], causeid, causeid == -1 ? NULL : &lid);
if (u_state == 0) {
u_state = eval (_me->up[PRSSIM_WEAK]);
u_state = eval (_me->up[PRSSIM_WEAK], causeid,
causeid == -1 ? NULL : &lid);
if (u_state != 0) {
u_weak = 1;
}
}

d_state = eval (_me->dn[PRSSIM_NORM]);
d_state = eval (_me->dn[PRSSIM_NORM], causeid,
causeid == -1 ? NULL : &lid);
if (d_state == 0) {
d_state = eval (_me->dn[PRSSIM_WEAK]);
d_state = eval (_me->dn[PRSSIM_WEAK], causeid,
causeid == -1 ? NULL : &lid);
if (d_state != 0) {
d_weak = 1;
}
Expand Down Expand Up @@ -1297,3 +1319,8 @@ void OnePrsSim::sPrintCause (char *buf, int sz)
int cv = _proc->getBool (_me->vid);
snprintf (buf + pos, sz, " <- %c", (cv == 2 ? 'X' : ((char)cv + '0')));
}

int OnePrsSim::causeGlobalIdx ()
{
return _proc->getGlobalOffset (_me->vid, 0);
}
34 changes: 24 additions & 10 deletions prssim.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,31 @@ class PrsSim : public ActSimObj {

void computeFanout ();

int getBool (int lid) { int off = getGlobalOffset (lid, 0); return _sc->getBool (off); }
int isSpecialBool (int lid) { int off = getGlobalOffset (lid, 0); return _sc->isSpecialBool (off); }

bool isHazard (int lid) { int off = getGlobalOffset (lid, 0); return _sc->isHazard (off); }
int getBool (int lid, int *gid = NULL) {
int off = getGlobalOffset (lid, 0);
if (gid) {
*gid = off;
}
return _sc->getBool (off);
}

int isSpecialBool (int lid) {
int off = getGlobalOffset (lid, 0);
return _sc->isSpecialBool (off);
}

bool isHazard (int lid) {
int off = getGlobalOffset (lid, 0);
return _sc->isHazard (off);
}

int myGid (int lid) { return getGlobalOffset (lid, 0); }


/*
me, cause are both used for cause tracing
*/
bool setBool (int lid, int v, OnePrsSim *me, ActSimObj *cause = NULL);

void printName (FILE *fp, int lid);
void sPrintName (char *buf, int sz, int lid);

Expand All @@ -133,10 +150,6 @@ class PrsSim : public ActSimObj {
private:
void _computeFanout (prssim_expr *, SimDES *);

void varSet (int id, int type, BigInt &v);
int varSend (int pc, int wakeup, int id, BigInt &v);
int varRecv (int pc, int wakeup, int id, BigInt *v);

PrsSimGraph *_g;
list_t *_sim; // simulation objects
};
Expand All @@ -148,7 +161,7 @@ class OnePrsSim : public ActSimDES {
PrsSim *_proc; // process core [maps, etc]
struct prssim_stmt *_me; // the rule
Event *_pending;
int eval (prssim_expr *);
int eval (prssim_expr *, int cause_id = -1, int *lid = NULL);

public:
OnePrsSim (PrsSim *p, struct prssim_stmt *x);
Expand All @@ -161,6 +174,7 @@ class OnePrsSim : public ActSimDES {
int isPending() { return _pending == NULL ? 0 : 1; }

void sPrintCause (char *buf, int sz);
int causeGlobalIdx ();
};


Expand Down

0 comments on commit be18acb

Please sign in to comment.