abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcCollapse.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcCollapse.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Collapsing the network into two-levels.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcCollapse.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "misc/extra/extraBdd.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static Abc_Ntk_t * Abc_NtkFromGlobalBdds( Abc_Ntk_t * pNtk );
32 static Abc_Obj_t * Abc_NodeFromGlobalBdds( Abc_Ntk_t * pNtkNew, DdManager * dd, DdNode * bFunc );
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Function*************************************************************
39 
40  Synopsis [Collapses the network.]
41 
42  Description []
43 
44  SideEffects []
45 
46  SeeAlso []
47 
48 ***********************************************************************/
49 Abc_Ntk_t * Abc_NtkCollapse( Abc_Ntk_t * pNtk, int fBddSizeMax, int fDualRail, int fReorder, int fVerbose )
50 {
51  Abc_Ntk_t * pNtkNew;
52  abctime clk = Abc_Clock();
53 
54  assert( Abc_NtkIsStrash(pNtk) );
55  // compute the global BDDs
56  if ( Abc_NtkBuildGlobalBdds(pNtk, fBddSizeMax, 1, fReorder, fVerbose) == NULL )
57  return NULL;
58  if ( fVerbose )
59  {
60  DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
61  printf( "Shared BDD size = %6d nodes. ", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
62  ABC_PRT( "BDD construction time", Abc_Clock() - clk );
63  }
64 
65  // create the new network
66  pNtkNew = Abc_NtkFromGlobalBdds( pNtk );
67 // Abc_NtkFreeGlobalBdds( pNtk );
68  Abc_NtkFreeGlobalBdds( pNtk, 1 );
69  if ( pNtkNew == NULL )
70  {
71 // Cudd_Quit( pNtk->pManGlob );
72 // pNtk->pManGlob = NULL;
73  return NULL;
74  }
75 // Extra_StopManager( pNtk->pManGlob );
76 // pNtk->pManGlob = NULL;
77 
78  // make the network minimum base
79  Abc_NtkMinimumBase( pNtkNew );
80 
81  if ( pNtk->pExdc )
82  pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
83 
84  // make sure that everything is okay
85  if ( !Abc_NtkCheck( pNtkNew ) )
86  {
87  printf( "Abc_NtkCollapse: The network check has failed.\n" );
88  Abc_NtkDelete( pNtkNew );
89  return NULL;
90  }
91  return pNtkNew;
92 }
93 
94 
95 //int runtime1, runtime2;
96 
97 /**Function*************************************************************
98 
99  Synopsis [Derives the network with the given global BDD.]
100 
101  Description []
102 
103  SideEffects []
104 
105  SeeAlso []
106 
107 ***********************************************************************/
109 {
110 // extern void Extra_ShuffleTest( reo_man * p, DdManager * dd, DdNode * Func );
111 // reo_man * pReo;
112 
113  ProgressBar * pProgress;
114  Abc_Ntk_t * pNtkNew;
115  Abc_Obj_t * pNode, * pDriver, * pNodeNew;
116 // DdManager * dd = pNtk->pManGlob;
117  DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
118  int i;
119 
120  // extract don't-care and compute ISOP
121  if ( pNtk->pExdc )
122  {
123  DdManager * ddExdc = NULL;
124  DdNode * bBddMin, * bBddDc, * bBddL, * bBddU;
125  assert( Abc_NtkIsStrash(pNtk->pExdc) );
126  assert( Abc_NtkCoNum(pNtk->pExdc) == 1 );
127  // compute the global BDDs
128  if ( Abc_NtkBuildGlobalBdds(pNtk->pExdc, 10000000, 1, 1, 0) == NULL )
129  return NULL;
130  // transfer tot the same manager
131  ddExdc = (DdManager *)Abc_NtkGlobalBddMan( pNtk->pExdc );
132  bBddDc = (DdNode *)Abc_ObjGlobalBdd(Abc_NtkCo(pNtk->pExdc, 0));
133  bBddDc = Cudd_bddTransfer( ddExdc, dd, bBddDc ); Cudd_Ref( bBddDc );
134  Abc_NtkFreeGlobalBdds( pNtk->pExdc, 1 );
135  // minimize the output
136  Abc_NtkForEachCo( pNtk, pNode, i )
137  {
138  bBddMin = (DdNode *)Abc_ObjGlobalBdd(pNode);
139  // derive lower and uppwer bound
140  bBddL = Cudd_bddAnd( dd, bBddMin, Cudd_Not(bBddDc) ); Cudd_Ref( bBddL );
141  bBddU = Cudd_bddAnd( dd, Cudd_Not(bBddMin), Cudd_Not(bBddDc) ); Cudd_Ref( bBddU );
142  Cudd_RecursiveDeref( dd, bBddMin );
143  // compute new one
144  bBddMin = Cudd_bddIsop( dd, bBddL, Cudd_Not(bBddU) ); Cudd_Ref( bBddMin );
145  Cudd_RecursiveDeref( dd, bBddL );
146  Cudd_RecursiveDeref( dd, bBddU );
147  // update global BDD
148  Abc_ObjSetGlobalBdd( pNode, bBddMin );
149  //Extra_bddPrint( dd, bBddMin ); printf( "\n" );
150  }
151  Cudd_RecursiveDeref( dd, bBddDc );
152  }
153 
154 // pReo = Extra_ReorderInit( Abc_NtkCiNum(pNtk), 1000 );
155 // runtime1 = runtime2 = 0;
156 
157  // start the new network
158  pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
159  // make sure the new manager has the same number of inputs
160  Cudd_bddIthVar( (DdManager *)pNtkNew->pManFunc, dd->size-1 );
161  // process the POs
162  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
163  Abc_NtkForEachCo( pNtk, pNode, i )
164  {
165  Extra_ProgressBarUpdate( pProgress, i, NULL );
166  pDriver = Abc_ObjFanin0(pNode);
167  if ( Abc_ObjIsCi(pDriver) && !strcmp(Abc_ObjName(pNode), Abc_ObjName(pDriver)) )
168  {
169  Abc_ObjAddFanin( pNode->pCopy, pDriver->pCopy );
170  continue;
171  }
172 // pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, Vec_PtrEntry(pNtk->vFuncsGlob, i) );
173  pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, (DdNode *)Abc_ObjGlobalBdd(pNode) );
174  Abc_ObjAddFanin( pNode->pCopy, pNodeNew );
175 
176 // Extra_ShuffleTest( pReo, dd, Abc_ObjGlobalBdd(pNode) );
177 
178  }
179  Extra_ProgressBarStop( pProgress );
180 
181 // Extra_ReorderQuit( pReo );
182 //ABC_PRT( "Reo ", runtime1 );
183 //ABC_PRT( "Cudd", runtime2 );
184 
185  return pNtkNew;
186 }
187 
188 /**Function*************************************************************
189 
190  Synopsis [Derives the network with the given global BDD.]
191 
192  Description []
193 
194  SideEffects []
195 
196  SeeAlso []
197 
198 ***********************************************************************/
200 {
201  Abc_Obj_t * pNodeNew, * pTemp;
202  int i;
203  // create a new node
204  pNodeNew = Abc_NtkCreateNode( pNtkNew );
205  // add the fanins in the order, in which they appear in the reordered manager
206  Abc_NtkForEachCi( pNtkNew, pTemp, i )
207  Abc_ObjAddFanin( pNodeNew, Abc_NtkCi(pNtkNew, dd->invperm[i]) );
208  // transfer the function
209  pNodeNew->pData = Extra_TransferLevelByLevel( dd, (DdManager *)pNtkNew->pManFunc, bFunc ); Cudd_Ref( (DdNode *)pNodeNew->pData );
210  return pNodeNew;
211 }
212 
213 ////////////////////////////////////////////////////////////////////////
214 /// END OF FILE ///
215 ////////////////////////////////////////////////////////////////////////
216 
217 
219 
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static int Abc_ObjIsCi(Abc_Obj_t *pObj)
Definition: abc.h:351
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
Definition: cudd.h:278
#define Cudd_Not(node)
Definition: cudd.h:367
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcMinBase.c:48
Abc_Ntk_t * pExdc
Definition: abc.h:201
int size
Definition: cuddInt.h:361
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static Abc_Obj_t * Abc_NtkCi(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:317
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static abctime Abc_Clock()
Definition: abc_global.h:279
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_NtkCoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:288
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
DdNode * Cudd_bddTransfer(DdManager *ddSource, DdManager *ddDestination, DdNode *f)
Definition: cuddBridge.c:409
static Abc_Obj_t * Abc_NtkCo(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:318
static void * Abc_ObjGlobalBdd(Abc_Obj_t *pObj)
Definition: abc.h:431
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
int strcmp()
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
Definition: abcNtbdd.c:476
void * pManFunc
Definition: abc.h:191
DdNode * Extra_TransferLevelByLevel(DdManager *ddSource, DdManager *ddDestination, DdNode *f)
Definition: extraBddMisc.c:112
DECLARATIONS ///.
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition: abcNtk.c:106
Abc_Obj_t * pCopy
Definition: abc.h:148
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkFromGlobalBdds(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: abcCollapse.c:108
Abc_Ntk_t * Abc_NtkCollapse(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDualRail, int fReorder, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcCollapse.c:49
void Extra_ProgressBarStop(ProgressBar *p)
static void Abc_ObjSetGlobalBdd(Abc_Obj_t *pObj, void *bF)
Definition: abc.h:432
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
DdNode * Cudd_bddIsop(DdManager *dd, DdNode *L, DdNode *U)
Definition: cuddZddIsop.c:174
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
static void * Abc_NtkGlobalBddMan(Abc_Ntk_t *pNtk)
Definition: abc.h:429
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
#define ABC_PRT(a, t)
Definition: abc_global.h:220
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
Definition: cuddAPI.c:416
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
unsigned int Cudd_ReadKeys(DdManager *dd)
Definition: cuddAPI.c:1626
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
Definition: cuddBddIte.c:314
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
int * invperm
Definition: cuddInt.h:388
void * pData
Definition: abc.h:145
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fVerbose)
Definition: abcNtbdd.c:251
void Cudd_Ref(DdNode *n)
Definition: cuddRef.c:129
unsigned int Cudd_ReadDead(DdManager *dd)
Definition: cuddAPI.c:1646
ABC_INT64_T abctime
Definition: abc_global.h:278
static Abc_Obj_t * Abc_NodeFromGlobalBdds(Abc_Ntk_t *pNtkNew, DdManager *dd, DdNode *bFunc)
Definition: abcCollapse.c:199