ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcOrchestration.c
Go to the documentation of this file.
1
20#include <stdio.h>
21#include <stdlib.h>
22#include <time.h>
23#include "base/abc/abc.h"
24#include "bool/dec/dec.h"
25#include "opt/rwr/rwr.h"
26#include "bool/kit/kit.h"
27
29
30
34static Cut_Man_t * Abc_NtkStartCutManForRewrite( Abc_Ntk_t * pNtk );
35extern void Abc_NodePrintCuts( Abc_Obj_t * pNode );
36extern void Abc_ManShowCutCone( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves );
37
38extern void Abc_PlaceBegin( Abc_Ntk_t * pNtk );
39extern void Abc_PlaceEnd( Abc_Ntk_t * pNtk );
40extern void Abc_PlaceUpdate( Vec_Ptr_t * vAddedCells, Vec_Ptr_t * vUpdatedNets );
41
42extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
43
44#define ABC_RS_DIV1_MAX 150 // the max number of divisors to consider
45#define ABC_RS_DIV2_MAX 500 // the max number of pair-wise divisors to consider
46
49{
50 // paramers
51 int nLeavesMax; // the max number of leaves in the cone
52 int nDivsMax; // the max number of divisors in the cone
53 // representation of the cone
54 Abc_Obj_t * pRoot; // the root of the cone
55 int nLeaves; // the number of leaves
56 int nDivs; // the number of all divisor (including leaves)
57 int nMffc; // the size of MFFC
58 int nLastGain; // the gain the number of nodes
59 Vec_Ptr_t * vDivs; // the divisors
60 // representation of the simulation info
61 int nBits; // the number of simulation bits
62 int nWords; // the number of unsigneds for siminfo
63 Vec_Ptr_t * vSims; // simulation info
64 unsigned * pInfo; // pointer to simulation info
65 // observability don't-cares
66 unsigned * pCareSet;
67 // internal divisor storage
68 Vec_Ptr_t * vDivs1UP; // the single-node unate divisors
69 Vec_Ptr_t * vDivs1UN; // the single-node unate divisors
70 Vec_Ptr_t * vDivs1B; // the single-node binate divisors
71 Vec_Ptr_t * vDivs2UP0; // the double-node unate divisors
72 Vec_Ptr_t * vDivs2UP1; // the double-node unate divisors
73 Vec_Ptr_t * vDivs2UN0; // the double-node unate divisors
74 Vec_Ptr_t * vDivs2UN1; // the double-node unate divisors
75 // other data
76 Vec_Ptr_t * vTemp; // temporary array of nodes
77 // runtime statistics
90 // improvement statistics
107};
108
109// external procedures
110static Abc_ManRes_t* Abc_ManResubStart( int nLeavesMax, int nDivsMax );
111static void Abc_ManResubStop( Abc_ManRes_t * p );
112static Dec_Graph_t * Abc_ManResubEval( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, int nSteps, int fUpdateLevel, int fVerbose );
113static void Abc_ManResubCleanup( Abc_ManRes_t * p );
114static void Abc_ManResubPrint( Abc_ManRes_t * p );
115
116// other procedures
117static int Abc_ManResubCollectDivs( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, int Required );
118static void Abc_ManResubSimulate( Vec_Ptr_t * vDivs, int nLeaves, Vec_Ptr_t * vSims, int nLeavesMax, int nWords );
119static void Abc_ManResubPrintDivs( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves );
120
121static void Abc_ManResubDivsS( Abc_ManRes_t * p, int Required );
122static void Abc_ManResubDivsD( Abc_ManRes_t * p, int Required );
123static Dec_Graph_t * Abc_ManResubQuit( Abc_ManRes_t * p );
124static Dec_Graph_t * Abc_ManResubDivs0( Abc_ManRes_t * p );
125static Dec_Graph_t * Abc_ManResubDivs1( Abc_ManRes_t * p, int Required );
126static Dec_Graph_t * Abc_ManResubDivs12( Abc_ManRes_t * p, int Required );
127static Dec_Graph_t * Abc_ManResubDivs2( Abc_ManRes_t * p, int Required );
128static Dec_Graph_t * Abc_ManResubDivs3( Abc_ManRes_t * p, int Required );
129
130static Vec_Ptr_t * Abc_CutFactorLarge( Abc_Obj_t * pNode, int nLeavesMax );
131static int Abc_CutVolumeCheck( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves );
132
133extern abctime s_ResubTime;
134
137{
138 int nNodeSizeMax; // the limit on the size of the supernode
139 int nConeSizeMax; // the limit on the size of the containing cone
140 int fVerbose; // the verbosity flag
141 Vec_Ptr_t * vVars; // truth tables
142 Vec_Ptr_t * vFuncs; // functions
143 Vec_Int_t * vMemory; // memory
144 Vec_Str_t * vCube; // temporary
145 Vec_Int_t * vForm; // temporary
146 Vec_Ptr_t * vVisited; // temporary
147 Vec_Ptr_t * vLeaves; // temporary
163};
164
167
170
171int Abc_NtkRewrite3( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rw, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose, int fPlaceEnable )
172{
173 ProgressBar * pProgress;
174 Cut_Man_t * pManCut;
175 Rwr_Man_t * pManRwr;
176 Abc_Obj_t * pNode;
177 FILE *fpt;
178 Dec_Graph_t * pGraph;
179 int i, nNodes, nGain, fCompl;
180 int success = 0;
181 int fail = 0;
182 abctime clk, clkStart = Abc_Clock();
183 assert( Abc_NtkIsStrash(pNtk) );
185 pManRwr = Rwr_ManStart( 0 );
186 if ( pManRwr == NULL )
187 return 0;
188 if ( fUpdateLevel )
189 Abc_NtkStartReverseLevels( pNtk, 0 );
190clk = Abc_Clock();
191 pManCut = Abc_NtkStartCutManForRewrite( pNtk );
192Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
193 pNtk->pManCut = pManCut;
194
195 if ( fVeryVerbose )
196 Rwr_ScoresClean( pManRwr );
197
198 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
199 nNodes = Abc_NtkObjNumMax(pNtk);
200
201 //printf("nNodes: %d\n", nNodes);
202 if ( pGain_rw ) *pGain_rw = Vec_IntAlloc(1);
203
204 pProgress = Extra_ProgressBarStart( stdout, nNodes );
205 fpt = fopen("rewrite_id_nGain.csv", "w");
206 Abc_NtkForEachNode( pNtk, pNode, i )
207 {
208 //printf("rewrite: %d\n", pNode->Id);
209 Extra_ProgressBarUpdate( pProgress, i, NULL );
210 if ( i >= nNodes )
211 break;
212 if ( Abc_NodeIsPersistant(pNode) )
213 {
214 Vec_IntPush( (*pGain_rw), -99);
215 fprintf(fpt, "%d, %d\n", pNode->Id, -99);
216 continue;
217 }
218 if ( Abc_ObjFanoutNum(pNode) > 1000 )
219 {
220 fprintf(fpt, "%d, %d\n", pNode->Id, -99);
221 Vec_IntPush( (*pGain_rw), -99);
222 continue;
223 }
224 nGain = Rwr_NodeRewrite( pManRwr, pManCut, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
225 //printf("nGain3: %d id: %d\n", nGain, i);
226 fprintf(fpt, "%d, %d\n", pNode->Id, nGain);
227 Vec_IntPush( (*pGain_rw), nGain);
228 //printf("size of vector: %d\n", (**pGain_rw).nSize);
229 //printf("write nGain in vector.\n");
230
231 if ( !(nGain > 0 || (nGain == 0 && fUseZeros)) ){
232 fail++;
233 continue;
234 }
235 success++;
236 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
237 fCompl = Rwr_ManReadCompl(pManRwr);
238
239 if ( fPlaceEnable )
241 if ( fCompl ) Dec_GraphComplement( pGraph );
242clk = Abc_Clock();
243 //Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
244
245 if ( fCompl ) Dec_GraphComplement( pGraph );
246 }
247 fclose(fpt);
248 printf("size of vector: %d\n", (**pGain_rw).nSize);
249 //printf("nGain in vector: %d\n", (**pGain_rw).pArray[61]);
250 Extra_ProgressBarStop( pProgress );
251Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
252 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
253 if ( fVerbose )
254 Rwr_ManPrintStats( pManRwr );
255 if ( fVeryVerbose )
256 Rwr_ScoresReport( pManRwr );
257 Rwr_ManStop( pManRwr );
258 Cut_ManStop( pManCut );
259 pNtk->pManCut = NULL;
260
261 {
262 Abc_NtkReassignIds( pNtk );
263 }
264 if ( fUpdateLevel )
266 else
267 Abc_NtkLevel( pNtk );
268 if ( !Abc_NtkCheck( pNtk ) )
269 {
270 printf( "Abc_NtkRewrite3: The network check has failed.\n" );
271 return 0;
272 }
273 printf( "Abc_NtkRewrite3: success : %d; fail : %d\n", success, fail );
274 return 1;
275}
276
277Cut_Man_t * Abc_NtkStartCutManForRewrite( Abc_Ntk_t * pNtk )
278{
279 static Cut_Params_t Params, * pParams = &Params;
280 Cut_Man_t * pManCut;
281 Abc_Obj_t * pObj;
282 int i;
283 memset( pParams, 0, sizeof(Cut_Params_t) );
284 pParams->nVarsMax = 4; // the max cut size ("k" of the k-feasible cuts)
285 pParams->nKeepMax = 250; // the max number of cuts kept at a node
286 pParams->fTruth = 1; // compute truth tables
287 pParams->fFilter = 1; // filter dominated cuts
288 pParams->fSeq = 0; // compute sequential cuts
289 pParams->fDrop = 0; // drop cuts on the fly
290 pParams->fVerbose = 0; // the verbosiness flag
291 pParams->nIdsMax = Abc_NtkObjNumMax( pNtk );
292 pManCut = Cut_ManStart( pParams );
293 if ( pParams->fDrop )
295 Abc_NtkForEachCi( pNtk, pObj, i )
296 if ( Abc_ObjFanoutNum(pObj) > 0 )
297 Cut_NodeSetTriv( pManCut, pObj->Id );
298 return pManCut;
299}
300
301/******Function******************************************
302 Refactor
303********************************************************/
304word * Abc_NodeConeTruth_1( Vec_Ptr_t * vVars, Vec_Ptr_t * vFuncs, int nWordsMax, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVisited )
305{
306 Abc_Obj_t * pNode;
307 word * pTruth0, * pTruth1, * pTruth = NULL;
308 int i, k, nWords = Abc_Truth6WordNum( Vec_PtrSize(vLeaves) );
309 Abc_NodeConeCollect( &pRoot, 1, vLeaves, vVisited, 0 );
310 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pNode, i )
311 pNode->pCopy = (Abc_Obj_t *)Vec_PtrEntry( vVars, i );
312 for ( i = Vec_PtrSize(vFuncs); i < Vec_PtrSize(vVisited); i++ )
313 Vec_PtrPush( vFuncs, ABC_ALLOC(word, nWordsMax) );
314 Vec_PtrForEachEntry( Abc_Obj_t *, vVisited, pNode, i )
315 {
316 assert( !Abc_ObjIsPi(pNode) );
317 pTruth0 = (word *)Abc_ObjFanin0(pNode)->pCopy;
318 pTruth1 = (word *)Abc_ObjFanin1(pNode)->pCopy;
319 pTruth = (word *)Vec_PtrEntry( vFuncs, i );
320 if ( Abc_ObjFaninC0(pNode) )
321 {
322 if ( Abc_ObjFaninC1(pNode) )
323 for ( k = 0; k < nWords; k++ )
324 pTruth[k] = ~pTruth0[k] & ~pTruth1[k];
325 else
326 for ( k = 0; k < nWords; k++ )
327 pTruth[k] = ~pTruth0[k] & pTruth1[k];
328 }
329 else
330 {
331 if ( Abc_ObjFaninC1(pNode) )
332 for ( k = 0; k < nWords; k++ )
333 pTruth[k] = pTruth0[k] & ~pTruth1[k];
334 else
335 for ( k = 0; k < nWords; k++ )
336 pTruth[k] = pTruth0[k] & pTruth1[k];
337 }
338 pNode->pCopy = (Abc_Obj_t *)pTruth;
339 }
340 return pTruth;
341}
342int Abc_NodeConeIsConst0_1( word * pTruth, int nVars )
343{
344 int k, nWords = Abc_Truth6WordNum( nVars );
345 for ( k = 0; k < nWords; k++ )
346 if ( pTruth[k] )
347 return 0;
348 return 1;
349}
350int Abc_NodeConeIsConst1_1( word * pTruth, int nVars )
351{
352 int k, nWords = Abc_Truth6WordNum( nVars );
353 for ( k = 0; k < nWords; k++ )
354 if ( ~pTruth[k] )
355 return 0;
356 return 1;
357}
358
359
360
361Dec_Graph_t * Abc_NodeRefactor_1( Abc_ManRef_t * p, Abc_Obj_t * pNode, Vec_Ptr_t * vFanins, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose )
362{
363 extern int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
364 int fVeryVerbose = 0;
365 int nVars = Vec_PtrSize(vFanins);
366 int nWordsMax = Abc_Truth6WordNum(p->nNodeSizeMax);
367 Dec_Graph_t * pFForm;
368 Abc_Obj_t * pFanin;
369 word * pTruth;
370 abctime clk;
371 int i, nNodesSaved, nNodesAdded, Required;
372
373 p->nNodesConsidered++;
374
375 Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
376clk = Abc_Clock();
377 pTruth = Abc_NodeConeTruth_1( p->vVars, p->vFuncs, nWordsMax, pNode, vFanins, p->vVisited );
378p->timeTru += Abc_Clock() - clk;
379 if ( pTruth == NULL )
380 return NULL;
381 if ( Abc_NodeConeIsConst0_1(pTruth, nVars) || Abc_NodeConeIsConst1_1(pTruth, nVars) )
382 {
383 p->nLastGain = Abc_NodeMffcSize( pNode );
384 p->nNodesGained += p->nLastGain;
385 p->nNodesRefactored++;
386 return Abc_NodeConeIsConst0_1(pTruth, nVars) ? Dec_GraphCreateConst0() : Dec_GraphCreateConst1();
387 }
388clk = Abc_Clock();
389 pFForm = (Dec_Graph_t *)Kit_TruthToGraph( (unsigned *)pTruth, nVars, p->vMemory );
390p->timeFact += Abc_Clock() - clk;
391 Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
392 pFanin->vFanouts.nSize++;
393 Abc_NtkIncrementTravId( pNode->pNtk );
394 nNodesSaved = Abc_NodeMffcLabelAig( pNode );
395 Vec_PtrForEachEntry( Abc_Obj_t *, vFanins, pFanin, i )
396 {
397 pFanin->vFanouts.nSize--;
398 Dec_GraphNode(pFForm, i)->pFunc = pFanin;
399 }
400clk = Abc_Clock();
401 nNodesAdded = Dec_GraphToNetworkCount( pNode, pFForm, nNodesSaved, Required );
402p->timeEval += Abc_Clock() - clk;
403 if ( nNodesAdded == -1 || (nNodesAdded == nNodesSaved && !fUseZeros) )
404 {
405 Dec_GraphFree( pFForm );
406 return NULL;
407 }
408
409 p->nLastGain = nNodesSaved - nNodesAdded;
410 p->nNodesGained += p->nLastGain;
411 p->nNodesRefactored++;
412
413 if ( fVeryVerbose )
414 {
415 printf( "Node %6s : ", Abc_ObjName(pNode) );
416 printf( "Cone = %2d. ", vFanins->nSize );
417 printf( "FF = %2d. ", 1 + Dec_GraphNodeNum(pFForm) );
418 printf( "MFFC = %2d. ", nNodesSaved );
419 printf( "Add = %2d. ", nNodesAdded );
420 printf( "GAIN = %2d. ", p->nLastGain );
421 printf( "\n" );
422 }
423 return pFForm;
424}
425
426
427
428Abc_ManRef_t * Abc_NtkManRefStart_1( int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose )
429{
430 Abc_ManRef_t * p;
431 p = ABC_ALLOC( Abc_ManRef_t, 1 );
432 memset( p, 0, sizeof(Abc_ManRef_t) );
433 p->vCube = Vec_StrAlloc( 100 );
434 p->vVisited = Vec_PtrAlloc( 100 );
435 p->nNodeSizeMax = nNodeSizeMax;
436 p->nConeSizeMax = nConeSizeMax;
437 p->fVerbose = fVerbose;
438 p->vVars = Vec_PtrAllocTruthTables( Abc_MaxInt(nNodeSizeMax, 6) );
439 p->vFuncs = Vec_PtrAlloc( 100 );
440 p->vMemory = Vec_IntAlloc( 1 << 16 );
441 return p;
442}
443
445{
446 Vec_PtrFreeFree( p->vFuncs );
447 Vec_PtrFree( p->vVars );
448 Vec_IntFree( p->vMemory );
449 Vec_PtrFree( p->vVisited );
450 Vec_StrFree( p->vCube );
451 ABC_FREE( p );
452}
453
455{
456 printf( "Refactoring statistics:\n" );
457 printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
458 printf( "Nodes refactored = %8d.\n", p->nNodesRefactored );
459 printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
460 ABC_PRT( "Cuts ", p->timeCut );
461 ABC_PRT( "Resynthesis", p->timeRes );
462 ABC_PRT( " BDD ", p->timeTru );
463 ABC_PRT( " DCs ", p->timeDcs );
464 ABC_PRT( " SOP ", p->timeSop );
465 ABC_PRT( " FF ", p->timeFact );
466 ABC_PRT( " Eval ", p->timeEval );
467 ABC_PRT( "AIG update ", p->timeNtk );
468 ABC_PRT( "TOTAL ", p->timeTotal );
469}
470
471int Abc_NtkRefactor3( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_ref, int nNodeSizeMax, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose )
472{
473 ProgressBar * pProgress;
474 Abc_ManRef_t * pManRef;
475 Abc_ManCut_t * pManCut;
476 Dec_Graph_t * pFForm;
477 Vec_Ptr_t * vFanins;
478 Abc_Obj_t * pNode;
479 FILE *fpt;
480 abctime clk, clkStart = Abc_Clock();
481 int i, nNodes, RetValue = 1;
482
483 assert( Abc_NtkIsStrash(pNtk) );
485 pManCut = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
486 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
487 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCut );
488 if ( fUpdateLevel )
489 Abc_NtkStartReverseLevels( pNtk, 0 );
490 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
491 nNodes = Abc_NtkObjNumMax(pNtk);
492 //printf("nNodes: %d\n", nNodes);
493 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
494
495 pProgress = Extra_ProgressBarStart( stdout, nNodes );
496 fpt = fopen("refactor_id_nGain.csv", "w");
497
498 Abc_NtkForEachNode( pNtk, pNode, i )
499 {
500 //printf("Refactor3 Id: %d\n", pNode->Id);
501 Extra_ProgressBarUpdate( pProgress, i, NULL );
502 if ( Abc_NodeIsPersistant(pNode) )
503 continue;
504 if ( Abc_ObjFanoutNum(pNode) > 1000 )
505 continue;
506 if ( i >= nNodes )
507 break;
508clk = Abc_Clock();
509 vFanins = Abc_NodeFindCut( pManCut, pNode, fUseDcs );
510pManRef->timeCut += Abc_Clock() - clk;
511clk = Abc_Clock();
512 pFForm = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
513pManRef->timeRes += Abc_Clock() - clk;
514 //printf("nLastGain3: %d\n", pManRef->nLastGain);
515 fprintf(fpt, "%d, %d\n", pNode->Id, pManRef->nLastGain);
516 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
517
518 if ( pFForm == NULL )
519 continue;
520clk = Abc_Clock();
521
522/*
523 if ( !Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRef->nLastGain ) )
524 {
525 Dec_GraphFree( pFForm );
526 RetValue = -1;
527 break;
528 }
529*/
530
531pManRef->timeNtk += Abc_Clock() - clk;
532 Dec_GraphFree( pFForm );
533 }
534 fclose(fpt);
535 printf("size of vector: %d\n", (**pGain_ref).nSize);
536 //printf("nGain in vector: %d\n", (**pGain_ref).pArray[20]);
537 Extra_ProgressBarStop( pProgress );
538pManRef->timeTotal = Abc_Clock() - clkStart;
539 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
540
541 if ( fVerbose )
542 Abc_NtkManRefPrintStats_1( pManRef );
543 Abc_NtkManCutStop( pManCut );
544 Abc_NtkManRefStop_1( pManRef );
545 Abc_NtkReassignIds( pNtk );
546 if ( RetValue != -1 )
547 {
548 if ( fUpdateLevel )
550 else
551 Abc_NtkLevel( pNtk );
552 if ( !Abc_NtkCheck( pNtk ) )
553 {
554 printf( "Abc_NtkRefactor: The network check has failed.\n" );
555 return 0;
556 }
557 }
558 return RetValue;
559}
560
571
572int Abc_NtkResubstitute3( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_res, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose )
573{
574 ProgressBar * pProgress;
575 Abc_ManRes_t * pManRes;
576 Abc_ManCut_t * pManCut;
577 Odc_Man_t * pManOdc = NULL;
578 Dec_Graph_t * pFForm;
579 Vec_Ptr_t * vLeaves;
580 Abc_Obj_t * pNode;
581 FILE *fpt;
582 abctime clk, clkStart = Abc_Clock();
584 int i, nNodes;
585
586 assert( Abc_NtkIsStrash(pNtk) );
587
588 // cleanup the AIG
590 // start the managers
591 pManCut = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
592 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
593 if ( nLevelsOdc > 0 )
594 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
595
596 // compute the reverse levels if level update is requested
597 if ( fUpdateLevel )
598 Abc_NtkStartReverseLevels( pNtk, 0 );
599
600 if ( Abc_NtkLatchNum(pNtk) ) {
601 Abc_NtkForEachLatch(pNtk, pNode, i)
602 pNode->pNext = (Abc_Obj_t *)pNode->pData;
603 }
604
605 // resynthesize each node once
606 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
607 nNodes = Abc_NtkObjNumMax(pNtk);
608 //printf("nNodes: %d\n", nNodes);
609 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
610
611 pProgress = Extra_ProgressBarStart( stdout, nNodes );
612 fpt = fopen("resub_id_nGain.csv", "w");
613
614 Abc_NtkForEachNode( pNtk, pNode, i )
615 {
616 //printf("resub id: %d\n", pNode->Id);
617 Extra_ProgressBarUpdate( pProgress, i, NULL );
618 // skip the constant node
619// if ( Abc_NodeIsConst(pNode) )
620// continue;
621 // skip persistant nodes
622 if ( Abc_NodeIsPersistant(pNode) )
623 {
624 fprintf(fpt, "%d, %d\n", pNode->Id, -99);
625 Vec_IntPush((*pGain_res), -99);
626 continue;
627 }
628 // skip the nodes with many fanouts
629 if ( Abc_ObjFanoutNum(pNode) > 1000 )
630 {
631 fprintf(fpt, "%d, %d\n", pNode->Id, -99);
632 Vec_IntPush((*pGain_res), -99);
633 continue;
634 }
635 // stop if all nodes have been tried once
636 if ( i >= nNodes )
637 break;
638
639 // compute a reconvergence-driven cut
640clk = Abc_Clock();
641 vLeaves = Abc_NodeFindCut( pManCut, pNode, 0 );
642// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
643pManRes->timeCut += Abc_Clock() - clk;
644/*
645 if ( fVerbose && vLeaves )
646 printf( "Node %6d : Leaves = %3d. Volume = %3d.\n", pNode->Id, Vec_PtrSize(vLeaves), Abc_CutVolumeCheck(pNode, vLeaves) );
647 if ( vLeaves == NULL )
648 continue;
649*/
650 // get the don't-cares
651 if ( pManOdc )
652 {
653clk = Abc_Clock();
654 Abc_NtkDontCareClear( pManOdc );
655 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
656pManRes->timeTruth += Abc_Clock() - clk;
657 }
658
659 // evaluate this cut
660clk = Abc_Clock();
661 pFForm = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
662// Vec_PtrFree( vLeaves );
663// Abc_ManResubCleanup( pManRes );
664pManRes->timeRes += Abc_Clock() - clk;
665 // put nGain in Vector
666 //printf("nLastGain3: %d\n", pManRes->nLastGain);
667 fprintf(fpt, "%d, %d\n", pNode->Id, pManRes->nLastGain);
668 Vec_IntPush((*pGain_res), pManRes->nLastGain);
669 // printf("size of vector %d\n", (**pGain).nSize);
670 if ( pFForm == NULL )
671 continue;
672 pManRes->nTotalGain += pManRes->nLastGain;
673/*
674 if ( pManRes->nLeaves == 4 && pManRes->nMffc == 2 && pManRes->nLastGain == 1 )
675 {
676 printf( "%6d : L = %2d. V = %2d. Mffc = %2d. Divs = %3d. Up = %3d. Un = %3d. B = %3d.\n",
677 pNode->Id, pManRes->nLeaves, Abc_CutVolumeCheck(pNode, vLeaves), pManRes->nMffc, pManRes->nDivs,
678 pManRes->vDivs1UP->nSize, pManRes->vDivs1UN->nSize, pManRes->vDivs1B->nSize );
679 Abc_ManResubPrintDivs( pManRes, pNode, vLeaves );
680 }
681*/
682
683clk = Abc_Clock();
684 //Dec_GraphUpdateNetwork( pNode, pFForm, fUpdateLevel, pManRes->nLastGain );
685pManRes->timeNtk += Abc_Clock() - clk;
686 Dec_GraphFree( pFForm );
687
688 }
689 fclose(fpt);
690 printf("size of vector %d\n", (**pGain_res).nSize);
691 //printf("nGain in vector: %d\n", (**pGain_res).pArray[20]);
692 Extra_ProgressBarStop( pProgress );
693pManRes->timeTotal = Abc_Clock() - clkStart;
694 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
695
696 // print statistics
697 if ( fVerbose )
698 Abc_ManResubPrint( pManRes );
699
700 // delete the managers
701 Abc_ManResubStop( pManRes );
702 Abc_NtkManCutStop( pManCut );
703 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
704
705 // clean the data field
706 Abc_NtkForEachObj( pNtk, pNode, i )
707 pNode->pData = NULL;
708
709 if ( Abc_NtkLatchNum(pNtk) ) {
710 Abc_NtkForEachLatch(pNtk, pNode, i)
711 pNode->pData = pNode->pNext, pNode->pNext = NULL;
712 }
713
714 // put the nodes into the DFS order and reassign their IDs
715 Abc_NtkReassignIds( pNtk );
716// Abc_AigCheckFaninOrder( pNtk->pManFunc );
717 // fix the levels
718 if ( fUpdateLevel )
720 else
721 Abc_NtkLevel( pNtk );
722 // check
723 if ( !Abc_NtkCheck( pNtk ) )
724 {
725 printf( "Abc_NtkRefactor: The network check has failed.\n" );
726 return 0;
727 }
728s_ResubTime = Abc_Clock() - clkStart;
729 return 1;
730}
731
732
744Abc_ManRes_t * Abc_ManResubStart( int nLeavesMax, int nDivsMax )
745{
746 Abc_ManRes_t * p;
747 unsigned * pData;
748 int i, k;
749 assert( sizeof(unsigned) == 4 );
750 p = ABC_ALLOC( Abc_ManRes_t, 1 );
751 memset( p, 0, sizeof(Abc_ManRes_t) );
752 p->nLeavesMax = nLeavesMax;
753 p->nDivsMax = nDivsMax;
754 p->vDivs = Vec_PtrAlloc( p->nDivsMax );
755 // allocate simulation info
756 p->nBits = (1 << p->nLeavesMax);
757 p->nWords = (p->nBits <= 32)? 1 : (p->nBits / 32);
758 p->pInfo = ABC_ALLOC( unsigned, p->nWords * (p->nDivsMax + 1) );
759 memset( p->pInfo, 0, sizeof(unsigned) * p->nWords * p->nLeavesMax );
760 p->vSims = Vec_PtrAlloc( p->nDivsMax );
761 for ( i = 0; i < p->nDivsMax; i++ )
762 Vec_PtrPush( p->vSims, p->pInfo + i * p->nWords );
763 // assign the care set
764 p->pCareSet = p->pInfo + p->nDivsMax * p->nWords;
765 Abc_InfoFill( p->pCareSet, p->nWords );
766 // set elementary truth tables
767 for ( k = 0; k < p->nLeavesMax; k++ )
768 {
769 pData = (unsigned *)p->vSims->pArray[k];
770 for ( i = 0; i < p->nBits; i++ )
771 if ( i & (1 << k) )
772 pData[i>>5] |= (1 << (i&31));
773 }
774 // create the remaining divisors
775 p->vDivs1UP = Vec_PtrAlloc( p->nDivsMax );
776 p->vDivs1UN = Vec_PtrAlloc( p->nDivsMax );
777 p->vDivs1B = Vec_PtrAlloc( p->nDivsMax );
778 p->vDivs2UP0 = Vec_PtrAlloc( p->nDivsMax );
779 p->vDivs2UP1 = Vec_PtrAlloc( p->nDivsMax );
780 p->vDivs2UN0 = Vec_PtrAlloc( p->nDivsMax );
781 p->vDivs2UN1 = Vec_PtrAlloc( p->nDivsMax );
782 p->vTemp = Vec_PtrAlloc( p->nDivsMax );
783 return p;
784}
785
797void Abc_ManResubStop( Abc_ManRes_t * p )
798{
799 Vec_PtrFree( p->vDivs );
800 Vec_PtrFree( p->vSims );
801 Vec_PtrFree( p->vDivs1UP );
802 Vec_PtrFree( p->vDivs1UN );
803 Vec_PtrFree( p->vDivs1B );
804 Vec_PtrFree( p->vDivs2UP0 );
805 Vec_PtrFree( p->vDivs2UP1 );
806 Vec_PtrFree( p->vDivs2UN0 );
807 Vec_PtrFree( p->vDivs2UN1 );
808 Vec_PtrFree( p->vTemp );
809 ABC_FREE( p->pInfo );
810 ABC_FREE( p );
811}
812
824void Abc_ManResubPrint( Abc_ManRes_t * p )
825{
826 printf( "Used constants = %6d. ", p->nUsedNodeC ); ABC_PRT( "Cuts ", p->timeCut );
827 printf( "Used replacements = %6d. ", p->nUsedNode0 ); ABC_PRT( "Resub ", p->timeRes );
828 printf( "Used single ORs = %6d. ", p->nUsedNode1Or ); ABC_PRT( " Div ", p->timeDiv );
829 printf( "Used single ANDs = %6d. ", p->nUsedNode1And ); ABC_PRT( " Mffc ", p->timeMffc );
830 printf( "Used double ORs = %6d. ", p->nUsedNode2Or ); ABC_PRT( " Sim ", p->timeSim );
831 printf( "Used double ANDs = %6d. ", p->nUsedNode2And ); ABC_PRT( " 1 ", p->timeRes1 );
832 printf( "Used OR-AND = %6d. ", p->nUsedNode2OrAnd ); ABC_PRT( " D ", p->timeResD );
833 printf( "Used AND-OR = %6d. ", p->nUsedNode2AndOr ); ABC_PRT( " 2 ", p->timeRes2 );
834 printf( "Used OR-2ANDs = %6d. ", p->nUsedNode3OrAnd ); ABC_PRT( "Truth ", p->timeTruth ); //ABC_PRT( " 3 ", p->timeRes3 );
835 printf( "Used AND-2ORs = %6d. ", p->nUsedNode3AndOr ); ABC_PRT( "AIG ", p->timeNtk );
836 printf( "TOTAL = %6d. ", p->nUsedNodeC +
837 p->nUsedNode0 +
838 p->nUsedNode1Or +
839 p->nUsedNode1And +
840 p->nUsedNode2Or +
841 p->nUsedNode2And +
842 p->nUsedNode2OrAnd +
843 p->nUsedNode2AndOr +
844 p->nUsedNode3OrAnd +
845 p->nUsedNode3AndOr
846 ); ABC_PRT( "TOTAL ", p->timeTotal );
847 printf( "Total leaves = %8d.\n", p->nTotalLeaves );
848 printf( "Total divisors = %8d.\n", p->nTotalDivs );
849// printf( "Total gain = %8d.\n", p->nTotalGain );
850 printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
851}
852
853
865
867{
868 // skip visited nodes
869 if ( Abc_NodeIsTravIdCurrent(pNode) )
870 return;
871 Abc_NodeSetTravIdCurrent(pNode);
872 // collect the fanins
873 Abc_ManResubCollectDivs_rec1( Abc_ObjFanin0(pNode), vInternal );
874 Abc_ManResubCollectDivs_rec1( Abc_ObjFanin1(pNode), vInternal );
875 // collect the internal node
876 if ( pNode->fMarkA == 0 )
877 Vec_PtrPush( vInternal, pNode );
878}
879
880
892int Abc_ManResubCollectDivs( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, int Required )
893{
894 Abc_Obj_t * pNode, * pFanout;
895 int i, k, Limit, Counter;
896
897 Vec_PtrClear( p->vDivs1UP );
898 Vec_PtrClear( p->vDivs1UN );
899 Vec_PtrClear( p->vDivs1B );
900
901 // add the leaves of the cuts to the divisors
902 Vec_PtrClear( p->vDivs );
903 Abc_NtkIncrementTravId( pRoot->pNtk );
904 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pNode, i )
905 {
906 Vec_PtrPush( p->vDivs, pNode );
907 Abc_NodeSetTravIdCurrent( pNode );
908 }
909
910 // mark nodes in the MFFC
911 Vec_PtrForEachEntry( Abc_Obj_t *, p->vTemp, pNode, i )
912 pNode->fMarkA = 1;
913 // collect the cone (without MFFC)
914 Abc_ManResubCollectDivs_rec1( pRoot, p->vDivs );
915 // unmark the current MFFC
916 Vec_PtrForEachEntry( Abc_Obj_t *, p->vTemp, pNode, i )
917 pNode->fMarkA = 0;
918
919 // check if the number of divisors is not exceeded
920 if ( Vec_PtrSize(p->vDivs) - Vec_PtrSize(vLeaves) + Vec_PtrSize(p->vTemp) >= Vec_PtrSize(p->vSims) - p->nLeavesMax )
921 return 0;
922
923 // get the number of divisors to collect
924 Limit = Vec_PtrSize(p->vSims) - p->nLeavesMax - (Vec_PtrSize(p->vDivs) - Vec_PtrSize(vLeaves) + Vec_PtrSize(p->vTemp));
925
926 // explore the fanouts, which are not in the MFFC
927 Counter = 0;
928 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pNode, i )
929 {
930 if ( Abc_ObjFanoutNum(pNode) > 100 )
931 {
932// printf( "%d ", Abc_ObjFanoutNum(pNode) );
933 continue;
934 }
935 // if the fanout has both fanins in the set, add it
936 Abc_ObjForEachFanout( pNode, pFanout, k )
937 {
938 if ( Abc_NodeIsTravIdCurrent(pFanout) || Abc_ObjIsCo(pFanout) || (int)pFanout->Level > Required )
939 continue;
940 if ( Abc_NodeIsTravIdCurrent(Abc_ObjFanin0(pFanout)) && Abc_NodeIsTravIdCurrent(Abc_ObjFanin1(pFanout)) )
941 {
942 if ( Abc_ObjFanin0(pFanout) == pRoot || Abc_ObjFanin1(pFanout) == pRoot )
943 continue;
944 Vec_PtrPush( p->vDivs, pFanout );
945 Abc_NodeSetTravIdCurrent( pFanout );
946 // quit computing divisors if there is too many of them
947 if ( ++Counter == Limit )
948 goto Quits;
949 }
950 }
951 }
952
953Quits :
954 // get the number of divisors
955 p->nDivs = Vec_PtrSize(p->vDivs);
956
957 // add the nodes in the MFFC
958 Vec_PtrForEachEntry( Abc_Obj_t *, p->vTemp, pNode, i )
959 Vec_PtrPush( p->vDivs, pNode );
960 assert( pRoot == Vec_PtrEntryLast(p->vDivs) );
961
962 assert( Vec_PtrSize(p->vDivs) - Vec_PtrSize(vLeaves) <= Vec_PtrSize(p->vSims) - p->nLeavesMax );
963 return 1;
964}
965
977void Abc_ManResubPrintDivs( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves )
978{
979 Abc_Obj_t * pFanin, * pNode;
980 int i, k;
981 // print the nodes
982 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pNode, i )
983 {
984 if ( i < Vec_PtrSize(vLeaves) )
985 {
986 printf( "%6d : %c\n", pNode->Id, 'a'+i );
987 continue;
988 }
989 printf( "%6d : %2d = ", pNode->Id, i );
990 // find the first fanin
991 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pFanin, k )
992 if ( Abc_ObjFanin0(pNode) == pFanin )
993 break;
994 if ( k < Vec_PtrSize(vLeaves) )
995 printf( "%c", 'a' + k );
996 else
997 printf( "%d", k );
998 printf( "%s ", Abc_ObjFaninC0(pNode)? "\'" : "" );
999 // find the second fanin
1000 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pFanin, k )
1001 if ( Abc_ObjFanin1(pNode) == pFanin )
1002 break;
1003 if ( k < Vec_PtrSize(vLeaves) )
1004 printf( "%c", 'a' + k );
1005 else
1006 printf( "%d", k );
1007 printf( "%s ", Abc_ObjFaninC1(pNode)? "\'" : "" );
1008 if ( pNode == pRoot )
1009 printf( " root" );
1010 printf( "\n" );
1011 }
1012 printf( "\n" );
1013}
1014
1015
1027void Abc_ManResubSimulate( Vec_Ptr_t * vDivs, int nLeaves, Vec_Ptr_t * vSims, int nLeavesMax, int nWords )
1028{
1029 Abc_Obj_t * pObj;
1030 unsigned * puData0, * puData1, * puData;
1031 int i, k;
1032 assert( Vec_PtrSize(vDivs) - nLeaves <= Vec_PtrSize(vSims) - nLeavesMax );
1033 // simulate
1034 Vec_PtrForEachEntry( Abc_Obj_t *, vDivs, pObj, i )
1035 {
1036 if ( i < nLeaves )
1037 { // initialize the leaf
1038 pObj->pData = Vec_PtrEntry( vSims, i );
1039 continue;
1040 }
1041 // set storage for the node's simulation info
1042 pObj->pData = Vec_PtrEntry( vSims, i - nLeaves + nLeavesMax );
1043 // get pointer to the simulation info
1044 puData = (unsigned *)pObj->pData;
1045 puData0 = (unsigned *)Abc_ObjFanin0(pObj)->pData;
1046 puData1 = (unsigned *)Abc_ObjFanin1(pObj)->pData;
1047 // simulate
1048 if ( Abc_ObjFaninC0(pObj) && Abc_ObjFaninC1(pObj) )
1049 for ( k = 0; k < nWords; k++ )
1050 puData[k] = ~puData0[k] & ~puData1[k];
1051 else if ( Abc_ObjFaninC0(pObj) )
1052 for ( k = 0; k < nWords; k++ )
1053 puData[k] = ~puData0[k] & puData1[k];
1054 else if ( Abc_ObjFaninC1(pObj) )
1055 for ( k = 0; k < nWords; k++ )
1056 puData[k] = puData0[k] & ~puData1[k];
1057 else
1058 for ( k = 0; k < nWords; k++ )
1059 puData[k] = puData0[k] & puData1[k];
1060 }
1061 // normalize
1062 Vec_PtrForEachEntry( Abc_Obj_t *, vDivs, pObj, i )
1063 {
1064 puData = (unsigned *)pObj->pData;
1065 pObj->fPhase = (puData[0] & 1);
1066 if ( pObj->fPhase )
1067 for ( k = 0; k < nWords; k++ )
1068 puData[k] = ~puData[k];
1069 }
1070}
1071
1072
1084
1086{
1087 Dec_Graph_t * pGraph;
1088 Dec_Edge_t eRoot;
1089 pGraph = Dec_GraphCreate( 1 );
1090 Dec_GraphNode( pGraph, 0 )->pFunc = pObj;
1091 eRoot = Dec_EdgeCreate( 0, pObj->fPhase );
1092 Dec_GraphSetRoot( pGraph, eRoot );
1093 if ( pRoot->fPhase )
1094 Dec_GraphComplement( pGraph );
1095 return pGraph;
1096}
1097
1109
1110Dec_Graph_t * Abc_ManResubQuit1_1( Abc_Obj_t * pRoot, Abc_Obj_t * pObj0, Abc_Obj_t * pObj1, int fOrGate )
1111{
1112 Dec_Graph_t * pGraph;
1113 Dec_Edge_t eRoot, eNode0, eNode1;
1114 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj1) );
1115 pGraph = Dec_GraphCreate( 2 );
1116 Dec_GraphNode( pGraph, 0 )->pFunc = Abc_ObjRegular(pObj0);
1117 Dec_GraphNode( pGraph, 1 )->pFunc = Abc_ObjRegular(pObj1);
1118 eNode0 = Dec_EdgeCreate( 0, Abc_ObjRegular(pObj0)->fPhase ^ Abc_ObjIsComplement(pObj0) );
1119 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase ^ Abc_ObjIsComplement(pObj1) );
1120 if ( fOrGate )
1121 eRoot = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
1122 else
1123 eRoot = Dec_GraphAddNodeAnd( pGraph, eNode0, eNode1 );
1124 Dec_GraphSetRoot( pGraph, eRoot );
1125 if ( pRoot->fPhase )
1126 Dec_GraphComplement( pGraph );
1127 return pGraph;
1128}
1129
1141
1142Dec_Graph_t * Abc_ManResubQuit21_1( Abc_Obj_t * pRoot, Abc_Obj_t * pObj0, Abc_Obj_t * pObj1, Abc_Obj_t * pObj2, int fOrGate )
1143{
1144 Dec_Graph_t * pGraph;
1145 Dec_Edge_t eRoot, eNode0, eNode1, eNode2;
1146 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj1) );
1147 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj2) );
1148 assert( Abc_ObjRegular(pObj1) != Abc_ObjRegular(pObj2) );
1149 pGraph = Dec_GraphCreate( 3 );
1150 Dec_GraphNode( pGraph, 0 )->pFunc = Abc_ObjRegular(pObj0);
1151 Dec_GraphNode( pGraph, 1 )->pFunc = Abc_ObjRegular(pObj1);
1152 Dec_GraphNode( pGraph, 2 )->pFunc = Abc_ObjRegular(pObj2);
1153 eNode0 = Dec_EdgeCreate( 0, Abc_ObjRegular(pObj0)->fPhase ^ Abc_ObjIsComplement(pObj0) );
1154 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase ^ Abc_ObjIsComplement(pObj1) );
1155 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase ^ Abc_ObjIsComplement(pObj2) );
1156 if ( fOrGate )
1157 {
1158 eRoot = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
1159 eRoot = Dec_GraphAddNodeOr( pGraph, eNode2, eRoot );
1160 }
1161 else
1162 {
1163 eRoot = Dec_GraphAddNodeAnd( pGraph, eNode0, eNode1 );
1164 eRoot = Dec_GraphAddNodeAnd( pGraph, eNode2, eRoot );
1165 }
1166 Dec_GraphSetRoot( pGraph, eRoot );
1167 if ( pRoot->fPhase )
1168 Dec_GraphComplement( pGraph );
1169 return pGraph;
1170}
1171
1172
1184
1185Dec_Graph_t * Abc_ManResubQuit2_1( Abc_Obj_t * pRoot, Abc_Obj_t * pObj0, Abc_Obj_t * pObj1, Abc_Obj_t * pObj2, int fOrGate )
1186{
1187 Dec_Graph_t * pGraph;
1188 Dec_Edge_t eRoot, ePrev, eNode0, eNode1, eNode2;
1189 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj1) );
1190 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj2) );
1191 assert( Abc_ObjRegular(pObj1) != Abc_ObjRegular(pObj2) );
1192 pGraph = Dec_GraphCreate( 3 );
1193 Dec_GraphNode( pGraph, 0 )->pFunc = Abc_ObjRegular(pObj0);
1194 Dec_GraphNode( pGraph, 1 )->pFunc = Abc_ObjRegular(pObj1);
1195 Dec_GraphNode( pGraph, 2 )->pFunc = Abc_ObjRegular(pObj2);
1196 eNode0 = Dec_EdgeCreate( 0, Abc_ObjRegular(pObj0)->fPhase ^ Abc_ObjIsComplement(pObj0) );
1197 if ( Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1198 {
1199 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase );
1200 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase );
1201 ePrev = Dec_GraphAddNodeOr( pGraph, eNode1, eNode2 );
1202 }
1203 else
1204 {
1205 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase ^ Abc_ObjIsComplement(pObj1) );
1206 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase ^ Abc_ObjIsComplement(pObj2) );
1207 ePrev = Dec_GraphAddNodeAnd( pGraph, eNode1, eNode2 );
1208 }
1209 if ( fOrGate )
1210 eRoot = Dec_GraphAddNodeOr( pGraph, eNode0, ePrev );
1211 else
1212 eRoot = Dec_GraphAddNodeAnd( pGraph, eNode0, ePrev );
1213 Dec_GraphSetRoot( pGraph, eRoot );
1214 if ( pRoot->fPhase )
1215 Dec_GraphComplement( pGraph );
1216 return pGraph;
1217}
1218
1219
1231
1232Dec_Graph_t * Abc_ManResubQuit3_1( Abc_Obj_t * pRoot, Abc_Obj_t * pObj0, Abc_Obj_t * pObj1, Abc_Obj_t * pObj2, Abc_Obj_t * pObj3, int fOrGate )
1233{
1234 Dec_Graph_t * pGraph;
1235 Dec_Edge_t eRoot, ePrev0, ePrev1, eNode0, eNode1, eNode2, eNode3;
1236 assert( Abc_ObjRegular(pObj0) != Abc_ObjRegular(pObj1) );
1237 assert( Abc_ObjRegular(pObj2) != Abc_ObjRegular(pObj3) );
1238 pGraph = Dec_GraphCreate( 4 );
1239 Dec_GraphNode( pGraph, 0 )->pFunc = Abc_ObjRegular(pObj0);
1240 Dec_GraphNode( pGraph, 1 )->pFunc = Abc_ObjRegular(pObj1);
1241 Dec_GraphNode( pGraph, 2 )->pFunc = Abc_ObjRegular(pObj2);
1242 Dec_GraphNode( pGraph, 3 )->pFunc = Abc_ObjRegular(pObj3);
1243 if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) )
1244 {
1245 eNode0 = Dec_EdgeCreate( 0, Abc_ObjRegular(pObj0)->fPhase );
1246 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase );
1247 ePrev0 = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
1248 if ( Abc_ObjIsComplement(pObj2) && Abc_ObjIsComplement(pObj3) )
1249 {
1250 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase );
1251 eNode3 = Dec_EdgeCreate( 3, Abc_ObjRegular(pObj3)->fPhase );
1252 ePrev1 = Dec_GraphAddNodeOr( pGraph, eNode2, eNode3 );
1253 }
1254 else
1255 {
1256 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase ^ Abc_ObjIsComplement(pObj2) );
1257 eNode3 = Dec_EdgeCreate( 3, Abc_ObjRegular(pObj3)->fPhase ^ Abc_ObjIsComplement(pObj3) );
1258 ePrev1 = Dec_GraphAddNodeAnd( pGraph, eNode2, eNode3 );
1259 }
1260 }
1261 else
1262 {
1263 eNode0 = Dec_EdgeCreate( 0, Abc_ObjRegular(pObj0)->fPhase ^ Abc_ObjIsComplement(pObj0) );
1264 eNode1 = Dec_EdgeCreate( 1, Abc_ObjRegular(pObj1)->fPhase ^ Abc_ObjIsComplement(pObj1) );
1265 ePrev0 = Dec_GraphAddNodeAnd( pGraph, eNode0, eNode1 );
1266 if ( Abc_ObjIsComplement(pObj2) && Abc_ObjIsComplement(pObj3) )
1267 {
1268 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase );
1269 eNode3 = Dec_EdgeCreate( 3, Abc_ObjRegular(pObj3)->fPhase );
1270 ePrev1 = Dec_GraphAddNodeOr( pGraph, eNode2, eNode3 );
1271 }
1272 else
1273 {
1274 eNode2 = Dec_EdgeCreate( 2, Abc_ObjRegular(pObj2)->fPhase ^ Abc_ObjIsComplement(pObj2) );
1275 eNode3 = Dec_EdgeCreate( 3, Abc_ObjRegular(pObj3)->fPhase ^ Abc_ObjIsComplement(pObj3) );
1276 ePrev1 = Dec_GraphAddNodeAnd( pGraph, eNode2, eNode3 );
1277 }
1278 }
1279 if ( fOrGate )
1280 eRoot = Dec_GraphAddNodeOr( pGraph, ePrev0, ePrev1 );
1281 else
1282 eRoot = Dec_GraphAddNodeAnd( pGraph, ePrev0, ePrev1 );
1283 Dec_GraphSetRoot( pGraph, eRoot );
1284 if ( pRoot->fPhase )
1285 Dec_GraphComplement( pGraph );
1286 return pGraph;
1287}
1288
1289
1290
1291
1303void Abc_ManResubDivsS( Abc_ManRes_t * p, int Required )
1304{
1305 int fMoreDivs = 1; // bug fix by Siang-Yun Lee
1306 Abc_Obj_t * pObj;
1307 unsigned * puData, * puDataR;
1308 int i, w;
1309 Vec_PtrClear( p->vDivs1UP );
1310 Vec_PtrClear( p->vDivs1UN );
1311 Vec_PtrClear( p->vDivs1B );
1312 puDataR = (unsigned *)p->pRoot->pData;
1313 Vec_PtrForEachEntryStop( Abc_Obj_t *, p->vDivs, pObj, i, p->nDivs )
1314 {
1315 if ( (int)pObj->Level > Required - 1 )
1316 continue;
1317
1318 puData = (unsigned *)pObj->pData;
1319 // check positive containment
1320 for ( w = 0; w < p->nWords; w++ )
1321// if ( puData[w] & ~puDataR[w] )
1322 if ( puData[w] & ~puDataR[w] & p->pCareSet[w] ) // care set
1323 break;
1324 if ( w == p->nWords )
1325 {
1326 Vec_PtrPush( p->vDivs1UP, pObj );
1327 continue;
1328 }
1329 if ( fMoreDivs )
1330 {
1331 for ( w = 0; w < p->nWords; w++ )
1332 // if ( ~puData[w] & ~puDataR[w] )
1333 if ( ~puData[w] & ~puDataR[w] & p->pCareSet[w] ) // care set
1334 break;
1335 if ( w == p->nWords )
1336 {
1337 Vec_PtrPush( p->vDivs1UP, Abc_ObjNot(pObj) );
1338 continue;
1339 }
1340 }
1341 // check negative containment
1342 for ( w = 0; w < p->nWords; w++ )
1343// if ( ~puData[w] & puDataR[w] )
1344 if ( ~puData[w] & puDataR[w] & p->pCareSet[w] ) // care set
1345 break;
1346 if ( w == p->nWords )
1347 {
1348 Vec_PtrPush( p->vDivs1UN, pObj );
1349 continue;
1350 }
1351 if ( fMoreDivs )
1352 {
1353 for ( w = 0; w < p->nWords; w++ )
1354 // if ( puData[w] & puDataR[w] )
1355 if ( puData[w] & puDataR[w] & p->pCareSet[w] ) // care set
1356 break;
1357 if ( w == p->nWords )
1358 {
1359 Vec_PtrPush( p->vDivs1UN, Abc_ObjNot(pObj) );
1360 continue;
1361 }
1362 }
1363 // add the node to binates
1364 Vec_PtrPush( p->vDivs1B, pObj );
1365 }
1366}
1367
1379void Abc_ManResubDivsD( Abc_ManRes_t * p, int Required )
1380{
1381 Abc_Obj_t * pObj0, * pObj1;
1382 unsigned * puData0, * puData1, * puDataR;
1383 int i, k, w;
1384 Vec_PtrClear( p->vDivs2UP0 );
1385 Vec_PtrClear( p->vDivs2UP1 );
1386 Vec_PtrClear( p->vDivs2UN0 );
1387 Vec_PtrClear( p->vDivs2UN1 );
1388 puDataR = (unsigned *)p->pRoot->pData;
1389 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1B, pObj0, i )
1390 {
1391 if ( (int)pObj0->Level > Required - 2 )
1392 continue;
1393
1394 puData0 = (unsigned *)pObj0->pData;
1395 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1B, pObj1, k, i + 1 )
1396 {
1397 if ( (int)pObj1->Level > Required - 2 )
1398 continue;
1399
1400 puData1 = (unsigned *)pObj1->pData;
1401
1402 if ( Vec_PtrSize(p->vDivs2UP0) < ABC_RS_DIV2_MAX )
1403 {
1404 // get positive unate divisors
1405 for ( w = 0; w < p->nWords; w++ )
1406// if ( (puData0[w] & puData1[w]) & ~puDataR[w] )
1407 if ( (puData0[w] & puData1[w]) & ~puDataR[w] & p->pCareSet[w] ) // care set
1408 break;
1409 if ( w == p->nWords )
1410 {
1411 Vec_PtrPush( p->vDivs2UP0, pObj0 );
1412 Vec_PtrPush( p->vDivs2UP1, pObj1 );
1413 }
1414 for ( w = 0; w < p->nWords; w++ )
1415// if ( (~puData0[w] & puData1[w]) & ~puDataR[w] )
1416 if ( (~puData0[w] & puData1[w]) & ~puDataR[w] & p->pCareSet[w] ) // care set
1417 break;
1418 if ( w == p->nWords )
1419 {
1420 Vec_PtrPush( p->vDivs2UP0, Abc_ObjNot(pObj0) );
1421 Vec_PtrPush( p->vDivs2UP1, pObj1 );
1422 }
1423 for ( w = 0; w < p->nWords; w++ )
1424// if ( (puData0[w] & ~puData1[w]) & ~puDataR[w] )
1425 if ( (puData0[w] & ~puData1[w]) & ~puDataR[w] & p->pCareSet[w] ) // care set
1426 break;
1427 if ( w == p->nWords )
1428 {
1429 Vec_PtrPush( p->vDivs2UP0, pObj0 );
1430 Vec_PtrPush( p->vDivs2UP1, Abc_ObjNot(pObj1) );
1431 }
1432 for ( w = 0; w < p->nWords; w++ )
1433// if ( (puData0[w] | puData1[w]) & ~puDataR[w] )
1434 if ( (puData0[w] | puData1[w]) & ~puDataR[w] & p->pCareSet[w] ) // care set
1435 break;
1436 if ( w == p->nWords )
1437 {
1438 Vec_PtrPush( p->vDivs2UP0, Abc_ObjNot(pObj0) );
1439 Vec_PtrPush( p->vDivs2UP1, Abc_ObjNot(pObj1) );
1440 }
1441 }
1442
1443 if ( Vec_PtrSize(p->vDivs2UN0) < ABC_RS_DIV2_MAX )
1444 {
1445 // get negative unate divisors
1446 for ( w = 0; w < p->nWords; w++ )
1447// if ( ~(puData0[w] & puData1[w]) & puDataR[w] )
1448 if ( ~(puData0[w] & puData1[w]) & puDataR[w] & p->pCareSet[w] ) // care set
1449 break;
1450 if ( w == p->nWords )
1451 {
1452 Vec_PtrPush( p->vDivs2UN0, pObj0 );
1453 Vec_PtrPush( p->vDivs2UN1, pObj1 );
1454 }
1455 for ( w = 0; w < p->nWords; w++ )
1456// if ( ~(~puData0[w] & puData1[w]) & puDataR[w] )
1457 if ( ~(~puData0[w] & puData1[w]) & puDataR[w] & p->pCareSet[w] ) // care set
1458 break;
1459 if ( w == p->nWords )
1460 {
1461 Vec_PtrPush( p->vDivs2UN0, Abc_ObjNot(pObj0) );
1462 Vec_PtrPush( p->vDivs2UN1, pObj1 );
1463 }
1464 for ( w = 0; w < p->nWords; w++ )
1465// if ( ~(puData0[w] & ~puData1[w]) & puDataR[w] )
1466 if ( ~(puData0[w] & ~puData1[w]) & puDataR[w] & p->pCareSet[w] ) // care set
1467 break;
1468 if ( w == p->nWords )
1469 {
1470 Vec_PtrPush( p->vDivs2UN0, pObj0 );
1471 Vec_PtrPush( p->vDivs2UN1, Abc_ObjNot(pObj1) );
1472 }
1473 for ( w = 0; w < p->nWords; w++ )
1474// if ( ~(puData0[w] | puData1[w]) & puDataR[w] )
1475 if ( ~(puData0[w] | puData1[w]) & puDataR[w] & p->pCareSet[w] ) // care set
1476 break;
1477 if ( w == p->nWords )
1478 {
1479 Vec_PtrPush( p->vDivs2UN0, Abc_ObjNot(pObj0) );
1480 Vec_PtrPush( p->vDivs2UN1, Abc_ObjNot(pObj1) );
1481 }
1482 }
1483 }
1484 }
1485// printf( "%d %d ", Vec_PtrSize(p->vDivs2UP0), Vec_PtrSize(p->vDivs2UN0) );
1486}
1487
1488
1489
1501Dec_Graph_t * Abc_ManResubQuit( Abc_ManRes_t * p )
1502{
1503 Dec_Graph_t * pGraph;
1504 unsigned * upData;
1505 int w;
1506 upData = (unsigned *)p->pRoot->pData;
1507 for ( w = 0; w < p->nWords; w++ )
1508// if ( upData[w] )
1509 if ( upData[w] & p->pCareSet[w] ) // care set
1510 break;
1511 if ( w != p->nWords )
1512 return NULL;
1513 // get constant node graph
1514 if ( p->pRoot->fPhase )
1515 pGraph = Dec_GraphCreateConst1();
1516 else
1517 pGraph = Dec_GraphCreateConst0();
1518 return pGraph;
1519}
1520
1532Dec_Graph_t * Abc_ManResubDivs0( Abc_ManRes_t * p )
1533{
1534 Abc_Obj_t * pObj;
1535 unsigned * puData, * puDataR;
1536 int i, w;
1537 puDataR = (unsigned *)p->pRoot->pData;
1538 Vec_PtrForEachEntryStop( Abc_Obj_t *, p->vDivs, pObj, i, p->nDivs )
1539 {
1540 puData = (unsigned *)pObj->pData;
1541 for ( w = 0; w < p->nWords; w++ )
1542// if ( puData[w] != puDataR[w] )
1543 if ( (puData[w] ^ puDataR[w]) & p->pCareSet[w] ) // care set
1544 break;
1545 if ( w == p->nWords )
1546 return Abc_ManResubQuit0_1( p->pRoot, pObj );
1547 }
1548 return NULL;
1549}
1550
1562Dec_Graph_t * Abc_ManResubDivs1( Abc_ManRes_t * p, int Required )
1563{
1564 Abc_Obj_t * pObj0, * pObj1;
1565 unsigned * puData0, * puData1, * puDataR;
1566 int i, k, w;
1567 puDataR = (unsigned *)p->pRoot->pData;
1568 // check positive unate divisors
1569 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UP, pObj0, i )
1570 {
1571 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1572 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UP, pObj1, k, i + 1 )
1573 {
1574 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1575 if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) )
1576 {
1577 for ( w = 0; w < p->nWords; w++ )
1578 // if ( (puData0[w] | puData1[w]) != puDataR[w] )
1579 if ( ((~puData0[w] | ~puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1580 break;
1581 }
1582 else if ( Abc_ObjIsComplement(pObj0) )
1583 {
1584 for ( w = 0; w < p->nWords; w++ )
1585 // if ( (puData0[w] | puData1[w]) != puDataR[w] )
1586 if ( ((~puData0[w] | puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1587 break;
1588 }
1589 else if ( Abc_ObjIsComplement(pObj1) )
1590 {
1591 for ( w = 0; w < p->nWords; w++ )
1592 // if ( (puData0[w] | puData1[w]) != puDataR[w] )
1593 if ( ((puData0[w] | ~puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1594 break;
1595 }
1596 else
1597 {
1598 for ( w = 0; w < p->nWords; w++ )
1599 // if ( (puData0[w] | puData1[w]) != puDataR[w] )
1600 if ( ((puData0[w] | puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1601 break;
1602 }
1603 if ( w == p->nWords )
1604 {
1605 p->nUsedNode1Or++;
1606 return Abc_ManResubQuit1_1( p->pRoot, pObj0, pObj1, 1 );
1607 }
1608 }
1609 }
1610 // check negative unate divisors
1611 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UN, pObj0, i )
1612 {
1613 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1614 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UN, pObj1, k, i + 1 )
1615 {
1616 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1617 if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) )
1618 {
1619 for ( w = 0; w < p->nWords; w++ )
1620 // if ( (puData0[w] & puData1[w]) != puDataR[w] )
1621 if ( ((~puData0[w] & ~puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1622 break;
1623 }
1624 if ( Abc_ObjIsComplement(pObj0) )
1625 {
1626 for ( w = 0; w < p->nWords; w++ )
1627 // if ( (puData0[w] & puData1[w]) != puDataR[w] )
1628 if ( ((~puData0[w] & puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1629 break;
1630 }
1631 if ( Abc_ObjIsComplement(pObj1) )
1632 {
1633 for ( w = 0; w < p->nWords; w++ )
1634 // if ( (puData0[w] & puData1[w]) != puDataR[w] )
1635 if ( ((puData0[w] & ~puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1636 break;
1637 }
1638 else
1639 {
1640 for ( w = 0; w < p->nWords; w++ )
1641 // if ( (puData0[w] & puData1[w]) != puDataR[w] )
1642 if ( ((puData0[w] & puData1[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1643 break;
1644 }
1645 if ( w == p->nWords )
1646 {
1647 p->nUsedNode1And++;
1648 return Abc_ManResubQuit1_1( p->pRoot, pObj0, pObj1, 0 );
1649 }
1650 }
1651 }
1652 return NULL;
1653}
1654
1666Dec_Graph_t * Abc_ManResubDivs12( Abc_ManRes_t * p, int Required )
1667{
1668 Abc_Obj_t * pObj0, * pObj1, * pObj2, * pObjMax, * pObjMin0 = NULL, * pObjMin1 = NULL;
1669 unsigned * puData0, * puData1, * puData2, * puDataR;
1670 int i, k, j, w, LevelMax;
1671 puDataR = (unsigned *)p->pRoot->pData;
1672 // check positive unate divisors
1673 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UP, pObj0, i )
1674 {
1675 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1676 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UP, pObj1, k, i + 1 )
1677 {
1678 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1679 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UP, pObj2, j, k + 1 )
1680 {
1681 puData2 = (unsigned *)Abc_ObjRegular(pObj2)->pData;
1682 if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1683 {
1684 for ( w = 0; w < p->nWords; w++ )
1685 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1686 if ( ((~puData0[w] | ~puData1[w] | ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1687 break;
1688 }
1689 else if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1690 {
1691 for ( w = 0; w < p->nWords; w++ )
1692 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1693 if ( ((~puData0[w] | ~puData1[w] | puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1694 break;
1695 }
1696 else if ( Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1697 {
1698 for ( w = 0; w < p->nWords; w++ )
1699 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1700 if ( ((~puData0[w] | puData1[w] | ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1701 break;
1702 }
1703 else if ( Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1704 {
1705 for ( w = 0; w < p->nWords; w++ )
1706 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1707 if ( ((~puData0[w] | puData1[w] | puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1708 break;
1709 }
1710 else if ( !Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1711 {
1712 for ( w = 0; w < p->nWords; w++ )
1713 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1714 if ( ((puData0[w] | ~puData1[w] | ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1715 break;
1716 }
1717 else if ( !Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1718 {
1719 for ( w = 0; w < p->nWords; w++ )
1720 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1721 if ( ((puData0[w] | ~puData1[w] | puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1722 break;
1723 }
1724 else if ( !Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1725 {
1726 for ( w = 0; w < p->nWords; w++ )
1727 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1728 if ( ((puData0[w] | puData1[w] | ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1729 break;
1730 }
1731 else if ( !Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1732 {
1733 for ( w = 0; w < p->nWords; w++ )
1734 // if ( (puData0[w] | puData1[w] | puData2[w]) != puDataR[w] )
1735 if ( ((puData0[w] | puData1[w] | puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1736 break;
1737 }
1738 else assert( 0 );
1739 if ( w == p->nWords )
1740 {
1741 LevelMax = Abc_MaxInt( Abc_ObjRegular(pObj0)->Level, Abc_MaxInt(Abc_ObjRegular(pObj1)->Level, Abc_ObjRegular(pObj2)->Level) );
1742 assert( LevelMax <= Required - 1 );
1743
1744 pObjMax = NULL;
1745 if ( (int)Abc_ObjRegular(pObj0)->Level == LevelMax )
1746 pObjMax = pObj0, pObjMin0 = pObj1, pObjMin1 = pObj2;
1747 if ( (int)Abc_ObjRegular(pObj1)->Level == LevelMax )
1748 {
1749 if ( pObjMax ) continue;
1750 pObjMax = pObj1, pObjMin0 = pObj0, pObjMin1 = pObj2;
1751 }
1752 if ( (int)Abc_ObjRegular(pObj2)->Level == LevelMax )
1753 {
1754 if ( pObjMax ) continue;
1755 pObjMax = pObj2, pObjMin0 = pObj0, pObjMin1 = pObj1;
1756 }
1757
1758 p->nUsedNode2Or++;
1759 assert(pObjMin0);
1760 assert(pObjMin1);
1761 return Abc_ManResubQuit21_1( p->pRoot, pObjMin0, pObjMin1, pObjMax, 1 );
1762 }
1763 }
1764 }
1765 }
1766 // check negative unate divisors
1767 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UN, pObj0, i )
1768 {
1769 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1770 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UN, pObj1, k, i + 1 )
1771 {
1772 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1773 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs1UN, pObj2, j, k + 1 )
1774 {
1775 puData2 = (unsigned *)Abc_ObjRegular(pObj2)->pData;
1776 if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1777 {
1778 for ( w = 0; w < p->nWords; w++ )
1779 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1780 if ( ((~puData0[w] & ~puData1[w] & ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1781 break;
1782 }
1783 else if ( Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1784 {
1785 for ( w = 0; w < p->nWords; w++ )
1786 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1787 if ( ((~puData0[w] & ~puData1[w] & puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1788 break;
1789 }
1790 else if ( Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1791 {
1792 for ( w = 0; w < p->nWords; w++ )
1793 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1794 if ( ((~puData0[w] & puData1[w] & ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1795 break;
1796 }
1797 else if ( Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1798 {
1799 for ( w = 0; w < p->nWords; w++ )
1800 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1801 if ( ((~puData0[w] & puData1[w] & puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1802 break;
1803 }
1804 else if ( !Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1805 {
1806 for ( w = 0; w < p->nWords; w++ )
1807 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1808 if ( ((puData0[w] & ~puData1[w] & ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1809 break;
1810 }
1811 else if ( !Abc_ObjIsComplement(pObj0) && Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1812 {
1813 for ( w = 0; w < p->nWords; w++ )
1814 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1815 if ( ((puData0[w] & ~puData1[w] & puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1816 break;
1817 }
1818 else if ( !Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1819 {
1820 for ( w = 0; w < p->nWords; w++ )
1821 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1822 if ( ((puData0[w] & puData1[w] & ~puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1823 break;
1824 }
1825 else if ( !Abc_ObjIsComplement(pObj0) && !Abc_ObjIsComplement(pObj1) && !Abc_ObjIsComplement(pObj2) )
1826 {
1827 for ( w = 0; w < p->nWords; w++ )
1828 // if ( (puData0[w] & puData1[w] & puData2[w]) != puDataR[w] )
1829 if ( ((puData0[w] & puData1[w] & puData2[w]) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1830 break;
1831 }
1832 else assert( 0 );
1833 if ( w == p->nWords )
1834 {
1835 LevelMax = Abc_MaxInt( Abc_ObjRegular(pObj0)->Level, Abc_MaxInt(Abc_ObjRegular(pObj1)->Level, Abc_ObjRegular(pObj2)->Level) );
1836 assert( LevelMax <= Required - 1 );
1837
1838 pObjMax = NULL;
1839 if ( (int)Abc_ObjRegular(pObj0)->Level == LevelMax )
1840 pObjMax = pObj0, pObjMin0 = pObj1, pObjMin1 = pObj2;
1841 if ( (int)Abc_ObjRegular(pObj1)->Level == LevelMax )
1842 {
1843 if ( pObjMax ) continue;
1844 pObjMax = pObj1, pObjMin0 = pObj0, pObjMin1 = pObj2;
1845 }
1846 if ( (int)Abc_ObjRegular(pObj2)->Level == LevelMax )
1847 {
1848 if ( pObjMax ) continue;
1849 pObjMax = pObj2, pObjMin0 = pObj0, pObjMin1 = pObj1;
1850 }
1851
1852 p->nUsedNode2And++;
1853 assert(pObjMin0);
1854 assert(pObjMin1);
1855 return Abc_ManResubQuit21_1( p->pRoot, pObjMin0, pObjMin1, pObjMax, 0 );
1856 }
1857 }
1858 }
1859 }
1860 return NULL;
1861}
1862
1874Dec_Graph_t * Abc_ManResubDivs2( Abc_ManRes_t * p, int Required )
1875{
1876 Abc_Obj_t * pObj0, * pObj1, * pObj2;
1877 unsigned * puData0, * puData1, * puData2, * puDataR;
1878 int i, k, w;
1879 puDataR = (unsigned *)p->pRoot->pData;
1880 // check positive unate divisors
1881 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UP, pObj0, i )
1882 {
1883 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1884 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs2UP0, pObj1, k )
1885 {
1886 pObj2 = (Abc_Obj_t *)Vec_PtrEntry( p->vDivs2UP1, k );
1887
1888 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1889 puData2 = (unsigned *)Abc_ObjRegular(pObj2)->pData;
1890 if ( Abc_ObjIsComplement(pObj0) )
1891 {
1892 if ( Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1893 {
1894 for ( w = 0; w < p->nWords; w++ )
1895 // if ( (puData0[w] | (puData1[w] | puData2[w])) != puDataR[w] )
1896 if ( ((~puData0[w] | (puData1[w] | puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1897 break;
1898 }
1899 else if ( Abc_ObjIsComplement(pObj1) )
1900 {
1901 for ( w = 0; w < p->nWords; w++ )
1902 // if ( (puData0[w] | (~puData1[w] & puData2[w])) != puDataR[w] )
1903 if ( ((~puData0[w] | (~puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1904 break;
1905 }
1906 else if ( Abc_ObjIsComplement(pObj2) )
1907 {
1908 for ( w = 0; w < p->nWords; w++ )
1909 // if ( (puData0[w] | (puData1[w] & ~puData2[w])) != puDataR[w] )
1910 if ( ((~puData0[w] | (puData1[w] & ~puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1911 break;
1912 }
1913 else
1914 {
1915 for ( w = 0; w < p->nWords; w++ )
1916 // if ( (puData0[w] | (puData1[w] & puData2[w])) != puDataR[w] )
1917 if ( ((~puData0[w] | (puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1918 break;
1919 }
1920 }
1921 else
1922 {
1923 if ( Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1924 {
1925 for ( w = 0; w < p->nWords; w++ )
1926 // if ( (puData0[w] | (puData1[w] | puData2[w])) != puDataR[w] )
1927 if ( ((puData0[w] | (puData1[w] | puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1928 break;
1929 }
1930 else if ( Abc_ObjIsComplement(pObj1) )
1931 {
1932 for ( w = 0; w < p->nWords; w++ )
1933 // if ( (puData0[w] | (~puData1[w] & puData2[w])) != puDataR[w] )
1934 if ( ((puData0[w] | (~puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1935 break;
1936 }
1937 else if ( Abc_ObjIsComplement(pObj2) )
1938 {
1939 for ( w = 0; w < p->nWords; w++ )
1940 // if ( (puData0[w] | (puData1[w] & ~puData2[w])) != puDataR[w] )
1941 if ( ((puData0[w] | (puData1[w] & ~puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1942 break;
1943 }
1944 else
1945 {
1946 for ( w = 0; w < p->nWords; w++ )
1947 // if ( (puData0[w] | (puData1[w] & puData2[w])) != puDataR[w] )
1948 if ( ((puData0[w] | (puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1949 break;
1950 }
1951 }
1952 if ( w == p->nWords )
1953 {
1954 p->nUsedNode2OrAnd++;
1955 return Abc_ManResubQuit2_1( p->pRoot, pObj0, pObj1, pObj2, 1 );
1956 }
1957 }
1958 }
1959 // check negative unate divisors
1960 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs1UN, pObj0, i )
1961 {
1962 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
1963 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs2UN0, pObj1, k )
1964 {
1965 pObj2 = (Abc_Obj_t *)Vec_PtrEntry( p->vDivs2UN1, k );
1966
1967 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
1968 puData2 = (unsigned *)Abc_ObjRegular(pObj2)->pData;
1969 if ( Abc_ObjIsComplement(pObj0) )
1970 {
1971 if ( Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
1972 {
1973 for ( w = 0; w < p->nWords; w++ )
1974 // if ( (puData0[w] & (puData1[w] | puData2[w])) != puDataR[w] )
1975 if ( ((~puData0[w] & (puData1[w] | puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1976 break;
1977 }
1978 else if ( Abc_ObjIsComplement(pObj1) )
1979 {
1980 for ( w = 0; w < p->nWords; w++ )
1981 // if ( (puData0[w] & (~puData1[w] & puData2[w])) != puDataR[w] )
1982 if ( ((~puData0[w] & (~puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1983 break;
1984 }
1985 else if ( Abc_ObjIsComplement(pObj2) )
1986 {
1987 for ( w = 0; w < p->nWords; w++ )
1988 // if ( (puData0[w] & (puData1[w] & ~puData2[w])) != puDataR[w] )
1989 if ( ((~puData0[w] & (puData1[w] & ~puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1990 break;
1991 }
1992 else
1993 {
1994 for ( w = 0; w < p->nWords; w++ )
1995 // if ( (puData0[w] & (puData1[w] & puData2[w])) != puDataR[w] )
1996 if ( ((~puData0[w] & (puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
1997 break;
1998 }
1999 }
2000 else
2001 {
2002 if ( Abc_ObjIsComplement(pObj1) && Abc_ObjIsComplement(pObj2) )
2003 {
2004 for ( w = 0; w < p->nWords; w++ )
2005 // if ( (puData0[w] & (puData1[w] | puData2[w])) != puDataR[w] )
2006 if ( ((puData0[w] & (puData1[w] | puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2007 break;
2008 }
2009 else if ( Abc_ObjIsComplement(pObj1) )
2010 {
2011 for ( w = 0; w < p->nWords; w++ )
2012 // if ( (puData0[w] & (~puData1[w] & puData2[w])) != puDataR[w] )
2013 if ( ((puData0[w] & (~puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2014 break;
2015 }
2016 else if ( Abc_ObjIsComplement(pObj2) )
2017 {
2018 for ( w = 0; w < p->nWords; w++ )
2019 // if ( (puData0[w] & (puData1[w] & ~puData2[w])) != puDataR[w] )
2020 if ( ((puData0[w] & (puData1[w] & ~puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2021 break;
2022 }
2023 else
2024 {
2025 for ( w = 0; w < p->nWords; w++ )
2026 // if ( (puData0[w] & (puData1[w] & puData2[w])) != puDataR[w] )
2027 if ( ((puData0[w] & (puData1[w] & puData2[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2028 break;
2029 }
2030 }
2031 if ( w == p->nWords )
2032 {
2033 p->nUsedNode2AndOr++;
2034 return Abc_ManResubQuit2_1( p->pRoot, pObj0, pObj1, pObj2, 0 );
2035 }
2036 }
2037 }
2038 return NULL;
2039}
2040
2052Dec_Graph_t * Abc_ManResubDivs3( Abc_ManRes_t * p, int Required )
2053{
2054 Abc_Obj_t * pObj0, * pObj1, * pObj2, * pObj3;
2055 unsigned * puData0, * puData1, * puData2, * puData3, * puDataR;
2056 int i, k, w = 0, Flag;
2057 puDataR = (unsigned *)p->pRoot->pData;
2058 // check positive unate divisors
2059 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs2UP0, pObj0, i )
2060 {
2061 pObj1 = (Abc_Obj_t *)Vec_PtrEntry( p->vDivs2UP1, i );
2062 puData0 = (unsigned *)Abc_ObjRegular(pObj0)->pData;
2063 puData1 = (unsigned *)Abc_ObjRegular(pObj1)->pData;
2064 Flag = (Abc_ObjIsComplement(pObj0) << 3) | (Abc_ObjIsComplement(pObj1) << 2);
2065
2066 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs2UP0, pObj2, k, i + 1 )
2067 {
2068 pObj3 = (Abc_Obj_t *)Vec_PtrEntry( p->vDivs2UP1, k );
2069 puData2 = (unsigned *)Abc_ObjRegular(pObj2)->pData;
2070 puData3 = (unsigned *)Abc_ObjRegular(pObj3)->pData;
2071
2072 Flag = (Flag & 12) | ((int)Abc_ObjIsComplement(pObj2) << 1) | (int)Abc_ObjIsComplement(pObj3);
2073 assert( Flag < 16 );
2074 switch( Flag )
2075 {
2076 case 0: // 0000
2077 for ( w = 0; w < p->nWords; w++ )
2078// if ( ((puData0[w] & puData1[w]) | (puData2[w] & puData3[w])) != puDataR[w] )
2079 if ( (((puData0[w] & puData1[w]) | (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2080 break;
2081 break;
2082 case 1: // 0001
2083 for ( w = 0; w < p->nWords; w++ )
2084// if ( ((puData0[w] & puData1[w]) | (puData2[w] & ~puData3[w])) != puDataR[w] )
2085 if ( (((puData0[w] & puData1[w]) | (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2086 break;
2087 break;
2088 case 2: // 0010
2089 for ( w = 0; w < p->nWords; w++ )
2090// if ( ((puData0[w] & puData1[w]) | (~puData2[w] & puData3[w])) != puDataR[w] )
2091 if ( (((puData0[w] & puData1[w]) | (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2092 break;
2093 break;
2094 case 3: // 0011
2095 for ( w = 0; w < p->nWords; w++ )
2096// if ( ((puData0[w] & puData1[w]) | (puData2[w] | puData3[w])) != puDataR[w] )
2097 if ( (((puData0[w] & puData1[w]) | (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2098 break;
2099 break;
2100
2101 case 4: // 0100
2102 for ( w = 0; w < p->nWords; w++ )
2103// if ( ((puData0[w] & ~puData1[w]) | (puData2[w] & puData3[w])) != puDataR[w] )
2104 if ( (((puData0[w] & ~puData1[w]) | (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2105 break;
2106 break;
2107 case 5: // 0101
2108 for ( w = 0; w < p->nWords; w++ )
2109// if ( ((puData0[w] & ~puData1[w]) | (puData2[w] & ~puData3[w])) != puDataR[w] )
2110 if ( (((puData0[w] & ~puData1[w]) | (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2111 break;
2112 break;
2113 case 6: // 0110
2114 for ( w = 0; w < p->nWords; w++ )
2115// if ( ((puData0[w] & ~puData1[w]) | (~puData2[w] & puData3[w])) != puDataR[w] )
2116 if ( (((puData0[w] & ~puData1[w]) | (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2117 break;
2118 break;
2119 case 7: // 0111
2120 for ( w = 0; w < p->nWords; w++ )
2121// if ( ((puData0[w] & ~puData1[w]) | (puData2[w] | puData3[w])) != puDataR[w] )
2122 if ( (((puData0[w] & ~puData1[w]) | (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2123 break;
2124 break;
2125
2126 case 8: // 1000
2127 for ( w = 0; w < p->nWords; w++ )
2128// if ( ((~puData0[w] & puData1[w]) | (puData2[w] & puData3[w])) != puDataR[w] )
2129 if ( (((~puData0[w] & puData1[w]) | (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2130 break;
2131 break;
2132 case 9: // 1001
2133 for ( w = 0; w < p->nWords; w++ )
2134// if ( ((~puData0[w] & puData1[w]) | (puData2[w] & ~puData3[w])) != puDataR[w] )
2135 if ( (((~puData0[w] & puData1[w]) | (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2136 break;
2137 break;
2138 case 10: // 1010
2139 for ( w = 0; w < p->nWords; w++ )
2140// if ( ((~puData0[w] & puData1[w]) | (~puData2[w] & puData3[w])) != puDataR[w] )
2141 if ( (((~puData0[w] & puData1[w]) | (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2142 break;
2143 break;
2144 case 11: // 1011
2145 for ( w = 0; w < p->nWords; w++ )
2146// if ( ((~puData0[w] & puData1[w]) | (puData2[w] | puData3[w])) != puDataR[w] )
2147 if ( (((~puData0[w] & puData1[w]) | (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2148 break;
2149 break;
2150
2151 case 12: // 1100
2152 for ( w = 0; w < p->nWords; w++ )
2153// if ( ((puData0[w] | puData1[w]) | (puData2[w] & puData3[w])) != puDataR[w] )
2154 if ( (((puData0[w] | puData1[w]) | (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] ) // care set
2155 break;
2156 break;
2157 case 13: // 1101
2158 for ( w = 0; w < p->nWords; w++ )
2159// if ( ((puData0[w] | puData1[w]) | (puData2[w] & ~puData3[w])) != puDataR[w] )
2160 if ( (((puData0[w] | puData1[w]) | (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2161 break;
2162 break;
2163 case 14: // 1110
2164 for ( w = 0; w < p->nWords; w++ )
2165// if ( ((puData0[w] | puData1[w]) | (~puData2[w] & puData3[w])) != puDataR[w] )
2166 if ( (((puData0[w] | puData1[w]) | (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2167 break;
2168 break;
2169 case 15: // 1111
2170 for ( w = 0; w < p->nWords; w++ )
2171// if ( ((puData0[w] | puData1[w]) | (puData2[w] | puData3[w])) != puDataR[w] )
2172 if ( (((puData0[w] | puData1[w]) | (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2173 break;
2174 break;
2175
2176 }
2177 if ( w == p->nWords )
2178 {
2179 p->nUsedNode3OrAnd++;
2180 return Abc_ManResubQuit3_1( p->pRoot, pObj0, pObj1, pObj2, pObj3, 1 );
2181 }
2182 }
2183 }
2184
2185/*
2186 // check negative unate divisors
2187 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs2UN0, pObj0, i )
2188 {
2189 pObj1 = Vec_PtrEntry( p->vDivs2UN1, i );
2190 puData0 = Abc_ObjRegular(pObj0)->pData;
2191 puData1 = Abc_ObjRegular(pObj1)->pData;
2192 Flag = (Abc_ObjIsComplement(pObj0) << 3) | (Abc_ObjIsComplement(pObj1) << 2);
2193
2194 Vec_PtrForEachEntryStart( Abc_Obj_t *, p->vDivs2UN0, pObj2, k, i + 1 )
2195 {
2196 pObj3 = Vec_PtrEntry( p->vDivs2UN1, k );
2197 puData2 = Abc_ObjRegular(pObj2)->pData;
2198 puData3 = Abc_ObjRegular(pObj3)->pData;
2199
2200 Flag = (Flag & 12) | (Abc_ObjIsComplement(pObj2) << 1) | Abc_ObjIsComplement(pObj3);
2201 assert( Flag < 16 );
2202 switch( Flag )
2203 {
2204 case 0: // 0000
2205 for ( w = 0; w < p->nWords; w++ )
2206 if ( (((puData0[w] & puData1[w]) & (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2207 break;
2208 break;
2209 case 1: // 0001
2210 for ( w = 0; w < p->nWords; w++ )
2211 if ( (((puData0[w] & puData1[w]) & (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2212 break;
2213 break;
2214 case 2: // 0010
2215 for ( w = 0; w < p->nWords; w++ )
2216 if ( (((puData0[w] & puData1[w]) & (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2217 break;
2218 break;
2219 case 3: // 0011
2220 for ( w = 0; w < p->nWords; w++ )
2221 if ( (((puData0[w] & puData1[w]) & (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2222 break;
2223 break;
2224
2225 case 4: // 0100
2226 for ( w = 0; w < p->nWords; w++ )
2227 if ( (((puData0[w] & ~puData1[w]) & (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2228 break;
2229 break;
2230 case 5: // 0101
2231 for ( w = 0; w < p->nWords; w++ )
2232 if ( (((puData0[w] & ~puData1[w]) & (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2233 break;
2234 break;
2235 case 6: // 0110
2236 for ( w = 0; w < p->nWords; w++ )
2237 if ( (((puData0[w] & ~puData1[w]) & (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2238 break;
2239 break;
2240 case 7: // 0111
2241 for ( w = 0; w < p->nWords; w++ )
2242 if ( (((puData0[w] & ~puData1[w]) & (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2243 break;
2244 break;
2245
2246 case 8: // 1000
2247 for ( w = 0; w < p->nWords; w++ )
2248 if ( (((~puData0[w] & puData1[w]) & (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2249 break;
2250 break;
2251 case 9: // 1001
2252 for ( w = 0; w < p->nWords; w++ )
2253 if ( (((~puData0[w] & puData1[w]) & (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2254 break;
2255 break;
2256 case 10: // 1010
2257 for ( w = 0; w < p->nWords; w++ )
2258 if ( (((~puData0[w] & puData1[w]) & (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2259 break;
2260 break;
2261 case 11: // 1011
2262 for ( w = 0; w < p->nWords; w++ )
2263 if ( (((~puData0[w] & puData1[w]) & (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2264 break;
2265 break;
2266
2267 case 12: // 1100
2268 for ( w = 0; w < p->nWords; w++ )
2269 if ( (((puData0[w] | puData1[w]) & (puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2270 break;
2271 break;
2272 case 13: // 1101
2273 for ( w = 0; w < p->nWords; w++ )
2274 if ( (((puData0[w] | puData1[w]) & (puData2[w] & ~puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2275 break;
2276 break;
2277 case 14: // 1110
2278 for ( w = 0; w < p->nWords; w++ )
2279 if ( (((puData0[w] | puData1[w]) & (~puData2[w] & puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2280 break;
2281 break;
2282 case 15: // 1111
2283 for ( w = 0; w < p->nWords; w++ )
2284 if ( (((puData0[w] | puData1[w]) & (puData2[w] | puData3[w])) ^ puDataR[w]) & p->pCareSet[w] )
2285 break;
2286 break;
2287
2288 }
2289 if ( w == p->nWords )
2290 {
2291 p->nUsedNode3AndOr++;
2292 return Abc_ManResubQuit3_1( p->pRoot, pObj0, pObj1, pObj2, pObj3, 0 );
2293 }
2294 }
2295 }
2296*/
2297 return NULL;
2298}
2299
2311void Abc_ManResubCleanup( Abc_ManRes_t * p )
2312{
2313 Abc_Obj_t * pObj;
2314 int i;
2315 Vec_PtrForEachEntry( Abc_Obj_t *, p->vDivs, pObj, i )
2316 pObj->pData = NULL;
2317 Vec_PtrClear( p->vDivs );
2318 p->pRoot = NULL;
2319}
2320
2332Dec_Graph_t * Abc_ManResubEval( Abc_ManRes_t * p, Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, int nSteps, int fUpdateLevel, int fVerbose )
2333{
2334 extern int Abc_NodeMffcInside( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vInside );
2335 Dec_Graph_t * pGraph;
2336 int Required;
2337 abctime clk;
2338
2339 Required = fUpdateLevel? Abc_ObjRequiredLevel(pRoot) : ABC_INFINITY;
2340
2341 assert( nSteps >= 0 );
2342 assert( nSteps <= 3 );
2343 p->pRoot = pRoot;
2344 p->nLeaves = Vec_PtrSize(vLeaves);
2345 p->nLastGain = -1;
2346
2347 // collect the MFFC
2348clk = Abc_Clock();
2349 p->nMffc = Abc_NodeMffcInside( pRoot, vLeaves, p->vTemp );
2350p->timeMffc += Abc_Clock() - clk;
2351 assert( p->nMffc > 0 );
2352
2353 // collect the divisor nodes
2354clk = Abc_Clock();
2355 if ( !Abc_ManResubCollectDivs( p, pRoot, vLeaves, Required ) )
2356 return NULL;
2357 p->timeDiv += Abc_Clock() - clk;
2358
2359 p->nTotalDivs += p->nDivs;
2360 p->nTotalLeaves += p->nLeaves;
2361
2362 // simulate the nodes
2363clk = Abc_Clock();
2364 Abc_ManResubSimulate( p->vDivs, p->nLeaves, p->vSims, p->nLeavesMax, p->nWords );
2365p->timeSim += Abc_Clock() - clk;
2366
2367clk = Abc_Clock();
2368 // consider constants
2369 if ( (pGraph = Abc_ManResubQuit( p )) )
2370 {
2371 p->nUsedNodeC++;
2372 p->nLastGain = p->nMffc;
2373 return pGraph;
2374 }
2375
2376 // consider equal nodes
2377 if ( (pGraph = Abc_ManResubDivs0( p )) )
2378 {
2379p->timeRes1 += Abc_Clock() - clk;
2380 p->nUsedNode0++;
2381 p->nLastGain = p->nMffc;
2382 return pGraph;
2383 }
2384 if ( nSteps == 0 || p->nMffc == 1 )
2385 {
2386p->timeRes1 += Abc_Clock() - clk;
2387 return NULL;
2388 }
2389
2390 // get the one level divisors
2391 Abc_ManResubDivsS( p, Required );
2392
2393 // consider one node
2394 if ( (pGraph = Abc_ManResubDivs1( p, Required )) )
2395 {
2396p->timeRes1 += Abc_Clock() - clk;
2397 p->nLastGain = p->nMffc - 1;
2398 return pGraph;
2399 }
2400p->timeRes1 += Abc_Clock() - clk;
2401 if ( nSteps == 1 || p->nMffc == 2 )
2402 return NULL;
2403
2404clk = Abc_Clock();
2405 // consider triples
2406 if ( (pGraph = Abc_ManResubDivs12( p, Required )) )
2407 {
2408p->timeRes2 += Abc_Clock() - clk;
2409 p->nLastGain = p->nMffc - 2;
2410 return pGraph;
2411 }
2412p->timeRes2 += Abc_Clock() - clk;
2413
2414 // get the two level divisors
2415clk = Abc_Clock();
2416 Abc_ManResubDivsD( p, Required );
2417p->timeResD += Abc_Clock() - clk;
2418
2419 // consider two nodes
2420clk = Abc_Clock();
2421 if ( (pGraph = Abc_ManResubDivs2( p, Required )) )
2422 {
2423p->timeRes2 += Abc_Clock() - clk;
2424 p->nLastGain = p->nMffc - 2;
2425 return pGraph;
2426 }
2427p->timeRes2 += Abc_Clock() - clk;
2428 if ( nSteps == 2 || p->nMffc == 3 )
2429 return NULL;
2430
2431 // consider two nodes
2432clk = Abc_Clock();
2433 if ( (pGraph = Abc_ManResubDivs3( p, Required )) )
2434 {
2435p->timeRes3 += Abc_Clock() - clk;
2436 p->nLastGain = p->nMffc - 3;
2437 return pGraph;
2438 }
2439p->timeRes3 += Abc_Clock() - clk;
2440 if ( nSteps == 3 || p->nLeavesMax == 4 )
2441 return NULL;
2442 return NULL;
2443}
2444
2445
2446
2447
2459
2461{
2462 // quit if the node is visited (or if it is a leaf)
2463 if ( Abc_NodeIsTravIdCurrent(pObj) )
2464 return 0;
2465 Abc_NodeSetTravIdCurrent(pObj);
2466 // report the error
2467 if ( Abc_ObjIsCi(pObj) )
2468 printf( "Abc_CutVolumeCheck() ERROR: The set of nodes is not a cut!\n" );
2469 // count the number of nodes in the leaves
2470 return 1 + Abc_CutVolumeCheck_rec_1( Abc_ObjFanin0(pObj) ) +
2471 Abc_CutVolumeCheck_rec_1( Abc_ObjFanin1(pObj) );
2472}
2473
2484int Abc_CutVolumeCheck( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves )
2485{
2486 Abc_Obj_t * pObj;
2487 int i;
2488 // mark the leaves
2489 Abc_NtkIncrementTravId( pNode->pNtk );
2490 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
2491 Abc_NodeSetTravIdCurrent( pObj );
2492 // traverse the nodes starting from the given one and count them
2493 return Abc_CutVolumeCheck_rec_1( pNode );
2494}
2495
2507
2508void Abc_CutFactor_rec_1( Abc_Obj_t * pObj, Vec_Ptr_t * vLeaves )
2509{
2510 if ( pObj->fMarkA )
2511 return;
2512 if ( Abc_ObjIsCi(pObj) || (Abc_ObjFanoutNum(pObj) > 1 && !Abc_NodeIsMuxControlType(pObj)) )
2513 {
2514 Vec_PtrPush( vLeaves, pObj );
2515 pObj->fMarkA = 1;
2516 return;
2517 }
2518 Abc_CutFactor_rec_1( Abc_ObjFanin0(pObj), vLeaves );
2519 Abc_CutFactor_rec_1( Abc_ObjFanin1(pObj), vLeaves );
2520}
2521
2522
2536
2538{
2539 Vec_Ptr_t * vLeaves;
2540 Abc_Obj_t * pObj;
2541 int i;
2542 assert( !Abc_ObjIsCi(pNode) );
2543 vLeaves = Vec_PtrAlloc( 10 );
2544 Abc_CutFactor_rec_1( Abc_ObjFanin0(pNode), vLeaves );
2545 Abc_CutFactor_rec_1( Abc_ObjFanin1(pNode), vLeaves );
2546 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
2547 pObj->fMarkA = 0;
2548 return vLeaves;
2549}
2550
2551
2568Vec_Ptr_t * Abc_CutFactorLarge( Abc_Obj_t * pNode, int nLeavesMax )
2569{
2570 Vec_Ptr_t * vLeaves, * vFactors, * vFact, * vNext;
2571 Vec_Int_t * vFeasible;
2572 Abc_Obj_t * pLeaf, * pTemp;
2573 int i, k, Counter, RandLeaf;
2574 int BestCut, BestShare;
2575 assert( Abc_ObjIsNode(pNode) );
2576 // get one factor-cut
2577 vLeaves = Abc_CutFactor_1( pNode );
2578 if ( Vec_PtrSize(vLeaves) > nLeavesMax )
2579 {
2580 Vec_PtrFree(vLeaves);
2581 return NULL;
2582 }
2583 if ( Vec_PtrSize(vLeaves) == nLeavesMax )
2584 return vLeaves;
2585 // initialize the factor cuts for the leaves
2586 vFactors = Vec_PtrAlloc( nLeavesMax );
2587 Abc_NtkIncrementTravId( pNode->pNtk );
2588 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pLeaf, i )
2589 {
2590 Abc_NodeSetTravIdCurrent( pLeaf );
2591 if ( Abc_ObjIsCi(pLeaf) )
2592 Vec_PtrPush( vFactors, NULL );
2593 else
2594 Vec_PtrPush( vFactors, Abc_CutFactor_1(pLeaf) );
2595 }
2596 // construct larger factor cuts
2597 vFeasible = Vec_IntAlloc( nLeavesMax );
2598 while ( 1 )
2599 {
2600 BestCut = -1, BestShare = -1;
2601 // find the next feasible cut to add
2602 Vec_IntClear( vFeasible );
2603 Vec_PtrForEachEntry( Vec_Ptr_t *, vFactors, vFact, i )
2604 {
2605 if ( vFact == NULL )
2606 continue;
2607 // count the number of unmarked leaves of this factor cut
2608 Counter = 0;
2609 Vec_PtrForEachEntry( Abc_Obj_t *, vFact, pTemp, k )
2610 Counter += !Abc_NodeIsTravIdCurrent(pTemp);
2611 // if the number of new leaves is smaller than the diff, it is feasible
2612 if ( Counter <= nLeavesMax - Vec_PtrSize(vLeaves) + 1 )
2613 {
2614 Vec_IntPush( vFeasible, i );
2615 if ( BestCut == -1 || BestShare < Vec_PtrSize(vFact) - Counter )
2616 BestCut = i, BestShare = Vec_PtrSize(vFact) - Counter;
2617 }
2618 }
2619 // quit if there is no feasible factor cuts
2620 if ( Vec_IntSize(vFeasible) == 0 )
2621 break;
2622 // randomly choose one leaf and get its factor cut
2623// RandLeaf = Vec_IntEntry( vFeasible, rand() % Vec_IntSize(vFeasible) );
2624 // choose the cut that has most sharing with the other cuts
2625 RandLeaf = BestCut;
2626
2627 pLeaf = (Abc_Obj_t *)Vec_PtrEntry( vLeaves, RandLeaf );
2628 vNext = (Vec_Ptr_t *)Vec_PtrEntry( vFactors, RandLeaf );
2629 // unmark this leaf
2630 Abc_NodeSetTravIdPrevious( pLeaf );
2631 // remove this cut from the leaves and factor cuts
2632 for ( i = RandLeaf; i < Vec_PtrSize(vLeaves)-1; i++ )
2633 {
2634 Vec_PtrWriteEntry( vLeaves, i, Vec_PtrEntry(vLeaves, i+1) );
2635 Vec_PtrWriteEntry( vFactors, i, Vec_PtrEntry(vFactors,i+1) );
2636 }
2637 Vec_PtrShrink( vLeaves, Vec_PtrSize(vLeaves) -1 );
2638 Vec_PtrShrink( vFactors, Vec_PtrSize(vFactors)-1 );
2639 // add new leaves, compute their factor cuts
2640 Vec_PtrForEachEntry( Abc_Obj_t *, vNext, pLeaf, i )
2641 {
2642 if ( Abc_NodeIsTravIdCurrent(pLeaf) )
2643 continue;
2644 Abc_NodeSetTravIdCurrent( pLeaf );
2645 Vec_PtrPush( vLeaves, pLeaf );
2646 if ( Abc_ObjIsCi(pLeaf) )
2647 Vec_PtrPush( vFactors, NULL );
2648 else
2649 Vec_PtrPush( vFactors, Abc_CutFactor_1(pLeaf) );
2650 }
2651 Vec_PtrFree( vNext );
2652 assert( Vec_PtrSize(vLeaves) <= nLeavesMax );
2653 if ( Vec_PtrSize(vLeaves) == nLeavesMax )
2654 break;
2655 }
2656
2657 // remove temporary storage
2658 Vec_PtrForEachEntry( Vec_Ptr_t *, vFactors, vFact, i )
2659 if ( vFact ) Vec_PtrFree( vFact );
2660 Vec_PtrFree( vFactors );
2661 Vec_IntFree( vFeasible );
2662 return vLeaves;
2663}
2664
2665
2666int Abc_NtkOrchSA( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res,Vec_Int_t **pGain_ref, Vec_Int_t **PolicyList, char * DecisionFile, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
2667{
2668 ProgressBar * pProgress;
2669 // For resub
2670 Abc_ManRes_t * pManRes;
2671 Abc_ManCut_t * pManCutRes;
2672 Odc_Man_t * pManOdc = NULL;
2673 Dec_Graph_t * pFFormRes;
2674 Vec_Ptr_t * vLeaves;
2675 // For rewrite
2676 Cut_Man_t * pManCutRwr;
2677 Rwr_Man_t * pManRwr;
2678 Dec_Graph_t * pGraph;
2679 // For refactor
2680 Abc_ManRef_t * pManRef;
2681 Abc_ManCut_t * pManCutRef;
2682 Dec_Graph_t * pFFormRef;
2683 Vec_Ptr_t * vFanins;
2684 Vec_Int_t * DecisionMask = Vec_IntAlloc(1);
2685
2686 Abc_Obj_t * pNode;
2687 FILE *fpt;
2688 abctime clk, clkStart = Abc_Clock();
2690 int i, nNodes, nGain, fCompl, RetValue = 1;
2691 int ops_rwr = 0;
2692 int ops_res = 0;
2693 int ops_ref = 0;
2694 int ops_null = 0;
2695 int sOpsOrder = 0;
2696 assert( Abc_NtkIsStrash(pNtk) );
2697
2698 // cleanup the AIG
2700
2701 // start the managers resub
2702 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
2703 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
2704 if ( nLevelsOdc > 0 )
2705 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
2706 // start the managers refactor
2707 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
2708 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
2709 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
2710 // start the managers rewrite
2711 pManRwr = Rwr_ManStart( 0 );
2712 if ( pManRwr == NULL )
2713 return 0;
2714
2715 // compute the reverse levels if level update is requested
2716 if ( fUpdateLevel )
2717 Abc_NtkStartReverseLevels( pNtk, 0 );
2718 if ( Abc_NtkLatchNum(pNtk) ) {
2719 Abc_NtkForEachLatch(pNtk, pNode, i)
2720 pNode->pNext = (Abc_Obj_t *)pNode->pData;
2721 }
2722clk = Abc_Clock();
2723 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
2724Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
2725 pNtk->pManCut = pManCutRwr;
2726
2727 if ( fVeryVerbose )
2728 Rwr_ScoresClean( pManRwr );
2729
2730 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
2731 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
2732 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
2733
2734 nNodes = Abc_NtkObjNumMax(pNtk);
2735 //printf("nNodes: %d\n", nNodes);
2736 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
2737 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
2738 if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
2739 for(int i=0; i < nNodes; i++){Vec_IntPush(DecisionMask, atoi("-1"));}
2740
2741 pProgress = Extra_ProgressBarStart( stdout, nNodes );
2742 fpt = fopen(DecisionFile, "w");
2743
2744 Abc_NtkForEachNode( pNtk, pNode, i )
2745 {
2746 int iterNode = pNode->Id;
2747 Extra_ProgressBarUpdate( pProgress, i, NULL );
2748 if ( Abc_NodeIsPersistant(pNode) )
2749 {
2750 //fprintf(fpt, "%d, %d\n", iterNode, -99);
2751 Vec_IntPush((*pGain_res), -99);
2752 Vec_IntPush((*pGain_ref), -99);
2753 Vec_IntPush((*pGain_rwr), -99);
2754 continue;
2755 }
2756 if ( Abc_ObjFanoutNum(pNode) > 1000 )
2757 {
2758 //fprintf(fpt, "%d, %d\n", iterNode, -99);
2759 Vec_IntPush((*pGain_res), -99);
2760 Vec_IntPush((*pGain_ref), -99);
2761 Vec_IntPush((*pGain_rwr), -99);
2762 continue;
2763 }
2764 if ( i >= nNodes )
2765 break;
2766
2767//refactor
2768clk = Abc_Clock();
2769 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
2770pManRef->timeCut += Abc_Clock() - clk;
2771clk = Abc_Clock();
2772 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
2773pManRef->timeRes += Abc_Clock() - clk;
2774 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
2775//resub
2776 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
2777pManRes->timeCut += Abc_Clock() - clk;
2778 if ( pManOdc )
2779 {
2780clk = Abc_Clock();
2781 Abc_NtkDontCareClear( pManOdc );
2782 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
2783pManRes->timeTruth += Abc_Clock() - clk;
2784 }
2785clk = Abc_Clock();
2786 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
2787pManRes->timeRes += Abc_Clock() - clk;
2788 Vec_IntPush((*pGain_res), pManRes->nLastGain);
2789//rewrite
2790 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
2791 Vec_IntPush( (*pGain_rwr), nGain);
2792 //fprintf(fpt, "%d, %s, %d, %s, %d, %s, %d\n", pNode->Id, "Oches_Res", pManRes->nLastGain, "Oches_Ref", pManRef->nLastGain, "Oches_Rwr", nGain);
2793
2794 if ((**PolicyList).pArray[iterNode] == 0){sOpsOrder = 0;}
2795 if ((**PolicyList).pArray[iterNode] == 1){sOpsOrder = 1;}
2796 if ((**PolicyList).pArray[iterNode] == 2){sOpsOrder = 2;}
2797 if ((**PolicyList).pArray[iterNode] == 3){sOpsOrder = 3;}
2798 if ((**PolicyList).pArray[iterNode] == 4){sOpsOrder = 4;}
2799 if ((**PolicyList).pArray[iterNode] == 5){sOpsOrder = 5;}
2800
2801 if ( sOpsOrder == 0)
2802 {
2803 //printf("policy orchestration with o1.");
2804 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
2805 {
2806 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
2807 fCompl = Rwr_ManReadCompl(pManRwr);
2808 if ( fPlaceEnable )
2810 if ( fCompl ) Dec_GraphComplement( pGraph );
2811clk = Abc_Clock();
2812 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
2813Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
2814 if ( fCompl ) Dec_GraphComplement( pGraph );
2815 ops_rwr++;
2816 //fprintf(fpt, "%d, %d\n", iterNode, 0);
2817 (DecisionMask)->pArray[iterNode] = 0;
2818 continue;
2819 }
2820
2821 if (pManRes->nLastGain > 0)
2822 {
2823
2824 if ( pFFormRes == NULL )
2825 continue;
2826 pManRes->nTotalGain += pManRes->nLastGain;
2827clk = Abc_Clock();
2828 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
2829pManRes->timeNtk += Abc_Clock() - clk;
2830 Dec_GraphFree( pFFormRes );
2831 ops_res++;
2832 //fprintf(fpt, "%d, %d\n", iterNode, 1);
2833 (DecisionMask)->pArray[iterNode] = 2;
2834 continue;
2835 }
2836
2837 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
2838 {
2839 if ( pFFormRef == NULL )
2840 continue;
2841clk = Abc_Clock();
2842 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
2843 {
2844 Dec_GraphFree( pFFormRef );
2845 RetValue = -1;
2846 break;
2847 }
2848pManRef->timeNtk += Abc_Clock() - clk;
2849 Dec_GraphFree( pFFormRef );
2850 ops_ref++;
2851 //fprintf(fpt, "%d, %d\n", iterNode, 2);
2852 (DecisionMask)->pArray[iterNode] = 3;
2853 continue;
2854 }
2855 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
2856 {
2857 ops_null++;
2858 //fprintf(fpt, "%d, %d\n", iterNode, -1);
2859 continue;
2860 }
2861 }
2862
2863 if ( sOpsOrder == 1)
2864 {
2865 //printf("policy orchestration with o2.");
2866 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
2867 {
2868 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
2869 fCompl = Rwr_ManReadCompl(pManRwr);
2870 if ( fPlaceEnable )
2872 if ( fCompl ) Dec_GraphComplement( pGraph );
2873clk = Abc_Clock();
2874 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
2875Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
2876 if ( fCompl ) Dec_GraphComplement( pGraph );
2877 ops_rwr++;
2878 //fprintf(fpt, "%d, %d\n", iterNode, 0);
2879 (DecisionMask)->pArray[iterNode] = 0;
2880 continue;
2881 }
2882
2883 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
2884 {
2885 if ( pFFormRef == NULL )
2886 continue;
2887clk = Abc_Clock();
2888 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
2889 {
2890 Dec_GraphFree( pFFormRef );
2891 RetValue = -1;
2892 break;
2893 }
2894pManRef->timeNtk += Abc_Clock() - clk;
2895 Dec_GraphFree( pFFormRef );
2896 ops_ref++;
2897 //fprintf(fpt, "%d, %d\n", iterNode, 2);
2898 (DecisionMask)->pArray[iterNode] = 3;
2899 continue;
2900 }
2901
2902 if (pManRes->nLastGain > 0)
2903 {
2904 if ( pFFormRes == NULL )
2905 continue;
2906 pManRes->nTotalGain += pManRes->nLastGain;
2907clk = Abc_Clock();
2908 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
2909pManRes->timeNtk += Abc_Clock() - clk;
2910 Dec_GraphFree( pFFormRes );
2911 ops_res++;
2912 //fprintf(fpt, "%d, %d\n", iterNode, 1);
2913 (DecisionMask)->pArray[iterNode] = 2;
2914 continue;
2915 }
2916 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
2917 {
2918 ops_null++;
2919 //fprintf(fpt, "%d, %d\n", iterNode, -1);
2920 continue;
2921 }
2922 }
2923
2924 if ( sOpsOrder == 2)
2925 {
2926 //printf("policy orchestration with o3.");
2927 if (pManRes->nLastGain > 0)
2928 {
2929 if ( pFFormRes == NULL )
2930 continue;
2931 pManRes->nTotalGain += pManRes->nLastGain;
2932clk = Abc_Clock();
2933 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
2934pManRes->timeNtk += Abc_Clock() - clk;
2935 Dec_GraphFree( pFFormRes );
2936 ops_res++;
2937 //fprintf(fpt, "%d, %d\n", iterNode, 1);
2938 (DecisionMask)->pArray[iterNode] = 2;
2939 continue;
2940 }
2941
2942 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
2943 {
2944 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
2945 fCompl = Rwr_ManReadCompl(pManRwr);
2946 if ( fPlaceEnable )
2948 if ( fCompl ) Dec_GraphComplement( pGraph );
2949clk = Abc_Clock();
2950 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
2951Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
2952 if ( fCompl ) Dec_GraphComplement( pGraph );
2953 ops_rwr++;
2954 //fprintf(fpt, "%d, %d\n", iterNode, 0);
2955 (DecisionMask)->pArray[iterNode] = 0;
2956 continue;
2957 }
2958
2959 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
2960 {
2961 if ( pFFormRef == NULL )
2962 continue;
2963clk = Abc_Clock();
2964 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
2965 {
2966 Dec_GraphFree( pFFormRef );
2967 RetValue = -1;
2968 break;
2969 }
2970pManRef->timeNtk += Abc_Clock() - clk;
2971 Dec_GraphFree( pFFormRef );
2972 ops_ref++;
2973 //fprintf(fpt, "%d, %d\n", iterNode, 2);
2974 (DecisionMask)->pArray[iterNode] = 3;
2975 continue;
2976 }
2977 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
2978 {
2979 ops_null++;
2980 //fprintf(fpt, "%d, %d\n", iterNode, -1);
2981 continue;
2982 }
2983 }
2984
2985 if ( sOpsOrder == 3)
2986 {
2987 //printf("policy orchestration with o4.");
2988 if (pManRes->nLastGain > 0)
2989 {
2990 if ( pFFormRes == NULL )
2991 continue;
2992 pManRes->nTotalGain += pManRes->nLastGain;
2993clk = Abc_Clock();
2994 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
2995pManRes->timeNtk += Abc_Clock() - clk;
2996 Dec_GraphFree( pFFormRes );
2997 ops_res++;
2998 //fprintf(fpt, "%d, %d\n", iterNode, 1);
2999 (DecisionMask)->pArray[iterNode] = 2;
3000 continue;
3001 }
3002
3003 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3004 {
3005 if ( pFFormRef == NULL )
3006 continue;
3007clk = Abc_Clock();
3008 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3009 {
3010 Dec_GraphFree( pFFormRef );
3011 RetValue = -1;
3012 break;
3013 }
3014pManRef->timeNtk += Abc_Clock() - clk;
3015 Dec_GraphFree( pFFormRef );
3016 ops_ref++;
3017 //fprintf(fpt, "%d, %d\n", iterNode, 2);
3018 (DecisionMask)->pArray[iterNode] = 3;
3019 continue;
3020 }
3021
3022 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3023 {
3024 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3025 fCompl = Rwr_ManReadCompl(pManRwr);
3026 if ( fPlaceEnable )
3028 if ( fCompl ) Dec_GraphComplement( pGraph );
3029clk = Abc_Clock();
3030 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3031Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3032 if ( fCompl ) Dec_GraphComplement( pGraph );
3033 ops_rwr++;
3034 //fprintf(fpt, "%d, %d\n", iterNode, 0);
3035 (DecisionMask)->pArray[iterNode] = 0;
3036 continue;
3037 }
3038
3039 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
3040 {
3041 ops_null++;
3042 //fprintf(fpt, "%d, %d\n", iterNode, -1);
3043 continue;
3044 }
3045 }
3046
3047 if ( sOpsOrder == 4)
3048 {
3049 //printf("policy orchestration with o5.");
3050 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3051 {
3052 if ( pFFormRef == NULL )
3053 continue;
3054clk = Abc_Clock();
3055 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3056 {
3057 Dec_GraphFree( pFFormRef );
3058 RetValue = -1;
3059 break;
3060 }
3061pManRef->timeNtk += Abc_Clock() - clk;
3062 Dec_GraphFree( pFFormRef );
3063 ops_ref++;
3064 //fprintf(fpt, "%d, %d\n", iterNode, 2);
3065 (DecisionMask)->pArray[iterNode] = 3;
3066 continue;
3067 }
3068
3069 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3070 {
3071 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3072 fCompl = Rwr_ManReadCompl(pManRwr);
3073 if ( fPlaceEnable )
3075 if ( fCompl ) Dec_GraphComplement( pGraph );
3076clk = Abc_Clock();
3077 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3078Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3079 if ( fCompl ) Dec_GraphComplement( pGraph );
3080 ops_rwr++;
3081 //fprintf(fpt, "%d, %d\n", iterNode, 0);
3082 (DecisionMask)->pArray[iterNode] = 0;
3083 continue;
3084 }
3085
3086 if (pManRes->nLastGain > 0)
3087 {
3088 if ( pFFormRes == NULL )
3089 continue;
3090 pManRes->nTotalGain += pManRes->nLastGain;
3091clk = Abc_Clock();
3092 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3093pManRes->timeNtk += Abc_Clock() - clk;
3094 Dec_GraphFree( pFFormRes );
3095 ops_res++;
3096 //fprintf(fpt, "%d, %d\n", iterNode, 1);
3097 (DecisionMask)->pArray[iterNode] = 2;
3098 continue;
3099 }
3100 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
3101 {
3102 ops_null++;
3103 //fprintf(fpt, "%d, %d\n", iterNode, -1);
3104 continue;
3105 }
3106 }
3107
3108 if ( sOpsOrder == 5)
3109 {
3110 //printf("policy orchestration with o6.");
3111 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3112 {
3113 if ( pFFormRef == NULL )
3114 continue;
3115clk = Abc_Clock();
3116 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3117 {
3118 Dec_GraphFree( pFFormRef );
3119 RetValue = -1;
3120 break;
3121 }
3122pManRef->timeNtk += Abc_Clock() - clk;
3123 Dec_GraphFree( pFFormRef );
3124 ops_ref++;
3125 //fprintf(fpt, "%d, %d\n", iterNode, 2);
3126 (DecisionMask)->pArray[iterNode] = 3;
3127 continue;
3128 }
3129
3130 if (pManRes->nLastGain > 0)
3131 {
3132 if ( pFFormRes == NULL )
3133 continue;
3134 pManRes->nTotalGain += pManRes->nLastGain;
3135clk = Abc_Clock();
3136 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3137pManRes->timeNtk += Abc_Clock() - clk;
3138 Dec_GraphFree( pFFormRes );
3139 ops_res++;
3140 //fprintf(fpt, "%d, %d\n", iterNode, 1);
3141 (DecisionMask)->pArray[iterNode] = 2;
3142 continue;
3143 }
3144
3145 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3146 {
3147 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3148 fCompl = Rwr_ManReadCompl(pManRwr);
3149 if ( fPlaceEnable )
3151 if ( fCompl ) Dec_GraphComplement( pGraph );
3152clk = Abc_Clock();
3153 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3154Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3155 if ( fCompl ) Dec_GraphComplement( pGraph );
3156 ops_rwr++;
3157 //fprintf(fpt, "%d, %d\n", iterNode, 0);
3158 (DecisionMask)->pArray[iterNode] = 0;
3159 continue;
3160 }
3161 if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
3162 {
3163 ops_null++;
3164 //fprintf(fpt, "%d, %d\n", iterNode, -1);
3165 continue;
3166 }
3167 }
3168
3169 }
3170 for (int i=0; i<nNodes; i++){fprintf(fpt, "%d\n", (DecisionMask)->pArray[i]);}
3171 fclose(fpt);
3172 /*
3173 printf("size of vector %d\n", (**pGain_res).nSize);
3174 printf("Nodes with rewrite: %d\n", ops_rwr);
3175 printf("Nodes with resub: %d\n", ops_res);
3176 printf("Nodes with refactor: %d\n", ops_ref);
3177 printf("Nodes without updates: %d\n", ops_null);
3178 */
3179 Extra_ProgressBarStop( pProgress );
3180Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
3181 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
3182
3183pManRes->timeTotal = Abc_Clock() - clkStart;
3184 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
3185
3186pManRef->timeTotal = Abc_Clock() - clkStart;
3187 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
3188
3189 if ( fVerbose ){
3190 Abc_ManResubPrint( pManRes );
3191 Rwr_ManPrintStats( pManRwr );
3192 Abc_NtkManRefPrintStats_1( pManRef );
3193 }
3194 if ( fVeryVerbose )
3195 Rwr_ScoresReport( pManRwr );
3196
3197 Abc_ManResubStop( pManRes );
3198 Abc_NtkManCutStop( pManCutRes );
3199
3200 Rwr_ManStop( pManRwr );
3201 Cut_ManStop( pManCutRwr );
3202 pNtk->pManCut = NULL;
3203
3204 Abc_NtkManCutStop( pManCutRef );
3205 Abc_NtkManRefStop_1( pManRef );
3206
3207 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
3208
3209 Abc_NtkForEachObj( pNtk, pNode, i )
3210 pNode->pData = NULL;
3211
3212 if ( Abc_NtkLatchNum(pNtk) ) {
3213 Abc_NtkForEachLatch(pNtk, pNode, i)
3214 pNode->pData = pNode->pNext, pNode->pNext = NULL;
3215 }
3216 Abc_NtkReassignIds( pNtk );
3217 if ( fUpdateLevel )
3219 else
3220 Abc_NtkLevel( pNtk );
3221 if ( !Abc_NtkCheck( pNtk ) )
3222 {
3223 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
3224 return 0;
3225 }
3226s_ResubTime = Abc_Clock() - clkStart;
3227 return 1;
3228}
3229
3230// local greedy orchestration
3231int Abc_NtkOrchLocal( Abc_Ntk_t * pNtk, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
3232{
3233 ProgressBar * pProgress;
3234 // For resub
3235 Abc_ManRes_t * pManRes;
3236 Abc_ManCut_t * pManCutRes;
3237 Odc_Man_t * pManOdc = NULL;
3238 Dec_Graph_t * pFFormRes;
3239 //Dec_Graph_t * pFFormRef_zeros;
3240 Vec_Ptr_t * vLeaves;
3241 // For rewrite
3242 Cut_Man_t * pManCutRwr;
3243 Rwr_Man_t * pManRwr;
3244 Dec_Graph_t * pGraph;
3245 // For refactor
3246 Abc_ManRef_t * pManRef;
3247 Abc_ManCut_t * pManCutRef;
3248 Dec_Graph_t * pFFormRef;
3249 Vec_Ptr_t * vFanins;
3250
3251 Abc_Obj_t * pNode;//, * pFanin;
3252 //int fanin_i;
3253 //FILE * fpt;
3254 abctime clk, clkStart = Abc_Clock();
3256 int i, nNodes, nGain, fCompl, RetValue = 1;//, nGain_zeros;
3257 //int decisionOps = 0;
3258 int ops_rwr = 0;
3259 int ops_res = 0;
3260 int ops_ref = 0;
3261 int ops_null = 0;
3262 assert( Abc_NtkIsStrash(pNtk) );
3263
3264 // cleanup the AIG
3266
3267 // start the managers resub
3268 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
3269 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
3270 if ( nLevelsOdc > 0 )
3271 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
3272 // start the managers refactor
3273 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
3274 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
3275 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
3276 // start the managers rewrite
3277 pManRwr = Rwr_ManStart( 0 );
3278 if ( pManRwr == NULL )
3279 return 0;
3280
3281 // compute the reverse levels if level update is requested
3282 if ( fUpdateLevel )
3283 Abc_NtkStartReverseLevels( pNtk, 0 );
3284
3285 // 'Resub only'
3286 if ( Abc_NtkLatchNum(pNtk) ) {
3287 Abc_NtkForEachLatch(pNtk, pNode, i)
3288 pNode->pNext = (Abc_Obj_t *)pNode->pData;
3289 }
3290 // cut manager for rewrite
3291clk = Abc_Clock();
3292 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
3293Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
3294 pNtk->pManCut = pManCutRwr;
3295
3296 if ( fVeryVerbose )
3297 Rwr_ScoresClean( pManRwr );
3298
3299 // resynthesize each node once
3300 // resub
3301 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
3302 // rewrite
3303 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
3304 // refactor
3305 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
3306
3307 nNodes = Abc_NtkObjNumMax(pNtk);
3308 //printf("nNodes: %d\n", nNodes);
3309 //if (pGain_res) *pGain_res = Vec_IntAlloc(1);
3310 //if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
3311 //if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
3312
3313 pProgress = Extra_ProgressBarStart( stdout, nNodes );
3314
3315 Abc_NtkForEachNode( pNtk, pNode, i )
3316 {
3317 //int iterNode = pNode->Id;
3318 //printf("Nodes ID: %d\n", pNode->Id);
3319 Extra_ProgressBarUpdate( pProgress, i, NULL );
3320 // skip the constant node
3321// if ( Abc_NodeIsConst(pNode) )
3322// continue;
3323 // skip persistant nodes
3324
3325 if ( Abc_NodeIsPersistant(pNode) )
3326 {
3327 continue;
3328 }
3329 // skip the nodes with many fanouts
3330 if ( Abc_ObjFanoutNum(pNode) > 1000 )
3331 {
3332 continue;
3333 }
3334 // stop if all nodes have been tried once
3335 if ( i >= nNodes )
3336 break;
3337
3338clk = Abc_Clock();
3339
3340//Refactor
3341 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
3342pManRef->timeCut += Abc_Clock() - clk;
3343clk = Abc_Clock();
3344 //pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
3345 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
3346pManRef->timeRes += Abc_Clock() - clk;
3347
3348// Resub
3349 // compute a reconvergence-driven cut
3350 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
3351// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
3352pManRes->timeCut += Abc_Clock() - clk;
3353 // get the don't-cares
3354 if ( pManOdc )
3355 {
3356clk = Abc_Clock();
3357 Abc_NtkDontCareClear( pManOdc );
3358 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
3359pManRes->timeTruth += Abc_Clock() - clk;
3360 }
3361 // evaluate this cut
3362clk = Abc_Clock();
3363 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
3364// Vec_PtrFree( vLeaves );
3365// Abc_ManResubCleanup( pManRes );
3366pManRes->timeRes += Abc_Clock() - clk;
3367
3368// Rewrite
3369 //nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
3370 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
3371
3372 // compare local reward and update
3373 // if (((! (nGain < 0)) && (! (nGain < pManRes->nLastGain)) && (! (pManRes->nLastGain < pManRef->nLastGain))) || ((! (nGain < 0)) && (! (nGain < pManRef->nLastGain)) && (! (pManRef->nLastGain < pManRes->nLastGain)))){
3374 if (((! (nGain < 0)) && (! (nGain < pManRes->nLastGain)) && (! (nGain < pManRef->nLastGain)))){
3375 // update with rewrite
3376 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3377 fCompl = Rwr_ManReadCompl(pManRwr);
3378 if ( fPlaceEnable )
3380 if ( fCompl ) Dec_GraphComplement( pGraph );
3381clk = Abc_Clock();
3382 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3383Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3384 if ( fCompl ) Dec_GraphComplement( pGraph );
3385 ops_rwr++;
3386 if(pFFormRef != NULL){
3387 Dec_GraphFree( pFFormRef );
3388 }
3389 if(pFFormRes != NULL){
3390 Dec_GraphFree( pFFormRes );
3391 }
3392 continue;
3393 }
3394 // if (((! (pManRes->nLastGain < 0)) && (! (pManRes->nLastGain < nGain)) && (! (nGain < pManRef->nLastGain))) || ((! (pManRes->nLastGain < 0)) && (! (pManRes->nLastGain < pManRef->nLastGain)) && (! (pManRef->nLastGain < nGain)))){
3395 if (((! (pManRes->nLastGain < 0)) && (! (pManRes->nLastGain < nGain)) && (! (pManRes->nLastGain < pManRef->nLastGain)))){
3396 // update with Resub
3397 if ( pFFormRes == NULL ) {
3398 if (pFFormRef != NULL) {
3399 Dec_GraphFree(pFFormRef);
3400 }
3401 continue;
3402 }
3403 pManRes->nTotalGain += pManRes->nLastGain;
3404clk = Abc_Clock();
3405 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3406pManRes->timeNtk += Abc_Clock() - clk;
3407 Dec_GraphFree( pFFormRes );
3408 ops_res++;
3409 if( pFFormRef != NULL ){
3410 Dec_GraphFree( pFFormRef);
3411 }
3412 continue;
3413 }
3414 // if (((! (pManRef->nLastGain < 0)) && (! (pManRef->nLastGain < nGain)) && (! (nGain < pManRes->nLastGain))) || ((! (pManRef->nLastGain < 0)) && (! (pManRef->nLastGain < pManRes->nLastGain)) && (! (pManRes->nLastGain < nGain)))){
3415 if (((! (pManRef->nLastGain < 0)) && (! (pManRef->nLastGain < nGain)) && (! (pManRef->nLastGain < pManRes->nLastGain)))){
3416 // update with Refactor
3417 if ( pFFormRef == NULL ) {
3418 if( pFFormRes != NULL) {
3419 Dec_GraphFree(pFFormRes);
3420 }
3421 continue;
3422 }
3423clk = Abc_Clock();
3424 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3425 {
3426 Dec_GraphFree( pFFormRef );
3427 RetValue = -1;
3428 break;
3429 }
3430pManRef->timeNtk += Abc_Clock() - clk;
3431 Dec_GraphFree( pFFormRef );
3432 ops_ref++;
3433 if(pFFormRes != NULL){
3434 Dec_GraphFree( pFFormRes );
3435 }
3436 continue;
3437 }
3438 else{
3439 ops_null++;
3440 if( pFFormRef != NULL ){
3441 Dec_GraphFree( pFFormRef);
3442 }
3443 if(pFFormRes != NULL){
3444 Dec_GraphFree( pFFormRes );
3445 }
3446 continue;
3447 }
3448 }
3449
3450 /*
3451 printf("Nodes with rewrite: %d\n", ops_rwr);
3452 printf("Nodes with resub: %d\n", ops_res);
3453 printf("Nodes with refactor: %d\n", ops_ref);
3454 printf("Nodes without updates: %d\n", ops_null);
3455 Extra_ProgressBarStop( pProgress );
3456 */
3457
3458// Rewrite
3459Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
3460 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
3461
3462// Resub
3463pManRes->timeTotal = Abc_Clock() - clkStart;
3464 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
3465
3466// Refactor
3467pManRef->timeTotal = Abc_Clock() - clkStart;
3468 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
3469
3470 // print statistics
3471 if ( fVerbose ){
3472 Abc_ManResubPrint( pManRes );
3473 Rwr_ManPrintStats( pManRwr );
3474 Abc_NtkManRefPrintStats_1( pManRef );
3475 }
3476 if ( fVeryVerbose )
3477 Rwr_ScoresReport( pManRwr );
3478 // delete the managers
3479 // resub
3480 Abc_ManResubStop( pManRes );
3481 Abc_NtkManCutStop( pManCutRes );
3482 // rewrite
3483 Rwr_ManStop( pManRwr );
3484 Cut_ManStop( pManCutRwr );
3485 pNtk->pManCut = NULL;
3486 // refactor
3487 Abc_NtkManCutStop( pManCutRef );
3488 Abc_NtkManRefStop_1( pManRef );
3489
3490 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
3491
3492 // clean the data field
3493 Abc_NtkForEachObj( pNtk, pNode, i )
3494 pNode->pData = NULL;
3495
3496 if ( Abc_NtkLatchNum(pNtk) ) {
3497 Abc_NtkForEachLatch(pNtk, pNode, i)
3498 pNode->pData = pNode->pNext, pNode->pNext = NULL;
3499 }
3500
3501 // put the nodes into the DFS order and reassign their IDs
3502 Abc_NtkReassignIds( pNtk );
3503// Abc_AigCheckFaninOrder( pNtk->pManFunc );
3504
3505 // fix the levels
3506 if ( fUpdateLevel )
3508 else
3509 Abc_NtkLevel( pNtk );
3510 // check
3511 if ( !Abc_NtkCheck( pNtk ) )
3512 {
3513 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
3514 return 0;
3515 }
3516s_ResubTime = Abc_Clock() - clkStart;
3517 return 1;
3518}
3519
3520
3521// priority order orchestration (runtime improved TBD)
3522int Abc_NtkOchestration( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res,Vec_Int_t **pGain_ref, int sOpsOrder, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
3523{
3524 ProgressBar * pProgress;
3525 // For resub
3526 Abc_ManRes_t * pManRes;
3527 Abc_ManCut_t * pManCutRes;
3528 Odc_Man_t * pManOdc = NULL;
3529 Dec_Graph_t * pFFormRes = NULL;
3530 Vec_Ptr_t * vLeaves;
3531 // For rewrite
3532 Cut_Man_t * pManCutRwr;
3533 Rwr_Man_t * pManRwr;
3534 Dec_Graph_t * pGraph;
3535 // For refactor
3536 Abc_ManRef_t * pManRef;
3537 Abc_ManCut_t * pManCutRef;
3538 Dec_Graph_t * pFFormRef;
3539 Vec_Ptr_t * vFanins;
3540
3541 Abc_Obj_t * pNode;
3542 FILE *fpt;
3543 abctime clk, clkStart = Abc_Clock();
3545 int i, nNodes, nGain, fCompl;
3546 int RetValue = 1;
3547 int ops_rwr = 0;
3548 int ops_res = 0;
3549 int ops_ref = 0;
3550 int ops_null = 0;
3551 fUseZeros_rwr = 0;
3552 fUseZeros_ref = 0;
3553 //clock_t begin= clock();
3554 assert( Abc_NtkIsStrash(pNtk) );
3555
3556 // cleanup the AIG
3558
3559 // start the managers resub
3560 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
3561 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
3562 if ( nLevelsOdc > 0 )
3563 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
3564 // start the managers refactor
3565 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
3566 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
3567 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
3568 // start the managers rewrite
3569 pManRwr = Rwr_ManStart( 0 );
3570 if ( pManRwr == NULL )
3571 return 0;
3572
3573 // compute the reverse levels if level update is requested
3574 if ( fUpdateLevel )
3575 Abc_NtkStartReverseLevels( pNtk, 0 );
3576
3577 // 'Resub only'
3578
3579 if ( Abc_NtkLatchNum(pNtk) ) {
3580 Abc_NtkForEachLatch(pNtk, pNode, i)
3581 pNode->pNext = (Abc_Obj_t *)pNode->pData;
3582 }
3583
3584 // cut manager for rewrite
3585clk = Abc_Clock();
3586 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
3587Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
3588 pNtk->pManCut = pManCutRwr;
3589
3590 if ( fVeryVerbose )
3591 Rwr_ScoresClean( pManRwr );
3592
3593 // resynthesize each node once
3594 // resub
3595 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
3596 // rewrite
3597 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
3598 // refactor
3599 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
3600
3601//clock_t resyn_end=clock();
3602//double resyn_time_spent = (double)(resyn_end-begin)/CLOCKS_PER_SEC;
3603//printf("time %f\n", resyn_time_spent);
3604 nNodes = Abc_NtkObjNumMax(pNtk);
3605 //printf("nNodes: %d\n", nNodes);
3606 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
3607 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
3608 if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
3609
3610 pProgress = Extra_ProgressBarStart( stdout, nNodes );
3611 fpt = fopen("Ochestration_id_ops_nGain.csv", "w");
3612
3613 Abc_NtkForEachNode( pNtk, pNode, i )
3614 {
3615 //printf("Ochestration id: %d\n", pNode->Id);
3616 Extra_ProgressBarUpdate( pProgress, i, NULL );
3617 // skip the constant node
3618// if ( Abc_NodeIsConst(pNode) )
3619// continue;
3620 // stop if all nodes have been tried once
3621 if ( i >= nNodes )
3622 break;
3623 // skip persistant nodes
3624 if ( Abc_NodeIsPersistant(pNode) )
3625 {
3626 fprintf(fpt, "%d, %s, %d\n", pNode->Id, "None" , -99);
3627 Vec_IntPush((*pGain_res), -99);
3628 Vec_IntPush((*pGain_ref), -99);
3629 Vec_IntPush((*pGain_rwr), -99);
3630 continue;
3631 }
3632 // skip the nodes with many fanouts
3633 if ( Abc_ObjFanoutNum(pNode) > 1000 )
3634 {
3635 fprintf(fpt, "%d, %s, %d\n", pNode->Id,"None", -99);
3636 Vec_IntPush((*pGain_res), -99);
3637 Vec_IntPush((*pGain_ref), -99);
3638 Vec_IntPush((*pGain_rwr), -99);
3639 continue;
3640 }
3641clk = Abc_Clock();
3642/*
3643 if ( sOpsOrder == 0)
3644 {
3645// the order is rwr res ref
3646 //printf("The graph update order is rwr res ref.\n");
3647 //printf("fUsezeros:%d \n", fUseZeros_rwr);
3648
3649 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
3650 //printf("nGain:%d\n", nGain);
3651 Vec_IntPush( (*pGain_rwr), nGain);
3652 if ((nGain > 0 || (nGain == 0 && fUseZeros_rwr)))
3653 {
3654// Graph update with Rewrite
3655 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3656 fCompl = Rwr_ManReadCompl(pManRwr);
3657 if ( fPlaceEnable )
3658 Abc_AigUpdateReset( (Abc_Aig_t *)pNtk->pManFunc );
3659 if ( fCompl ) Dec_GraphComplement( pGraph );
3660clk = Abc_Clock();
3661 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3662Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3663 if ( fCompl ) Dec_GraphComplement( pGraph );
3664 ops_rwr++;
3665 continue;
3666 }
3667
3668 else{
3669 //printf("Rewrite not work--resub\n");
3670 //check res
3671 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
3672// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
3673pManRes->timeCut += Abc_Clock() - clk;
3674 // get the don't-cares
3675 if ( pManOdc )
3676 {
3677clk = Abc_Clock();
3678 Abc_NtkDontCareClear( pManOdc );
3679 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
3680pManRes->timeTruth += Abc_Clock() - clk;
3681 }
3682 // evaluate this cut
3683clk = Abc_Clock();
3684 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
3685// Vec_PtrFree( vLeaves );
3686// Abc_ManResubCleanup( pManRes );
3687pManRes->timeRes += Abc_Clock() - clk;
3688 // put nGain in Vector
3689 Vec_IntPush((*pGain_res), pManRes->nLastGain);
3690 if (pManRes->nLastGain > 0)
3691 {
3692// Graph update with Resub
3693 //printf("Graph Update with Resub\n");
3694 if ( pFFormRes == NULL )
3695 continue;
3696 pManRes->nTotalGain += pManRes->nLastGain;
3697clk = Abc_Clock();
3698 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3699pManRes->timeNtk += Abc_Clock() - clk;
3700 Dec_GraphFree( pFFormRes );
3701 ops_res++;
3702 continue;
3703 }
3704 else{
3705 //check ref
3706 //printf("Rewrite not work--ref\n");
3707 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
3708pManRef->timeCut += Abc_Clock() - clk;
3709clk = Abc_Clock();
3710 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
3711pManRef->timeRes += Abc_Clock() - clk;
3712
3713 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
3714 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3715 {
3716// Graph update with Refactor
3717 //printf("Graph Update with Refactor\n");
3718 if ( pFFormRef == NULL )
3719 continue;
3720clk = Abc_Clock();
3721 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3722 {
3723 Dec_GraphFree( pFFormRef );
3724 RetValue = -1;
3725 break;
3726 }
3727pManRef->timeNtk += Abc_Clock() - clk;
3728 Dec_GraphFree( pFFormRef );
3729 ops_ref++;
3730 continue;
3731 }
3732//}
3733//}
3734 ops_null++;
3735 //continue;
3736}
3737*/
3738
3739
3740// Update the graph with pre-defined order!
3741 if ( sOpsOrder == 0)
3742 {
3743// the order is rwr res ref
3744 //printf("new imp: The graph update order is rwr res ref.\n");
3745 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
3746 Vec_IntPush( (*pGain_rwr), nGain);
3747 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3748 {
3749// Graph update with Rewrite
3750 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3751 fCompl = Rwr_ManReadCompl(pManRwr);
3752 if ( fPlaceEnable )
3754 if ( fCompl ) Dec_GraphComplement( pGraph );
3755clk = Abc_Clock();
3756 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3757Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3758 if ( fCompl ) Dec_GraphComplement( pGraph );
3759 ops_rwr++;
3760 continue;
3761 }
3762 else{
3763 //printf("Rewrite not work--resub\n");
3764 //check res
3765 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
3766// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
3767pManRes->timeCut += Abc_Clock() - clk;
3768 // get the don't-cares
3769 if ( pManOdc )
3770 {
3771clk = Abc_Clock();
3772 Abc_NtkDontCareClear( pManOdc );
3773 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
3774pManRes->timeTruth += Abc_Clock() - clk;
3775 }
3776 // evaluate this cut
3777clk = Abc_Clock();
3778 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
3779// Vec_PtrFree( vLeaves );
3780// Abc_ManResubCleanup( pManRes );
3781pManRes->timeRes += Abc_Clock() - clk;
3782 // put nGain in Vector
3783 Vec_IntPush((*pGain_res), pManRes->nLastGain);
3784 if (pManRes->nLastGain > 0)
3785 {
3786// Graph update with Resub
3787 //printf("Graph Update with Resub\n");
3788 if ( pFFormRes != NULL ){
3789 //continue;
3790 pManRes->nTotalGain += pManRes->nLastGain;
3791clk = Abc_Clock();
3792 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3793pManRes->timeNtk += Abc_Clock() - clk;
3794 Dec_GraphFree( pFFormRes );
3795 ops_res++;
3796 continue;}
3797 }
3798 else{
3799 //check ref
3800 //printf("Rewrite not work--ref\n");
3801 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
3802pManRef->timeCut += Abc_Clock() - clk;
3803clk = Abc_Clock();
3804 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
3805pManRef->timeRes += Abc_Clock() - clk;
3806
3807 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
3808 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3809 {
3810// Graph update with Refactor
3811 //printf("Graph Update with Refactor\n");
3812 if ( pFFormRef != NULL ){
3813 //continue;
3814clk = Abc_Clock();
3815
3816 Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain);
3817
3818/*
3819 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3820 {
3821 Dec_GraphFree( pFFormRef );
3822 RetValue = -1;
3823 break;
3824 }
3825*/
3826
3827pManRef->timeNtk += Abc_Clock() - clk;
3828 Dec_GraphFree( pFFormRef );
3829 ops_ref++;
3830 continue;}
3831 }
3832}
3833}
3834 ops_null++;
3835 continue;
3836}
3837
3838
3839 if ( sOpsOrder == 1)
3840 {
3841// the order is rwr ref res
3842 //printf("The graph update order is rwr ref res.\n");
3843 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
3844 Vec_IntPush( (*pGain_rwr), nGain);
3845 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3846 {
3847// Graph update with Rewrite
3848 //printf("Graph Update with Rewrite");
3849 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3850 fCompl = Rwr_ManReadCompl(pManRwr);
3851 if ( fPlaceEnable )
3853 if ( fCompl ) Dec_GraphComplement( pGraph );
3854clk = Abc_Clock();
3855 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3856Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3857 if ( fCompl ) Dec_GraphComplement( pGraph );
3858 ops_rwr++;
3859 continue;
3860 }
3861 else{
3862 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
3863pManRef->timeCut += Abc_Clock() - clk;
3864clk = Abc_Clock();
3865 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
3866pManRef->timeRes += Abc_Clock() - clk;
3867 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
3868 }
3869 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3870 {
3871// Graph update with Refactor
3872 //printf("Graph Update with Refactor");
3873 if ( pFFormRef != NULL ){
3874 //continue;
3875clk = Abc_Clock();
3876 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3877 {
3878 Dec_GraphFree( pFFormRef );
3879 RetValue = -1;
3880 break;
3881 }
3882pManRef->timeNtk += Abc_Clock() - clk;
3883 Dec_GraphFree( pFFormRef );
3884 ops_ref++;
3885 continue;}
3886 }
3887 else{
3888 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
3889pManRes->timeCut += Abc_Clock() - clk;
3890 if ( pManOdc )
3891 {
3892clk = Abc_Clock();
3893 Abc_NtkDontCareClear( pManOdc );
3894 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
3895pManRes->timeTruth += Abc_Clock() - clk;
3896 }
3897clk = Abc_Clock();
3898 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
3899pManRes->timeRes += Abc_Clock() - clk;
3900 Vec_IntPush((*pGain_res), pManRes->nLastGain);
3901 }
3902 if (pManRes->nLastGain > 0)
3903 {
3904// Graph update with Resub
3905 //printf("Graph Update with Resub");
3906 if ( pFFormRes != NULL ){
3907 //continue;
3908 pManRes->nTotalGain += pManRes->nLastGain;
3909clk = Abc_Clock();
3910 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3911pManRes->timeNtk += Abc_Clock() - clk;
3912 Dec_GraphFree( pFFormRes );
3913 ops_res++;
3914 continue;}
3915 }
3916// No available updats
3917 //if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
3918 else{
3919 ops_null++;
3920 continue;
3921 }
3922// }
3923// }
3924 }
3925
3926 if ( sOpsOrder == 2)
3927 {
3928// the order is res rwr ref
3929 //printf("The graph update order is res rwr ref.\n");
3930 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
3931pManRes->timeCut += Abc_Clock() - clk;
3932 if ( pManOdc )
3933 {
3934clk = Abc_Clock();
3935 Abc_NtkDontCareClear( pManOdc );
3936 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
3937pManRes->timeTruth += Abc_Clock() - clk;
3938 }
3939clk = Abc_Clock();
3940 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
3941pManRes->timeRes += Abc_Clock() - clk;
3942 Vec_IntPush((*pGain_res), pManRes->nLastGain);
3943
3944 if (pManRes->nLastGain > 0)
3945 {
3946// Graph update with Resub
3947 //printf("Graph Update with Resub");
3948 if ( pFFormRes != NULL ){
3949 //continue;
3950 pManRes->nTotalGain += pManRes->nLastGain;
3951clk = Abc_Clock();
3952 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
3953pManRes->timeNtk += Abc_Clock() - clk;
3954 Dec_GraphFree( pFFormRes );
3955 ops_res++;
3956 continue;}
3957 }
3958 else{
3959 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
3960 Vec_IntPush( (*pGain_rwr), nGain);
3961
3962 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
3963 {
3964// Graph update with Rewrite
3965 //printf("Graph Update with Rewrite");
3966 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
3967 fCompl = Rwr_ManReadCompl(pManRwr);
3968 if ( fPlaceEnable )
3970 if ( fCompl ) Dec_GraphComplement( pGraph );
3971clk = Abc_Clock();
3972 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
3973Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
3974 if ( fCompl ) Dec_GraphComplement( pGraph );
3975 ops_rwr++;
3976 continue;
3977 }
3978 else{
3979 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
3980pManRef->timeCut += Abc_Clock() - clk;
3981clk = Abc_Clock();
3982 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
3983pManRef->timeRes += Abc_Clock() - clk;
3984 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
3985
3986 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
3987 {
3988// Graph update with Refactor
3989 //printf("Graph Update with Refactor");
3990 if ( pFFormRef != NULL ){
3991 //continue;
3992clk = Abc_Clock();
3993 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
3994 {
3995 Dec_GraphFree( pFFormRef );
3996 RetValue = -1;
3997 break;
3998 }
3999pManRef->timeNtk += Abc_Clock() - clk;
4000 Dec_GraphFree( pFFormRef );
4001 ops_ref++;
4002 continue;}
4003 }
4004// No available updates
4005 //if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4006 else{
4007 ops_null++;
4008 continue;
4009 }
4010}}
4011 }
4012
4013 if ( sOpsOrder == 3)
4014 {
4015// the order is res ref rwr
4016 //printf("The graph update order is res ref rwr.\n");
4017 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
4018pManRes->timeCut += Abc_Clock() - clk;
4019 if ( pManOdc )
4020 {
4021clk = Abc_Clock();
4022 Abc_NtkDontCareClear( pManOdc );
4023 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
4024pManRes->timeTruth += Abc_Clock() - clk;
4025 }
4026clk = Abc_Clock();
4027 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
4028pManRes->timeRes += Abc_Clock() - clk;
4029 Vec_IntPush((*pGain_res), pManRes->nLastGain);
4030
4031 if (pManRes->nLastGain > 0)
4032 {
4033// Graph update with Resub
4034 //printf("Graph Update with Resub");
4035 if ( pFFormRes != NULL ){
4036 //continue;
4037 pManRes->nTotalGain += pManRes->nLastGain;
4038clk = Abc_Clock();
4039 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
4040pManRes->timeNtk += Abc_Clock() - clk;
4041 Dec_GraphFree( pFFormRes );
4042 ops_res++;
4043 continue;}
4044 }
4045 else{
4046 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
4047pManRef->timeCut += Abc_Clock() - clk;
4048clk = Abc_Clock();
4049 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
4050pManRef->timeRes += Abc_Clock() - clk;
4051 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
4052 //printf("refactor gain: %d\n", pManRef->nLastGain);
4053 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
4054 {
4055// Graph update with Refactor
4056 //printf("Graph Update with Refactor");
4057 if ( pFFormRef != NULL ){
4058 //continue;
4059clk = Abc_Clock();
4060 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
4061 {
4062 Dec_GraphFree( pFFormRef );
4063 RetValue = -1;
4064 break;
4065 }
4066pManRef->timeNtk += Abc_Clock() - clk;
4067 Dec_GraphFree( pFFormRef );
4068 ops_ref++;
4069 continue;}
4070 }
4071 else{
4072 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
4073 Vec_IntPush( (*pGain_rwr), nGain);
4074 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
4075 {
4076// Graph update with Rewrite
4077 //printf("Graph Update with Rewrite");
4078 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4079 fCompl = Rwr_ManReadCompl(pManRwr);
4080 if ( fPlaceEnable )
4082 if ( fCompl ) Dec_GraphComplement( pGraph );
4083clk = Abc_Clock();
4084 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
4085Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4086 if ( fCompl ) Dec_GraphComplement( pGraph );
4087 ops_rwr++;
4088 continue;
4089 }
4090
4091// No available updates
4092 // if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4093 else{
4094 ops_null++;
4095 continue;
4096 }
4097}
4098}
4099 }
4100
4101 if ( sOpsOrder == 4)
4102 {
4103// the order is ref rwr res
4104 //printf("The graph update order is ref rwr res.\n");
4105 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
4106pManRef->timeCut += Abc_Clock() - clk;
4107clk = Abc_Clock();
4108 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
4109pManRef->timeRes += Abc_Clock() - clk;
4110 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
4111
4112 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
4113 {
4114// Graph update with Refactor
4115 //printf("Graph Update with Refactor");
4116 if ( pFFormRef != NULL ){
4117 //continue;
4118clk = Abc_Clock();
4119 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
4120 {
4121 Dec_GraphFree( pFFormRef );
4122 RetValue = -1;
4123 break;
4124 }
4125pManRef->timeNtk += Abc_Clock() - clk;
4126 Dec_GraphFree( pFFormRef );
4127 ops_ref++;
4128 continue;}
4129 }
4130 else{
4131 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
4132 Vec_IntPush( (*pGain_rwr), nGain);
4133
4134 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
4135 {
4136// Graph update with Rewrite
4137 //printf("Graph Update with Rewrite");
4138 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4139 fCompl = Rwr_ManReadCompl(pManRwr);
4140 if ( fPlaceEnable )
4142 if ( fCompl ) Dec_GraphComplement( pGraph );
4143clk = Abc_Clock();
4144 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
4145Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4146 if ( fCompl ) Dec_GraphComplement( pGraph );
4147 ops_rwr++;
4148 continue;
4149 }
4150 else{
4151 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
4152pManRes->timeCut += Abc_Clock() - clk;
4153 if ( pManOdc )
4154 {
4155clk = Abc_Clock();
4156 Abc_NtkDontCareClear( pManOdc );
4157 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
4158pManRes->timeTruth += Abc_Clock() - clk;
4159 }
4160clk = Abc_Clock();
4161 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
4162pManRes->timeRes += Abc_Clock() - clk;
4163 Vec_IntPush((*pGain_res), pManRes->nLastGain);
4164
4165 if (pManRes->nLastGain > 0)
4166 {
4167// Graph update with Resub
4168 //printf("Graph Update with Resub");
4169 if ( pFFormRes != NULL ){
4170 //continue;
4171 pManRes->nTotalGain += pManRes->nLastGain;
4172clk = Abc_Clock();
4173 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
4174pManRes->timeNtk += Abc_Clock() - clk;
4175 Dec_GraphFree( pFFormRes );
4176 ops_res++;
4177 continue;}
4178 }
4179// No available updates
4180 //if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4181 else{
4182 ops_null++;
4183 continue;
4184 }
4185}}
4186 }
4187
4188 if ( sOpsOrder == 5)
4189 {
4190// the order is ref res rwr
4191 //printf("The graph update order is ref res rwr.\n");
4192 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
4193pManRef->timeCut += Abc_Clock() - clk;
4194clk = Abc_Clock();
4195 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
4196pManRef->timeRes += Abc_Clock() - clk;
4197 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
4198
4199 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
4200 {
4201// Graph update with Refactor
4202 //printf("Graph Update with Refactor");
4203 if ( pFFormRef != NULL ){
4204 //continue;
4205clk = Abc_Clock();
4206 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
4207 {
4208 Dec_GraphFree( pFFormRef );
4209 RetValue = -1;
4210 break;
4211 }
4212pManRef->timeNtk += Abc_Clock() - clk;
4213 Dec_GraphFree( pFFormRef );
4214 ops_ref++;
4215 continue;}
4216 }
4217 else{
4218 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
4219pManRes->timeCut += Abc_Clock() - clk;
4220 if ( pManOdc )
4221 {
4222clk = Abc_Clock();
4223 Abc_NtkDontCareClear( pManOdc );
4224 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
4225pManRes->timeTruth += Abc_Clock() - clk;
4226 }
4227clk = Abc_Clock();
4228 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
4229pManRes->timeRes += Abc_Clock() - clk;
4230 Vec_IntPush((*pGain_res), pManRes->nLastGain);
4231
4232 if (pManRes->nLastGain > 0)
4233 {
4234// Graph update with Resub
4235 //printf("Graph Update with Resub");
4236 if ( pFFormRes != NULL ){
4237 //continue;
4238 pManRes->nTotalGain += pManRes->nLastGain;
4239clk = Abc_Clock();
4240 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
4241pManRes->timeNtk += Abc_Clock() - clk;
4242 Dec_GraphFree( pFFormRes );
4243 ops_res++;
4244 continue;}
4245 }
4246 else{
4247 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
4248 Vec_IntPush( (*pGain_rwr), nGain);
4249
4250 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
4251 {
4252// Graph update with Rewrite
4253 //printf("Graph Update with Rewrite");
4254 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4255 fCompl = Rwr_ManReadCompl(pManRwr);
4256 if ( fPlaceEnable )
4258 if ( fCompl ) Dec_GraphComplement( pGraph );
4259clk = Abc_Clock();
4260 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
4261Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4262 if ( fCompl ) Dec_GraphComplement( pGraph );
4263 ops_rwr++;
4264 continue;
4265 }
4266// No available updates
4267 //if (! (nGain > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4268 else{
4269 ops_null++;
4270 continue;
4271 }
4272}}
4273 }
4274
4275 }
4276
4277 fclose(fpt);
4278 //printf("size of vector %d\n", (**pGain_rwr).nSize);
4279 //printf("nGain in vector: %d\n", (**pGain_res).pArray[20]);
4280 //printf("Nodes with rewrite: %d\n", ops_rwr);
4281 //printf("Nodes with resub: %d\n", ops_res);
4282 //printf("Nodes with refactor: %d\n", ops_ref);
4283 //printf("Nodes without updates: %d\n", ops_null);
4284 Extra_ProgressBarStop( pProgress );
4285// Rewrite
4286Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
4287 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
4288
4289// Resub
4290pManRes->timeTotal = Abc_Clock() - clkStart;
4291 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
4292
4293// Refactor
4294pManRef->timeTotal = Abc_Clock() - clkStart;
4295 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
4296
4297 // print statistics
4298 if ( fVerbose ){
4299 Abc_ManResubPrint( pManRes );
4300 Rwr_ManPrintStats( pManRwr );
4301 Abc_NtkManRefPrintStats_1( pManRef );
4302 }
4303 if ( fVeryVerbose )
4304 Rwr_ScoresReport( pManRwr );
4305 // delete the managers
4306 // resub
4307 Abc_ManResubStop( pManRes );
4308 Abc_NtkManCutStop( pManCutRes );
4309 // rewrite
4310 Rwr_ManStop( pManRwr );
4311 Cut_ManStop( pManCutRwr );
4312 pNtk->pManCut = NULL;
4313 // refactor
4314 Abc_NtkManCutStop( pManCutRef );
4315 Abc_NtkManRefStop_1( pManRef );
4316
4317 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
4318
4319 // clean the data field
4320 Abc_NtkForEachObj( pNtk, pNode, i )
4321 pNode->pData = NULL;
4322
4323 if ( Abc_NtkLatchNum(pNtk) ) {
4324 Abc_NtkForEachLatch(pNtk, pNode, i)
4325 pNode->pData = pNode->pNext, pNode->pNext = NULL;
4326 }
4327
4328 // put the nodes into the DFS order and reassign their IDs
4329 Abc_NtkReassignIds( pNtk );
4330// Abc_AigCheckFaninOrder( pNtk->pManFunc );
4331
4332 // fix the levels
4333 if ( fUpdateLevel )
4335 else
4336 Abc_NtkLevel( pNtk );
4337 // check
4338 if ( !Abc_NtkCheck( pNtk ) )
4339 {
4340 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
4341 return 0;
4342 }
4343s_ResubTime = Abc_Clock() - clkStart;
4344//clock_t end=clock();
4345//double time_spent = (double)(end-begin)/CLOCKS_PER_SEC;
4346//printf("time %f\n", time_spent);
4347 return 1;
4348}
4349
4350// random orchestration with rw, rwz, rf, rfz, rs
4351int Abc_NtkOchestration3( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **pOps_num, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
4352{
4353 ProgressBar * pProgress;
4354 // For resub
4355 Abc_ManRes_t * pManRes;
4356 Abc_ManCut_t * pManCutRes;
4357 Odc_Man_t * pManOdc = NULL;
4358 Dec_Graph_t * pFFormRes;
4359 Dec_Graph_t * pFFormRef_zeros;
4360 Vec_Ptr_t * vLeaves;
4361 // For rewrite
4362 Cut_Man_t * pManCutRwr;
4363 Rwr_Man_t * pManRwr;
4364 Dec_Graph_t * pGraph;
4365 // For refactor
4366 Abc_ManRef_t * pManRef;
4367 Abc_ManCut_t * pManCutRef;
4368 Dec_Graph_t * pFFormRef;
4369 Vec_Ptr_t * vFanins;
4370
4371 Abc_Obj_t * pNode;
4372 FILE *fpt;
4373 abctime clk, clkStart = Abc_Clock();
4375 int i, nNodes, nGain, nGain_zeros, fCompl, RetValue = 1;
4376 int ops_rwr = 0;
4377 int ops_rwr_z = 0;
4378 int ops_res = 0;
4379 int ops_ref_z = 0;
4380 int ops_ref = 0;
4381 int ops_null = 0;
4382 assert( Abc_NtkIsStrash(pNtk) );
4383
4384 // cleanup the AIG
4386
4387 // start the managers resub
4388 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
4389 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
4390 if ( nLevelsOdc > 0 )
4391 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
4392 // start the managers refactor
4393 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
4394 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
4395 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
4396 // start the managers rewrite
4397 pManRwr = Rwr_ManStart( 0 );
4398 if ( pManRwr == NULL )
4399 return 0;
4400
4401 // compute the reverse levels if level update is requested
4402 if ( fUpdateLevel )
4403 Abc_NtkStartReverseLevels( pNtk, 0 );
4404
4405 // 'Resub only'
4406 if ( Abc_NtkLatchNum(pNtk) ) {
4407 Abc_NtkForEachLatch(pNtk, pNode, i)
4408 pNode->pNext = (Abc_Obj_t *)pNode->pData;
4409 }
4410 // cut manager for rewrite
4411clk = Abc_Clock();
4412 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
4413Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
4414 pNtk->pManCut = pManCutRwr;
4415
4416 if ( fVeryVerbose )
4417 Rwr_ScoresClean( pManRwr );
4418
4419 // resynthesize each node once
4420 // resub
4421 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
4422 // rewrite
4423 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
4424 // refactor
4425 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
4426
4427 nNodes = Abc_NtkObjNumMax(pNtk);
4428 //printf("nNodes: %d\n", nNodes);
4429 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
4430 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
4431 if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
4432
4433 pProgress = Extra_ProgressBarStart( stdout, nNodes );
4434 fpt = fopen("Ochestration_id_ops_nGain.csv", "w");
4435
4436 Abc_NtkForEachNode( pNtk, pNode, i )
4437 {
4438 if (pOps_num) *pOps_num = Vec_IntAlloc(1);
4439 //printf("Ochestration id: %d\n", pNode->Id);
4440 Extra_ProgressBarUpdate( pProgress, i, NULL );
4441 // skip the constant node
4442// if ( Abc_NodeIsConst(pNode) )
4443// continue;
4444 // skip persistant nodes
4445 if ( Abc_NodeIsPersistant(pNode) )
4446 {
4447 if (!(pGain_res && pGain_ref && pGain_rwr))
4448 return 0;
4449 fprintf(fpt, "%d, %s, %d\n", pNode->Id, "None" , -99);
4450 Vec_IntPush((*pGain_res), -99);
4451 Vec_IntPush((*pGain_ref), -99);
4452 Vec_IntPush((*pGain_rwr), -99);
4453 continue;
4454 }
4455 // skip the nodes with many fanouts
4456 if ( Abc_ObjFanoutNum(pNode) > 1000 )
4457 {
4458 if (!(pGain_res && pGain_ref && pGain_rwr))
4459 return 0;
4460 fprintf(fpt, "%d, %s, %d\n", pNode->Id,"None", -99);
4461 Vec_IntPush((*pGain_res), -99);
4462 Vec_IntPush((*pGain_ref), -99);
4463 Vec_IntPush((*pGain_rwr), -99);
4464 continue;
4465 }
4466 // stop if all nodes have been tried once
4467 if ( i >= nNodes )
4468 break;
4469clk = Abc_Clock();
4470
4471//Refactor
4472 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
4473pManRef->timeCut += Abc_Clock() - clk;
4474clk = Abc_Clock();
4475 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
4476 pFFormRef_zeros = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
4477pManRef->timeRes += Abc_Clock() - clk;
4478 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
4479
4480// Resub
4481 // compute a reconvergence-driven cut
4482 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
4483// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
4484pManRes->timeCut += Abc_Clock() - clk;
4485 // get the don't-cares
4486 if ( pManOdc )
4487 {
4488clk = Abc_Clock();
4489 Abc_NtkDontCareClear( pManOdc );
4490 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
4491pManRes->timeTruth += Abc_Clock() - clk;
4492 }
4493 // evaluate this cut
4494clk = Abc_Clock();
4495 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
4496// Vec_PtrFree( vLeaves );
4497// Abc_ManResubCleanup( pManRes );
4498pManRes->timeRes += Abc_Clock() - clk;
4499 // put nGain in Vector
4500 Vec_IntPush((*pGain_res), pManRes->nLastGain);
4501 // printf("size of vector %d\n", (**pGain).nSize);
4502
4503// Rewrite
4504 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
4505 nGain_zeros = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
4506 Vec_IntPush( (*pGain_rwr), nGain);
4507
4508 //printf("Res Ochestration: %d\n", pManRes->nLastGain);
4509 //printf("Ref Ochestration: %d\n", pManRef->nLastGain);
4510 //printf("Rwr Ochestration: %d\n", nGain);
4511 fprintf(fpt, "%d, %s, %d, %s, %d, %s, %d, %s, %d\n", pNode->Id, "Oches_Res", pManRes->nLastGain, "Oches_Ref", pManRef->nLastGain, "Oches_Rwr", nGain, "Oches_Rwr_Zeros", nGain_zeros);
4512
4513// Generate the valid operator array for the node
4514 if ( nGain > 0 )
4515 {
4516 Vec_IntPush((*pOps_num), 0);
4517 }
4518 if ( nGain_zeros > 0 )
4519 {
4520 Vec_IntPush((*pOps_num), 1);
4521 }
4522 if ( pManRef->nLastGain > 0 )
4523 {
4524 Vec_IntPush((*pOps_num), 2);
4525 Vec_IntPush((*pOps_num), 3);
4526 }
4527 if ( pManRes->nLastGain > 0 )
4528 {
4529 Vec_IntPush((*pOps_num), 4);
4530 }
4531// No available updats
4532 //if (! (nGain > 0 || nGain_zeros > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4533 //if (! (nGain > 0 ||(nGain == 0 && fUseZeros_rwr)))
4534 //{
4535 //ops_null++;
4536 //continue;
4537 //}
4538 if (! ((**pOps_num).nSize > 0))
4539 {
4540 ops_null++;
4541 continue;
4542 }
4543
4544 //printf("available operations: %d.\n", (**pOps_num).nSize);
4545// Randomly pick a operation number
4546 //int Ops_num = 0;
4547 int Ops_size = (**pOps_num).nSize;
4548 int r = rand() % Ops_size;
4549 int Ops_num = (**pOps_num).pArray[r];
4550 //printf("the picked operation: %d.\n", Ops_num);
4551
4552// Update the graph with random picked operation!
4553 if ( Ops_num == 0)
4554 {
4555// Graph update with Rewrite
4556 //printf("Graph Update with Rewrite");
4557 ops_rwr++;
4558 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4559 fCompl = Rwr_ManReadCompl(pManRwr);
4560 if ( fPlaceEnable )
4562 if ( fCompl ) Dec_GraphComplement( pGraph );
4563clk = Abc_Clock();
4564 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
4565Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4566 if ( fCompl ) Dec_GraphComplement( pGraph );
4567 continue;
4568 }
4569
4570 if ( Ops_num == 1)
4571 {
4572// Graph update with Rewrite -z
4573 //printf("Graph Update with Rewrite -z");
4574 ops_rwr_z++;
4575 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4576 fCompl = Rwr_ManReadCompl(pManRwr);
4577 if ( fPlaceEnable )
4579 if ( fCompl ) Dec_GraphComplement( pGraph );
4580clk = Abc_Clock();
4581 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain_zeros );
4582Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4583 if ( fCompl ) Dec_GraphComplement( pGraph );
4584 continue;
4585 }
4586
4587 if ( Ops_num == 2)
4588 {
4589// Graph update with Refactor
4590 //printf("Graph Update with Refactor");
4591 ops_ref++;
4592 if ( pFFormRef == NULL )
4593 continue;
4594clk = Abc_Clock();
4595 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
4596 {
4597 Dec_GraphFree( pFFormRef );
4598 RetValue = -1;
4599 break;
4600 }
4601pManRef->timeNtk += Abc_Clock() - clk;
4602 Dec_GraphFree( pFFormRef );
4603 continue;
4604 }
4605
4606 if ( Ops_num == 3)
4607 {
4608// Graph update with Refactor -z
4609 //printf("Graph Update with Refactor");
4610 ops_ref_z++;
4611 if ( pFFormRef_zeros == NULL )
4612 continue;
4613clk = Abc_Clock();
4614 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef_zeros, fUpdateLevel, pManRef->nLastGain ) )
4615 {
4616 Dec_GraphFree( pFFormRef_zeros );
4617 RetValue = -1;
4618 break;
4619 }
4620pManRef->timeNtk += Abc_Clock() - clk;
4621 Dec_GraphFree( pFFormRef_zeros );
4622 continue;
4623 }
4624
4625 if (Ops_num == 4)
4626 {
4627// Graph update with Resub
4628 //printf("Graph Update with Resub");
4629 ops_res++;
4630 if ( pFFormRes == NULL )
4631 continue;
4632 pManRes->nTotalGain += pManRes->nLastGain;
4633clk = Abc_Clock();
4634 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
4635pManRes->timeNtk += Abc_Clock() - clk;
4636 Dec_GraphFree( pFFormRes );
4637 continue;
4638 }
4639
4640 }
4641
4642 fclose(fpt);
4643 /*
4644 printf("size of vector %d\n", (**pGain_rwr).nSize);
4645 printf("nGain in vector: %d\n", (**pGain_res).pArray[20]);
4646 printf("Nodes with rewrite: %d\n", ops_rwr);
4647 printf("Nodes with rewrite -z: %d\n", ops_rwr_z);
4648 printf("Nodes with resub: %d\n", ops_res);
4649 printf("Nodes with refactor: %d\n", ops_ref);
4650 printf("Nodes with refactor -z: %d\n", ops_ref_z);
4651 printf("Nodes without updates: %d\n", ops_null);
4652 */
4653 Extra_ProgressBarStop( pProgress );
4654// Rewrite
4655Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
4656 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
4657
4658// Resub
4659pManRes->timeTotal = Abc_Clock() - clkStart;
4660 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
4661
4662// Refactor
4663pManRef->timeTotal = Abc_Clock() - clkStart;
4664 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
4665
4666 // print statistics
4667 if ( fVerbose ){
4668 Abc_ManResubPrint( pManRes );
4669 Rwr_ManPrintStats( pManRwr );
4670 Abc_NtkManRefPrintStats_1( pManRef );
4671 }
4672 if ( fVeryVerbose )
4673 Rwr_ScoresReport( pManRwr );
4674 // delete the managers
4675 // resub
4676 Abc_ManResubStop( pManRes );
4677 Abc_NtkManCutStop( pManCutRes );
4678 // rewrite
4679 Rwr_ManStop( pManRwr );
4680 Cut_ManStop( pManCutRwr );
4681 pNtk->pManCut = NULL;
4682 // refactor
4683 Abc_NtkManCutStop( pManCutRef );
4684 Abc_NtkManRefStop_1( pManRef );
4685
4686 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
4687
4688 // clean the data field
4689 Abc_NtkForEachObj( pNtk, pNode, i )
4690 pNode->pData = NULL;
4691
4692 if ( Abc_NtkLatchNum(pNtk) ) {
4693 Abc_NtkForEachLatch(pNtk, pNode, i)
4694 pNode->pData = pNode->pNext, pNode->pNext = NULL;
4695 }
4696
4697 // put the nodes into the DFS order and reassign their IDs
4698 Abc_NtkReassignIds( pNtk );
4699// Abc_AigCheckFaninOrder( pNtk->pManFunc );
4700
4701 // fix the levels
4702 if ( fUpdateLevel )
4704 else
4705 Abc_NtkLevel( pNtk );
4706 // check
4707 if ( !Abc_NtkCheck( pNtk ) )
4708 {
4709 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
4710 return 0;
4711 }
4712s_ResubTime = Abc_Clock() - clkStart;
4713 return 1;
4714}
4715
4716// random orchestration with rw, rs, rf
4717int Abc_NtkOchestration2( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **pOps_num, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
4718{
4719 ProgressBar * pProgress;
4720 // For resub
4721 Abc_ManRes_t * pManRes;
4722 Abc_ManCut_t * pManCutRes;
4723 Odc_Man_t * pManOdc = NULL;
4724 Dec_Graph_t * pFFormRes;
4725 Dec_Graph_t * pFFormRef_zeros;
4726 Vec_Ptr_t * vLeaves;
4727 // For rewrite
4728 Cut_Man_t * pManCutRwr;
4729 Rwr_Man_t * pManRwr;
4730 Dec_Graph_t * pGraph;
4731 // For refactor
4732 Abc_ManRef_t * pManRef;
4733 Abc_ManCut_t * pManCutRef;
4734 Dec_Graph_t * pFFormRef;
4735 Vec_Ptr_t * vFanins;
4736
4737 Abc_Obj_t * pNode;
4738 FILE *fpt;
4739 abctime clk, clkStart = Abc_Clock();
4741 int i, nNodes, nGain, nGain_zeros, fCompl, RetValue = 1;
4742 int ops_rwr = 0;
4743 int ops_res = 0;
4744 int ops_ref = 0;
4745 int ops_null = 0;
4746 int rwr_ok = 0;
4747 int res_ok = 0;
4748 int ref_ok = 0;
4749 int decisionOps = 0;
4750 assert( Abc_NtkIsStrash(pNtk) );
4751
4752 // cleanup the AIG
4754
4755 // start the managers resub
4756 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
4757 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
4758 if ( nLevelsOdc > 0 )
4759 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
4760 // start the managers refactor
4761 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
4762 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
4763 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
4764 // start the managers rewrite
4765 pManRwr = Rwr_ManStart( 0 );
4766 if ( pManRwr == NULL )
4767 return 0;
4768
4769 // compute the reverse levels if level update is requested
4770 if ( fUpdateLevel )
4771 Abc_NtkStartReverseLevels( pNtk, 0 );
4772
4773 // 'Resub only'
4774 if ( Abc_NtkLatchNum(pNtk) ) {
4775 Abc_NtkForEachLatch(pNtk, pNode, i)
4776 pNode->pNext = (Abc_Obj_t *)pNode->pData;
4777 }
4778 // cut manager for rewrite
4779clk = Abc_Clock();
4780 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
4781Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
4782 pNtk->pManCut = pManCutRwr;
4783
4784 if ( fVeryVerbose )
4785 Rwr_ScoresClean( pManRwr );
4786
4787 // resynthesize each node once
4788 // resub
4789 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
4790 // rewrite
4791 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
4792 // refactor
4793 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
4794
4795 nNodes = Abc_NtkObjNumMax(pNtk);
4796 //printf("nNodes: %d\n", nNodes);
4797 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
4798 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
4799 if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
4800
4801 pProgress = Extra_ProgressBarStart( stdout, nNodes );
4802 fpt = fopen("Ochestration_id_ops_nGain.csv", "w");
4803
4804 Abc_NtkForEachNode( pNtk, pNode, i )
4805 {
4806 //printf("Nodes ID: %d\n", pNode->Id);
4807 rwr_ok = 0;
4808 ref_ok = 0;
4809 res_ok = 0;
4810 if (pOps_num) *pOps_num = Vec_IntAlloc(1);
4811 //printf("Ochestration id: %d\n", pNode->Id);
4812 Extra_ProgressBarUpdate( pProgress, i, NULL );
4813 // skip the constant node
4814// if ( Abc_NodeIsConst(pNode) )
4815// continue;
4816 // skip persistant nodes
4817 if ( Abc_NodeIsPersistant(pNode) )
4818 {
4819 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, 0, 0, 0, 0);
4820 Vec_IntPush((*pGain_res), -99);
4821 Vec_IntPush((*pGain_ref), -99);
4822 Vec_IntPush((*pGain_rwr), -99);
4823 continue;
4824 }
4825 // skip the nodes with many fanouts
4826 if ( Abc_ObjFanoutNum(pNode) > 1000 )
4827 {
4828 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, 0, 0, 0, 0);
4829 Vec_IntPush((*pGain_res), -99);
4830 Vec_IntPush((*pGain_ref), -99);
4831 Vec_IntPush((*pGain_rwr), -99);
4832 continue;
4833 }
4834 // stop if all nodes have been tried once
4835 if ( i >= nNodes )
4836 break;
4837clk = Abc_Clock();
4838
4839//Refactor
4840 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
4841pManRef->timeCut += Abc_Clock() - clk;
4842clk = Abc_Clock();
4843 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
4844 pFFormRef_zeros = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
4845pManRef->timeRes += Abc_Clock() - clk;
4846 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
4847
4848// Resub
4849 // compute a reconvergence-driven cut
4850 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
4851// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
4852pManRes->timeCut += Abc_Clock() - clk;
4853 // get the don't-cares
4854 if ( pManOdc )
4855 {
4856clk = Abc_Clock();
4857 Abc_NtkDontCareClear( pManOdc );
4858 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
4859pManRes->timeTruth += Abc_Clock() - clk;
4860 }
4861 // evaluate this cut
4862clk = Abc_Clock();
4863 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
4864// Vec_PtrFree( vLeaves );
4865// Abc_ManResubCleanup( pManRes );
4866pManRes->timeRes += Abc_Clock() - clk;
4867 // put nGain in Vector
4868 Vec_IntPush((*pGain_res), pManRes->nLastGain);
4869 // printf("size of vector %d\n", (**pGain).nSize);
4870
4871// Rewrite
4872 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
4873 nGain_zeros = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
4874 Vec_IntPush( (*pGain_rwr), nGain);
4875
4876 //printf("Res Ochestration: %d\n", pManRes->nLastGain);
4877 //printf("Ref Ochestration: %d\n", pManRef->nLastGain);
4878 //printf("Rwr Ochestration: %d\n", nGain);
4879 fprintf(fpt, "%d, %s, %d, %s, %d, %s, %d, %s, %d\n", pNode->Id, "Oches_Res", pManRes->nLastGain, "Oches_Ref", pManRef->nLastGain, "Oches_Rwr", nGain, "Oches_Rwr_Zeros", nGain_zeros);
4880
4881 //fprintf(fpt, "%d, %s, %d, %s, %d, %s, %d, %s, %d\n", pNode->Id, "Oches_Res", pManRes->nLastGain, "Oches_Ref", pManRef->nLastGain, "Oches_Rwr", nGain, "Oches_Rwr_Zeros", nGain_zeros);
4882
4883// Generate the valid operator array for the node
4884 if ( nGain > 0 )
4885 {
4886 rwr_ok = 1;
4887 Vec_IntPush((*pOps_num), 0);
4888 }
4889 //if ( nGain_zeros > 0 )
4890 //{
4891 // Vec_IntPush((*pOps_num), 1);
4892 //}
4893 //take refactor put
4894
4895 if ( pManRef->nLastGain > 0 )
4896 {
4897 ref_ok = 1;
4898 Vec_IntPush((*pOps_num), 2);
4899 //Vec_IntPush((*pOps_num), 3);
4900 }
4901
4902 if ( pManRes->nLastGain > 0 )
4903 {
4904 res_ok = 1;
4905 Vec_IntPush((*pOps_num), 1);
4906 }
4907// No available updats
4908 //if (! (nGain > 0 || nGain_zeros > 0 || pManRef->nLastGain > 0 || pManRes->nLastGain > 0 || (nGain == 0 && fUseZeros_rwr)))
4909 //if (! (nGain > 0 ||(nGain == 0 && fUseZeros_rwr)))
4910 //{
4911 //ops_null++;
4912 //continue;
4913 //}
4914 if (! ((**pOps_num).nSize > 0))
4915 {
4916 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, 0, 0, 0, 0);
4917 ops_null++;
4918 continue;
4919 }
4920/*
4921 if (pManRes->nLastGain > 0){
4922 res_ok = 1;
4923 }
4924 if (pManRef->nLastGain > 0){
4925 ref_ok = 1;
4926 }
4927 if (nGain > 0){
4928 rwr_ok = 1;
4929 }
4930*/
4931
4932 //printf("available operations: %d.\n", (**pOps_num).nSize);
4933// Randomly pick a operation number
4934 //int Ops_num = 0;
4935 int Ops_size = (**pOps_num).nSize;
4936 int r = rand() % Ops_size;
4937 int Ops_num = (**pOps_num).pArray[r];
4938 //printf("the picked operation: %d.\n", Ops_num);
4939
4940// Update the graph with random picked operation!
4941 if ( Ops_num == 0)
4942 {
4943// Graph update with Rewrite
4944 //printf("Graph Update with Rewrite");
4945 decisionOps = 1;
4946 ops_rwr++;
4947 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4948 fCompl = Rwr_ManReadCompl(pManRwr);
4949 if ( fPlaceEnable )
4951 if ( fCompl ) Dec_GraphComplement( pGraph );
4952clk = Abc_Clock();
4953 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
4954Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4955 if ( fCompl ) Dec_GraphComplement( pGraph );
4956 //printf("Nodes ID: %d\n", pNode->Id);
4957 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, rwr_ok, ref_ok, res_ok, decisionOps);
4958 continue;
4959 }
4960/*
4961 if ( Ops_num == 1)
4962 {
4963// Graph update with Rewrite -z
4964 //printf("Graph Update with Rewrite -z");
4965 ops_rwr_z++;
4966 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
4967 fCompl = Rwr_ManReadCompl(pManRwr);
4968 if ( fPlaceEnable )
4969 Abc_AigUpdateReset( (Abc_Aig_t *)pNtk->pManFunc );
4970 if ( fCompl ) Dec_GraphComplement( pGraph );
4971clk = Abc_Clock();
4972 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain_zeros );
4973Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
4974 if ( fCompl ) Dec_GraphComplement( pGraph );
4975 continue;
4976 }
4977*/
4978 if ( Ops_num == 2)
4979 {
4980// Graph update with Refactor
4981 //printf("Graph Update with Refactor");
4982 decisionOps = 2;
4983 ops_ref++;
4984 if ( pFFormRef == NULL )
4985 continue;
4986clk = Abc_Clock();
4987 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
4988 {
4989 Dec_GraphFree( pFFormRef );
4990 RetValue = -1;
4991 break;
4992 }
4993pManRef->timeNtk += Abc_Clock() - clk;
4994 Dec_GraphFree( pFFormRef );
4995 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, rwr_ok, ref_ok, res_ok, decisionOps);
4996 continue;
4997 }
4998/*
4999 if ( Ops_num == 3)
5000 {
5001// Graph update with Refactor -z
5002 //printf("Graph Update with Refactor");
5003 ops_ref_z++;
5004 if ( pFFormRef_zeros == NULL )
5005 continue;
5006clk = Abc_Clock();
5007 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef_zeros, fUpdateLevel, pManRef->nLastGain ) )
5008 {
5009 Dec_GraphFree( pFFormRef_zeros );
5010 RetValue = -1;
5011 break;
5012 }
5013pManRef->timeNtk += Abc_Clock() - clk;
5014 Dec_GraphFree( pFFormRef_zeros );
5015 continue;
5016 }
5017*/
5018
5019 if (Ops_num == 1)
5020 {
5021// Graph update with Resub
5022 //printf("Graph Update with Resub");
5023 decisionOps = 3;
5024 ops_res++;
5025 if ( pFFormRes == NULL )
5026 continue;
5027 pManRes->nTotalGain += pManRes->nLastGain;
5028clk = Abc_Clock();
5029 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
5030pManRes->timeNtk += Abc_Clock() - clk;
5031 Dec_GraphFree( pFFormRes );
5032 fprintf(fpt, "%d, %d, %d, %d, %d\n", pNode->Id, rwr_ok, ref_ok, res_ok, decisionOps);
5033 continue;
5034 }
5035
5036 }
5037
5038 fclose(fpt);
5039
5040 /*
5041 printf("size of vector %d\n", (**pGain_rwr).nSize);
5042 printf("nGain in vector: %d\n", (**pGain_res).pArray[20]);
5043 printf("Nodes with rewrite: %d\n", ops_rwr);
5044 //printf("Nodes with rewrite -z: %d\n", ops_rwr_z);
5045 printf("Nodes with resub: %d\n", ops_res);
5046 printf("Nodes with refactor: %d\n", ops_ref);
5047 //printf("Nodes with refactor -z: %d\n", ops_ref_z);
5048 printf("Nodes without updates: %d\n", ops_null);
5049 */
5050 Extra_ProgressBarStop( pProgress );
5051// Rewrite
5052Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
5053 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
5054
5055// Resub
5056pManRes->timeTotal = Abc_Clock() - clkStart;
5057 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
5058
5059// Refactor
5060pManRef->timeTotal = Abc_Clock() - clkStart;
5061 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
5062
5063 // print statistics
5064 if ( fVerbose ){
5065 Abc_ManResubPrint( pManRes );
5066 Rwr_ManPrintStats( pManRwr );
5067 Abc_NtkManRefPrintStats_1( pManRef );
5068 }
5069 if ( fVeryVerbose )
5070 Rwr_ScoresReport( pManRwr );
5071 // delete the managers
5072 // resub
5073 Abc_ManResubStop( pManRes );
5074 Abc_NtkManCutStop( pManCutRes );
5075 // rewrite
5076 Rwr_ManStop( pManRwr );
5077 Cut_ManStop( pManCutRwr );
5078 pNtk->pManCut = NULL;
5079 // refactor
5080 Abc_NtkManCutStop( pManCutRef );
5081 Abc_NtkManRefStop_1( pManRef );
5082
5083 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
5084
5085 // clean the data field
5086 Abc_NtkForEachObj( pNtk, pNode, i )
5087 pNode->pData = NULL;
5088
5089 if ( Abc_NtkLatchNum(pNtk) ) {
5090 Abc_NtkForEachLatch(pNtk, pNode, i)
5091 pNode->pData = pNode->pNext, pNode->pNext = NULL;
5092 }
5093
5094 // put the nodes into the DFS order and reassign their IDs
5095 Abc_NtkReassignIds( pNtk );
5096// Abc_AigCheckFaninOrder( pNtk->pManFunc );
5097
5098 // fix the levels
5099 if ( fUpdateLevel )
5101 else
5102 Abc_NtkLevel( pNtk );
5103 // check
5104 if ( !Abc_NtkCheck( pNtk ) )
5105 {
5106 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
5107 return 0;
5108 }
5109s_ResubTime = Abc_Clock() - clkStart;
5110 return 1;
5111}
5112
5113// rw rs rf embedding generation for GNN learning
5114int Abc_NtkOrchGNN( Abc_Ntk_t * pNtk, char * edgelistFile, char * featFile, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
5115{
5116 ProgressBar * pProgress;
5117 // For resub
5118 Abc_ManRes_t * pManRes;
5119 Abc_ManCut_t * pManCutRes;
5120 Odc_Man_t * pManOdc = NULL;
5121 Dec_Graph_t * pFFormRes;
5122 Dec_Graph_t * pFFormRef_zeros;
5123 Vec_Ptr_t * vLeaves;
5124 // For rewrite
5125 Cut_Man_t * pManCutRwr;
5126 Rwr_Man_t * pManRwr;
5127 //Dec_Graph_t * pGraph;
5128 // For refactor
5129 Abc_ManRef_t * pManRef;
5130 Abc_ManCut_t * pManCutRef;
5131 Dec_Graph_t * pFFormRef;
5132 Vec_Ptr_t * vFanins;
5133
5134 Abc_Obj_t * pNode, * pFanin;
5135 int fanin_i;
5136 FILE * f_el;
5137 FILE * f_feats;
5138 //FILE * fpt;
5139 abctime clk, clkStart = Abc_Clock();
5141 int i, nNodes, nGain, nGain_zeros;//, fCompl, RetValue = 1;
5142 int rwr_ok = 0;
5143 int res_ok = 0;
5144 int ref_ok = 0;
5145 //int decisionOps = 0;
5146 assert( Abc_NtkIsStrash(pNtk) );
5147
5148 // cleanup the AIG
5150
5151 // start the managers resub
5152 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
5153 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
5154 if ( nLevelsOdc > 0 )
5155 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
5156 // start the managers refactor
5157 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
5158 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
5159 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
5160 // start the managers rewrite
5161 pManRwr = Rwr_ManStart( 0 );
5162 if ( pManRwr == NULL )
5163 return 0;
5164
5165 // compute the reverse levels if level update is requested
5166 if ( fUpdateLevel )
5167 Abc_NtkStartReverseLevels( pNtk, 0 );
5168
5169 // 'Resub only'
5170 if ( Abc_NtkLatchNum(pNtk) ) {
5171 Abc_NtkForEachLatch(pNtk, pNode, i)
5172 pNode->pNext = (Abc_Obj_t *)pNode->pData;
5173 }
5174 // cut manager for rewrite
5175clk = Abc_Clock();
5176 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
5177Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
5178 pNtk->pManCut = pManCutRwr;
5179
5180 if ( fVeryVerbose )
5181 Rwr_ScoresClean( pManRwr );
5182
5183 // resynthesize each node once
5184 // resub
5185 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
5186 // rewrite
5187 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
5188 // refactor
5189 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
5190
5191 nNodes = Abc_NtkObjNumMax(pNtk);
5192 //printf("nNodes: %d\n", nNodes);
5193 //if (pGain_res) *pGain_res = Vec_IntAlloc(1);
5194 //if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
5195 //if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
5196
5197 pProgress = Extra_ProgressBarStart( stdout, nNodes );
5198 //fpt = fopen("GNN_Embedding.csv", "w");
5199 f_el = fopen(edgelistFile, "w");
5200 f_feats = fopen(featFile, "w");
5201
5202 Abc_NtkForEachNode( pNtk, pNode, i )
5203 {
5204 int iterNode = pNode->Id;
5205 Abc_ObjForEachFanin(pNode, pFanin, fanin_i){
5206 fprintf(f_el, "%d %d\n", iterNode, Abc_ObjId(pFanin));
5207 }
5208 //printf("Nodes ID: %d\n", pNode->Id);
5209 rwr_ok = 0;
5210 ref_ok = 0;
5211 res_ok = 0;
5212 Extra_ProgressBarUpdate( pProgress, i, NULL );
5213 // skip the constant node
5214// if ( Abc_NodeIsConst(pNode) )
5215// continue;
5216 // skip persistant nodes
5217
5218 if ( Abc_NodeIsPersistant(pNode) )
5219 {
5220 //fprintf(f_el, "%d %d\n", iterNode, Abc_ObjId(pFanin));
5221 fprintf(f_feats, "%d, %d, %d, %d, %d, %d, %d, %d\n", Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), -1, -1, -1, -1, -1, -1);
5222 //fprintf(fpt, "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", iterNode, Abc_ObjId(pFanin), Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), -1, -1, -1, -1, -1, -1);
5223 continue;
5224 }
5225 // skip the nodes with many fanouts
5226 if ( Abc_ObjFanoutNum(pNode) > 1000 )
5227 {
5228 //fprintf(f_el, "%d %d\n", iterNode, Abc_ObjId(pFanin));
5229 fprintf(f_feats, "%d, %d, %d, %d, %d, %d, %d, %d\n", Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), -1, -1, -1, -1, -1, -1);
5230 //fprintf(fpt, "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", iterNode, Abc_ObjId(pFanin), Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), -1, -1, -1, -1, -1, -1);
5231 continue;
5232 }
5233 // stop if all nodes have been tried once
5234 if ( i >= nNodes )
5235 break;
5236
5237clk = Abc_Clock();
5238
5239//Refactor
5240 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
5241pManRef->timeCut += Abc_Clock() - clk;
5242clk = Abc_Clock();
5243 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros, fUseDcs, fVerbose );
5244 pFFormRef_zeros = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
5245pManRef->timeRes += Abc_Clock() - clk;
5246 if (! (pManRef->nLastGain < 0) ) {ref_ok = 1;}
5247
5248// Resub
5249 // compute a reconvergence-driven cut
5250 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
5251// vLeaves = Abc_CutFactorLarge( pNode, nCutMax );
5252pManRes->timeCut += Abc_Clock() - clk;
5253 // get the don't-cares
5254 if ( pManOdc )
5255 {
5256clk = Abc_Clock();
5257 Abc_NtkDontCareClear( pManOdc );
5258 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
5259pManRes->timeTruth += Abc_Clock() - clk;
5260 }
5261 // evaluate this cut
5262clk = Abc_Clock();
5263 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
5264// Vec_PtrFree( vLeaves );
5265// Abc_ManResubCleanup( pManRes );
5266pManRes->timeRes += Abc_Clock() - clk;
5267 // put nGain in Vector
5268 if (! (pManRes->nLastGain < 0) ) {res_ok = 1;}
5269
5270// Rewrite
5271 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros, fPlaceEnable );
5272 nGain_zeros = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
5273 if (! (nGain < 0) ) {rwr_ok = 1;}
5274
5275 //fprintf(f_el, "%d %d\n", iterNode, Abc_ObjId(pFanin));
5276 fprintf(f_feats, "%d, %d, %d, %d, %d, %d, %d, %d\n", Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), rwr_ok, nGain, res_ok, pManRes->nLastGain, ref_ok, pManRef->nLastGain);
5277 //fprintf(fpt, "%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", iterNode, Abc_ObjId(pFanin), Abc_ObjFaninC0(pNode), Abc_ObjFaninC1(pNode), rwr_ok, nGain, res_ok, pManRes->nLastGain, ref_ok, pManRef->nLastGain);
5278 //printf("Res Ochestration: %d\n", pManRes->nLastGain);
5279 //printf("Ref Ochestration: %d\n", pManRef->nLastGain);
5280 //printf("Rwr Ochestration: %d\n", nGain);
5281
5282 //continue;
5283 //}
5284 //continue;
5285 }
5286 fclose(f_el);
5287 fclose(f_feats);
5288 //fclose(fpt);
5289
5290
5291 Extra_ProgressBarStop( pProgress );
5292// Rewrite
5293Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
5294 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
5295
5296// Resub
5297pManRes->timeTotal = Abc_Clock() - clkStart;
5298 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
5299
5300// Refactor
5301pManRef->timeTotal = Abc_Clock() - clkStart;
5302 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
5303
5304 // print statistics
5305 if ( fVerbose ){
5306 Abc_ManResubPrint( pManRes );
5307 Rwr_ManPrintStats( pManRwr );
5308 Abc_NtkManRefPrintStats_1( pManRef );
5309 }
5310 if ( fVeryVerbose )
5311 Rwr_ScoresReport( pManRwr );
5312 // delete the managers
5313 // resub
5314 Abc_ManResubStop( pManRes );
5315 Abc_NtkManCutStop( pManCutRes );
5316 // rewrite
5317 Rwr_ManStop( pManRwr );
5318 Cut_ManStop( pManCutRwr );
5319 pNtk->pManCut = NULL;
5320 // refactor
5321 Abc_NtkManCutStop( pManCutRef );
5322 Abc_NtkManRefStop_1( pManRef );
5323
5324 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
5325
5326 // clean the data field
5327 Abc_NtkForEachObj( pNtk, pNode, i )
5328 pNode->pData = NULL;
5329
5330 if ( Abc_NtkLatchNum(pNtk) ) {
5331 Abc_NtkForEachLatch(pNtk, pNode, i)
5332 pNode->pData = pNode->pNext, pNode->pNext = NULL;
5333 }
5334
5335 // put the nodes into the DFS order and reassign their IDs
5336 Abc_NtkReassignIds( pNtk );
5337// Abc_AigCheckFaninOrder( pNtk->pManFunc );
5338
5339 // fix the levels
5340 if ( fUpdateLevel )
5342 else
5343 Abc_NtkLevel( pNtk );
5344 // check
5345 if ( !Abc_NtkCheck( pNtk ) )
5346 {
5347 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
5348 return 0;
5349 }
5350s_ResubTime = Abc_Clock() - clkStart;
5351 return 1;
5352}
5353
5354// orchestration with sudo random decision list
5355int Abc_NtkOrchRand( Abc_Ntk_t * pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res,Vec_Int_t **pGain_ref, Vec_Int_t **DecisionMask, char * DecisionFile, int Rand_Seed, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs )
5356{
5357 extern int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain );
5358 ProgressBar * pProgress;
5359 // For resub
5360 Abc_ManRes_t * pManRes;
5361 Abc_ManCut_t * pManCutRes;
5362 Odc_Man_t * pManOdc = NULL;
5363 Dec_Graph_t * pFFormRes;
5364 Vec_Ptr_t * vLeaves;
5365 // For rewrite
5366 Cut_Man_t * pManCutRwr;
5367 Rwr_Man_t * pManRwr;
5368 Dec_Graph_t * pGraph;
5369 // For refactor
5370 Abc_ManRef_t * pManRef;
5371 Abc_ManCut_t * pManCutRef;
5372 Dec_Graph_t * pFFormRef;
5373 Vec_Ptr_t * vFanins;
5374
5375 Abc_Obj_t * pNode;
5376 FILE *fpt;
5377 abctime clk, clkStart = Abc_Clock();
5378 int i, nNodes, nNodes_after, nGain, fCompl;
5379 int RetValue = 1;
5380 int ops_rwr = 0;
5381 int ops_res = 0;
5382 int ops_ref = 0;
5383 int ops_null = 0;
5384 int Valid_Len = 0;
5385 //Vec_Int_t *Valid_Ops;
5386
5387 //clock_t begin= clock();
5388 assert( Abc_NtkIsStrash(pNtk) );
5389
5390 // cleanup the AIG
5392
5393 // start the managers resub
5394 pManCutRes = Abc_NtkManCutStart( nCutMax, 100000, 100000, 100000 );
5395 pManRes = Abc_ManResubStart( nCutMax, ABC_RS_DIV1_MAX );
5396 if ( nLevelsOdc > 0 )
5397 pManOdc = Abc_NtkDontCareAlloc( nCutMax, nLevelsOdc, fVerbose, fVeryVerbose );
5398 // start the managers refactor
5399 pManCutRef = Abc_NtkManCutStart( nNodeSizeMax, nConeSizeMax, 2, 1000 );
5400 pManRef = Abc_NtkManRefStart_1( nNodeSizeMax, nConeSizeMax, fUseDcs, fVerbose );
5401 pManRef->vLeaves = Abc_NtkManCutReadCutLarge( pManCutRef );
5402 // start the managers rewrite
5403 pManRwr = Rwr_ManStart( 0 );
5404 if ( pManRwr == NULL )
5405 return 0;
5406
5407 // compute the reverse levels if level update is requested
5408 if ( fUpdateLevel )
5409 Abc_NtkStartReverseLevels( pNtk, 0 );
5410
5411 // 'Resub only'
5412
5413 if ( Abc_NtkLatchNum(pNtk) ) {
5414 Abc_NtkForEachLatch(pNtk, pNode, i)
5415 pNode->pNext = (Abc_Obj_t *)pNode->pData;
5416 }
5417
5418 // cut manager for rewrite
5419clk = Abc_Clock();
5420 pManCutRwr = Abc_NtkStartCutManForRewrite( pNtk );
5421Rwr_ManAddTimeCuts( pManRwr, Abc_Clock() - clk );
5422 pNtk->pManCut = pManCutRwr;
5423
5424 if ( fVeryVerbose )
5425 Rwr_ScoresClean( pManRwr );
5426
5427 // resynthesize each node once
5428 // resub
5429 pManRes->nNodesBeg = Abc_NtkNodeNum(pNtk);
5430 // rewrite
5431 pManRwr->nNodesBeg = Abc_NtkNodeNum(pNtk);
5432 // refactor
5433 pManRef->nNodesBeg = Abc_NtkNodeNum(pNtk);
5434
5435//clock_t resyn_end=clock();
5436//double resyn_time_spent = (double)(resyn_end-begin)/CLOCKS_PER_SEC;
5437//printf("time %f\n", resyn_time_spent);
5438 nNodes = Abc_NtkObjNumMax(pNtk);
5439 //printf("nNodes: %d\n", nNodes);
5440 //for(int i=0; i < nNodes; i++){printf("mask check: %d\n", (*DecisionMask)->pArray[i]);}
5441 //printf("mask size:%d", (**DecisionMask).nSize);
5442 if (pGain_res) *pGain_res = Vec_IntAlloc(1);
5443 if (pGain_ref) *pGain_ref = Vec_IntAlloc(1);
5444 if (pGain_rwr) *pGain_rwr = Vec_IntAlloc(1);
5445 Vec_Int_t *Valid_Ops = Vec_IntAlloc(1);
5446
5447 pProgress = Extra_ProgressBarStart( stdout, nNodes );
5448 fpt = fopen(DecisionFile, "w");
5449
5450 Abc_NtkForEachNode( pNtk, pNode, i )
5451 {
5452 //printf("Ochestration id: %d\n", pNode->Id);
5453 int iterNode = pNode->Id;
5454 Extra_ProgressBarUpdate( pProgress, i, NULL );
5455 // skip the constant node
5456// if ( Abc_NodeIsConst(pNode) )
5457// continue;
5458 // stop if all nodes have been tried once
5459 if ( i >= nNodes )
5460 break;
5461 // skip persistant nodes
5462 if ( Abc_NodeIsPersistant(pNode) )
5463 {
5464 //fprintf(fpt, "%d, %s, %d\n", pNode->Id, "None" , -99);
5465 Vec_IntPush((*pGain_res), -99);
5466 Vec_IntPush((*pGain_ref), -99);
5467 Vec_IntPush((*pGain_rwr), -99);
5468 continue;
5469 }
5470 // skip the nodes with many fanouts
5471 if ( Abc_ObjFanoutNum(pNode) > 1000 )
5472 {
5473 //fprintf(fpt, "%d, %s, %d\n", pNode->Id,"None", -99);
5474 Vec_IntPush((*pGain_res), -99);
5475 Vec_IntPush((*pGain_ref), -99);
5476 Vec_IntPush((*pGain_rwr), -99);
5477 continue;
5478 }
5479clk = Abc_Clock();
5480
5481// Generate random operation
5482// check transformability of all three operations
5483 Vec_IntPush( (Valid_Ops), -1);
5484 nGain = Rwr_NodeRewrite( pManRwr, pManCutRwr, pNode, fUpdateLevel, fUseZeros_rwr, fPlaceEnable );
5485 Vec_IntPush( (*pGain_rwr), nGain);
5486 if (nGain > 0 || (nGain == 0 && fUseZeros_rwr))
5487 {
5488 Vec_IntPush( (Valid_Ops), 0);
5489 }
5490 vLeaves = Abc_NodeFindCut( pManCutRes, pNode, 0 );
5491 pManRes->timeCut += Abc_Clock() - clk;
5492 if ( pManOdc )
5493 {
5494clk = Abc_Clock();
5495 Abc_NtkDontCareClear( pManOdc );
5496 Abc_NtkDontCareCompute( pManOdc, pNode, vLeaves, pManRes->pCareSet );
5497pManRes->timeTruth += Abc_Clock() - clk;
5498 }
5499clk = Abc_Clock();
5500 pFFormRes = Abc_ManResubEval( pManRes, pNode, vLeaves, nStepsMax, fUpdateLevel, fVerbose );
5501pManRes->timeRes += Abc_Clock() - clk;
5502 Vec_IntPush((*pGain_res), pManRes->nLastGain);
5503 if (pManRes->nLastGain > 0)
5504 {
5505 if ( pFFormRes != NULL ){
5506 Vec_IntPush( (Valid_Ops), 1);
5507 }
5508 }
5509
5510 vFanins = Abc_NodeFindCut( pManCutRef, pNode, fUseDcs );
5511pManRef->timeCut += Abc_Clock() - clk;
5512clk = Abc_Clock();
5513 pFFormRef = Abc_NodeRefactor_1( pManRef, pNode, vFanins, fUpdateLevel, fUseZeros_ref, fUseDcs, fVerbose );
5514pManRef->timeRes += Abc_Clock() - clk;
5515
5516 Vec_IntPush((*pGain_ref), pManRef->nLastGain);
5517 if (pManRef->nLastGain > 0 || (pManRef->nLastGain ==0 && fUseZeros_ref))
5518 {
5519 if ( pFFormRef != NULL ){
5520 Vec_IntPush( (Valid_Ops), 2);
5521 }
5522 }
5523 Valid_Len = (Valid_Ops)->nSize;
5524 //printf("The length of valid operations: %d\n", Valid_Len);
5525
5526//Pick a random operations from valid ones
5527if (Rand_Seed == -1)
5528{
5529 srand(time(NULL));
5530}
5531else
5532{
5533 srand(Rand_Seed);
5534}
5535
5536int r = rand() % Valid_Len;
5537
5538 if ((Valid_Ops)->pArray[r] == -1){
5539 (*DecisionMask)->pArray[iterNode] = -1;
5540 ops_null++;
5541 Vec_IntZero(Valid_Ops); // reset updates
5542 continue;
5543 }
5544 else if ((Valid_Ops->pArray[r]) == 0){
5545 // apply rewrite
5546 pGraph = (Dec_Graph_t *)Rwr_ManReadDecs(pManRwr);
5547 fCompl = Rwr_ManReadCompl(pManRwr);
5548 if ( fPlaceEnable )
5550 if ( fCompl ) Dec_GraphComplement( pGraph );
5551clk = Abc_Clock();
5552 Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
5553Rwr_ManAddTimeUpdate( pManRwr, Abc_Clock() - clk );
5554 if ( fCompl ) Dec_GraphComplement( pGraph );
5555 (*DecisionMask)->pArray[iterNode] = 0;
5556 ops_rwr++;
5557 Vec_IntZero(Valid_Ops); // reset updates
5558 continue;
5559 }
5560 else if ((Valid_Ops->pArray[r] == 1)){
5561 // apply res
5562 pManRes->nTotalGain += pManRes->nLastGain;
5563clk = Abc_Clock();
5564 Dec_GraphUpdateNetwork( pNode, pFFormRes, fUpdateLevel, pManRes->nLastGain );
5565pManRes->timeNtk += Abc_Clock() - clk;
5566 Dec_GraphFree( pFFormRes );
5567 (*DecisionMask)->pArray[iterNode] = 1;
5568 ops_res++;
5569 Vec_IntZero(Valid_Ops); // reset updates
5570 continue;
5571 }
5572 else if ((Valid_Ops->pArray[r] == 2)){
5573clk = Abc_Clock();
5574 if ( !Dec_GraphUpdateNetwork( pNode, pFFormRef, fUpdateLevel, pManRef->nLastGain ) )
5575 {
5576 Dec_GraphFree( pFFormRef );
5577 RetValue = -1;
5578 break;
5579 }
5580pManRef->timeNtk += Abc_Clock() - clk;
5581 Dec_GraphFree( pFFormRef );
5582 (*DecisionMask)->pArray[iterNode] = 2;
5583 ops_ref++;
5584 Vec_IntZero(Valid_Ops); // reset updates
5585 continue;
5586 }
5587 }
5588 //fwrite((**DecisionMask).pArray, sizeof(int), sizeof((**DecisionMask).pArray), fpt);
5589 for (int i = 0; i < (nNodes); i++){
5590 fprintf(fpt, "%d\n", (*DecisionMask)->pArray[i]);}
5591 fclose(fpt);
5592/*
5593 printf("size of vector %d\n", Valid_Len);
5594 printf("Nodes with rewrite: %d\n", ops_rwr);
5595 printf("Nodes with resub: %d\n", ops_res);
5596 printf("Nodes with refactor: %d\n", ops_ref);
5597 printf("Nodes without updates: %d\n", ops_null);
5598*/
5599 Extra_ProgressBarStop( pProgress );
5600// Rewrite
5601Rwr_ManAddTimeTotal( pManRwr, Abc_Clock() - clkStart );
5602 pManRwr->nNodesEnd = Abc_NtkNodeNum(pNtk);
5603
5604// Resub
5605pManRes->timeTotal = Abc_Clock() - clkStart;
5606 pManRes->nNodesEnd = Abc_NtkNodeNum(pNtk);
5607
5608// Refactor
5609pManRef->timeTotal = Abc_Clock() - clkStart;
5610 pManRef->nNodesEnd = Abc_NtkNodeNum(pNtk);
5611
5612 // print statistics
5613 if ( fVerbose ){
5614 Abc_ManResubPrint( pManRes );
5615 Rwr_ManPrintStats( pManRwr );
5616 Abc_NtkManRefPrintStats_1( pManRef );
5617 }
5618 if ( fVeryVerbose )
5619 Rwr_ScoresReport( pManRwr );
5620 // delete the managers
5621 // resub
5622 Abc_ManResubStop( pManRes );
5623 Abc_NtkManCutStop( pManCutRes );
5624 // rewrite
5625 Rwr_ManStop( pManRwr );
5626 Cut_ManStop( pManCutRwr );
5627 pNtk->pManCut = NULL;
5628 // refactor
5629 Abc_NtkManCutStop( pManCutRef );
5630 Abc_NtkManRefStop_1( pManRef );
5631
5632 if ( pManOdc ) Abc_NtkDontCareFree( pManOdc );
5633
5634 // clean the data field
5635 Abc_NtkForEachObj( pNtk, pNode, i )
5636 pNode->pData = NULL;
5637
5638 if ( Abc_NtkLatchNum(pNtk) ) {
5639 Abc_NtkForEachLatch(pNtk, pNode, i)
5640 pNode->pData = pNode->pNext, pNode->pNext = NULL;
5641 }
5642
5643 // put the nodes into the DFS order and reassign their IDs
5644 Abc_NtkReassignIds( pNtk );
5645// Abc_AigCheckFaninOrder( pNtk->pManFunc );
5646
5647 // fix the levels
5648 if ( fUpdateLevel )
5650 else
5651 Abc_NtkLevel( pNtk );
5652 // check
5653 if ( !Abc_NtkCheck( pNtk ) )
5654 {
5655 printf( "Abc_NtkOchestraction: The network check has failed.\n" );
5656 return 0;
5657 }
5658 nNodes_after = Abc_NtkObjNumMax(pNtk);
5659 //printf("nNodes after optimization: %d\n", nNodes_after);
5660//s_ResubTime = Abc_Clock() - clkStart;
5661//clock_t end=clock();
5662//double time_spent = (double)(end-begin)/CLOCKS_PER_SEC;
5663//printf("time %f\n", time_spent);
5664 return 1;
5665}
5666
5667
5671
5672
5674
int nWords
Definition abcNpn.c:127
Dec_Graph_t * Abc_ManResubQuit1_1(Abc_Obj_t *pRoot, Abc_Obj_t *pObj0, Abc_Obj_t *pObj1, int fOrGate)
int Abc_NtkOchestration3(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **pOps_num, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
void Abc_NodePrintCuts(Abc_Obj_t *pNode)
Definition abcRewrite.c:247
Dec_Graph_t * Abc_ManResubQuit2_1(Abc_Obj_t *pRoot, Abc_Obj_t *pObj0, Abc_Obj_t *pObj1, Abc_Obj_t *pObj2, int fOrGate)
Dec_Graph_t * Abc_NodeRefactor_1(Abc_ManRef_t *p, Abc_Obj_t *pNode, Vec_Ptr_t *vFanins, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose)
void Abc_PlaceUpdate(Vec_Ptr_t *vAddedCells, Vec_Ptr_t *vUpdatedNets)
Definition abcPlace.c:126
int Abc_NodeConeIsConst0_1(word *pTruth, int nVars)
int Abc_NtkOrchSA(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **PolicyList, char *DecisionFile, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
int Abc_NodeConeIsConst1_1(word *pTruth, int nVars)
Abc_ManRef_t * Abc_NtkManRefStart_1(int nNodeSizeMax, int nConeSizeMax, int fUseDcs, int fVerbose)
int Abc_NtkOrchRand(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **DecisionMask, char *DecisionFile, int Rand_Seed, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
abctime s_ResubTime
int Abc_NtkOrchGNN(Abc_Ntk_t *pNtk, char *edgelistFile, char *featFile, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
void Abc_ManShowCutCone(Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves)
Definition abcRewrite.c:347
void Abc_NtkManRefStop_1(Abc_ManRef_t *p)
int Dec_GraphUpdateNetwork(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition decAbc.c:240
void Abc_CutFactor_rec_1(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves)
Dec_Graph_t * Abc_ManResubQuit3_1(Abc_Obj_t *pRoot, Abc_Obj_t *pObj0, Abc_Obj_t *pObj1, Abc_Obj_t *pObj2, Abc_Obj_t *pObj3, int fOrGate)
int Abc_NtkRefactor3(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_ref, int nNodeSizeMax, int nConeSizeMax, int fUpdateLevel, int fUseZeros, int fUseDcs, int fVerbose)
void Abc_ManResubCollectDivs_rec1(Abc_Obj_t *pNode, Vec_Ptr_t *vInternal)
Vec_Ptr_t * Abc_CutFactor_1(Abc_Obj_t *pNode)
#define ABC_RS_DIV2_MAX
Dec_Graph_t * Abc_ManResubQuit0_1(Abc_Obj_t *pRoot, Abc_Obj_t *pObj)
struct Abc_ManRes_t_ Abc_ManRes_t
int Abc_NtkOchestration2(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, Vec_Int_t **pOps_num, int fUseZeros, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
Dec_Graph_t * Abc_ManResubQuit21_1(Abc_Obj_t *pRoot, Abc_Obj_t *pObj0, Abc_Obj_t *pObj1, Abc_Obj_t *pObj2, int fOrGate)
#define ABC_RS_DIV1_MAX
void Abc_PlaceBegin(Abc_Ntk_t *pNtk)
Definition abcPlace.c:178
int Abc_NtkOrchLocal(Abc_Ntk_t *pNtk, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
void Abc_NtkManRefPrintStats_1(Abc_ManRef_t *p)
void Abc_PlaceEnd(Abc_Ntk_t *pNtk)
Definition abcPlace.c:241
int Abc_NtkRewrite3(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rw, int fUpdateLevel, int fUseZeros, int fVerbose, int fVeryVerbose, int fPlaceEnable)
FUNCTION DEFINITIONS ///.
word * Abc_NodeConeTruth_1(Vec_Ptr_t *vVars, Vec_Ptr_t *vFuncs, int nWordsMax, Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVisited)
int Abc_NtkOchestration(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_rwr, Vec_Int_t **pGain_res, Vec_Int_t **pGain_ref, int sOpsOrder, int fUseZeros_rwr, int fUseZeros_ref, int fPlaceEnable, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose, int nNodeSizeMax, int nConeSizeMax, int fUseDcs)
int Abc_NtkResubstitute3(Abc_Ntk_t *pNtk, Vec_Int_t **pGain_res, int nCutMax, int nStepsMax, int nLevelsOdc, int fUpdateLevel, int fVerbose, int fVeryVerbose)
struct Abc_ManRef_t_ Abc_ManRef_t
int Abc_CutVolumeCheck_rec_1(Abc_Obj_t *pObj)
int Abc_NodeMffcInside(Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vInside)
Definition abcRefs.c:351
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_NodeMffcSize(Abc_Obj_t *pNode)
FUNCTION DEFINITIONS ///.
Definition abcRefs.c:48
ABC_DLL Odc_Man_t * Abc_NtkDontCareAlloc(int nVarsMax, int nLevels, int fVerbose, int fVeryVerbose)
FUNCTION DEFINITIONS ///.
Definition abcOdc.c:163
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition abcTiming.c:1214
ABC_DLL void Abc_AigUpdateReset(Abc_Aig_t *pMan)
Definition abcAig.c:1477
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
ABC_DLL int Abc_NtkDontCareCompute(Odc_Man_t *p, Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves, unsigned *puTruth)
Definition abcOdc.c:1042
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
Definition abcRefs.c:100
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
struct Abc_ManCut_t_ Abc_ManCut_t
Definition abc.h:119
struct Odc_Man_t_ Odc_Man_t
Definition abc.h:832
ABC_DLL void Abc_NodeConeCollect(Abc_Obj_t **ppRoots, int nRoots, Vec_Ptr_t *vFanins, Vec_Ptr_t *vVisited, int fIncludeFanins)
Definition abcReconv.c:444
ABC_DLL void Abc_NtkDontCareClear(Odc_Man_t *p)
Definition abcOdc.c:244
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition abcReconv.c:623
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition abcTiming.c:1302
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1741
ABC_DLL int Abc_NodeIsMuxControlType(Abc_Obj_t *pNode)
Definition abcUtil.c:1398
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition abcReconv.c:256
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition abcAig.c:194
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition abcTiming.c:1274
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutLarge(Abc_ManCut_t *p)
Definition abcReconv.c:644
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDontCareFree(Odc_Man_t *p)
Definition abcOdc.c:276
ABC_DLL void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1809
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition abcReconv.c:595
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_FREE(obj)
Definition abc_global.h:267
#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
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
struct Cut_ParamsStruct_t_ Cut_Params_t
Definition cut.h:51
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
Definition cutApi.c:145
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition cutMan.c:47
struct Cut_ManStruct_t_ Cut_Man_t
BASIC TYPES ///.
Definition cut.h:48
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
Definition cutMan.c:229
void Cut_ManStop(Cut_Man_t *p)
Definition cutMan.c:124
int Dec_GraphToNetworkCount(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int NodeMax, int LevelMax)
Definition decAbc.c:167
typedefABC_NAMESPACE_HEADER_START struct Dec_Edge_t_ Dec_Edge_t
INCLUDES ///.
Definition dec.h:42
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
Kit_Graph_t * Kit_TruthToGraph(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition kitGraph.c:356
#define fail(why)
Definition mincov.c:26
void Rwr_ManAddTimeUpdate(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:277
Rwr_Man_t * Rwr_ManStart(int fPrecompute)
DECLARATIONS ///.
Definition rwrMan.c:47
void Rwr_ScoresClean(Rwr_Man_t *p)
Definition rwrEva.c:504
void Rwr_ManAddTimeCuts(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:261
void Rwr_ManAddTimeTotal(Rwr_Man_t *p, abctime Time)
Definition rwrMan.c:293
void Rwr_ScoresReport(Rwr_Man_t *p)
Definition rwrEva.c:550
int Rwr_ManReadCompl(Rwr_Man_t *p)
Definition rwrMan.c:245
void Rwr_ManPrintStats(Rwr_Man_t *p)
Definition rwrMan.c:143
struct Rwr_Man_t_ Rwr_Man_t
Definition rwr.h:47
void Rwr_ManStop(Rwr_Man_t *p)
Definition rwrMan.c:109
int Rwr_NodeRewrite(Rwr_Man_t *p, Cut_Man_t *pManCut, Abc_Obj_t *pNode, int fUpdateLevel, int fUseZeros, int fPlaceEnable)
FUNCTION DEFINITIONS ///.
Definition rwrEva.c:59
void * Rwr_ManReadDecs(Rwr_Man_t *p)
Definition rwrMan.c:213
Vec_Str_t * vCube
Vec_Int_t * vMemory
Vec_Ptr_t * vFuncs
Vec_Ptr_t * vVisited
Vec_Int_t * vForm
Vec_Ptr_t * vVars
Vec_Ptr_t * vLeaves
Vec_Ptr_t * vDivs2UP1
Vec_Ptr_t * vDivs2UN0
Vec_Ptr_t * vDivs
Vec_Ptr_t * vDivs2UP0
Vec_Ptr_t * vDivs1UN
Vec_Ptr_t * vSims
Vec_Ptr_t * vDivs2UN1
Abc_Obj_t * pRoot
unsigned * pCareSet
Vec_Ptr_t * vDivs1UP
Vec_Ptr_t * vTemp
Vec_Ptr_t * vDivs1B
void * pManFunc
Definition abc.h:191
void * pManCut
Definition abc.h:193
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
int Id
Definition abc.h:132
Vec_Int_t vFanouts
Definition abc.h:144
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
unsigned fPhase
Definition abc.h:137
Abc_Obj_t * pNext
Definition abc.h:131
unsigned Level
Definition abc.h:142
int nNodesBeg
Definition rwr.h:82
int nNodesEnd
Definition rwr.h:83
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
Definition vecPtr.h:59
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55