abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcFxu.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcFxu.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Interface with the fast extract package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcFxu.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "opt/fxu/fxu.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk );
32 static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
33 static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
34 
35 extern int Fxu_FastExtract( Fxu_Data_t * pData );
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// FUNCTION DEFINITIONS ///
39 ////////////////////////////////////////////////////////////////////////
40 
41 /**Function*************************************************************
42 
43  Synopsis [Sets default values of the FXU parameters.]
44 
45  Description []
46 
47  SideEffects []
48 
49  SeeAlso []
50 
51 ***********************************************************************/
53 {
54  memset( p, 0, sizeof(Fxu_Data_t) );
55  p->nSingleMax = 20000;
56  p->nPairsMax = 30000;
57  p->nNodesExt =1000000;
58  p->WeightMin = 0;
59  p->LitCountMax= 0;
60  p->fOnlyS = 0;
61  p->fOnlyD = 0;
62  p->fUse0 = 0;
63  p->fUseCompl = 1;
64  p->fVerbose = 0;
65 }
66 
67 /**Function*************************************************************
68 
69  Synopsis [Performs fast_extract on the current network.]
70 
71  Description [Takes the network and the maximum number of nodes to extract.
72  Uses the concurrent double-cube and single cube divisor extraction procedure.
73  Modifies the network in the end, after extracting all nodes. Note that
74  Ntk_NetworkSweep() may increase the performance of this procedure because
75  the single-literal nodes will not be created in the sparse matrix. Returns 1
76  if the network has been changed.]
77 
78  SideEffects []
79 
80  SeeAlso []
81 
82 ***********************************************************************/
84 {
85  assert( Abc_NtkIsLogic(pNtk) );
86  // if the network is already in the SOP form, it may come from BLIF file
87  // and it may not be SCC-free, in which case FXU will not work correctly
88  if ( Abc_NtkIsSopLogic(pNtk) )
89  { // to make sure the SOPs are SCC-free
90 // Abc_NtkSopToBdd(pNtk);
91 // Abc_NtkBddToSop(pNtk);
92  }
93  // get the network in the SOP form
94  if ( !Abc_NtkToSop(pNtk, 0) )
95  {
96  printf( "Abc_NtkFastExtract(): Converting to SOPs has failed.\n" );
97  return 0;
98  }
99  // check if the network meets the requirements
100  if ( !Abc_NtkFxuCheck(pNtk) )
101  {
102  printf( "Abc_NtkFastExtract: Nodes have duplicated or complemented fanins. FXU is not performed.\n" );
103  return 0;
104  }
105  // sweep removes useless nodes
106  Abc_NtkCleanup( pNtk, 0 );
107  // collect information about the covers
108  Abc_NtkFxuCollectInfo( pNtk, p );
109  // call the fast extract procedure
110  if ( Fxu_FastExtract(p) > 0 )
111  {
112  // update the network
113  Abc_NtkFxuReconstruct( pNtk, p );
114  // make sure everything is okay
115  if ( !Abc_NtkCheck( pNtk ) )
116  printf( "Abc_NtkFastExtract: The network check has failed.\n" );
117  return 1;
118  }
119  else
120  printf( "Warning: The network has not been changed by \"fx\".\n" );
121  return 0;
122 }
123 
124 
125 /**Function*************************************************************
126 
127  Synopsis [Makes sure the nodes do not have complemented and duplicated fanins.]
128 
129  Description []
130 
131  SideEffects []
132 
133  SeeAlso []
134 
135 ***********************************************************************/
137 {
138  Abc_Obj_t * pNode, * pFanin1, * pFanin2;
139  int n, i, k;
140  Abc_NtkForEachNode( pNtk, pNode, n )
141  {
142  Abc_ObjForEachFanin( pNode, pFanin1, i )
143  {
144  if ( i < 2 && Abc_ObjFaninC(pNode, i) )
145  return 0;
146  Abc_ObjForEachFanin( pNode, pFanin2, k )
147  {
148  if ( i == k )
149  continue;
150  if ( pFanin1 == pFanin2 )
151  return 0;
152  }
153  }
154  }
155  return 1;
156 }
157 
158 /**Function*************************************************************
159 
160  Synopsis [Collect information about the network for fast_extract.]
161 
162  Description []
163 
164  SideEffects []
165 
166  SeeAlso []
167 
168 ***********************************************************************/
170 {
171  Abc_Obj_t * pNode;
172  int i;
173  // add information to the manager
174  p->pManSop = (Mem_Flex_t *)pNtk->pManFunc;
175  p->vSops = Vec_PtrAlloc(0);
176  p->vFanins = Vec_PtrAlloc(0);
177  p->vSopsNew = Vec_PtrAlloc(0);
178  p->vFaninsNew = Vec_PtrAlloc(0);
179  Vec_PtrFill( p->vSops, Abc_NtkObjNumMax(pNtk), NULL );
180  Vec_PtrFill( p->vFanins, Abc_NtkObjNumMax(pNtk), NULL );
181  Vec_PtrFill( p->vSopsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
182  Vec_PtrFill( p->vFaninsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
183  // add SOPs and fanin array
184  Abc_NtkForEachNode( pNtk, pNode, i )
185  {
186  if ( Abc_SopGetVarNum((char *)pNode->pData) < 2 )
187  continue;
188  if ( Abc_SopGetCubeNum((char *)pNode->pData) < 1 )
189  continue;
190  p->vSops->pArray[i] = pNode->pData;
191  p->vFanins->pArray[i] = &pNode->vFanins;
192  }
193  p->nNodesOld = Abc_NtkObjNumMax(pNtk);
194 }
195 
196 /**Function*************************************************************
197 
198  Synopsis []
199 
200  Description []
201 
202  SideEffects []
203 
204  SeeAlso []
205 
206 ***********************************************************************/
208 {
209  int i;
210  // free the arrays of new fanins
211  if ( p->vFaninsNew )
212  for ( i = 0; i < p->vFaninsNew->nSize; i++ )
213  if ( p->vFaninsNew->pArray[i] )
214  Vec_IntFree( (Vec_Int_t *)p->vFaninsNew->pArray[i] );
215  // free the arrays
216  if ( p->vSops ) Vec_PtrFree( p->vSops );
217  if ( p->vSopsNew ) Vec_PtrFree( p->vSopsNew );
218  if ( p->vFanins ) Vec_PtrFree( p->vFanins );
219  if ( p->vFaninsNew ) Vec_PtrFree( p->vFaninsNew );
220 // ABC_FREE( p );
221 }
222 
223 /**Function*************************************************************
224 
225  Synopsis [Reconstructs the network after FX.]
226 
227  Description []
228 
229  SideEffects []
230 
231  SeeAlso []
232 
233 ***********************************************************************/
235 {
236  Vec_Int_t * vFanins;
237  Abc_Obj_t * pNode, * pFanin;
238  int i, k;
239 
240  assert( p->vFanins->nSize < p->vFaninsNew->nSize );
241  // create the new nodes
242  for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
243  {
244  // start the node
245  pNode = Abc_NtkCreateNode( pNtk );
246  assert( i == (int)pNode->Id );
247  }
248  // update the old nodes
249  for ( i = 0; i < p->vFanins->nSize; i++ )
250  {
251  // the new array of fanins
252  vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
253  if ( vFanins == NULL )
254  continue;
255  // remove old fanins
256  pNode = Abc_NtkObj( pNtk, i );
257  Abc_ObjRemoveFanins( pNode );
258  // add new fanins
259  vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
260  for ( k = 0; k < vFanins->nSize; k++ )
261  {
262  pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
263  Abc_ObjAddFanin( pNode, pFanin );
264  }
265  pNode->pData = p->vSopsNew->pArray[i];
266  assert( pNode->pData != NULL );
267  }
268  // set up the new nodes
269  for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
270  {
271  // get the new node
272  pNode = Abc_NtkObj( pNtk, i );
273  // add the fanins
274  vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
275  for ( k = 0; k < vFanins->nSize; k++ )
276  {
277  pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
278  Abc_ObjAddFanin( pNode, pFanin );
279  }
280  pNode->pData = p->vSopsNew->pArray[i];
281  assert( pNode->pData != NULL );
282  }
283 }
284 
285 
286 ////////////////////////////////////////////////////////////////////////
287 /// END OF FILE ///
288 ////////////////////////////////////////////////////////////////////////
289 
290 
292 
char * memset()
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static void Vec_PtrFill(Vec_Ptr_t *p, int nSize, void *Entry)
Definition: vecPtr.h:449
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition: abcSop.c:489
void Abc_NtkFxuFreeInfo(Fxu_Data_t *p)
Definition: abcFxu.c:207
typedefABC_NAMESPACE_HEADER_START struct FxuDataStruct Fxu_Data_t
INCLUDES ///.
Definition: fxu.h:42
static void Abc_NtkFxuReconstruct(Abc_Ntk_t *pNtk, Fxu_Data_t *p)
Definition: abcFxu.c:234
Vec_Int_t vFanins
Definition: abc.h:143
int Abc_NtkFastExtract(Abc_Ntk_t *pNtk, Fxu_Data_t *p)
Definition: abcFxu.c:83
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static int Abc_NtkIsSopLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:264
ABC_DLL int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSweep.c:476
static Abc_Obj_t * Abc_NtkObj(Abc_Ntk_t *pNtk, int i)
Definition: abc.h:314
for(p=first;p->value< newval;p=p->next)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
void * pManFunc
Definition: abc.h:191
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
if(last==0)
Definition: sparse_int.h:34
void Abc_NtkSetDefaultFxParams(Fxu_Data_t *p)
FUNCTION DEFINITIONS ///.
Definition: abcFxu.c:52
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition: abcFanio.c:141
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static int Abc_ObjFaninC(Abc_Obj_t *pObj, int i)
Definition: abc.h:379
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
int Id
Definition: abc.h:132
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
static ABC_NAMESPACE_IMPL_START int Abc_NtkFxuCheck(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: abcFxu.c:136
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
int Fxu_FastExtract(Fxu_Data_t *pData)
FUNCTION DEFINITIONS ///.
Definition: fxu.c:58
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
static void Abc_NtkFxuCollectInfo(Abc_Ntk_t *pNtk, Fxu_Data_t *p)
Definition: abcFxu.c:169