ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcFxu.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "opt/fxu/fxu.h"
23
25
26
30
31static int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk );
32static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
33static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
34
35extern int Fxu_FastExtract( Fxu_Data_t * pData );
36
40
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= 4;
60 p->fOnlyS = 0;
61 p->fOnlyD = 0;
62 p->fUse0 = 0;
63 p->fUseCompl = 1;
64 p->fVerbose = 0;
65}
66
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, 1);
92 }
93 // get the network in the SOP form
94 if ( !Abc_NtkToSop(pNtk, -1, ABC_INFINITY) )
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
136int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk )
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
169void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
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
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
234void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
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
289
290
292
void Abc_NtkFxuFreeInfo(Fxu_Data_t *p)
Definition abcFxu.c:207
void Abc_NtkSetDefaultFxParams(Fxu_Data_t *p)
FUNCTION DEFINITIONS ///.
Definition abcFxu.c:52
int Abc_NtkFastExtract(Abc_Ntk_t *pNtk, Fxu_Data_t *p)
Definition abcFxu.c:83
int Fxu_FastExtract(Fxu_Data_t *pData)
FUNCTION DEFINITIONS ///.
Definition fxu.c:58
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL int Abc_NtkCleanup(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:478
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit)
Definition abcFunc.c:1261
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
Definition abcFanio.c:141
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
Definition abcSop.c:537
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
typedefABC_NAMESPACE_HEADER_START struct FxuDataStruct Fxu_Data_t
INCLUDES ///.
Definition fxu.h:42
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
Vec_Int_t vFanins
Definition abc.h:143
int Id
Definition abc.h:132
#define assert(ex)
Definition util_old.h:213
char * memset()