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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Abc_ConvertZddToSop (DdManager *dd, DdNode *zCover, char *pSop, int nFanins, Vec_Str_t *vCube, int fPhase)
 DECLARATIONS ///. More...
 
int Abc_CountZddCubes (DdManager *dd, DdNode *zCover)
 
int Abc_NtkDeriveFlatGiaSop (Gia_Man_t *pGia, int *gFanins, char *pSop)
 
int Gia_ManFactorNode (Gia_Man_t *p, char *pSop, Vec_Int_t *vLeaves)
 
Vec_Ptr_tGia_GetFakeNames (int nNames)
 FUNCTION DEFINITIONS ///. More...
 
int Gia_ManRebuildIsop (DdManager *dd, DdNode *bLocal, Gia_Man_t *pNew, Vec_Int_t *vFanins, Vec_Str_t *vSop, Vec_Str_t *vCube)
 
int Gia_ManRebuildNode (Dsd_Manager_t *pManDsd, Dsd_Node_t *pNodeDsd, Gia_Man_t *pNew, DdManager *ddNew, Vec_Int_t *vFanins, Vec_Str_t *vSop, Vec_Str_t *vCube)
 
Gia_Man_tGia_ManRebuild (Gia_Man_t *p, Dsd_Manager_t *pManDsd, DdManager *ddNew)
 
void Gia_ManCollapseDeref (DdManager *dd, Vec_Ptr_t *vFuncs)
 
void Gia_ObjCollapseDeref (Gia_Man_t *p, DdManager *dd, Vec_Ptr_t *vFuncs, int Id)
 
Vec_Ptr_tGia_ManCollapse (Gia_Man_t *p, DdManager *dd, int nBddLimit, int fVerbose)
 
Gia_Man_tGia_ManCollapseTest (Gia_Man_t *p, int fVerbose)
 
void Gia_ManCollapseTestTest (Gia_Man_t *p)
 

Function Documentation

int Abc_ConvertZddToSop ( DdManager dd,
DdNode zCover,
char *  pSop,
int  nFanins,
Vec_Str_t vCube,
int  fPhase 
)

DECLARATIONS ///.

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

FileName [giaClp.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Collapsing AIG.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
gia.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

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

Synopsis [Derive the BDD for the function in the cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 471 of file abcFunc.c.

472 {
473  int nCubes = 0;
474  Abc_ConvertZddToSop_rec( dd, zCover, pSop, nFanins, vCube, fPhase, &nCubes );
475  return nCubes;
476 }
void Abc_ConvertZddToSop_rec(DdManager *dd, DdNode *zCover, char *pSop, int nFanins, Vec_Str_t *vCube, int fPhase, int *pnCubes)
Definition: abcFunc.c:434
int Abc_CountZddCubes ( DdManager dd,
DdNode zCover 
)

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

Synopsis [Count the number of paths in the ZDD.]

Description []

SideEffects []

SeeAlso []

Definition at line 593 of file abcFunc.c.

594 {
595  int nCubes = 0;
596  Abc_CountZddCubes_rec( dd, zCover, &nCubes );
597  return nCubes;
598 }
void Abc_CountZddCubes_rec(DdManager *dd, DdNode *zCover, int *pnCubes)
Definition: abcFunc.c:564
int Abc_NtkDeriveFlatGiaSop ( Gia_Man_t pGia,
int *  gFanins,
char *  pSop 
)

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

Synopsis [Strashes one logic node using its SOP.]

Description []

SideEffects []

SeeAlso []

Definition at line 131 of file abcHieCec.c.

132 {
133  char * pCube;
134  int gAnd, gSum;
135  int i, Value, nFanins;
136  // get the number of variables
137  nFanins = Abc_SopGetVarNum(pSop);
138  if ( Abc_SopIsExorType(pSop) )
139  {
140  gSum = 0;
141  for ( i = 0; i < nFanins; i++ )
142  gSum = Gia_ManHashXor( pGia, gSum, gFanins[i] );
143  }
144  else
145  {
146  // go through the cubes of the node's SOP
147  gSum = 0;
148  Abc_SopForEachCube( pSop, nFanins, pCube )
149  {
150  // create the AND of literals
151  gAnd = 1;
152  Abc_CubeForEachVar( pCube, Value, i )
153  {
154  if ( Value == '1' )
155  gAnd = Gia_ManHashAnd( pGia, gAnd, gFanins[i] );
156  else if ( Value == '0' )
157  gAnd = Gia_ManHashAnd( pGia, gAnd, Abc_LitNot(gFanins[i]) );
158  }
159  // add to the sum of cubes
160  gSum = Gia_ManHashAnd( pGia, Abc_LitNot(gSum), Abc_LitNot(gAnd) );
161  gSum = Abc_LitNot( gSum );
162  }
163  }
164  // decide whether to complement the result
165  if ( Abc_SopIsComplement(pSop) )
166  gSum = Abc_LitNot(gSum);
167  return gSum;
168 }
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:658
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
#define Abc_CubeForEachVar(pCube, Value, i)
Definition: abc.h:529
ABC_DLL int Abc_SopIsExorType(char *pSop)
Definition: abcSop.c:802
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
ABC_DLL int Abc_SopIsComplement(char *pSop)
Definition: abcSop.c:655
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
Vec_Ptr_t* Gia_GetFakeNames ( int  nNames)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file giaClp.c.

52 {
53  Vec_Ptr_t * vNames;
54  char Buffer[5];
55  int i;
56 
57  vNames = Vec_PtrAlloc( nNames );
58  for ( i = 0; i < nNames; i++ )
59  {
60  if ( nNames < 26 )
61  {
62  Buffer[0] = 'a' + i;
63  Buffer[1] = 0;
64  }
65  else
66  {
67  Buffer[0] = 'a' + i%26;
68  Buffer[1] = '0' + i/26;
69  Buffer[2] = 0;
70  }
71  Vec_PtrPush( vNames, Extra_UtilStrsav(Buffer) );
72  }
73  return vNames;
74 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
char * Extra_UtilStrsav(const char *s)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Vec_Ptr_t* Gia_ManCollapse ( Gia_Man_t p,
DdManager dd,
int  nBddLimit,
int  fVerbose 
)

Definition at line 288 of file giaClp.c.

289 {
290  Vec_Ptr_t * vFuncs;
291  DdNode * bFunc0, * bFunc1, * bFunc;
292  Gia_Obj_t * pObj;
293  int i, Id;
294  Gia_ManCreateRefs( p );
295  // assign constant node
296  vFuncs = Vec_PtrStart( Gia_ManObjNum(p) );
297  if ( Gia_ObjRefNumId(p, 0) > 0 )
299  // assign elementary variables
300  Gia_ManForEachCiId( p, Id, i )
301  if ( Gia_ObjRefNumId(p, Id) > 0 )
302  Vec_PtrWriteEntry( vFuncs, Id, Cudd_bddIthVar(dd,i) ), Cudd_Ref(Cudd_bddIthVar(dd,i));
303  // create BDD for AND nodes
304  Gia_ManForEachAnd( p, pObj, i )
305  {
306  bFunc0 = Cudd_NotCond( (DdNode *)Vec_PtrEntry(vFuncs, Gia_ObjFaninId0(pObj, i)), Gia_ObjFaninC0(pObj) );
307  bFunc1 = Cudd_NotCond( (DdNode *)Vec_PtrEntry(vFuncs, Gia_ObjFaninId1(pObj, i)), Gia_ObjFaninC1(pObj) );
308  bFunc = Cudd_bddAndLimit( dd, bFunc0, bFunc1, nBddLimit );
309  if ( bFunc == NULL )
310  {
311  Gia_ManCollapseDeref( dd, vFuncs );
312  return NULL;
313  }
314  Cudd_Ref( bFunc );
315  Vec_PtrWriteEntry( vFuncs, i, bFunc );
316  Gia_ObjCollapseDeref( p, dd, vFuncs, Gia_ObjFaninId0(pObj, i) );
317  Gia_ObjCollapseDeref( p, dd, vFuncs, Gia_ObjFaninId1(pObj, i) );
318  }
319  // create BDD for outputs
320  Gia_ManForEachCoId( p, Id, i )
321  {
322  pObj = Gia_ManCo( p, i );
323  bFunc0 = Cudd_NotCond( (DdNode *)Vec_PtrEntry(vFuncs, Gia_ObjFaninId0(pObj, Id)), Gia_ObjFaninC0(pObj) );
324  Vec_PtrWriteEntry( vFuncs, Id, bFunc0 ); Cudd_Ref( bFunc0 );
325  Gia_ObjCollapseDeref( p, dd, vFuncs, Gia_ObjFaninId0(pObj, Id) );
326  }
327  assert( Vec_PtrSize(vFuncs) == Vec_PtrCountZero(vFuncs) + Gia_ManCoNum(p) );
328  // compact
329  Gia_ManForEachCoId( p, Id, i )
330  Vec_PtrWriteEntry( vFuncs, i, Vec_PtrEntry(vFuncs, Id) );
331  Vec_PtrShrink( vFuncs, Gia_ManCoNum(p) );
332  return vFuncs;
333 }
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition: giaUtil.c:715
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Definition: cudd.h:278
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
DdNode * Cudd_ReadLogicZero(DdManager *dd)
Definition: cuddAPI.c:1058
static int Gia_ObjRefNumId(Gia_Man_t *p, int Id)
Definition: gia.h:518
DdNode * Cudd_bddAndLimit(DdManager *dd, DdNode *f, DdNode *g, unsigned int limit)
Definition: cuddBddIte.c:346
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: gia.h:75
#define Gia_ManForEachCiId(p, Id, i)
Definition: gia.h:1018
if(last==0)
Definition: sparse_int.h:34
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static int Vec_PtrCountZero(Vec_Ptr_t *p)
Definition: vecPtr.h:343
void Gia_ObjCollapseDeref(Gia_Man_t *p, DdManager *dd, Vec_Ptr_t *vFuncs, int Id)
Definition: giaClp.c:281
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static Gia_Obj_t * Gia_ManCo(Gia_Man_t *p, int v)
Definition: gia.h:404
void Gia_ManCollapseDeref(DdManager *dd, Vec_Ptr_t *vFuncs)
Definition: giaClp.c:273
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
#define Cudd_NotCond(node, c)
Definition: cudd.h:383
#define assert(ex)
Definition: util_old.h:213
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:461
#define Gia_ManForEachCoId(p, Id, i)
Definition: gia.h:1026
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)
Definition: gia.h:460
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
void Gia_ManCollapseDeref ( DdManager dd,
Vec_Ptr_t vFuncs 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 273 of file giaClp.c.

274 {
275  DdNode * bFunc; int i;
276  Vec_PtrForEachEntry( DdNode *, vFuncs, bFunc, i )
277  if ( bFunc )
278  Cudd_RecursiveDeref( dd, bFunc );
279  Vec_PtrFree( vFuncs );
280 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
if(last==0)
Definition: sparse_int.h:34
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Gia_Man_t* Gia_ManCollapseTest ( Gia_Man_t p,
int  fVerbose 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 346 of file giaClp.c.

347 {
348  Gia_Man_t * pNew;
349  DdManager * dd, * ddNew;
350  Dsd_Manager_t * pManDsd;
351  Vec_Ptr_t * vFuncs;
352  // derive global BDDs
355  vFuncs = Gia_ManCollapse( p, dd, 10000, 0 );
356  Cudd_AutodynDisable( dd );
357  if ( vFuncs == NULL )
358  {
359  Extra_StopManager( dd );
360  return Gia_ManDup(p);
361  }
362  // start ISOP manager
364  Cudd_zddVarsFromBddVars( ddNew, 2 );
365 // Cudd_ReduceHeap( dd, CUDD_REORDER_SYMM_SIFT, 100 );
366  if ( fVerbose )
367  printf( "Ins = %d. Outs = %d. Shared BDD nodes = %d. Peak live nodes = %d. Peak nodes = %d.\n",
368  Gia_ManCiNum(p), Gia_ManCoNum(p),
369  Cudd_SharingSize( (DdNode **)Vec_PtrArray(vFuncs), Vec_PtrSize(vFuncs) ),
371  // perform decomposition
372  pManDsd = Dsd_ManagerStart( dd, Gia_ManCiNum(p), 0 );
373  Dsd_Decompose( pManDsd, (DdNode **)Vec_PtrArray(vFuncs), Vec_PtrSize(vFuncs) );
374  if ( fVerbose )
375  {
376  Vec_Ptr_t * vNamesCi = Gia_GetFakeNames( Gia_ManCiNum(p) );
377  Vec_Ptr_t * vNamesCo = Gia_GetFakeNames( Gia_ManCoNum(p) );
378  char ** ppNamesCi = (char **)Vec_PtrArray( vNamesCi );
379  char ** ppNamesCo = (char **)Vec_PtrArray( vNamesCo );
380  Dsd_TreePrint( stdout, pManDsd, ppNamesCi, ppNamesCo, 0, -1 );
381  Vec_PtrFreeFree( vNamesCi );
382  Vec_PtrFreeFree( vNamesCo );
383  }
384 
385  pNew = Gia_ManRebuild( p, pManDsd, ddNew );
386  Dsd_ManagerStop( pManDsd );
387  // return manager
388  Gia_ManCollapseDeref( dd, vFuncs );
389  Extra_StopManager( dd );
390  Extra_StopManager( ddNew );
391  return pNew;
392 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
#define CUDD_UNIQUE_SLOTS
Definition: cudd.h:97
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
Definition: cudd.h:278
void Dsd_ManagerStop(Dsd_Manager_t *dMan)
Definition: dsdMan.c:100
static void Vec_PtrFreeFree(Vec_Ptr_t *p)
Definition: vecPtr.h:569
#define CUDD_CACHE_SLOTS
Definition: cudd.h:98
void Extra_StopManager(DdManager *dd)
Definition: extraBddMisc.c:223
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
int Cudd_ReadPeakLiveNodeCount(DdManager *dd)
Definition: cuddAPI.c:3151
Vec_Ptr_t * Gia_ManCollapse(Gia_Man_t *p, DdManager *dd, int nBddLimit, int fVerbose)
Definition: giaClp.c:288
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
Definition: cuddInit.c:125
STRUCTURE DEFINITIONS ///.
Definition: dsdInt.h:40
Dsd_Manager_t * Dsd_ManagerStart(DdManager *dd, int nSuppMax, int fVerbose)
FUNCTION DECLARATIONS ///.
Definition: dsdMan.c:47
void Cudd_AutodynDisable(DdManager *unique)
Definition: cuddAPI.c:708
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
long Cudd_ReadNodeCount(DdManager *dd)
Definition: cuddAPI.c:3179
Vec_Ptr_t * Gia_GetFakeNames(int nNames)
FUNCTION DEFINITIONS ///.
Definition: giaClp.c:51
Gia_Man_t * Gia_ManRebuild(Gia_Man_t *p, Dsd_Manager_t *pManDsd, DdManager *ddNew)
Definition: giaClp.c:206
void Gia_ManCollapseDeref(DdManager *dd, Vec_Ptr_t *vFuncs)
Definition: giaClp.c:273
Definition: gia.h:95
int Cudd_zddVarsFromBddVars(DdManager *dd, int multiplicity)
Definition: cuddAPI.c:519
void Cudd_AutodynEnable(DdManager *unique, Cudd_ReorderingType method)
Definition: cuddAPI.c:669
void Dsd_Decompose(Dsd_Manager_t *dMan, DdNode **pbFuncs, int nFuncs)
DECOMPOSITION FUNCTIONS ///.
Definition: dsdProc.c:113
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
int Cudd_SharingSize(DdNode **nodeArray, int n)
Definition: cuddUtil.c:544
void Dsd_TreePrint(FILE *pFile, Dsd_Manager_t *dMan, char *pInputNames[], char *pOutputNames[], int fShortNames, int Output)
Definition: dsdTree.c:641
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
void Gia_ManCollapseTestTest ( Gia_Man_t p)

Definition at line 393 of file giaClp.c.

394 {
395  Gia_Man_t * pNew;
396  pNew = Gia_ManCollapseTest( p, 0 );
397  Gia_ManPrintStats( p, NULL );
398  Gia_ManPrintStats( pNew, NULL );
399  Gia_ManStop( pNew );
400 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition: giaMan.c:389
Gia_Man_t * Gia_ManCollapseTest(Gia_Man_t *p, int fVerbose)
Definition: giaClp.c:346
Definition: gia.h:95
int Gia_ManFactorNode ( Gia_Man_t p,
char *  pSop,
Vec_Int_t vLeaves 
)

Definition at line 99 of file giaFx.c.

100 {
101  if ( Kit_PlaGetVarNum(pSop) == 0 )
102  return Abc_LitNotCond( 1, Kit_PlaIsConst0(pSop) );
103  assert( Kit_PlaGetVarNum(pSop) == Vec_IntSize(vLeaves) );
104  if ( Kit_PlaGetVarNum(pSop) > 2 && Kit_PlaGetCubeNum(pSop) > 1 )
105  {
106  Dec_Graph_t * pFForm;
107  Dec_Node_t * pFFNode;
108  int i, Lit;
109  pFForm = Dec_Factor( pSop );
110  // assign fanins
111  Dec_GraphForEachLeaf( pFForm, pFFNode, i )
112  {
113  assert( Vec_IntEntry(vLeaves, i) >= 0 );
114  pFFNode->iFunc = Vec_IntEntry(vLeaves, i);
115  }
116  // perform strashing
117  Lit = Gia_ManGraphToAig( p, pFForm );
118  Dec_GraphFree( pFForm );
119  return Lit;
120  }
121  return Gia_ManSopToAig( p, pSop, vLeaves );
122 }
int Kit_PlaIsConst0(char *pSop)
DECLARATIONS ///.
Definition: kitPla.c:46
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition: decFactor.c:55
int Kit_PlaGetCubeNum(char *pSop)
Definition: kitPla.c:138
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
ABC_NAMESPACE_IMPL_START int Gia_ManGraphToAig(Gia_Man_t *p, Dec_Graph_t *pGraph)
DECLARATIONS ///.
Definition: giaFx.c:50
int Gia_ManSopToAig(Gia_Man_t *p, char *pSop, Vec_Int_t *vLeaves)
Definition: giaFx.c:70
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int iFunc
Definition: dec.h:55
#define Dec_GraphForEachLeaf(pGraph, pLeaf, i)
ITERATORS ///.
Definition: dec.h:98
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
#define assert(ex)
Definition: util_old.h:213
int Kit_PlaGetVarNum(char *pSop)
Definition: kitPla.c:118
Gia_Man_t* Gia_ManRebuild ( Gia_Man_t p,
Dsd_Manager_t pManDsd,
DdManager ddNew 
)

Definition at line 206 of file giaClp.c.

207 {
208  Gia_Man_t * pNew;
209  Dsd_Node_t ** ppNodesDsd;
210  Dsd_Node_t * pNodeDsd;
211  int i, nNodesDsd, iLit = -1;
212  Vec_Str_t * vSop, * vCube;
213  Vec_Int_t * vFanins;
214 
215  vFanins = Vec_IntAlloc( 1000 );
216  vSop = Vec_StrAlloc( 10000 );
217  vCube = Vec_StrAlloc( 1000 );
218 
219  pNew = Gia_ManStart( 2*Gia_ManObjNum(p) );
220  pNew->pName = Abc_UtilStrsav( p->pName );
221  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
222  Gia_ManHashAlloc( pNew );
223 
224  // save the CI nodes in the DSD nodes
225  Dsd_NodeSetMark( Dsd_ManagerReadConst1(pManDsd), 1 );
226  for ( i = 0; i < Gia_ManCiNum(p); i++ )
227  {
228  pNodeDsd = Dsd_ManagerReadInput( pManDsd, i );
229  Dsd_NodeSetMark( pNodeDsd, Gia_ManAppendCi( pNew ) );
230  }
231 
232  // collect DSD nodes in DFS order (leaves and const1 are not collected)
233  ppNodesDsd = Dsd_TreeCollectNodesDfs( pManDsd, &nNodesDsd );
234  for ( i = 0; i < nNodesDsd; i++ )
235  {
236  iLit = Gia_ManRebuildNode( pManDsd, ppNodesDsd[i], pNew, ddNew, vFanins, vSop, vCube );
237  if ( iLit == -1 )
238  break;
239  }
240  ABC_FREE( ppNodesDsd );
241  Vec_IntFree( vFanins );
242  Vec_StrFree( vSop );
243  Vec_StrFree( vCube );
244  if ( iLit == -1 )
245  {
246  Gia_ManStop( pNew );
247  return Gia_ManDup(p);
248  }
249 
250  // set the pointers to the CO drivers
251  for ( i = 0; i < Gia_ManCoNum(p); i++ )
252  {
253  pNodeDsd = Dsd_ManagerReadRoot( pManDsd, i );
254  iLit = Dsd_NodeReadMark( Dsd_Regular(pNodeDsd) );
255  iLit = Abc_LitNotCond( iLit, Dsd_IsComplement(pNodeDsd) );
256  Gia_ManAppendCo( pNew, iLit );
257  }
258  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
259  return pNew;
260 }
int Gia_ManRebuildNode(Dsd_Manager_t *pManDsd, Dsd_Node_t *pNodeDsd, Gia_Man_t *pNew, DdManager *ddNew, Vec_Int_t *vFanins, Vec_Str_t *vSop, Vec_Str_t *vCube)
Definition: giaClp.c:143
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Dsd_Node_t ** Dsd_TreeCollectNodesDfs(Dsd_Manager_t *dMan, int *pnNodes)
Definition: dsdTree.c:555
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
Dsd_Node_t * Dsd_ManagerReadInput(Dsd_Manager_t *pMan, int i)
Definition: dsdApi.c:94
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
static Vec_Str_t * Vec_StrAlloc(int nCap)
Definition: bblif.c:495
Dsd_Node_t * Dsd_ManagerReadRoot(Dsd_Manager_t *pMan, int i)
Definition: dsdApi.c:93
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Dsd_Node_t * Dsd_ManagerReadConst1(Dsd_Manager_t *pMan)
Definition: dsdApi.c:95
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void Vec_StrFree(Vec_Str_t *p)
Definition: bblif.c:616
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
#define Dsd_Regular(p)
Definition: dsd.h:69
#define Dsd_IsComplement(p)
MACRO DEFINITIONS ///.
Definition: dsd.h:68
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
int Dsd_NodeReadMark(Dsd_Node_t *p)
Definition: dsdApi.c:59
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
void Dsd_NodeSetMark(Dsd_Node_t *p, int Mark)
Definition: dsdApi.c:77
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ManCoNum(Gia_Man_t *p)
Definition: gia.h:384
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
int Gia_ManRebuildIsop ( DdManager dd,
DdNode bLocal,
Gia_Man_t pNew,
Vec_Int_t vFanins,
Vec_Str_t vSop,
Vec_Str_t vCube 
)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file giaClp.c.

88 {
89  char * pSop;
90  DdNode * bCover, * zCover, * zCover0, * zCover1;
91  int nFanins = Vec_IntSize(vFanins);
92  int fPhase, nCubes, nCubes0, nCubes1;
93 
94  // get the ZDD of the negative polarity
95  bCover = Cudd_zddIsop( dd, Cudd_Not(bLocal), Cudd_Not(bLocal), &zCover0 );
96  Cudd_Ref( zCover0 );
97  Cudd_Ref( bCover );
98  Cudd_RecursiveDeref( dd, bCover );
99  nCubes0 = Abc_CountZddCubes( dd, zCover0 );
100 
101  // get the ZDD of the positive polarity
102  bCover = Cudd_zddIsop( dd, bLocal, bLocal, &zCover1 );
103  Cudd_Ref( zCover1 );
104  Cudd_Ref( bCover );
105  Cudd_RecursiveDeref( dd, bCover );
106  nCubes1 = Abc_CountZddCubes( dd, zCover1 );
107 
108  // compare the number of cubes
109  if ( nCubes1 <= nCubes0 )
110  { // use positive polarity
111  nCubes = nCubes1;
112  zCover = zCover1;
113  Cudd_RecursiveDerefZdd( dd, zCover0 );
114  fPhase = 1;
115  }
116  else
117  { // use negative polarity
118  nCubes = nCubes0;
119  zCover = zCover0;
120  Cudd_RecursiveDerefZdd( dd, zCover1 );
121  fPhase = 0;
122  }
123  if ( nCubes > 1000 )
124  {
125  Cudd_RecursiveDerefZdd( dd, zCover );
126  return -1;
127  }
128 
129  // allocate memory for the cover
130  Vec_StrGrow( vSop, (nFanins + 3) * nCubes + 1 );
131  pSop = Vec_StrArray( vSop );
132  pSop[(nFanins + 3) * nCubes] = 0;
133  // create the SOP
134  Vec_StrFill( vCube, nFanins, '-' );
135  Vec_StrPush( vCube, '\0' );
136  Abc_ConvertZddToSop( dd, zCover, pSop, nFanins, vCube, fPhase );
137  Cudd_RecursiveDerefZdd( dd, zCover );
138 
139  // perform factoring
140 // return Abc_NtkDeriveFlatGiaSop( pNew, Vec_IntArray(vFanins), pSop );
141  return Gia_ManFactorNode( pNew, pSop, vFanins );
142 }
void Cudd_RecursiveDerefZdd(DdManager *table, DdNode *n)
Definition: cuddRef.c:385
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
static char * Vec_StrArray(Vec_Str_t *p)
Definition: vecStr.h:272
static void Vec_StrPush(Vec_Str_t *p, char Entry)
Definition: vecStr.h:535
static void Vec_StrGrow(Vec_Str_t *p, int nCapMin)
Definition: vecStr.h:404
ABC_NAMESPACE_IMPL_START int Abc_ConvertZddToSop(DdManager *dd, DdNode *zCover, char *pSop, int nFanins, Vec_Str_t *vCube, int fPhase)
DECLARATIONS ///.
Definition: abcFunc.c:471
static void Vec_StrFill(Vec_Str_t *p, int nSize, char Fill)
Definition: vecStr.h:423
DdNode * Cudd_zddIsop(DdManager *dd, DdNode *L, DdNode *U, DdNode **zdd_I)
Definition: cuddZddIsop.c:136
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int Abc_CountZddCubes(DdManager *dd, DdNode *zCover)
Definition: abcFunc.c:593
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
int Gia_ManFactorNode(Gia_Man_t *p, char *pSop, Vec_Int_t *vLeaves)
Definition: giaFx.c:99
int Gia_ManRebuildNode ( Dsd_Manager_t pManDsd,
Dsd_Node_t pNodeDsd,
Gia_Man_t pNew,
DdManager ddNew,
Vec_Int_t vFanins,
Vec_Str_t vSop,
Vec_Str_t vCube 
)

Definition at line 143 of file giaClp.c.

144 {
145  DdManager * ddDsd = Dsd_ManagerReadDd( pManDsd );
146  DdNode * bLocal, * bTemp;
147  Dsd_Node_t * pFaninDsd;
148  Dsd_Type_t Type;
149  int i, nDecs, iLit = -1;
150 
151  // add the fanins
152  Type = Dsd_NodeReadType( pNodeDsd );
153  nDecs = Dsd_NodeReadDecsNum( pNodeDsd );
154  assert( nDecs > 1 );
155  Vec_IntClear( vFanins );
156  for ( i = 0; i < nDecs; i++ )
157  {
158  pFaninDsd = Dsd_NodeReadDec( pNodeDsd, i );
159  iLit = Dsd_NodeReadMark( Dsd_Regular(pFaninDsd) );
160  iLit = Abc_LitNotCond( iLit, Dsd_IsComplement(pFaninDsd) );
161  assert( Type == DSD_NODE_OR || !Dsd_IsComplement(pFaninDsd) );
162  Vec_IntPush( vFanins, iLit );
163  }
164 
165  // create the local function depending on the type of the node
166  switch ( Type )
167  {
168  case DSD_NODE_CONST1:
169  {
170  iLit = 1;
171  break;
172  }
173  case DSD_NODE_OR:
174  {
175  iLit = 0;
176  for ( i = 0; i < nDecs; i++ )
177  iLit = Gia_ManHashOr( pNew, iLit, Vec_IntEntry(vFanins, i) );
178  break;
179  }
180  case DSD_NODE_EXOR:
181  {
182  iLit = 0;
183  for ( i = 0; i < nDecs; i++ )
184  iLit = Gia_ManHashXor( pNew, iLit, Vec_IntEntry(vFanins, i) );
185  break;
186  }
187  case DSD_NODE_PRIME:
188  {
189  bLocal = Dsd_TreeGetPrimeFunction( ddDsd, pNodeDsd ); Cudd_Ref( bLocal );
190  bLocal = Extra_TransferLevelByLevel( ddDsd, ddNew, bTemp = bLocal ); Cudd_Ref( bLocal );
191  Cudd_RecursiveDeref( ddDsd, bTemp );
192  // bLocal is now in the new BDD manager
193  iLit = Gia_ManRebuildIsop( ddNew, bLocal, pNew, vFanins, vSop, vCube );
194  Cudd_RecursiveDeref( ddNew, bLocal );
195  break;
196  }
197  default:
198  {
199  assert( 0 );
200  break;
201  }
202  }
203  Dsd_NodeSetMark( pNodeDsd, iLit );
204  return iLit;
205 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:658
DdManager * Dsd_ManagerReadDd(Dsd_Manager_t *pMan)
Definition: dsdApi.c:96
int Dsd_NodeReadDecsNum(Dsd_Node_t *p)
Definition: dsdApi.c:58
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
DdNode * Extra_TransferLevelByLevel(DdManager *ddSource, DdManager *ddDestination, DdNode *f)
Definition: extraBddMisc.c:112
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Dsd_Regular(p)
Definition: dsd.h:69
#define Dsd_IsComplement(p)
MACRO DEFINITIONS ///.
Definition: dsd.h:68
DdNode * Dsd_TreeGetPrimeFunction(DdManager *dd, Dsd_Node_t *pNode)
FUNCTION DEFINITIONS ///.
Definition: dsdLocal.c:54
int Dsd_NodeReadMark(Dsd_Node_t *p)
Definition: dsdApi.c:59
#define assert(ex)
Definition: util_old.h:213
enum Dsd_Type_t_ Dsd_Type_t
Definition: dsd.h:61
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
Dsd_Type_t Dsd_NodeReadType(Dsd_Node_t *p)
FUNCTION DEFINITIONS ///.
Definition: dsdApi.c:53
Dsd_Node_t * Dsd_NodeReadDec(Dsd_Node_t *p, int i)
Definition: dsdApi.c:57
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
int Gia_ManRebuildIsop(DdManager *dd, DdNode *bLocal, Gia_Man_t *pNew, Vec_Int_t *vFanins, Vec_Str_t *vSop, Vec_Str_t *vCube)
Definition: giaClp.c:87
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:611
void Dsd_NodeSetMark(Dsd_Node_t *p, int Mark)
Definition: dsdApi.c:77
void Gia_ObjCollapseDeref ( Gia_Man_t p,
DdManager dd,
Vec_Ptr_t vFuncs,
int  Id 
)

Definition at line 281 of file giaClp.c.

282 {
283  if ( Gia_ObjRefDecId(p, Id) )
284  return;
285  Cudd_RecursiveDeref( dd, (DdNode *)Vec_PtrEntry(vFuncs, Id) );
286  Vec_PtrWriteEntry( vFuncs, Id, NULL );
287 }
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
static int Gia_ObjRefDecId(Gia_Man_t *p, int Id)
Definition: gia.h:520
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362