abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
extraBddCas.c File Reference
#include "extraBdd.h"

Go to the source code of this file.

Data Structures

struct  _HashEntry_cof
 
struct  _HashEntry_mint
 
struct  traventry
 

Macros

#define _TABLESIZE_COF   51113
 
#define _TABLESIZE_MINT   15113
 

Functions

static DdNodeCreateTheCodes_rec (DdManager *dd, DdNode *bEncoded, int Level, DdNode **pCVars)
 
static void EvaluateEncodings_rec (DdManager *dd, DdNode *bVarsCol, int nVarsCol, int nMulti, int Level)
 
static DdNodeComputeVarSetAndCountMinterms (DdManager *dd, DdNode *bVars, DdNode *bVarTop, unsigned *Cost)
 
static DdNodeComputeVarSetAndCountMinterms2 (DdManager *dd, DdNode *bVars, DdNode *bVarTop, unsigned *Cost)
 
unsigned Extra_CountCofactorMinterms (DdManager *dd, DdNode *bFunc, DdNode *bVarsCof, DdNode *bVarsAll)
 
static unsigned Extra_CountMintermsSimple (DdNode *bFunc, unsigned max)
 
static void CountNodeVisits_rec (DdManager *dd, DdNode *aFunc, st__table *Visited)
 
static void CollectNodesAndComputePaths_rec (DdManager *dd, DdNode *aFunc, DdNode *bCube, st__table *Visited, st__table *CutNodes)
 
DdNodeExtra_bddEncodingBinary (DdManager *dd, DdNode **pbFuncs, int nFuncs, DdNode **pbVars, int nVars)
 
DdNodeExtra_bddEncodingNonStrict (DdManager *dd, DdNode **pbColumns, int nColumns, DdNode *bVarsCol, DdNode **pCVars, int nMulti, int *pSimple)
 
st__tableExtra_bddNodePathsUnderCut (DdManager *dd, DdNode *bFunc, int CutLevel)
 
int Extra_bddNodePathsUnderCutArray (DdManager *dd, DdNode **paNodes, DdNode **pbCubes, int nNodes, DdNode **paNodesRes, DdNode **pbCubesRes, int CutLevel)
 
void extraCollectNodes (DdNode *Func, st__table *tNodes)
 
st__tableExtra_CollectNodes (DdNode *Func)
 
void extraProfileUpdateTopLevel (st__table *tNodeTopRef, int TopLevelNew, DdNode *node)
 
int Extra_ProfileWidth (DdManager *dd, DdNode *Func, int *pProfile, int CutLevel)
 

Variables

_HashEntry_cof HHTable1 [_TABLESIZE_COF]
 
_HashEntry_mint HHTable2 [_TABLESIZE_MINT]
 
static unsigned s_Signature = 1
 
static int s_CutLevel = 0
 
static int s_MaxDepth = 5
 
static int s_nVarsBest
 
static int s_VarOrderBest [32]
 
static int s_VarOrderCur [32]
 
static DdNodes_Field [8][256]
 
static DdNodes_Encoded
 
static DdNodes_VarAll
 
static int s_MultiStart
 
static DdNode ** s_pbTemp
 
static int s_BackTracks
 
static int s_BackTrackLimit = 100
 
static DdNodes_Terminal
 
static int s_EncodingVarsLevel
 

Macro Definition Documentation

#define _TABLESIZE_COF   51113

CFile****************************************************************

FileName [extraBddCas.c]

PackageName [extra]

Synopsis [Procedures related to LUT cascade synthesis.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 2.0. Started - September 1, 2003.]

Revision [

Id:
extraBddCas.c,v 1.0 2003/05/21 18:03:50 alanmi Exp

]

Definition at line 37 of file extraBddCas.c.

#define _TABLESIZE_MINT   15113

Definition at line 46 of file extraBddCas.c.

Function Documentation

void CollectNodesAndComputePaths_rec ( DdManager dd,
DdNode aFunc,
DdNode bCube,
st__table Visited,
st__table CutNodes 
)
static

Function********************************************************************

Synopsis [Revisits the nodes and computes the paths.]

Description [This function visits the nodes above the cut having the goal of summing all the incomming BDD edges; when this function comes across the node below the cut, it saves this node in the CutNode table.]

SideEffects []

SeeAlso []

Definition at line 1159 of file extraBddCas.c.

1160 {
1161  // find the node in the visited table
1162  DdNode * bTemp;
1163  traventry * p;
1164  char **slot;
1165  if ( st__find_or_add(Visited, (char*)aFunc, &slot) )
1166  { // the node is found
1167  // get the pointer to the traversal entry
1168  p = (traventry*) *slot;
1169 
1170  // make sure that the counter of incoming edges is positive
1171  assert( p->nEdges > 0 );
1172 
1173  // add the cube to the currently accumulated cubes
1174  p->bSum = Cudd_bddOr( dd, bTemp = p->bSum, bCube ); Cudd_Ref( p->bSum );
1175  Cudd_RecursiveDeref( dd, bTemp );
1176 
1177  // decrement the number of visits
1178  p->nEdges--;
1179 
1180  // if more visits to this node are expected, return
1181  if ( p->nEdges )
1182  return;
1183  else // if ( p->nEdges == 0 )
1184  { // this is the last visit - propagate the cube
1185 
1186  // check where this node is
1187  if ( cuddI(dd,aFunc->index) < s_CutLevel )
1188  { // the node is above the cut
1189  DdNode * bCube0, * bCube1;
1190 
1191  // get the top-most variable
1192  DdNode * bVarTop = dd->vars[aFunc->index];
1193 
1194  // compute the propagated cubes
1195  bCube0 = Cudd_bddAnd( dd, p->bSum, Cudd_Not( bVarTop ) ); Cudd_Ref( bCube0 );
1196  bCube1 = Cudd_bddAnd( dd, p->bSum, bVarTop ); Cudd_Ref( bCube1 );
1197 
1198  // call recursively
1199  CollectNodesAndComputePaths_rec( dd, cuddE(aFunc), bCube0, Visited, CutNodes );
1200  CollectNodesAndComputePaths_rec( dd, cuddT(aFunc), bCube1, Visited, CutNodes );
1201 
1202  // dereference the cubes
1203  Cudd_RecursiveDeref( dd, bCube0 );
1204  Cudd_RecursiveDeref( dd, bCube1 );
1205  return;
1206  }
1207  else
1208  { // the node is below the cut
1209  // add this node to the cut node table, if it is not yet there
1210 
1211 // DdNode * bNode;
1212 // bNode = Cudd_addBddPattern( dd, aFunc ); Cudd_Ref( bNode );
1213  if ( st__find_or_add(CutNodes, (char*)aFunc, &slot) )
1214  { // the node exists - should never happen
1215  assert( 0 );
1216  }
1217  *slot = (char*) p->bSum; Cudd_Ref( p->bSum );
1218  // the table takes the reference of bNode
1219  return;
1220  }
1221  }
1222  }
1223 
1224  // the node does not exist in the visited table - should never happen
1225  assert(0);
1226 
1227 } /* end of CollectNodesAndComputePaths_rec */
static void CollectNodesAndComputePaths_rec(DdManager *dd, DdNode *aFunc, DdNode *bCube, st__table *Visited, st__table *CutNodes)
Definition: extraBddCas.c:1159
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nEdges
Definition: extraBddCas.c:57
DdNode * bSum
Definition: extraBddCas.c:58
int st__find_or_add(st__table *table, char *key, char ***slot)
Definition: st.c:230
static int s_CutLevel
Definition: extraBddCas.c:64
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:381
#define cuddT(node)
Definition: cuddInt.h:636
#define cuddI(dd, index)
Definition: cuddInt.h:686
DdHalfWord index
Definition: cudd.h:279
DdNode ** vars
Definition: cuddInt.h:390
#define cuddE(node)
Definition: cuddInt.h:652
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
DdNode * ComputeVarSetAndCountMinterms ( DdManager dd,
DdNode bVars,
DdNode bVarTop,
unsigned *  Cost 
)
static

Function********************************************************************

Synopsis [Computes the current set of variables and counts the number of minterms.]

Description []

SideEffects []

SeeAlso []

Definition at line 852 of file extraBddCas.c.

856 {
857  DdNode * bVarsRes;
858 
859  // get the resulting set of variables
860  bVarsRes = Cudd_bddAnd( dd, bVars, bVarTop ); Cudd_Ref( bVarsRes );
861 
862  // increment signature before calling Cudd_CountCofactorMinterms()
863  s_Signature++;
864  *Cost = Extra_CountCofactorMinterms( dd, s_Encoded, bVarsRes, s_VarAll );
865 
866  Cudd_Deref( bVarsRes );
867 // s_CountCalls++;
868  return bVarsRes;
869 }
static unsigned s_Signature
Definition: extraBddCas.c:62
Definition: cudd.h:278
unsigned Extra_CountCofactorMinterms(DdManager *dd, DdNode *bFunc, DdNode *bVarsCof, DdNode *bVarsAll)
Definition: extraBddCas.c:910
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
static DdNode * s_VarAll
Definition: extraBddCas.c:81
static DdNode * s_Encoded
Definition: extraBddCas.c:80
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
DdNode * ComputeVarSetAndCountMinterms2 ( DdManager dd,
DdNode bVars,
DdNode bVarTop,
unsigned *  Cost 
)
static

Function********************************************************************

Synopsis [Computes the current set of variables and counts the number of minterms.]

Description [The old implementation, which is approximately 4 times slower.]

SideEffects []

SeeAlso []

Definition at line 882 of file extraBddCas.c.

883 {
884  DdNode * bVarsRes;
885  DdNode * bCof, * bFun;
886 
887  bVarsRes = Cudd_bddAnd( dd, bVars, bVarTop ); Cudd_Ref( bVarsRes );
888 
889  bCof = Cudd_Cofactor( dd, s_Encoded, bVarsRes ); Cudd_Ref( bCof );
890  bFun = Cudd_bddExistAbstract( dd, bCof, s_VarAll ); Cudd_Ref( bFun );
891  *Cost = (unsigned)Cudd_CountMinterm( dd, bFun, s_MultiStart );
892  Cudd_RecursiveDeref( dd, bFun );
893  Cudd_RecursiveDeref( dd, bCof );
894 
895  Cudd_Deref( bVarsRes );
896 // s_CountCalls++;
897  return bVarsRes;
898 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
double Cudd_CountMinterm(DdManager *manager, DdNode *node, int nvars)
Definition: cuddUtil.c:578
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
static DdNode * s_VarAll
Definition: extraBddCas.c:81
DdNode * Cudd_bddExistAbstract(DdManager *manager, DdNode *f, DdNode *cube)
Definition: cuddBddAbs.c:130
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddCof.c:123
static DdNode * s_Encoded
Definition: extraBddCas.c:80
static int s_MultiStart
Definition: extraBddCas.c:82
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
void CountNodeVisits_rec ( DdManager dd,
DdNode aFunc,
st__table Visited 
)
static

Function********************************************************************

Synopsis [Visits the nodes.]

Description [Visits the nodes above the cut and the nodes pointed to below the cut; collects the visited nodes, counts how many times each node is visited, and sets the path-sum to be the constant zero BDD.]

SideEffects []

SeeAlso []

Definition at line 1113 of file extraBddCas.c.

1115 {
1116  traventry * p;
1117  char **slot;
1118  if ( st__find_or_add(Visited, (char*)aFunc, &slot) )
1119  { // the entry already exists
1120  p = (traventry*) *slot;
1121  // increment the counter of incoming edges
1122  p->nEdges++;
1123  return;
1124  }
1125  // this node has not been visited
1126  assert( !Cudd_IsComplement(aFunc) );
1127 
1128  // create the new traversal entry
1129  p = (traventry *) ABC_ALLOC( char, sizeof(traventry) );
1130  // set the initial sum of edges to zero BDD
1131  p->bSum = b0; Cudd_Ref( b0 );
1132  // set the starting number of incoming edges
1133  p->nEdges = 1;
1134  // set this entry into the slot
1135  *slot = (char*)p;
1136 
1137  // recur if the node is above the cut
1138  if ( cuddI(dd,aFunc->index) < s_CutLevel )
1139  {
1140  CountNodeVisits_rec( dd, cuddE(aFunc), Visited );
1141  CountNodeVisits_rec( dd, cuddT(aFunc), Visited );
1142  }
1143 } /* end of CountNodeVisits_rec */
static void CountNodeVisits_rec(DdManager *dd, DdNode *aFunc, st__table *Visited)
Definition: extraBddCas.c:1113
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nEdges
Definition: extraBddCas.c:57
DdNode * bSum
Definition: extraBddCas.c:58
#define Cudd_IsComplement(node)
Definition: cudd.h:425
int st__find_or_add(st__table *table, char *key, char ***slot)
Definition: st.c:230
static int s_CutLevel
Definition: extraBddCas.c:64
#define cuddT(node)
Definition: cuddInt.h:636
#define cuddI(dd, index)
Definition: cuddInt.h:686
#define b0
Definition: extraBdd.h:75
DdHalfWord index
Definition: cudd.h:279
#define cuddE(node)
Definition: cuddInt.h:652
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
DdNode * CreateTheCodes_rec ( DdManager dd,
DdNode bEncoded,
int  Level,
DdNode **  pCVars 
)
static

AutomaticStart

Function********************************************************************

Synopsis [Computes the non-strict codes when evaluation is finished.]

Description [The information about the best code is stored in s_VarOrderBest, which has s_nVarsBest entries.]

SideEffects [None]

Definition at line 599 of file extraBddCas.c.

603 {
604  DdNode * bRes;
605  if ( Level == s_nVarsBest )
606  { // the terminal case, when we need to remap the encoded function
607  // from the preliminary encoded variables to the new ones
608  st__table * CutNodes;
609  int nCols;
610 // double nMints;
611 /*
612 #ifdef _DEBUG
613 
614  {
615  DdNode * bTemp;
616  // make sure that the given number of variables is enough
617  bTemp = Cudd_bddExistAbstract( dd, bEncoded, s_VarAll ); Cudd_Ref( bTemp );
618 // nMints = Cudd_CountMinterm( dd, bTemp, s_MultiStart );
619  nMints = Extra_CountMintermsSimple( bTemp, (1<<s_MultiStart) );
620  if ( nMints > Extra_Power2( s_MultiStart-Level ) )
621  { // the number of minterms is too large to encode the columns
622  // using the given minimum number of encoding variables
623  assert( 0 );
624  }
625  Cudd_RecursiveDeref( dd, bTemp );
626  }
627 #endif
628 */
629  // get the columns to be re-encoded
630  CutNodes = Extra_bddNodePathsUnderCut( dd, bEncoded, s_EncodingVarsLevel );
631  // LUT size is the cut level because because the temporary encoding variables
632  // are above the functional variables - this is not true!!!
633  // the temporary variables are below!
634 
635  // put the entries from the table into the temporary array
636  {
637  st__generator * gen;
638  DdNode * bColumn, * bCode;
639  nCols = 0;
640  st__foreach_item( CutNodes, gen, (const char**)&bCode, (char**)&bColumn )
641  {
642  if ( bCode == b0 )
643  { // the unused part of the columns
644  Cudd_RecursiveDeref( dd, bColumn );
645  Cudd_RecursiveDeref( dd, bCode );
646  continue;
647  }
648  else
649  {
650  s_pbTemp[ nCols ] = bColumn; // takes ref
651  Cudd_RecursiveDeref( dd, bCode );
652  nCols++;
653  }
654  }
655  st__free_table( CutNodes );
656 // assert( nCols == (int)nMints );
657  }
658 
659  // encode the columns
660  if ( s_MultiStart-Level == 0 ) // we reached the bottom level of recursion
661  {
662  assert( nCols == 1 );
663 // assert( (int)nMints == 1 );
664  bRes = s_pbTemp[0]; Cudd_Ref( bRes );
665  }
666  else
667  {
668  bRes = Extra_bddEncodingBinary( dd, s_pbTemp, nCols, pCVars+Level, s_MultiStart-Level ); Cudd_Ref( bRes );
669  }
670 
671  // deref the columns
672  {
673  int i;
674  for ( i = 0; i < nCols; i++ )
675  Cudd_RecursiveDeref( dd, s_pbTemp[i] );
676  }
677  }
678  else
679  {
680  // cofactor the problem as specified in the best solution
681  DdNode * bCof0, * bCof1;
682  DdNode * bRes0, * bRes1;
683  DdNode * bProd0, * bProd1;
684  DdNode * bTemp;
685  DdNode * bVarNext = dd->vars[ s_VarOrderBest[Level] ];
686 
687  bCof0 = Cudd_Cofactor( dd, bEncoded, Cudd_Not( bVarNext ) ); Cudd_Ref( bCof0 );
688  bCof1 = Cudd_Cofactor( dd, bEncoded, bVarNext ); Cudd_Ref( bCof1 );
689 
690  // call recursively
691  bRes0 = CreateTheCodes_rec( dd, bCof0, Level+1, pCVars ); Cudd_Ref( bRes0 );
692  bRes1 = CreateTheCodes_rec( dd, bCof1, Level+1, pCVars ); Cudd_Ref( bRes1 );
693 
694  Cudd_RecursiveDeref( dd, bCof0 );
695  Cudd_RecursiveDeref( dd, bCof1 );
696 
697  // compose the result using the identity (bVarNext <=> pCVars[Level]) - this is wrong!
698  // compose the result as follows: x'y'F0 + xyF1
699  bProd0 = Cudd_bddAnd( dd, Cudd_Not(bVarNext), Cudd_Not(pCVars[Level]) ); Cudd_Ref( bProd0 );
700  bProd1 = Cudd_bddAnd( dd, bVarNext , pCVars[Level] ); Cudd_Ref( bProd1 );
701 
702  bProd0 = Cudd_bddAnd( dd, bTemp = bProd0, bRes0 ); Cudd_Ref( bProd0 );
703  Cudd_RecursiveDeref( dd, bTemp );
704  Cudd_RecursiveDeref( dd, bRes0 );
705 
706  bProd1 = Cudd_bddAnd( dd, bTemp = bProd1, bRes1 ); Cudd_Ref( bProd1 );
707  Cudd_RecursiveDeref( dd, bTemp );
708  Cudd_RecursiveDeref( dd, bRes1 );
709 
710  bRes = Cudd_bddOr( dd, bProd0, bProd1 ); Cudd_Ref( bRes );
711 
712  Cudd_RecursiveDeref( dd, bProd0 );
713  Cudd_RecursiveDeref( dd, bProd1 );
714  }
715  Cudd_Deref( bRes );
716  return bRes;
717 }
void st__free_table(st__table *table)
Definition: st.c:81
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
static DdNode ** s_pbTemp
Definition: extraBddCas.c:85
DdNode * Cudd_Cofactor(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddCof.c:123
Definition: st.h:52
static DdNode * CreateTheCodes_rec(DdManager *dd, DdNode *bEncoded, int Level, DdNode **pCVars)
Definition: extraBddCas.c:599
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:381
static int s_MultiStart
Definition: extraBddCas.c:82
#define b0
Definition: extraBdd.h:75
static int s_EncodingVarsLevel
Definition: extraBddCas.c:93
DdNode ** vars
Definition: cuddInt.h:390
DdNode * Extra_bddEncodingBinary(DdManager *dd, DdNode **pbFuncs, int nFuncs, DdNode **pbVars, int nVars)
Definition: extraBddCas.c:138
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
static int s_VarOrderBest[32]
Definition: extraBddCas.c:75
static int s_nVarsBest
Definition: extraBddCas.c:74
st__table * Extra_bddNodePathsUnderCut(DdManager *dd, DdNode *bFunc, int CutLevel)
Definition: extraBddCas.c:263
void EvaluateEncodings_rec ( DdManager dd,
DdNode bVarsCol,
int  nVarsCol,
int  nMulti,
int  Level 
)
static

Function********************************************************************

Synopsis [Computes the current set of variables and counts the number of minterms.]

Description [Old implementation.]

SideEffects []

SeeAlso []

Definition at line 730 of file extraBddCas.c.

736 {
737  int i, k;
738  int nEntries = (1<<(Level-1)); // the number of entries in the field of the previous level
739  DdNode * bVars0, * bVars1; // the cofactors
740  unsigned nMint0, nMint1; // the number of minterms
741  DdNode * bTempV;
742  DdNode * bVarTop;
743  int fBreak;
744 
745 
746  // there is no need to search above this level
747  if ( Level > s_MaxDepth )
748  return;
749 
750  // if there are no variables left, quit the research
751  if ( bVarsCol == b1 )
752  return;
753 
755  return;
756 
757  s_BackTracks++;
758 
759  // otherwise, go through the remaining variables
760  for ( bTempV = bVarsCol; bTempV != b1; bTempV = cuddT(bTempV) )
761  {
762  // the currently tested variable
763  bVarTop = dd->vars[bTempV->index];
764 
765  // put it into the array
766  s_VarOrderCur[Level-1] = bTempV->index;
767 
768  // go through the entries and fill them out by cofactoring
769  fBreak = 0;
770  for ( i = 0; i < nEntries; i++ )
771  {
772  bVars0 = ComputeVarSetAndCountMinterms( dd, s_Field[Level-1][i], Cudd_Not(bVarTop), &nMint0 );
773  Cudd_Ref( bVars0 );
774 
775  if ( nMint0 > Extra_Power2( nMulti-1 ) )
776  {
777  // there is no way to encode - dereference and return
778  Cudd_RecursiveDeref( dd, bVars0 );
779  fBreak = 1;
780  break;
781  }
782 
783  bVars1 = ComputeVarSetAndCountMinterms( dd, s_Field[Level-1][i], bVarTop, &nMint1 );
784  Cudd_Ref( bVars1 );
785 
786  if ( nMint1 > Extra_Power2( nMulti-1 ) )
787  {
788  // there is no way to encode - dereference and return
789  Cudd_RecursiveDeref( dd, bVars0 );
790  Cudd_RecursiveDeref( dd, bVars1 );
791  fBreak = 1;
792  break;
793  }
794 
795  // otherwise, add these two cofactors
796  s_Field[Level][2*i + 0] = bVars0; // takes ref
797  s_Field[Level][2*i + 1] = bVars1; // takes ref
798  }
799 
800  if ( !fBreak )
801  {
802  DdNode * bVarsRem;
803  // if we ended up here, it means that the cofactors w.r.t. variable bVarTop satisfy the condition
804  // save this situation
805  if ( s_nVarsBest < Level )
806  {
807  s_nVarsBest = Level;
808  // copy the variable assignment
809  for ( k = 0; k < Level; k++ )
811  }
812 
813  // call recursively
814  // get the new variable set
815  if ( nMulti-1 > 0 )
816  {
817  bVarsRem = Cudd_bddExistAbstract( dd, bVarsCol, bVarTop ); Cudd_Ref( bVarsRem );
818  EvaluateEncodings_rec( dd, bVarsRem, nVarsCol-1, nMulti-1, Level+1 );
819  Cudd_RecursiveDeref( dd, bVarsRem );
820  }
821  }
822 
823  // deref the contents of the array
824  for ( k = 0; k < i; k++ )
825  {
826  Cudd_RecursiveDeref( dd, s_Field[Level][2*k + 0] );
827  Cudd_RecursiveDeref( dd, s_Field[Level][2*k + 1] );
828  }
829 
830  // if the solution is found, there is no need to continue
831  if ( s_nVarsBest == s_MaxDepth )
832  return;
833 
834  // if the solution is found, there is no need to continue
835  if ( s_nVarsBest == s_MultiStart )
836  return;
837  }
838  // at this point, we have tried all possible directions in the space of variables
839 }
static int s_BackTrackLimit
Definition: extraBddCas.c:88
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
#define b1
Definition: extraBdd.h:76
DdNode * Cudd_bddExistAbstract(DdManager *manager, DdNode *f, DdNode *cube)
Definition: cuddBddAbs.c:130
static int s_VarOrderCur[32]
Definition: extraBddCas.c:76
double Extra_Power2(int Num)
Definition: extraUtilMisc.c:98
static int s_BackTracks
Definition: extraBddCas.c:87
static DdNode * s_Field[8][256]
Definition: extraBddCas.c:79
static int s_MaxDepth
Definition: extraBddCas.c:72
#define cuddT(node)
Definition: cuddInt.h:636
static DdNode * ComputeVarSetAndCountMinterms(DdManager *dd, DdNode *bVars, DdNode *bVarTop, unsigned *Cost)
Definition: extraBddCas.c:852
static int s_MultiStart
Definition: extraBddCas.c:82
DdHalfWord index
Definition: cudd.h:279
DdNode ** vars
Definition: cuddInt.h:390
static void EvaluateEncodings_rec(DdManager *dd, DdNode *bVarsCol, int nVarsCol, int nMulti, int Level)
Definition: extraBddCas.c:730
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
static int s_VarOrderBest[32]
Definition: extraBddCas.c:75
static int s_nVarsBest
Definition: extraBddCas.c:74
DdNode* Extra_bddEncodingBinary ( DdManager dd,
DdNode **  pbFuncs,
int  nFuncs,
DdNode **  pbVars,
int  nVars 
)

AutomaticEnd Function********************************************************************

Synopsis [Performs the binary encoding of the set of function using the given vars.]

Description [Performs a straight binary encoding of the set of functions using the variable cubes formed from the given set of variables. ]

SideEffects []

SeeAlso []

Definition at line 138 of file extraBddCas.c.

144 {
145  int i;
146  DdNode * bResult;
147  DdNode * bCube, * bTemp, * bProd;
148 
149  assert( nVars >= Abc_Base2Log(nFuncs) );
150 
151  bResult = b0; Cudd_Ref( bResult );
152  for ( i = 0; i < nFuncs; i++ )
153  {
154  bCube = Extra_bddBitsToCube( dd, i, nVars, pbVars, 1 ); Cudd_Ref( bCube );
155  bProd = Cudd_bddAnd( dd, bCube, pbFuncs[i] ); Cudd_Ref( bProd );
156  Cudd_RecursiveDeref( dd, bCube );
157 
158  bResult = Cudd_bddOr( dd, bProd, bTemp = bResult ); Cudd_Ref( bResult );
159  Cudd_RecursiveDeref( dd, bTemp );
160  Cudd_RecursiveDeref( dd, bProd );
161  }
162 
163  Cudd_Deref( bResult );
164  return bResult;
165 } /* end of Extra_bddEncodingBinary */
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:381
#define b0
Definition: extraBdd.h:75
static int Abc_Base2Log(unsigned n)
Definition: abc_global.h:251
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
DdNode * Extra_bddBitsToCube(DdManager *dd, int Code, int CodeWidth, DdNode **pbVars, int fMsbFirst)
Definition: extraBddMisc.c:730
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
DdNode* Extra_bddEncodingNonStrict ( DdManager dd,
DdNode **  pbColumns,
int  nColumns,
DdNode bVarsCol,
DdNode **  pCVars,
int  nMulti,
int *  pSimple 
)

Function********************************************************************

Synopsis [Solves the column encoding problem using a sophisticated method.]

Description [The encoding is based on the idea of deriving functions which depend on only one variable, which corresponds to the case of non-disjoint decompostion. It is assumed that the variables pCVars are ordered below the variables representing the solumns, and the first variable pCVars[0] is the topmost one.]

SideEffects []

SeeAlso [Extra_bddEncodingBinary]

Definition at line 184 of file extraBddCas.c.

192 {
193  DdNode * bEncoded, * bResult;
194  int nVarsCol = Cudd_SupportSize(dd,bVarsCol);
195  abctime clk;
196 
197  // cannot work with more that 32-bit codes
198  assert( nMulti < 32 );
199 
200  // perform the preliminary encoding using the straight binary code
201  bEncoded = Extra_bddEncodingBinary( dd, pbColumns, nColumns, pCVars, nMulti ); Cudd_Ref( bEncoded );
202  //printf( "Node count = %d", Cudd_DagSize(bEncoded) );
203 
204  // set the backgroup value for counting minterms
205  s_Terminal = b0;
206  // set the level of the encoding variables
207  s_EncodingVarsLevel = dd->invperm[pCVars[0]->index];
208 
209  // the current number of backtracks
210  s_BackTracks = 0;
211  // the variables that are cofactored on the topmost level where everything starts (no vars)
212  s_Field[0][0] = b1;
213  // the size of the best set of "simple" encoding variables found so far
214  s_nVarsBest = 0;
215 
216  // set the relation to be accessible to traversal procedures
217  s_Encoded = bEncoded;
218  // the set of all vars to be accessible to traversal procedures
219  s_VarAll = bVarsCol;
220  // the column multiplicity
221  s_MultiStart = nMulti;
222 
223 
224  clk = Abc_Clock();
225  // find the simplest encoding
226  if ( nColumns > 2 )
227  EvaluateEncodings_rec( dd, bVarsCol, nVarsCol, nMulti, 1 );
228 // printf( "The number of backtracks = %d\n", s_BackTracks );
229 // s_EncSearchTime += Abc_Clock() - clk;
230 
231  // allocate the temporary storage for the columns
232  s_pbTemp = (DdNode **)ABC_ALLOC( char, nColumns * sizeof(DdNode *) );
233 
234 // clk = Abc_Clock();
235  bResult = CreateTheCodes_rec( dd, bEncoded, 0, pCVars ); Cudd_Ref( bResult );
236 // s_EncComputeTime += Abc_Clock() - clk;
237 
238  // delocate the preliminarily encoded set
239  Cudd_RecursiveDeref( dd, bEncoded );
240 // Cudd_RecursiveDeref( dd, aEncoded );
241 
242  ABC_FREE( s_pbTemp );
243 
244  *pSimple = s_nVarsBest;
245  Cudd_Deref( bResult );
246  return bResult;
247 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
static DdNode * s_VarAll
Definition: extraBddCas.c:81
static DdNode * s_Terminal
Definition: extraBddCas.c:90
#define b1
Definition: extraBdd.h:76
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static abctime Abc_Clock()
Definition: abc_global.h:279
static DdNode ** s_pbTemp
Definition: extraBddCas.c:85
static int s_BackTracks
Definition: extraBddCas.c:87
static DdNode * s_Field[8][256]
Definition: extraBddCas.c:79
static DdNode * CreateTheCodes_rec(DdManager *dd, DdNode *bEncoded, int Level, DdNode **pCVars)
Definition: extraBddCas.c:599
static DdNode * s_Encoded
Definition: extraBddCas.c:80
static int s_MultiStart
Definition: extraBddCas.c:82
#define b0
Definition: extraBdd.h:75
DdHalfWord index
Definition: cudd.h:279
static int s_EncodingVarsLevel
Definition: extraBddCas.c:93
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdNode * Extra_bddEncodingBinary(DdManager *dd, DdNode **pbFuncs, int nFuncs, DdNode **pbVars, int nVars)
Definition: extraBddCas.c:138
static void EvaluateEncodings_rec(DdManager *dd, DdNode *bVarsCol, int nVarsCol, int nMulti, int Level)
Definition: extraBddCas.c:730
#define assert(ex)
Definition: util_old.h:213
int * invperm
Definition: cuddInt.h:388
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
ABC_INT64_T abctime
Definition: abc_global.h:278
int Cudd_SupportSize(DdManager *dd, DdNode *f)
Definition: cuddUtil.c:857
static int s_nVarsBest
Definition: extraBddCas.c:74
st__table* Extra_bddNodePathsUnderCut ( DdManager dd,
DdNode bFunc,
int  CutLevel 
)

Function********************************************************************

Synopsis [Collects the nodes under the cut and, for each node, computes the sum of paths leading to it from the root.]

Description [The table returned contains the set of BDD nodes pointed to under the cut and, for each node, the BDD of the sum of paths leading to this node from the root The sums of paths in the table are referenced. CutLevel is the first DD level considered to be under the cut.]

SideEffects []

SeeAlso [Extra_bddNodePaths]

Definition at line 263 of file extraBddCas.c.

264 {
265  st__table * Visited; // temporary table to remember the visited nodes
266  st__table * CutNodes; // the result goes here
267  st__table * Result; // the result goes here
268  DdNode * aFunc;
269 
270  s_CutLevel = CutLevel;
271 
273  // the terminal cases
274  if ( Cudd_IsConstant( bFunc ) )
275  {
276  if ( bFunc == b1 )
277  {
278  st__insert( Result, (char*)b1, (char*)b1 );
279  Cudd_Ref( b1 );
280  Cudd_Ref( b1 );
281  }
282  else
283  {
284  st__insert( Result, (char*)b0, (char*)b0 );
285  Cudd_Ref( b0 );
286  Cudd_Ref( b0 );
287  }
288  return Result;
289  }
290 
291  // create the ADD to simplify processing (no complemented edges)
292  aFunc = Cudd_BddToAdd( dd, bFunc ); Cudd_Ref( aFunc );
293 
294  // Step 1: Start the tables and collect information about the nodes above the cut
295  // this information tells how many edges point to each node
296  Visited = st__init_table( st__ptrcmp, st__ptrhash);;
297  CutNodes = st__init_table( st__ptrcmp, st__ptrhash);;
298 
299  CountNodeVisits_rec( dd, aFunc, Visited );
300 
301  // Step 2: Traverse the BDD using the visited table and compute the sum of paths
302  CollectNodesAndComputePaths_rec( dd, aFunc, b1, Visited, CutNodes );
303 
304  // at this point the table of cut nodes is ready and the table of visited is useless
305  {
306  st__generator * gen;
307  DdNode * aNode;
308  traventry * p;
309  st__foreach_item( Visited, gen, (const char**)&aNode, (char**)&p )
310  {
311  Cudd_RecursiveDeref( dd, p->bSum );
312  ABC_FREE( p );
313  }
314  st__free_table( Visited );
315  }
316 
317  // go through the table CutNodes and create the BDD and the path to be returned
318  {
319  st__generator * gen;
320  DdNode * aNode, * bNode, * bSum;
321  st__foreach_item( CutNodes, gen, (const char**)&aNode, (char**)&bSum)
322  {
323  // aNode is not referenced, because aFunc is holding it
324  bNode = Cudd_addBddPattern( dd, aNode ); Cudd_Ref( bNode );
325  st__insert( Result, (char*)bNode, (char*)bSum );
326  // the new table takes both refs
327  }
328  st__free_table( CutNodes );
329  }
330 
331  // dereference the ADD
332  Cudd_RecursiveDeref( dd, aFunc );
333 
334  // return the table
335  return Result;
336 
337 } /* end of Extra_bddNodePathsUnderCut */
static void CountNodeVisits_rec(DdManager *dd, DdNode *aFunc, st__table *Visited)
Definition: extraBddCas.c:1113
void st__free_table(st__table *table)
Definition: st.c:81
static void CollectNodesAndComputePaths_rec(DdManager *dd, DdNode *aFunc, DdNode *bCube, st__table *Visited, st__table *CutNodes)
Definition: extraBddCas.c:1159
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
DdNode * Cudd_addBddPattern(DdManager *dd, DdNode *f)
Definition: cuddBridge.c:379
#define b1
Definition: extraBdd.h:76
#define Cudd_IsConstant(node)
Definition: cudd.h:352
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
DdNode * bSum
Definition: extraBddCas.c:58
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
static int s_CutLevel
Definition: extraBddCas.c:64
DdNode * Cudd_BddToAdd(DdManager *dd, DdNode *B)
Definition: cuddBridge.c:349
#define b0
Definition: extraBdd.h:75
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
int st__ptrhash(const char *, int)
Definition: st.c:468
int Extra_bddNodePathsUnderCutArray ( DdManager dd,
DdNode **  paNodes,
DdNode **  pbCubes,
int  nNodes,
DdNode **  paNodesRes,
DdNode **  pbCubesRes,
int  CutLevel 
)

Function********************************************************************

Synopsis [Collects the nodes under the cut in the ADD starting from the given set of ADD nodes.]

Description [Takes the array, paNodes, of ADD nodes to start the traversal, the array, pbCubes, of BDD cubes to start the traversal with in each node, and the number, nNodes, of ADD nodes and BDD cubes in paNodes and pbCubes. Returns the number of columns found. Fills in paNodesRes (pbCubesRes) with the set of ADD columns (BDD paths). These arrays should be allocated by the user.]

SideEffects []

SeeAlso [Extra_bddNodePaths]

Definition at line 355 of file extraBddCas.c.

356 {
357  st__table * Visited; // temporary table to remember the visited nodes
358  st__table * CutNodes; // the nodes under the cut go here
359  int i, Counter;
360 
361  s_CutLevel = CutLevel;
362 
363  // there should be some nodes
364  assert( nNodes > 0 );
365  if ( nNodes == 1 && Cudd_IsConstant( paNodes[0] ) )
366  {
367  if ( paNodes[0] == a1 )
368  {
369  paNodesRes[0] = a1; Cudd_Ref( a1 );
370  pbCubesRes[0] = pbCubes[0]; Cudd_Ref( pbCubes[0] );
371  }
372  else
373  {
374  paNodesRes[0] = a0; Cudd_Ref( a0 );
375  pbCubesRes[0] = pbCubes[0]; Cudd_Ref( pbCubes[0] );
376  }
377  return 1;
378  }
379 
380  // Step 1: Start the table and collect information about the nodes above the cut
381  // this information tells how many edges point to each node
382  CutNodes = st__init_table( st__ptrcmp, st__ptrhash);;
383  Visited = st__init_table( st__ptrcmp, st__ptrhash);;
384 
385  for ( i = 0; i < nNodes; i++ )
386  CountNodeVisits_rec( dd, paNodes[i], Visited );
387 
388  // Step 2: Traverse the BDD using the visited table and compute the sum of paths
389  for ( i = 0; i < nNodes; i++ )
390  CollectNodesAndComputePaths_rec( dd, paNodes[i], pbCubes[i], Visited, CutNodes );
391 
392  // at this point, the table of cut nodes is ready and the table of visited is useless
393  {
394  st__generator * gen;
395  DdNode * aNode;
396  traventry * p;
397  st__foreach_item( Visited, gen, (const char**)&aNode, (char**)&p )
398  {
399  Cudd_RecursiveDeref( dd, p->bSum );
400  ABC_FREE( p );
401  }
402  st__free_table( Visited );
403  }
404 
405  // go through the table CutNodes and create the BDD and the path to be returned
406  {
407  st__generator * gen;
408  DdNode * aNode, * bSum;
409  Counter = 0;
410  st__foreach_item( CutNodes, gen, (const char**)&aNode, (char**)&bSum)
411  {
412  paNodesRes[Counter] = aNode; Cudd_Ref( aNode );
413  pbCubesRes[Counter] = bSum;
414  Counter++;
415  }
416  st__free_table( CutNodes );
417  }
418 
419  // return the number of cofactors found
420  return Counter;
421 
422 } /* end of Extra_bddNodePathsUnderCutArray */
static void CountNodeVisits_rec(DdManager *dd, DdNode *aFunc, st__table *Visited)
Definition: extraBddCas.c:1113
void st__free_table(st__table *table)
Definition: st.c:81
static void CollectNodesAndComputePaths_rec(DdManager *dd, DdNode *aFunc, DdNode *bCube, st__table *Visited, st__table *CutNodes)
Definition: extraBddCas.c:1159
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define Cudd_IsConstant(node)
Definition: cudd.h:352
#define a1
Definition: extraBdd.h:80
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
DdNode * bSum
Definition: extraBddCas.c:58
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
static int s_CutLevel
Definition: extraBddCas.c:64
static int Counter
#define a0
Definition: extraBdd.h:79
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
int st__ptrhash(const char *, int)
Definition: st.c:468
st__table* Extra_CollectNodes ( DdNode Func)

Function*************************************************************

Synopsis [Collects all the nodes of one DD into the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 458 of file extraBddCas.c.

459 {
460  st__table * tNodes;
462  extraCollectNodes( Func, tNodes );
463  return tNodes;
464 }
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
void extraCollectNodes(DdNode *Func, st__table *tNodes)
Definition: extraBddCas.c:435
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
int st__ptrhash(const char *, int)
Definition: st.c:468
unsigned Extra_CountCofactorMinterms ( DdManager dd,
DdNode bFunc,
DdNode bVarsCof,
DdNode bVarsAll 
)

Function********************************************************************

Synopsis [Counts the number of encoding minterms pointed to by the cofactor of the function.]

Description []

SideEffects [None]

Definition at line 910 of file extraBddCas.c.

915 {
916  unsigned HKey;
917  DdNode * bFuncR;
918 
919  // if the function is zero, there are no minterms
920 // if ( bFunc == b0 )
921 // return 0;
922 
923 // if ( st__lookup(Visited, (char*)bFunc, NULL) )
924 // return 0;
925 
926 // HKey = hashKey2c( s_Signature, bFuncR );
927 // if ( HHTable1[HKey].Sign == s_Signature && HHTable1[HKey].Arg1 == bFuncR ) // this node is visited
928 // return 0;
929 
930 
931  // check the hash-table
932  bFuncR = Cudd_Regular(bFunc);
933 // HKey = hashKey2( s_Signature, bFuncR, _TABLESIZE_COF );
934  HKey = hashKey2( s_Signature, bFunc, _TABLESIZE_COF );
935  for ( ; HHTable1[HKey].Sign == s_Signature; HKey = (HKey+1) % _TABLESIZE_COF )
936 // if ( HHTable1[HKey].Arg1 == bFuncR ) // this node is visited
937  if ( HHTable1[HKey].Arg1 == bFunc ) // this node is visited
938  return 0;
939 
940 
941  // if the function is already the code
942  if ( dd->perm[bFuncR->index] >= s_EncodingVarsLevel )
943  {
944 // st__insert(Visited, (char*)bFunc, NULL);
945 
946 // HHTable1[HKey].Sign = s_Signature;
947 // HHTable1[HKey].Arg1 = bFuncR;
948 
949  assert( HHTable1[HKey].Sign != s_Signature );
950  HHTable1[HKey].Sign = s_Signature;
951 // HHTable1[HKey].Arg1 = bFuncR;
952  HHTable1[HKey].Arg1 = bFunc;
953 
954  return Extra_CountMintermsSimple( bFunc, (1<<s_MultiStart) );
955  }
956  else
957  {
958  DdNode * bFunc0, * bFunc1;
959  DdNode * bVarsCof0, * bVarsCof1;
960  DdNode * bVarsCofR = Cudd_Regular(bVarsCof);
961  unsigned Res;
962 
963  // get the levels
964  int LevelF = dd->perm[bFuncR->index];
965  int LevelC = cuddI(dd,bVarsCofR->index);
966  int LevelA = dd->perm[bVarsAll->index];
967 
968  int LevelTop = LevelF;
969 
970  if ( LevelTop > LevelC )
971  LevelTop = LevelC;
972 
973  if ( LevelTop > LevelA )
974  LevelTop = LevelA;
975 
976  // the top var in the function or in cofactoring vars always belongs to the set of all vars
977  assert( !( LevelTop == LevelF || LevelTop == LevelC ) || LevelTop == LevelA );
978 
979  // cofactor the function
980  if ( LevelTop == LevelF )
981  {
982  if ( bFuncR != bFunc ) // bFunc is complemented
983  {
984  bFunc0 = Cudd_Not( cuddE(bFuncR) );
985  bFunc1 = Cudd_Not( cuddT(bFuncR) );
986  }
987  else
988  {
989  bFunc0 = cuddE(bFuncR);
990  bFunc1 = cuddT(bFuncR);
991  }
992  }
993  else // bVars is higher in the variable order
994  bFunc0 = bFunc1 = bFunc;
995 
996  // cofactor the cube
997  if ( LevelTop == LevelC )
998  {
999  if ( bVarsCofR != bVarsCof ) // bFunc is complemented
1000  {
1001  bVarsCof0 = Cudd_Not( cuddE(bVarsCofR) );
1002  bVarsCof1 = Cudd_Not( cuddT(bVarsCofR) );
1003  }
1004  else
1005  {
1006  bVarsCof0 = cuddE(bVarsCofR);
1007  bVarsCof1 = cuddT(bVarsCofR);
1008  }
1009  }
1010  else // bVars is higher in the variable order
1011  bVarsCof0 = bVarsCof1 = bVarsCof;
1012 
1013  // there are two cases:
1014  // (1) the top variable belongs to the cofactoring variables
1015  // (2) the top variable does not belong to the cofactoring variables
1016 
1017  // (1) the top variable belongs to the cofactoring variables
1018  Res = 0;
1019  if ( LevelTop == LevelC )
1020  {
1021  if ( bVarsCof1 == b0 ) // this is a negative cofactor
1022  {
1023  if ( bFunc0 != b0 )
1024  Res = Extra_CountCofactorMinterms( dd, bFunc0, bVarsCof0, cuddT(bVarsAll) );
1025  }
1026  else // this is a positive cofactor
1027  {
1028  if ( bFunc1 != b0 )
1029  Res = Extra_CountCofactorMinterms( dd, bFunc1, bVarsCof1, cuddT(bVarsAll) );
1030  }
1031  }
1032  else
1033  {
1034  if ( bFunc0 != b0 )
1035  Res += Extra_CountCofactorMinterms( dd, bFunc0, bVarsCof0, cuddT(bVarsAll) );
1036 
1037  if ( bFunc1 != b0 )
1038  Res += Extra_CountCofactorMinterms( dd, bFunc1, bVarsCof1, cuddT(bVarsAll) );
1039  }
1040 
1041 // st__insert(Visited, (char*)bFunc, NULL);
1042 
1043 // HHTable1[HKey].Sign = s_Signature;
1044 // HHTable1[HKey].Arg1 = bFuncR;
1045 
1046  // skip through the entries with the same signatures
1047  // (these might have been created at the time of recursive calls)
1048  for ( ; HHTable1[HKey].Sign == s_Signature; HKey = (HKey+1) % _TABLESIZE_COF );
1049  assert( HHTable1[HKey].Sign != s_Signature );
1050  HHTable1[HKey].Sign = s_Signature;
1051 // HHTable1[HKey].Arg1 = bFuncR;
1052  HHTable1[HKey].Arg1 = bFunc;
1053 
1054  return Res;
1055  }
1056 }
#define hashKey2(a, b, TSIZE)
Definition: extraBdd.h:86
static unsigned s_Signature
Definition: extraBddCas.c:62
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
unsigned Extra_CountCofactorMinterms(DdManager *dd, DdNode *bFunc, DdNode *bVarsCof, DdNode *bVarsAll)
Definition: extraBddCas.c:910
#define Cudd_Regular(node)
Definition: cudd.h:397
static unsigned Extra_CountMintermsSimple(DdNode *bFunc, unsigned max)
Definition: extraBddCas.c:1069
#define cuddT(node)
Definition: cuddInt.h:636
#define cuddI(dd, index)
Definition: cuddInt.h:686
static int s_MultiStart
Definition: extraBddCas.c:82
#define b0
Definition: extraBdd.h:75
DdHalfWord index
Definition: cudd.h:279
static int s_EncodingVarsLevel
Definition: extraBddCas.c:93
#define cuddE(node)
Definition: cuddInt.h:652
#define assert(ex)
Definition: util_old.h:213
unsigned Sign
Definition: extraBddCas.c:40
DdNode * Arg1
Definition: extraBddCas.c:41
#define _TABLESIZE_COF
Definition: extraBddCas.c:37
int * perm
Definition: cuddInt.h:386
_HashEntry_cof HHTable1[_TABLESIZE_COF]
Definition: extraBddCas.c:43
unsigned Extra_CountMintermsSimple ( DdNode bFunc,
unsigned  max 
)
static

Function********************************************************************

Synopsis [Counts the number of minterms.]

Description [This function counts minterms for functions up to 32 variables using a local cache. The terminal value (s_Termina) should be adjusted for BDDs and ADDs.]

SideEffects [None]

Definition at line 1069 of file extraBddCas.c.

1070 {
1071  unsigned HKey;
1072 
1073  // normalize
1074  if ( Cudd_IsComplement(bFunc) )
1075  return max - Extra_CountMintermsSimple( Cudd_Not(bFunc), max );
1076 
1077  // now it is known that the function is not complemented
1078  if ( cuddIsConstant(bFunc) )
1079  return ((bFunc==s_Terminal)? 0: max);
1080 
1081  // check cache
1082  HKey = hashKey2( bFunc, max, _TABLESIZE_MINT );
1083  if ( HHTable2[HKey].Arg1 == bFunc && HHTable2[HKey].Arg2 == max )
1084  return HHTable2[HKey].Res;
1085  else
1086  {
1087  // min = min0/2 + min1/2;
1088  unsigned min = (Extra_CountMintermsSimple( cuddE(bFunc), max ) >> 1) +
1089  (Extra_CountMintermsSimple( cuddT(bFunc), max ) >> 1);
1090 
1091  HHTable2[HKey].Arg1 = bFunc;
1092  HHTable2[HKey].Arg2 = max;
1093  HHTable2[HKey].Res = min;
1094 
1095  return min;
1096  }
1097 } /* end of Extra_CountMintermsSimple */
#define hashKey2(a, b, TSIZE)
Definition: extraBdd.h:86
#define Cudd_Not(node)
Definition: cudd.h:367
static DdNode * s_Terminal
Definition: extraBddCas.c:90
static unsigned Extra_CountMintermsSimple(DdNode *bFunc, unsigned max)
Definition: extraBddCas.c:1069
#define _TABLESIZE_MINT
Definition: extraBddCas.c:46
DdNode * Arg1
Definition: extraBddCas.c:49
unsigned Res
Definition: extraBddCas.c:51
#define Cudd_IsComplement(node)
Definition: cudd.h:425
#define cuddIsConstant(node)
Definition: cuddInt.h:620
static double max
Definition: cuddSubsetHB.c:134
#define cuddT(node)
Definition: cuddInt.h:636
_HashEntry_mint HHTable2[_TABLESIZE_MINT]
Definition: extraBddCas.c:53
unsigned Arg2
Definition: extraBddCas.c:50
#define cuddE(node)
Definition: cuddInt.h:652
int Extra_ProfileWidth ( DdManager dd,
DdNode Func,
int *  pProfile,
int  CutLevel 
)

Function*************************************************************

Synopsis [Fast computation of the BDD profile.]

Description [The array to store the profile is given by the user and should contain at least as many entries as there is the maximum of the BDD/ZDD size of the manager PLUS ONE. When we say that the widths of the DD on level L is W, we mean the following. Let us create the cut between the level L-1 and the level L and count the number of different DD nodes pointed to across the cut. This number is the width W. From this it follows the on level 0, the width is equal to the number of external pointers to the considered DDs. If there is only one DD, then the profile on level 0 is always 1. If this DD is rooted in the topmost variable, then the width on level 1 is always 2, etc. The width at the level equal to dd->size is the number of terminal nodes in the DD. (Because we consider the first level #0 and the last level #dd->size, the profile array should contain dd->size+1 entries.) ]

SideEffects [This procedure will not work for BDDs w/ complement edges, only for ADDs and ZDDs]

SeeAlso []

Definition at line 519 of file extraBddCas.c.

520 {
521  st__generator * gen;
522  st__table * tNodeTopRef; // this table stores the top level from which this node is pointed to
523  st__table * tNodes;
524  DdNode * node;
525  DdNode * nodeR;
526  int LevelStart, Limit;
527  int i, size;
528  int WidthMax;
529 
530  // start the mapping table
531  tNodeTopRef = st__init_table( st__ptrcmp, st__ptrhash);;
532  // add the topmost node to the profile
533  extraProfileUpdateTopLevel( tNodeTopRef, 0, Func );
534 
535  // collect all nodes
536  tNodes = Extra_CollectNodes( Func );
537  // go though all the nodes and set the top level the cofactors are pointed from
538 // Cudd_ForeachNode( dd, Func, genDD, node )
539  st__foreach_item( tNodes, gen, (const char**)&node, NULL )
540  {
541 // assert( Cudd_Regular(node) ); // this procedure works only with ADD/ZDD (not BDD w/ compl.edges)
542  nodeR = Cudd_Regular(node);
543  if ( cuddIsConstant(nodeR) )
544  continue;
545  // this node is not a constant - consider its cofactors
546  extraProfileUpdateTopLevel( tNodeTopRef, dd->perm[node->index]+1, cuddE(nodeR) );
547  extraProfileUpdateTopLevel( tNodeTopRef, dd->perm[node->index]+1, cuddT(nodeR) );
548  }
549  st__free_table( tNodes );
550 
551  // clean the profile
552  size = ddMax(dd->size, dd->sizeZ) + 1;
553  for ( i = 0; i < size; i++ )
554  pProfile[i] = 0;
555 
556  // create the profile
557  st__foreach_item( tNodeTopRef, gen, (const char**)&node, (char**)&LevelStart )
558  {
559  nodeR = Cudd_Regular(node);
560  Limit = (cuddIsConstant(nodeR))? dd->size: dd->perm[nodeR->index];
561  for ( i = LevelStart; i <= Limit; i++ )
562  pProfile[i]++;
563  }
564 
565  if ( CutLevel != -1 && CutLevel != 0 )
566  size = CutLevel;
567 
568  // get the max width
569  WidthMax = 0;
570  for ( i = 0; i < size; i++ )
571  if ( WidthMax < pProfile[i] )
572  WidthMax = pProfile[i];
573 
574  // deref the table
575  st__free_table( tNodeTopRef );
576 
577  return WidthMax;
578 } /* end of Extra_ProfileWidth */
void st__free_table(st__table *table)
Definition: st.c:81
Definition: cudd.h:278
int size
Definition: cuddInt.h:361
#define Cudd_Regular(node)
Definition: cudd.h:397
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
for(p=first;p->value< newval;p=p->next)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
#define cuddIsConstant(node)
Definition: cuddInt.h:620
#define ddMax(x, y)
Definition: cuddInt.h:832
static int size
Definition: cuddSign.c:86
#define cuddT(node)
Definition: cuddInt.h:636
st__table * Extra_CollectNodes(DdNode *Func)
Definition: extraBddCas.c:458
int sizeZ
Definition: cuddInt.h:362
DdHalfWord index
Definition: cudd.h:279
#define cuddE(node)
Definition: cuddInt.h:652
#define st__foreach_item(table, gen, key, value)
Definition: st.h:107
void extraProfileUpdateTopLevel(st__table *tNodeTopRef, int TopLevelNew, DdNode *node)
Definition: extraBddCas.c:480
int * perm
Definition: cuddInt.h:386
int st__ptrhash(const char *, int)
Definition: st.c:468
void extraCollectNodes ( DdNode Func,
st__table tNodes 
)

Function*************************************************************

Synopsis [Collects all the BDD nodes into the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 435 of file extraBddCas.c.

436 {
437  DdNode * FuncR;
438  FuncR = Cudd_Regular(Func);
439  if ( st__find_or_add( tNodes, (char*)FuncR, NULL ) )
440  return;
441  if ( cuddIsConstant(FuncR) )
442  return;
443  extraCollectNodes( cuddE(FuncR), tNodes );
444  extraCollectNodes( cuddT(FuncR), tNodes );
445 }
Definition: cudd.h:278
#define Cudd_Regular(node)
Definition: cudd.h:397
void extraCollectNodes(DdNode *Func, st__table *tNodes)
Definition: extraBddCas.c:435
int st__find_or_add(st__table *table, char *key, char ***slot)
Definition: st.c:230
#define cuddIsConstant(node)
Definition: cuddInt.h:620
#define cuddT(node)
Definition: cuddInt.h:636
#define cuddE(node)
Definition: cuddInt.h:652
void extraProfileUpdateTopLevel ( st__table tNodeTopRef,
int  TopLevelNew,
DdNode node 
)

Function*************************************************************

Synopsis [Updates the topmost level from which the given node is referenced.]

Description [Takes the table which maps each BDD nodes (including the constants) into the topmost level on which this node counts as a cofactor. Takes the topmost level, on which this node counts as a cofactor (see Extra_ProfileWidthFast(). Takes the node, for which the table entry should be updated.]

SideEffects []

SeeAlso []

Definition at line 480 of file extraBddCas.c.

481 {
482  int * pTopLevel;
483 
484  if ( st__find_or_add( tNodeTopRef, (char*)node, (char***)&pTopLevel ) )
485  { // the node is already referenced
486  // the current top level should be updated if it is larger than the new level
487  if ( *pTopLevel > TopLevelNew )
488  *pTopLevel = TopLevelNew;
489  }
490  else
491  { // the node is not referenced
492  // its level should be set to the current new level
493  *pTopLevel = TopLevelNew;
494  }
495 }
int st__find_or_add(st__table *table, char *key, char ***slot)
Definition: st.c:230

Variable Documentation

Definition at line 43 of file extraBddCas.c.

Definition at line 53 of file extraBddCas.c.

int s_BackTrackLimit = 100
static

Definition at line 88 of file extraBddCas.c.

int s_BackTracks
static

Definition at line 87 of file extraBddCas.c.

int s_CutLevel = 0
static

Definition at line 64 of file extraBddCas.c.

DdNode* s_Encoded
static

Definition at line 80 of file extraBddCas.c.

int s_EncodingVarsLevel
static

Definition at line 93 of file extraBddCas.c.

DdNode* s_Field[8][256]
static

Definition at line 79 of file extraBddCas.c.

int s_MaxDepth = 5
static

Definition at line 72 of file extraBddCas.c.

int s_MultiStart
static

Definition at line 82 of file extraBddCas.c.

int s_nVarsBest
static

Definition at line 74 of file extraBddCas.c.

DdNode** s_pbTemp
static

Definition at line 85 of file extraBddCas.c.

unsigned s_Signature = 1
static

Definition at line 62 of file extraBddCas.c.

DdNode* s_Terminal
static

Definition at line 90 of file extraBddCas.c.

DdNode* s_VarAll
static

Definition at line 81 of file extraBddCas.c.

int s_VarOrderBest[32]
static

Definition at line 75 of file extraBddCas.c.

int s_VarOrderCur[32]
static

Definition at line 76 of file extraBddCas.c.