Ejemplo n.º 1
0
/*
NAME   {* bdd\_init *}
SECTION {* kernel *}
SHORT  {* initializes the BDD package *}
PROTO  {* int bdd_init(int nodesize, int cachesize) *}
DESCR  {* This function initiates the bdd package and {\em must} be called
          before any bdd operations are done. The argument {\tt nodesize}
	  is the initial number of nodes in the nodetable and {\tt cachesize}
	  is the fixed size of the internal caches. Typical values for
	  {\tt nodesize} are 10000 nodes for small test examples and up to
	  1000000 nodes for large examples. A cache size of 10000 seems to
	  work good even for large examples, but lesser values should do it
	  for smaller examples.

	  The number of cache entries can also be set to depend on the size
	  of the nodetable using a call to {\tt bdd\_setcacheratio}.
	  
	  The initial number of nodes is not critical for any bdd operation
	  as the table will be resized whenever there are to few nodes left
	  after a garbage collection. But it does have some impact on the
	  efficency of the operations. *}
RETURN {* If no errors occur then 0 is returned, otherwise
          a negative error code. *}
ALSO   {* bdd\_done, bdd\_resize\_hook *}
*/
int bdd_init(int initnodesize, int cs)
{
   int n, err;
   
   if (bddrunning)
      return bdd_error(BDD_RUNNING);
   
   bddnodesize = bdd_prime_gte(initnodesize);
   
   if ((bddnodes=(BddNode*)malloc(sizeof(BddNode)*bddnodesize)) == NULL)
      return bdd_error(BDD_MEMORY);

   bddresized = 0;
   
   for (n=0 ; n<bddnodesize ; n++)
   {
      bddnodes[n].refcou = 0;
      LOW(n) = -1;
      bddnodes[n].hash = 0;
      LEVEL(n) = 0;
      bddnodes[n].next = n+1;
   }
   bddnodes[bddnodesize-1].next = 0;

   bddnodes[0].refcou = bddnodes[1].refcou = MAXREF;
   LOW(0) = HIGH(0) = 0;
   LOW(1) = HIGH(1) = 1;
   
   if ((err=bdd_operator_init(cs)) < 0)
   {
      bdd_done();
      return err;
   }

   bddfreepos = 2;
   bddfreenum = bddnodesize-2;
   bddrunning = 1;
   bddvarnum = 0;
   gbcollectnum = 0;
   gbcclock = 0;
   cachesize = cs;
   usednodes_nextreorder = bddnodesize;
   bddmaxnodeincrease = DEFAULTMAXNODEINC;

   bdderrorcond = 0;
   
   bddcachestats.uniqueAccess = 0;
   bddcachestats.uniqueChain = 0;
   bddcachestats.uniqueHit = 0;
   bddcachestats.uniqueMiss = 0;
   bddcachestats.opHit = 0;
   bddcachestats.opMiss = 0;
   bddcachestats.swapCount = 0;
 
   bdd_gbc_hook(bdd_default_gbchandler);
   bdd_error_hook(bdd_default_errhandler);
   bdd_resize_hook(NULL);
   bdd_pairs_init();
   bdd_reorder_init();
   bdd_fdd_init();
   
   if (setjmp(bddexception) != 0)
      assert(0);

   return 0;
}
Ejemplo n.º 2
0
/*
NAME   {* bdd\_init *}
SECTION {* kernel *}
SHORT  {* initializes the BDD package *}
PROTO  {* int bdd_init(int nodesize, int cachesize) *}
DESCR  {* This function initiates the bdd package and {\em must} be called
          before any bdd operations are done. The argument {\tt nodesize}
	  is the initial number of nodes in the nodetable and {\tt cachesize}
	  is the fixed size of the internal caches. Typical values for
	  {\tt nodesize} are 10000 nodes for small test examples and up to
	  1000000 nodes for large examples. A cache size of 10000 seems to
	  work good even for large examples, but lesser values should do it
	  for smaller examples.

	  The number of cache entries can also be set to depend on the size
	  of the nodetable using a call to {\tt bdd\_setcacheratio}.
	  
	  The initial number of nodes is not critical for any bdd operation
	  as the table will be resized whenever there are to few nodes left
	  after a garbage collection. But it does have some impact on the
	  efficency of the operations. *}
RETURN {* If no errors occur then 0 is returned, otherwise
          a negative error code. *}
ALSO   {* bdd\_done, bdd\_resize\_hook *}
*/
int bdd_init(int initnodesize, int cs)
{
   /* Check to see if tracing is enabled */
   char * str;
   if( (str = getenv("BUDDY_TRACE_FILE")) != NULL) {
     trace_enable = 1;
     trace_init(str);
   }

   {
     int n, err;
     BUDDY_PROLOGUE;
     ADD_ARG1(T_INT,initnodesize);
     ADD_ARG1(T_INT,cs);
     
     srand48( SRAND48SEED ) ;
     
     if (bddrunning)
       RETURN(bdd_error(BDD_RUNNING));
     
     bddnodesize = bdd_prime_gte(initnodesize);
     
     if ((MAX_ALLOC_NODES == 0) ||
	 (alloced=(BddNode*)malloc(sizeof(BddNode)*MAX_ALLOC_NODES)) == NULL) {
       if ((alloced=(BddNode*)malloc(sizeof(BddNode)*bddnodesize)) == NULL) {
	 RETURN(bdd_error(BDD_MEMORY));
       }
       MAX_ALLOC_NODES = bddnodesize;
     }
     bddnodes = alloced;
     
     bddresized = 0;
     
     for (n=0 ; n<bddnodesize ; n++) {
       INIT_NODE(n);
     }
     SETNEXT(bddnodesize-1, 0);
     
     SETMAXREF(0);
     SETMAXREF(1);
     SETLOW(0,0); SETHIGH(0,0);
     SETLOW(1,1); SETHIGH(1,1);
     
     if ((err=bdd_operator_init(cs)) < 0) {
       bdd_done();
       RETURN(err);
     }
     
     bddfreepos = 2;
     bddfreenum = bddnodesize-2;
     bddrunning = 1;
     bddvarnum = 0;
     gbcollectnum = 0;
     gbcclock = 0;
     cachesize = cs;
     usednodes_nextreorder = bddnodesize;
     bddmaxnodeincrease = DEFAULTMAXNODEINC;
     bddincreasefactor = 2;
     
     bdderrorcond = 0;
     
     bddcachestats.uniqueAccess = 0;
     bddcachestats.uniqueChain = 0;
     bddcachestats.uniqueHit = 0;
     bddcachestats.uniqueMiss = 0;
     bddcachestats.opHit = 0;
     bddcachestats.opMiss = 0;
     bddcachestats.swapCount = 0;
     
     bdd_gbc_hook(bdd_default_gbchandler);
     bdd_error_hook(bdd_default_errhandler);
     bdd_resize_hook(NULL);
     bdd_pairs_init();
     bdd_reorder_init();
     bdd_fdd_init();
     
     if (setjmp(bddexception) != 0)
       assert(0);
     
     RETURN(0);
   }
}