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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START DdNodeKit_SopToBdd (DdManager *dd, Kit_Sop_t *cSop, int nVars)
 DECLARATIONS ///. More...
 
DdNodeKit_GraphToBdd (DdManager *dd, Kit_Graph_t *pGraph)
 
DdNodeKit_TruthToBdd_rec (DdManager *dd, unsigned *pTruth, int iBit, int nVars, int nVarsTotal, int fMSBonTop)
 
DdNodeKit_TruthToBdd (DdManager *dd, unsigned *pTruth, int nVars, int fMSBonTop)
 
int Kit_SopFactorVerify (Vec_Int_t *vCover, Kit_Graph_t *pFForm, int nVars)
 

Function Documentation

DdNode* Kit_GraphToBdd ( DdManager dd,
Kit_Graph_t pGraph 
)

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

Synopsis [Converts graph to BDD.]

Description []

SideEffects []

SeeAlso []

Definition at line 91 of file kitBdd.c.

92 {
93  DdNode * bFunc, * bFunc0, * bFunc1;
94  Kit_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
95  int i;
96 
97  // sanity checks
98  assert( Kit_GraphLeaveNum(pGraph) >= 0 );
99  assert( Kit_GraphLeaveNum(pGraph) <= pGraph->nSize );
100 
101  // check for constant function
102  if ( Kit_GraphIsConst(pGraph) )
103  return Cudd_NotCond( b1, Kit_GraphIsComplement(pGraph) );
104  // check for a literal
105  if ( Kit_GraphIsVar(pGraph) )
106  return Cudd_NotCond( Cudd_bddIthVar(dd, Kit_GraphVarInt(pGraph)), Kit_GraphIsComplement(pGraph) );
107 
108  // assign the elementary variables
109  Kit_GraphForEachLeaf( pGraph, pNode, i )
110  pNode->pFunc = Cudd_bddIthVar( dd, i );
111 
112  // compute the function for each internal node
113  Kit_GraphForEachNode( pGraph, pNode, i )
114  {
115  bFunc0 = Cudd_NotCond( Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
116  bFunc1 = Cudd_NotCond( Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
117  pNode->pFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( (DdNode *)pNode->pFunc );
118  }
119 
120  // deref the intermediate results
121  bFunc = (DdNode *)pNode->pFunc; Cudd_Ref( bFunc );
122  Kit_GraphForEachNode( pGraph, pNode, i )
123  Cudd_RecursiveDeref( dd, (DdNode *)pNode->pFunc );
124  Cudd_Deref( bFunc );
125 
126  // complement the result if necessary
127  return Cudd_NotCond( bFunc, Kit_GraphIsComplement(pGraph) );
128 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static Kit_Node_t * Kit_GraphNode(Kit_Graph_t *pGraph, int i)
Definition: kit.h:211
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
#define b1
Definition: extraBdd.h:76
static int Kit_GraphIsComplement(Kit_Graph_t *pGraph)
Definition: kit.h:205
static int Kit_GraphLeaveNum(Kit_Graph_t *pGraph)
Definition: kit.h:209
int nSize
Definition: kit.h:90
static int Kit_GraphIsVar(Kit_Graph_t *pGraph)
Definition: kit.h:206
#define Kit_GraphForEachLeaf(pGraph, pLeaf, i)
Definition: kit.h:502
void * pFunc
Definition: kit.h:73
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
#define Kit_GraphForEachNode(pGraph, pAnd, i)
Definition: kit.h:504
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define assert(ex)
Definition: util_old.h:213
static int Kit_GraphVarInt(Kit_Graph_t *pGraph)
Definition: kit.h:216
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
int Kit_SopFactorVerify ( Vec_Int_t vCover,
Kit_Graph_t pFForm,
int  nVars 
)

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

Synopsis [Verifies that the factoring is correct.]

Description []

SideEffects []

SeeAlso []

Definition at line 198 of file kitBdd.c.

199 {
200  static DdManager * dd = NULL;
201  Kit_Sop_t Sop, * cSop = &Sop;
202  DdNode * bFunc1, * bFunc2;
203  Vec_Int_t * vMemory;
204  int RetValue;
205  // get the manager
206  if ( dd == NULL )
207  dd = Cudd_Init( 16, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
208  // derive SOP
209  vMemory = Vec_IntAlloc( Vec_IntSize(vCover) );
210  Kit_SopCreate( cSop, vCover, nVars, vMemory );
211  // get the functions
212  bFunc1 = Kit_SopToBdd( dd, cSop, nVars ); Cudd_Ref( bFunc1 );
213  bFunc2 = Kit_GraphToBdd( dd, pFForm ); Cudd_Ref( bFunc2 );
214 //Extra_bddPrint( dd, bFunc1 ); printf("\n");
215 //Extra_bddPrint( dd, bFunc2 ); printf("\n");
216  RetValue = (bFunc1 == bFunc2);
217  if ( bFunc1 != bFunc2 )
218  {
219  int s;
220  Extra_bddPrint( dd, bFunc1 ); printf("\n");
221  Extra_bddPrint( dd, bFunc2 ); printf("\n");
222  s = 0;
223  }
224  Cudd_RecursiveDeref( dd, bFunc1 );
225  Cudd_RecursiveDeref( dd, bFunc2 );
226  Vec_IntFree( vMemory );
227  return RetValue;
228 }
#define CUDD_UNIQUE_SLOTS
Definition: cudd.h:97
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
#define CUDD_CACHE_SLOTS
Definition: cudd.h:98
DdNode * Kit_GraphToBdd(DdManager *dd, Kit_Graph_t *pGraph)
Definition: kitBdd.c:91
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
ABC_NAMESPACE_IMPL_START DdNode * Kit_SopToBdd(DdManager *dd, Kit_Sop_t *cSop, int nVars)
DECLARATIONS ///.
Definition: kitBdd.c:46
void Extra_bddPrint(DdManager *dd, DdNode *F)
Definition: extraBddMisc.c:246
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
Definition: cuddInit.c:125
typedefABC_NAMESPACE_HEADER_START struct Kit_Sop_t_ Kit_Sop_t
INCLUDES ///.
Definition: kit.h:51
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
void Kit_SopCreate(Kit_Sop_t *cResult, Vec_Int_t *vInput, int nVars, Vec_Int_t *vMemory)
DECLARATIONS ///.
Definition: kitSop.c:45
ABC_NAMESPACE_IMPL_START DdNode* Kit_SopToBdd ( DdManager dd,
Kit_Sop_t cSop,
int  nVars 
)

DECLARATIONS ///.

FUNCTION DECLARATIONS ///.

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

FileName [kitBdd.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Computation kit.]

Synopsis [Procedures involving BDDs.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - Dec 6, 2006.]

Revision [

Id:
kitBdd.c,v 1.00 2006/12/06 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Derives the BDD for the given SOP.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file kitBdd.c.

47 {
48  DdNode * bSum, * bCube, * bTemp, * bVar;
49  unsigned uCube;
50  int Value, i, v;
51  assert( nVars < 16 );
52  // start the cover
53  bSum = Cudd_ReadLogicZero(dd); Cudd_Ref( bSum );
54  // check the logic function of the node
55  Kit_SopForEachCube( cSop, uCube, i )
56  {
57  bCube = Cudd_ReadOne(dd); Cudd_Ref( bCube );
58  for ( v = 0; v < nVars; v++ )
59  {
60  Value = ((uCube >> 2*v) & 3);
61  if ( Value == 1 )
62  bVar = Cudd_Not( Cudd_bddIthVar( dd, v ) );
63  else if ( Value == 2 )
64  bVar = Cudd_bddIthVar( dd, v );
65  else
66  continue;
67  bCube = Cudd_bddAnd( dd, bTemp = bCube, bVar ); Cudd_Ref( bCube );
68  Cudd_RecursiveDeref( dd, bTemp );
69  }
70  bSum = Cudd_bddOr( dd, bTemp = bSum, bCube );
71  Cudd_Ref( bSum );
72  Cudd_RecursiveDeref( dd, bTemp );
73  Cudd_RecursiveDeref( dd, bCube );
74  }
75  // complement the result if necessary
76  Cudd_Deref( bSum );
77  return bSum;
78 }
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
DdNode * Cudd_ReadLogicZero(DdManager *dd)
Definition: cuddAPI.c:1058
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:381
#define Kit_SopForEachCube(cSop, uCube, i)
ITERATORS ///.
Definition: kit.h:497
DdNode * Cudd_ReadOne(DdManager *dd)
Definition: cuddAPI.c:987
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
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* Kit_TruthToBdd ( DdManager dd,
unsigned *  pTruth,
int  nVars,
int  fMSBonTop 
)

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

Synopsis [Compute BDD corresponding to the truth table.]

Description [If truth table has N vars, the BDD depends on N topmost variables of the BDD manager. The most significant variable of the table is encoded by the topmost variable of the manager. BDD construction is efficient in this case because BDD is constructed one node at a time, by simply adding BDD nodes on top of existent BDD nodes.]

SideEffects []

SeeAlso []

Definition at line 182 of file kitBdd.c.

183 {
184  return Kit_TruthToBdd_rec( dd, pTruth, 0, nVars, nVars, fMSBonTop );
185 }
DdNode * Kit_TruthToBdd_rec(DdManager *dd, unsigned *pTruth, int iBit, int nVars, int nVarsTotal, int fMSBonTop)
Definition: kitBdd.c:141
DdNode* Kit_TruthToBdd_rec ( DdManager dd,
unsigned *  pTruth,
int  iBit,
int  nVars,
int  nVarsTotal,
int  fMSBonTop 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 141 of file kitBdd.c.

142 {
143  DdNode * bF0, * bF1, * bF;
144  int Var;
145  if ( nVars <= 5 )
146  {
147  unsigned uTruth, uMask;
148  uMask = ((~(unsigned)0) >> (32 - (1<<nVars)));
149  uTruth = (pTruth[iBit>>5] >> (iBit&31)) & uMask;
150  if ( uTruth == 0 )
151  return b0;
152  if ( uTruth == uMask )
153  return b1;
154  }
155  // find the variable to use
156  Var = fMSBonTop? nVarsTotal-nVars : nVars-1;
157  // other special cases can be added
158  bF0 = Kit_TruthToBdd_rec( dd, pTruth, iBit, nVars-1, nVarsTotal, fMSBonTop ); Cudd_Ref( bF0 );
159  bF1 = Kit_TruthToBdd_rec( dd, pTruth, iBit+(1<<(nVars-1)), nVars-1, nVarsTotal, fMSBonTop ); Cudd_Ref( bF1 );
160  bF = Cudd_bddIte( dd, dd->vars[Var], bF1, bF0 ); Cudd_Ref( bF );
161  Cudd_RecursiveDeref( dd, bF0 );
162  Cudd_RecursiveDeref( dd, bF1 );
163  Cudd_Deref( bF );
164  return bF;
165 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
void Cudd_Deref(DdNode *node)
Definition: cuddRef.c:438
#define b1
Definition: extraBdd.h:76
DdNode * Cudd_bddIte(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)
Definition: cuddBddIte.c:143
#define b0
Definition: extraBdd.h:75
DdNode ** vars
Definition: cuddInt.h:390
int Var
Definition: SolverTypes.h:42
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
DdNode * Kit_TruthToBdd_rec(DdManager *dd, unsigned *pTruth, int iBit, int nVars, int nVarsTotal, int fMSBonTop)
Definition: kitBdd.c:141