void bdd_unmark(int i) { BddNode *node; if (i < 2) return; node = &bddnodes[i]; if (!MARKEDp(node) || LOWp(node) == INVALID_BDD) return; UNMARKp(node); bdd_unmark(LOWp(node)); bdd_unmark(HIGHp(node)); }
void bdd_fprinttable(FILE *ofile, BDD r) { BddNode *node; int n; fprintf(ofile, "ROOT: %d\n", r); if (r < 2) return; bdd_mark(r); for (n=0 ; n<bddnodesize ; n++) { if (MARKED(n)) { node = &bddnodes[n]; UNMARKp(node); fprintf(ofile, "[%5d] ", n); if (filehandler) filehandler(ofile, bddlevel2var[LEVELp(node)]); else fprintf(ofile, "%3d", bddlevel2var[LEVELp(node)]); fprintf(ofile, ": %3d", LOWp(node)); fprintf(ofile, " %3d", HIGHp(node)); fprintf(ofile, "\n"); } } }
void bdd_mark(int i) { BddNode *node; if (__unlikely(i < 2)) return; node = &bddnodes[i]; if (LEVELp(node) & MARKON || LOWp(node) == -1) return; LEVELp(node) |= MARKON; bdd_mark(LOWp(node)); bdd_mark(HIGHp(node)); }
void bdd_markcount(int i, int *cou) { BddNode *node; if (i < 2) return; node = &bddnodes[i]; if (MARKEDp(node) || LOWp(node) == -1) return; SETMARKp(node); *cou += 1; bdd_markcount(LOWp(node), cou); bdd_markcount(HIGHp(node), cou); }
void bdd_markshape(int i, int shape[]) { BddNode *node; if (i < 2) return; node = &bddnodes[i]; if (MARKEDp(node) || LOWp(node) == -1) return; shape[LEVELp(node)]++; SETMARKp(node); bdd_markshape(LOWp(node), shape); bdd_markshape(HIGHp(node), shape); }
void bdd_mark_upto(int i, int level) { BddNode *node = &bddnodes[i]; if (i < 2) return; if (LEVELp(node) & MARKON || LOWp(node) == -1) return; if (LEVELp(node) > level) return; LEVELp(node) |= MARKON; bdd_mark_upto(LOWp(node), level); bdd_mark_upto(HIGHp(node), level); }
void bdd_mark_upto(int i, int level) { BddNode *node = &bddnodes[i]; if (i < 2) return; if (MARKEDp(node) || LOWp(node) == INVALID_BDD) return; if (LEVELp(node) > level) return; SETMARKp(node); bdd_mark_upto(LOWp(node), level); bdd_mark_upto(HIGHp(node), level); }
static int bdd_save_rec(FILE *ofile, int root) { BddNode *node = &bddnodes[root]; int err; if (root < 2) return 0; if (LEVELp(node) & MARKON) return 0; LEVELp(node) |= MARKON; if ((err=bdd_save_rec(ofile, LOWp(node))) < 0) return err; if ((err=bdd_save_rec(ofile, HIGHp(node))) < 0) return err; fprintf(ofile, "%d %d %d %d\n", root, bddlevel2var[LEVELp(node) & MARKHIDE], LOWp(node), HIGHp(node)); return 0; }
void bdd_unmark_upto(int i, int level) { BddNode *node = &bddnodes[i]; if (i < 2) return; if (!(LEVELp(node) & MARKON)) return; LEVELp(node) &= MARKOFF; if (LEVELp(node) > level) return; bdd_unmark_upto(LOWp(node), level); bdd_unmark_upto(HIGHp(node), level); }
void bdd_unmark_upto(int i, int level) { BddNode *node = &bddnodes[i]; if (i < 2) return; if (!MARKEDp(node)) return; UNMARKp(node); if (LEVELp(node) > level) return; bdd_unmark_upto(LOWp(node), level); bdd_unmark_upto(HIGHp(node), level); }
int bdd_makenode(unsigned int level, int low, int high) { register BddNode *node; register unsigned int hash; register int res; #ifdef CACHESTATS bddcachestats.uniqueAccess++; #endif /* check whether childs are equal */ if (low == high) return low; /* Try to find an existing node of this kind */ hash = NODEHASH(level, low, high); res = bddnodes[hash].hash; while(res != 0) { if (LEVEL(res) == level && LOW(res) == low && HIGH(res) == high) { #ifdef CACHESTATS bddcachestats.uniqueHit++; #endif return res; } res = bddnodes[res].next; #ifdef CACHESTATS bddcachestats.uniqueChain++; #endif } /* No existing node -> build one */ #ifdef CACHESTATS bddcachestats.uniqueMiss++; #endif /* Any free nodes to use ? */ if (bddfreepos == 0) { if (bdderrorcond) return 0; /* Try to allocate more nodes */ bdd_gbc(); if ((bddnodesize-bddfreenum) >= usednodes_nextreorder && bdd_reorder_ready()) { longjmp(bddexception,1); } if ((bddfreenum*100) / bddnodesize <= minfreenodes) { bdd_noderesize(1); hash = NODEHASH(level, low, high); } /* Panic if that is not possible */ if (bddfreepos == 0) { bdd_error(BDD_NODENUM); bdderrorcond = abs(BDD_NODENUM); return 0; } } /* Build new node */ res = bddfreepos; bddfreepos = bddnodes[bddfreepos].next; bddfreenum--; bddproduced++; node = &bddnodes[res]; LEVELp(node) = level; LOWp(node) = low; HIGHp(node) = high; /* Insert node */ node->next = bddnodes[hash].hash; bddnodes[hash].hash = res; return res; }
void bdd_gbc(void) { int *r; int n; long int c2, c1 = clock(); if (gbc_handler != NULL) { bddGbcStat s; s.nodes = bddnodesize; s.freenodes = bddfreenum; s.time = 0; s.sumtime = gbcclock; s.num = gbcollectnum; gbc_handler(1, &s); } for (r=bddrefstack ; r<bddrefstacktop ; r++) bdd_mark(*r); for (n=0 ; n<bddnodesize ; n++) { if (bddnodes[n].refcou > 0) bdd_mark(n); bddnodes[n].hash = 0; } bddfreepos = 0; bddfreenum = 0; for (n=bddnodesize-1 ; n>=2 ; n--) { register BddNode *node = &bddnodes[n]; if ((LEVELp(node) & MARKON) && LOWp(node) != -1) { register unsigned int hash; LEVELp(node) &= MARKOFF; hash = NODEHASH(LEVELp(node), LOWp(node), HIGHp(node)); node->next = bddnodes[hash].hash; bddnodes[hash].hash = n; } else { LOWp(node) = -1; node->next = bddfreepos; bddfreepos = n; bddfreenum++; } } bdd_operator_reset(); c2 = clock(); gbcclock += c2-c1; gbcollectnum++; if (gbc_handler != NULL) { bddGbcStat s; s.nodes = bddnodesize; s.freenodes = bddfreenum; s.time = c2-c1; s.sumtime = gbcclock; s.num = gbcollectnum; gbc_handler(0, &s); } }
void bdd_gbc(void) { int *r; int n; long int c2, c1 = clock(); if (gbc_handler != NULL) { bddGbcStat s; s.nodes = bddnodesize; s.freenodes = bddfreenum; s.time = 0; s.sumtime = gbcclock; s.num = gbcollectnum; gbc_handler(1, &s); } for (r=bddrefstack ; r<bddrefstacktop ; r++) bdd_mark(*r); for (n=0 ; n<bddnodesize ; n++) { if (HASREF(n)) bdd_mark(n); SETHASH(n, 0); } bddfreepos = 0; bddfreenum = 0; for (n=bddnodesize-1 ; n>=2 ; n--) { register BddNode *node = &bddnodes[n]; if (MARKEDp(node) && LOWp(node) != INVALID_BDD) { register unsigned int hash; UNMARKp(node); hash = NODEHASH(LEVELp(node), LOWp(node), HIGHp(node)); SETNEXTp(node, HASH(hash)); SETHASH(hash, n); } else { SETLOWpz(node, INVALID_BDD); // obliterates refcount SETNEXTpz(node, bddfreepos); // obliterates lev, mark bddfreepos = n; bddfreenum++; } } bdd_operator_reset(); c2 = clock(); gbcclock += c2-c1; gbcollectnum++; if (gbc_handler != NULL) { bddGbcStat s; s.nodes = bddnodesize; s.freenodes = bddfreenum; s.time = c2-c1; s.sumtime = gbcclock; s.num = gbcollectnum; gbc_handler(0, &s); } }