ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcRr.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "proof/fraig/fraig.h"
23#include "opt/sim/sim.h"
24
26
27
31
34{
35 // the parameters
36 Abc_Ntk_t * pNtk; // the network
37 int nFaninLevels; // the number of fanin levels
38 int nFanoutLevels; // the number of fanout levels
39 // the node/fanin/fanout
40 Abc_Obj_t * pNode; // the node
41 Abc_Obj_t * pFanin; // the fanin
42 Abc_Obj_t * pFanout; // the fanout
43 // the intermediate cones
44 Vec_Ptr_t * vFaninLeaves; // the leaves of the fanin cone
45 Vec_Ptr_t * vFanoutRoots; // the roots of the fanout cone
46 // the window
47 Vec_Ptr_t * vLeaves; // the leaves of the window
48 Vec_Ptr_t * vCone; // the internal nodes of the window
49 Vec_Ptr_t * vRoots; // the roots of the window
50 Abc_Ntk_t * pWnd; // the window derived for the edge
51 // the miter
52 Abc_Ntk_t * pMiter; // the miter derived from the window
53 Prove_Params_t * pParams; // the miter proving parameters
54 // statistical variables
55 int nNodesOld; // the old number of nodes
56 int nLevelsOld; // the old number of levels
57 int nEdgesTried; // the number of nodes tried
58 int nEdgesRemoved; // the number of nodes proved
59 abctime timeWindow; // the time to construct the window
60 abctime timeMiter; // the time to construct the miter
61 abctime timeProve; // the time to prove the miter
62 abctime timeUpdate; // the network update time
63 abctime timeTotal; // the total runtime
64};
65
66static Abc_RRMan_t * Abc_RRManStart();
67static void Abc_RRManStop( Abc_RRMan_t * p );
68static void Abc_RRManPrintStats( Abc_RRMan_t * p );
69static void Abc_RRManClean( Abc_RRMan_t * p );
70static int Abc_NtkRRProve( Abc_RRMan_t * p );
71static int Abc_NtkRRUpdate( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode, Abc_Obj_t * pFanin, Abc_Obj_t * pFanout );
72static int Abc_NtkRRWindow( Abc_RRMan_t * p );
73
74static int Abc_NtkRRTfi_int( Vec_Ptr_t * vLeaves, int LevelLimit );
75static int Abc_NtkRRTfo_int( Vec_Ptr_t * vLeaves, Vec_Ptr_t * vRoots, int LevelLimit, Abc_Obj_t * pEdgeFanin, Abc_Obj_t * pEdgeFanout );
76static int Abc_NtkRRTfo_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vRoots, int LevelLimit );
77static void Abc_NtkRRTfi_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vCone, int LevelLimit );
78static Abc_Ntk_t * Abc_NtkWindow( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vCone, Vec_Ptr_t * vRoots );
79
80static void Abc_NtkRRSimulateStart( Abc_Ntk_t * pNtk );
81static void Abc_NtkRRSimulateStop( Abc_Ntk_t * pNtk );
82
86
98int Abc_NtkRR( Abc_Ntk_t * pNtk, int nFaninLevels, int nFanoutLevels, int fUseFanouts, int fVerbose )
99{
100 ProgressBar * pProgress;
101 Abc_RRMan_t * p;
102 Abc_Obj_t * pNode, * pFanin, * pFanout;
103 int i, k, m, nNodes, RetValue;
104 abctime clk, clkTotal = Abc_Clock();
105 // start the manager
106 p = Abc_RRManStart();
107 p->pNtk = pNtk;
108 p->nFaninLevels = nFaninLevels;
109 p->nFanoutLevels = nFanoutLevels;
110 p->nNodesOld = Abc_NtkNodeNum(pNtk);
111 p->nLevelsOld = Abc_AigLevel(pNtk);
112 // remember latch values
113// Abc_NtkForEachLatch( pNtk, pNode, i )
114// pNode->pNext = pNode->pData;
115 // go through the nodes
116 Abc_NtkCleanCopy(pNtk);
117 nNodes = Abc_NtkObjNumMax(pNtk);
118 Abc_NtkRRSimulateStart(pNtk);
119 pProgress = Extra_ProgressBarStart( stdout, nNodes );
120 Abc_NtkForEachNode( pNtk, pNode, i )
121 {
122 Extra_ProgressBarUpdate( pProgress, i, NULL );
123 // stop if all nodes have been tried once
124 if ( i >= nNodes )
125 break;
126 // skip the constant node
127// if ( Abc_NodeIsConst(pNode) )
128// continue;
129 // skip persistant nodes
130 if ( Abc_NodeIsPersistant(pNode) )
131 continue;
132 // skip the nodes with many fanouts
133 if ( Abc_ObjFanoutNum(pNode) > 1000 )
134 continue;
135 // construct the window
136 if ( !fUseFanouts )
137 {
138 Abc_ObjForEachFanin( pNode, pFanin, k )
139 {
140 // skip the nodes with only one fanout (tree nodes)
141 if ( Abc_ObjFanoutNum(pFanin) == 1 )
142 continue;
143/*
144 if ( pFanin->Id == 228 && pNode->Id == 2649 )
145 {
146 int k = 0;
147 }
148*/
149 p->nEdgesTried++;
150 Abc_RRManClean( p );
151 p->pNode = pNode;
152 p->pFanin = pFanin;
153 p->pFanout = NULL;
154
155 clk = Abc_Clock();
156 RetValue = Abc_NtkRRWindow( p );
157 p->timeWindow += Abc_Clock() - clk;
158 if ( !RetValue )
159 continue;
160/*
161 if ( pFanin->Id == 228 && pNode->Id == 2649 )
162 {
163 Abc_NtkShowAig( p->pWnd, 0 );
164 }
165*/
166 clk = Abc_Clock();
167 RetValue = Abc_NtkRRProve( p );
168 p->timeMiter += Abc_Clock() - clk;
169 if ( !RetValue )
170 continue;
171//printf( "%d -> %d (%d)\n", pFanin->Id, pNode->Id, k );
172
173 clk = Abc_Clock();
174 Abc_NtkRRUpdate( pNtk, p->pNode, p->pFanin, p->pFanout );
175 p->timeUpdate += Abc_Clock() - clk;
176
177 p->nEdgesRemoved++;
178 break;
179 }
180 continue;
181 }
182 // use the fanouts
183 Abc_ObjForEachFanin( pNode, pFanin, k )
184 Abc_ObjForEachFanout( pNode, pFanout, m )
185 {
186 // skip the nodes with only one fanout (tree nodes)
187// if ( Abc_ObjFanoutNum(pFanin) == 1 && Abc_ObjFanoutNum(pNode) == 1 )
188// continue;
189
190 p->nEdgesTried++;
191 Abc_RRManClean( p );
192 p->pNode = pNode;
193 p->pFanin = pFanin;
194 p->pFanout = pFanout;
195
196 clk = Abc_Clock();
197 RetValue = Abc_NtkRRWindow( p );
198 p->timeWindow += Abc_Clock() - clk;
199 if ( !RetValue )
200 continue;
201
202 clk = Abc_Clock();
203 RetValue = Abc_NtkRRProve( p );
204 p->timeMiter += Abc_Clock() - clk;
205 if ( !RetValue )
206 continue;
207
208 clk = Abc_Clock();
209 Abc_NtkRRUpdate( pNtk, p->pNode, p->pFanin, p->pFanout );
210 p->timeUpdate += Abc_Clock() - clk;
211
212 p->nEdgesRemoved++;
213 break;
214 }
215 }
216 Abc_NtkRRSimulateStop(pNtk);
217 Extra_ProgressBarStop( pProgress );
218 p->timeTotal = Abc_Clock() - clkTotal;
219 if ( fVerbose )
220 Abc_RRManPrintStats( p );
221 Abc_RRManStop( p );
222 // restore latch values
223// Abc_NtkForEachLatch( pNtk, pNode, i )
224// pNode->pData = pNode->pNext, pNode->pNext = NULL;
225 // put the nodes into the DFS order and reassign their IDs
226 Abc_NtkReassignIds( pNtk );
227 Abc_NtkLevel( pNtk );
228 // check
229 if ( !Abc_NtkCheck( pNtk ) )
230 {
231 printf( "Abc_NtkRR: The network check has failed.\n" );
232 return 0;
233 }
234 return 1;
235}
236
248Abc_RRMan_t * Abc_RRManStart()
249{
250 Abc_RRMan_t * p;
251 p = ABC_ALLOC( Abc_RRMan_t, 1 );
252 memset( p, 0, sizeof(Abc_RRMan_t) );
253 p->vFaninLeaves = Vec_PtrAlloc( 100 ); // the leaves of the fanin cone
254 p->vFanoutRoots = Vec_PtrAlloc( 100 ); // the roots of the fanout cone
255 p->vLeaves = Vec_PtrAlloc( 100 ); // the leaves of the window
256 p->vCone = Vec_PtrAlloc( 100 ); // the internal nodes of the window
257 p->vRoots = Vec_PtrAlloc( 100 ); // the roots of the window
258 p->pParams = ABC_ALLOC( Prove_Params_t, 1 );
259 memset( p->pParams, 0, sizeof(Prove_Params_t) );
260 Prove_ParamsSetDefault( p->pParams );
261 return p;
262}
263
275void Abc_RRManStop( Abc_RRMan_t * p )
276{
277 Abc_RRManClean( p );
278 Vec_PtrFree( p->vFaninLeaves );
279 Vec_PtrFree( p->vFanoutRoots );
280 Vec_PtrFree( p->vLeaves );
281 Vec_PtrFree( p->vCone );
282 Vec_PtrFree( p->vRoots );
283 ABC_FREE( p->pParams );
284 ABC_FREE( p );
285}
286
298void Abc_RRManPrintStats( Abc_RRMan_t * p )
299{
300 double Ratio = 100.0*(p->nNodesOld - Abc_NtkNodeNum(p->pNtk))/p->nNodesOld;
301 printf( "Redundancy removal statistics:\n" );
302 printf( "Edges tried = %6d.\n", p->nEdgesTried );
303 printf( "Edges removed = %6d. (%5.2f %%)\n", p->nEdgesRemoved, 100.0*p->nEdgesRemoved/p->nEdgesTried );
304 printf( "Node gain = %6d. (%5.2f %%)\n", p->nNodesOld - Abc_NtkNodeNum(p->pNtk), Ratio );
305 printf( "Level gain = %6d.\n", p->nLevelsOld - Abc_AigLevel(p->pNtk) );
306 ABC_PRT( "Windowing ", p->timeWindow );
307 ABC_PRT( "Miter ", p->timeMiter );
308 ABC_PRT( " Construct ", p->timeMiter - p->timeProve );
309 ABC_PRT( " Prove ", p->timeProve );
310 ABC_PRT( "Update ", p->timeUpdate );
311 ABC_PRT( "TOTAL ", p->timeTotal );
312}
313
325void Abc_RRManClean( Abc_RRMan_t * p )
326{
327 p->pNode = NULL;
328 p->pFanin = NULL;
329 p->pFanout = NULL;
330 Vec_PtrClear( p->vFaninLeaves );
331 Vec_PtrClear( p->vFanoutRoots );
332 Vec_PtrClear( p->vLeaves );
333 Vec_PtrClear( p->vCone );
334 Vec_PtrClear( p->vRoots );
335 if ( p->pWnd ) Abc_NtkDelete( p->pWnd );
336 if ( p->pMiter ) Abc_NtkDelete( p->pMiter );
337 p->pWnd = NULL;
338 p->pMiter = NULL;
339}
340
352int Abc_NtkRRProve( Abc_RRMan_t * p )
353{
354 Abc_Ntk_t * pWndCopy;
355 int RetValue;
356 abctime clk;
357// Abc_NtkShowAig( p->pWnd, 0 );
358 pWndCopy = Abc_NtkDup( p->pWnd );
359 Abc_NtkRRUpdate( pWndCopy, p->pNode->pCopy->pCopy, p->pFanin->pCopy->pCopy, p->pFanout? p->pFanout->pCopy->pCopy : NULL );
360 if ( !Abc_NtkIsDfsOrdered(pWndCopy) )
361 Abc_NtkReassignIds(pWndCopy);
362 p->pMiter = Abc_NtkMiter( p->pWnd, pWndCopy, 1, 0, 0, 0 );
363 Abc_NtkDelete( pWndCopy );
364clk = Abc_Clock();
365 RetValue = Abc_NtkMiterProve( &p->pMiter, p->pParams );
366p->timeProve += Abc_Clock() - clk;
367 if ( RetValue == 1 )
368 return 1;
369 return 0;
370}
371
385int Abc_NtkRRUpdate( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode, Abc_Obj_t * pFanin, Abc_Obj_t * pFanout )
386{
387 Abc_Obj_t * pNodeNew = NULL, * pFanoutNew = NULL;
388 assert( pFanout == NULL );
389 assert( !Abc_ObjIsComplement(pNode) );
390 assert( !Abc_ObjIsComplement(pFanin) );
391 assert( !Abc_ObjIsComplement(pFanout) );
392 // find the node after redundancy removal
393 if ( pFanin == Abc_ObjFanin0(pNode) )
394 pNodeNew = Abc_ObjChild1(pNode);
395 else if ( pFanin == Abc_ObjFanin1(pNode) )
396 pNodeNew = Abc_ObjChild0(pNode);
397 else assert( 0 );
398 // replace
399 if ( pFanout == NULL )
400 return Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pNode, pNodeNew, 1 );
401 // find the fanout after redundancy removal
402 if ( pNode == Abc_ObjFanin0(pFanout) )
403 pFanoutNew = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, Abc_ObjNotCond(pNodeNew,Abc_ObjFaninC0(pFanout)), Abc_ObjChild1(pFanout) );
404 else if ( pNode == Abc_ObjFanin1(pFanout) )
405 pFanoutNew = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, Abc_ObjNotCond(pNodeNew,Abc_ObjFaninC1(pFanout)), Abc_ObjChild0(pFanout) );
406 else assert( 0 );
407 // replace
408 Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pFanout, pFanoutNew, 1 );
409 return 1;
410}
411
426int Abc_NtkRRWindow( Abc_RRMan_t * p )
427{
428 Abc_Obj_t * pObj, * pEdgeFanin, * pEdgeFanout;
429 int i, LevelMin, LevelMax, RetValue;
430
431 // get the edge
432 pEdgeFanout = p->pFanout? p->pFanout : p->pNode;
433 pEdgeFanin = p->pFanout? p->pNode : p->pFanin;
434 // get the minimum and maximum levels of the window
435 LevelMin = Abc_MaxInt( 0, ((int)p->pFanin->Level) - p->nFaninLevels );
436 LevelMax = (int)pEdgeFanout->Level + p->nFanoutLevels;
437
438 // start the TFI leaves with the fanin
439 Abc_NtkIncrementTravId( p->pNtk );
440 Abc_NodeSetTravIdCurrent( p->pFanin );
441 Vec_PtrPush( p->vFaninLeaves, p->pFanin );
442 // mark the TFI cone and collect the leaves down to the given level
443 while ( Abc_NtkRRTfi_int(p->vFaninLeaves, LevelMin) );
444
445 // mark the leaves with the new TravId
446 Abc_NtkIncrementTravId( p->pNtk );
447 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninLeaves, pObj, i )
448 Abc_NodeSetTravIdCurrent( pObj );
449 // traverse the TFO cone of the leaves (while skipping the edge)
450 // (a) mark the nodes in the cone using the current TravId
451 // (b) collect the nodes that have external fanouts into p->vFanoutRoots
452 while ( Abc_NtkRRTfo_int(p->vFaninLeaves, p->vFanoutRoots, LevelMax, pEdgeFanin, pEdgeFanout) );
453
454 // mark the fanout roots
455 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanoutRoots, pObj, i )
456 pObj->fMarkA = 1;
457 // collect roots reachable from the fanout (p->vRoots)
458 RetValue = Abc_NtkRRTfo_rec( pEdgeFanout, p->vRoots, LevelMax + 1 );
459 // unmark the fanout roots
460 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanoutRoots, pObj, i )
461 pObj->fMarkA = 0;
462
463 // return if the window is infeasible
464 if ( RetValue == 0 )
465 return 0;
466
467 // collect the DFS-ordered new cone (p->vCone) and new leaves (p->vLeaves)
468 // using the previous marks coming from the TFO cone
469 Abc_NtkIncrementTravId( p->pNtk );
470 Vec_PtrForEachEntry( Abc_Obj_t *, p->vRoots, pObj, i )
471 Abc_NtkRRTfi_rec( pObj, p->vLeaves, p->vCone, LevelMin );
472
473 // create a new network
474 p->pWnd = Abc_NtkWindow( p->pNtk, p->vLeaves, p->vCone, p->vRoots );
475 return 1;
476}
477
489int Abc_NtkRRTfi_int( Vec_Ptr_t * vLeaves, int LevelLimit )
490{
491 Abc_Obj_t * pObj, * pNext;
492 int i, k, LevelMax, nSize;
493 assert( LevelLimit >= 0 );
494 // find the maximum level of leaves
495 LevelMax = 0;
496 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
497 if ( LevelMax < (int)pObj->Level )
498 LevelMax = pObj->Level;
499 // if the nodes are all PIs, LevelMax == 0
500 if ( LevelMax <= LevelLimit )
501 return 0;
502 // expand the nodes with the minimum level
503 nSize = Vec_PtrSize(vLeaves);
504 Vec_PtrForEachEntryStop( Abc_Obj_t *, vLeaves, pObj, i, nSize )
505 {
506 if ( LevelMax != (int)pObj->Level )
507 continue;
508 Abc_ObjForEachFanin( pObj, pNext, k )
509 {
510 if ( Abc_NodeIsTravIdCurrent(pNext) )
511 continue;
512 Abc_NodeSetTravIdCurrent( pNext );
513 Vec_PtrPush( vLeaves, pNext );
514 }
515 }
516 // remove old nodes (cannot remove a PI)
517 k = 0;
518 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
519 {
520 if ( LevelMax == (int)pObj->Level )
521 continue;
522 Vec_PtrWriteEntry( vLeaves, k++, pObj );
523 }
524 Vec_PtrShrink( vLeaves, k );
525 if ( Vec_PtrSize(vLeaves) > 2000 )
526 return 0;
527 return 1;
528}
529
541int Abc_NtkRRTfo_int( Vec_Ptr_t * vLeaves, Vec_Ptr_t * vRoots, int LevelLimit, Abc_Obj_t * pEdgeFanin, Abc_Obj_t * pEdgeFanout )
542{
543 Abc_Obj_t * pObj, * pNext;
544 int i, k, LevelMin, nSize, fObjIsRoot;
545 // find the minimum level of leaves
546 LevelMin = ABC_INFINITY;
547 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
548 if ( LevelMin > (int)pObj->Level )
549 LevelMin = pObj->Level;
550 // if the minimum level exceed the limit, we are done
551 if ( LevelMin > LevelLimit )
552 return 0;
553 // expand the nodes with the minimum level
554 nSize = Vec_PtrSize(vLeaves);
555 Vec_PtrForEachEntryStop( Abc_Obj_t *, vLeaves, pObj, i, nSize )
556 {
557 if ( LevelMin != (int)pObj->Level )
558 continue;
559 fObjIsRoot = 0;
560 Abc_ObjForEachFanout( pObj, pNext, k )
561 {
562 // check if the fanout is outside of the cone
563 if ( Abc_ObjIsCo(pNext) || pNext->Level > (unsigned)LevelLimit )
564 {
565 fObjIsRoot = 1;
566 continue;
567 }
568 // skip the edge under check
569 if ( pObj == pEdgeFanin && pNext == pEdgeFanout )
570 continue;
571 // skip the visited fanouts
572 if ( Abc_NodeIsTravIdCurrent(pNext) )
573 continue;
574 Abc_NodeSetTravIdCurrent( pNext );
575 Vec_PtrPush( vLeaves, pNext );
576 }
577 if ( fObjIsRoot )
578 Vec_PtrPush( vRoots, pObj );
579 }
580 // remove old nodes
581 k = 0;
582 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
583 {
584 if ( LevelMin == (int)pObj->Level )
585 continue;
586 Vec_PtrWriteEntry( vLeaves, k++, pObj );
587 }
588 Vec_PtrShrink( vLeaves, k );
589 if ( Vec_PtrSize(vLeaves) > 2000 )
590 return 0;
591 return 1;
592}
593
606int Abc_NtkRRTfo_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vRoots, int LevelLimit )
607{
608 Abc_Obj_t * pFanout;
609 int i;
610 // if we encountered a node outside of the TFO cone of the fanins, quit
611 if ( Abc_ObjIsCo(pNode) || pNode->Level > (unsigned)LevelLimit )
612 return 0;
613 // if we encountered a node on the boundary, add it to the roots
614 if ( pNode->fMarkA )
615 {
616 Vec_PtrPushUnique( vRoots, pNode );
617 return 1;
618 }
619 // mark the node with the current TravId (needed to have all internal nodes marked)
620 Abc_NodeSetTravIdCurrent( pNode );
621 // traverse the fanouts
622 Abc_ObjForEachFanout( pNode, pFanout, i )
623 if ( !Abc_NtkRRTfo_rec( pFanout, vRoots, LevelLimit ) )
624 return 0;
625 return 1;
626}
627
639void Abc_NtkRRTfi_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vCone, int LevelLimit )
640{
641 Abc_Obj_t * pFanin;
642 int i;
643 // skip visited nodes
644 if ( Abc_NodeIsTravIdCurrent(pNode) )
645 return;
646 // add node to leaves if it is not in TFI cone of the leaves (marked before) or below the limit
647 if ( !Abc_NodeIsTravIdPrevious(pNode) || (int)pNode->Level <= LevelLimit )
648 {
649 Abc_NodeSetTravIdCurrent( pNode );
650 Vec_PtrPush( vLeaves, pNode );
651 return;
652 }
653 // mark the node as visited
654 Abc_NodeSetTravIdCurrent( pNode );
655 // call for the node's fanins
656 Abc_ObjForEachFanin( pNode, pFanin, i )
657 Abc_NtkRRTfi_rec( pFanin, vLeaves, vCone, LevelLimit );
658 // add the node to the cone in topological order
659 Vec_PtrPush( vCone, pNode );
660}
661
673Abc_Ntk_t * Abc_NtkWindow( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vCone, Vec_Ptr_t * vRoots )
674{
675 Abc_Ntk_t * pNtkNew;
676 Abc_Obj_t * pObj;
677 int fCheck = 1;
678 int i;
679 assert( Abc_NtkIsStrash(pNtk) );
680 // start the network
681 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
682 // duplicate the name and the spec
683 pNtkNew->pName = Extra_UtilStrsav( "temp" );
684 // map the constant nodes
685 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
686 // create and map the PIs
687 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
688 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
689 // copy the AND gates
690 Vec_PtrForEachEntry( Abc_Obj_t *, vCone, pObj, i )
691 pObj->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
692 // compare the number of nodes before and after
693 if ( Vec_PtrSize(vCone) != Abc_NtkNodeNum(pNtkNew) )
694 printf( "Warning: Structural hashing during windowing reduced %d nodes (this is a bug).\n",
695 Vec_PtrSize(vCone) - Abc_NtkNodeNum(pNtkNew) );
696 // create the POs
697 Vec_PtrForEachEntry( Abc_Obj_t *, vRoots, pObj, i )
698 {
699 assert( !Abc_ObjIsComplement(pObj->pCopy) );
700 Abc_ObjAddFanin( Abc_NtkCreatePo(pNtkNew), pObj->pCopy );
701 }
702 // add the PI/PO names
703 Abc_NtkAddDummyPiNames( pNtkNew );
704 Abc_NtkAddDummyPoNames( pNtkNew );
705 // check
706 if ( fCheck && !Abc_NtkCheck( pNtkNew ) )
707 {
708 printf( "Abc_NtkWindow: The network check has failed.\n" );
709 return NULL;
710 }
711 return pNtkNew;
712}
713
714
726void Abc_NtkRRSimulateStart( Abc_Ntk_t * pNtk )
727{
728 Abc_Obj_t * pObj;
729 unsigned uData, uData0, uData1;
730 int i;
731 Abc_AigConst1(pNtk)->pData = (void *)~((unsigned)0);
732 Abc_NtkForEachCi( pNtk, pObj, i )
733 pObj->pData = (void *)(ABC_PTRUINT_T)SIM_RANDOM_UNSIGNED;
734 Abc_NtkForEachNode( pNtk, pObj, i )
735 {
736 if ( i == 0 ) continue;
737 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData;
738 uData1 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin1(pObj)->pData;
739 uData = Abc_ObjFaninC0(pObj)? ~uData0 : uData0;
740 uData &= Abc_ObjFaninC1(pObj)? ~uData1 : uData1;
741 assert( pObj->pData == NULL );
742 pObj->pData = (void *)(ABC_PTRUINT_T)uData;
743 }
744}
745
757void Abc_NtkRRSimulateStop( Abc_Ntk_t * pNtk )
758{
759 Abc_Obj_t * pObj;
760 int i;
761 Abc_NtkForEachObj( pNtk, pObj, i )
762 pObj->pData = NULL;
763}
764
765
766
767
768
769
770
771static void Sim_TraverseNodes_rec( Abc_Obj_t * pRoot, Vec_Str_t * vTargets, Vec_Ptr_t * vNodes );
772static void Sim_CollectNodes_rec( Abc_Obj_t * pRoot, Vec_Ptr_t * vField );
773static void Sim_SimulateCollected( Vec_Str_t * vTargets, Vec_Ptr_t * vNodes, Vec_Ptr_t * vField );
774
787{
788 Vec_Ptr_t * vNodes, * vField;
789 Vec_Str_t * vTargets;
790 Abc_Obj_t * pObj;
791 unsigned uData, uData0, uData1;
792 int PrevCi, Phase, i, k;
793
794 // start the candidates
795 vTargets = Vec_StrStart( Abc_NtkObjNumMax(pNtk) + 1 );
796 Abc_NtkForEachNode( pNtk, pObj, i )
797 {
798 Phase = ((Abc_ObjFanoutNum(Abc_ObjFanin1(pObj)) > 1) << 1);
799 Phase |= (Abc_ObjFanoutNum(Abc_ObjFanin0(pObj)) > 1);
800 Vec_StrWriteEntry( vTargets, pObj->Id, (char)Phase );
801 }
802
803 // simulate patters and store them in copy
804 Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)~((unsigned)0);
805 Abc_NtkForEachCi( pNtk, pObj, i )
806 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)SIM_RANDOM_UNSIGNED;
807 Abc_NtkForEachNode( pNtk, pObj, i )
808 {
809 if ( i == 0 ) continue;
810 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData;
811 uData1 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin1(pObj)->pData;
812 uData = Abc_ObjFaninC0(pObj)? ~uData0 : uData0;
813 uData &= Abc_ObjFaninC1(pObj)? ~uData1 : uData1;
814 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)uData;
815 }
816 // store the result in data
817 Abc_NtkForEachCo( pNtk, pObj, i )
818 {
819 uData0 = (unsigned)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData;
820 if ( Abc_ObjFaninC0(pObj) )
821 pObj->pData = (void *)(ABC_PTRUINT_T)~uData0;
822 else
823 pObj->pData = (void *)(ABC_PTRUINT_T)uData0;
824 }
825
826 // refine the candidates
827 for ( PrevCi = 0; PrevCi < Abc_NtkCiNum(pNtk); PrevCi = i )
828 {
829 vNodes = Vec_PtrAlloc( 10 );
830 Abc_NtkIncrementTravId( pNtk );
831 for ( i = PrevCi; i < Abc_NtkCiNum(pNtk); i++ )
832 {
833 Sim_TraverseNodes_rec( Abc_NtkCi(pNtk, i), vTargets, vNodes );
834 if ( Vec_PtrSize(vNodes) > 128 )
835 break;
836 }
837 // collect the marked nodes in the topological order
838 vField = Vec_PtrAlloc( 10 );
839 Abc_NtkIncrementTravId( pNtk );
840 Abc_NtkForEachCo( pNtk, pObj, k )
841 Sim_CollectNodes_rec( pObj, vField );
842
843 // simulate these nodes
844 Sim_SimulateCollected( vTargets, vNodes, vField );
845 // prepare for the next loop
846 Vec_PtrFree( vNodes );
847 }
848
849 // clean
850 Abc_NtkForEachObj( pNtk, pObj, i )
851 pObj->pData = NULL;
852 return vTargets;
853}
854
866void Sim_TraverseNodes_rec( Abc_Obj_t * pRoot, Vec_Str_t * vTargets, Vec_Ptr_t * vNodes )
867{
868 Abc_Obj_t * pFanout;
869 char Entry;
870 int k;
871 if ( Abc_NodeIsTravIdCurrent(pRoot) )
872 return;
873 Abc_NodeSetTravIdCurrent( pRoot );
874 // save the reached targets
875 Entry = Vec_StrEntry(vTargets, pRoot->Id);
876 if ( Entry & 1 )
877 Vec_PtrPush( vNodes, Abc_ObjNot(pRoot) );
878 if ( Entry & 2 )
879 Vec_PtrPush( vNodes, pRoot );
880 // explore the fanouts
881 Abc_ObjForEachFanout( pRoot, pFanout, k )
882 Sim_TraverseNodes_rec( pFanout, vTargets, vNodes );
883}
884
896void Sim_CollectNodes_rec( Abc_Obj_t * pRoot, Vec_Ptr_t * vField )
897{
898 Abc_Obj_t * pFanin;
899 int i;
900 if ( Abc_NodeIsTravIdCurrent(pRoot) )
901 return;
902 if ( !Abc_NodeIsTravIdPrevious(pRoot) )
903 return;
904 Abc_NodeSetTravIdCurrent( pRoot );
905 Abc_ObjForEachFanin( pRoot, pFanin, i )
906 Sim_CollectNodes_rec( pFanin, vField );
907 if ( !Abc_ObjIsCo(pRoot) )
908 pRoot->pData = (void *)(ABC_PTRUINT_T)Vec_PtrSize(vField);
909 Vec_PtrPush( vField, pRoot );
910}
911
923void Sim_SimulateCollected( Vec_Str_t * vTargets, Vec_Ptr_t * vNodes, Vec_Ptr_t * vField )
924{
925 Abc_Obj_t * pObj, * pFanin0, * pFanin1, * pDisproved;
926 Vec_Ptr_t * vSims;
927 unsigned * pUnsigned, * pUnsignedF;
928 int i, k, Phase, fCompl;
929 // get simulation info
930 vSims = Sim_UtilInfoAlloc( Vec_PtrSize(vField), Vec_PtrSize(vNodes), 0 );
931 // simulate the nodes
932 Vec_PtrForEachEntry( Abc_Obj_t *, vField, pObj, i )
933 {
934 if ( Abc_ObjIsCi(pObj) )
935 {
936 pUnsigned = (unsigned *)Vec_PtrEntry( vSims, i );
937 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
938 pUnsigned[k] = (unsigned)(ABC_PTRUINT_T)pObj->pCopy;
939 continue;
940 }
941 if ( Abc_ObjIsCo(pObj) )
942 {
943 pUnsigned = (unsigned *)Vec_PtrEntry( vSims, i );
944 pUnsignedF = (unsigned *)Vec_PtrEntry( vSims, (int)(ABC_PTRUINT_T)Abc_ObjFanin0(pObj)->pData );
945 if ( Abc_ObjFaninC0(pObj) )
946 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
947 pUnsigned[k] = ~pUnsignedF[k];
948 else
949 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
950 pUnsigned[k] = pUnsignedF[k];
951 // update targets
952 for ( k = 0; k < Vec_PtrSize(vNodes); k++ )
953 {
954 if ( pUnsigned[k] == (unsigned)(ABC_PTRUINT_T)pObj->pData )
955 continue;
956 pDisproved = (Abc_Obj_t *)Vec_PtrEntry( vNodes, k );
957 fCompl = Abc_ObjIsComplement(pDisproved);
958 pDisproved = Abc_ObjRegular(pDisproved);
959 Phase = Vec_StrEntry( vTargets, pDisproved->Id );
960 if ( fCompl )
961 Phase = (Phase & 2);
962 else
963 Phase = (Phase & 1);
964 Vec_StrWriteEntry( vTargets, pDisproved->Id, (char)Phase );
965 }
966 continue;
967 }
968 // simulate the node
969 pFanin0 = Abc_ObjFanin0(pObj);
970 pFanin1 = Abc_ObjFanin1(pObj);
971 }
972}
973
974
975
976/*
977 {
978 unsigned uData;
979 if ( pFanin == Abc_ObjFanin0(pNode) )
980 {
981 uData = (unsigned)Abc_ObjFanin1(pNode)->pData;
982 uData = Abc_ObjFaninC1(pNode)? ~uData : uData;
983 }
984 else if ( pFanin == Abc_ObjFanin1(pNode) )
985 {
986 uData = (unsigned)Abc_ObjFanin0(pNode)->pData;
987 uData = Abc_ObjFaninC0(pNode)? ~uData : uData;
988 }
989 uData ^= (unsigned)pNode->pData;
990// Extra_PrintBinary( stdout, &uData, 32 ); printf( "\n" );
991 if ( Extra_WordCountOnes(uData) > 8 )
992 continue;
993 }
994*/
995
999
1000
1002
typedefABC_NAMESPACE_IMPL_START struct Abc_RRMan_t_ Abc_RRMan_t
DECLARATIONS ///.
Definition abcRr.c:32
int Abc_NtkRR(Abc_Ntk_t *pNtk, int nFaninLevels, int nFanoutLevels, int fUseFanouts, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcRr.c:98
Vec_Str_t * Abc_NtkRRSimulate(Abc_Ntk_t *pNtk)
Definition abcRr.c:786
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL int Abc_NtkIsDfsOrdered(Abc_Ntk_t *pNtk)
Definition abcDfs.c:698
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
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
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
ABC_DLL int Abc_NtkMiterProve(Abc_Ntk_t **ppNtk, void *pParams)
FUNCTION DEFINITIONS ///.
Definition abcProve.c:62
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:521
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
ABC_DLL Abc_Ntk_t * Abc_NtkMiter(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fComb, int nPartSize, int fImplic, int fMulti)
FUNCTION DEFINITIONS ///.
Definition abcMiter.c:59
ABC_DLL int Abc_AigLevel(Abc_Ntk_t *pNtk)
Definition abcAig.c:292
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
ABC_DLL void Abc_NtkReassignIds(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1809
ABC_DLL int Abc_AigReplace(Abc_Aig_t *pMan, Abc_Obj_t *pOld, Abc_Obj_t *pNew, int fUpdateLevel)
Definition abcAig.c:850
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition abcNtk.c:472
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:495
#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
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_UtilStrsav(const char *s)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
void Prove_ParamsSetDefault(Prove_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition fraigMan.c:46
struct Prove_ParamsStruct_t_ Prove_Params_t
Definition ivyFraig.c:108
Vec_Ptr_t * Sim_UtilInfoAlloc(int nSize, int nWords, int fClean)
FUNCTION DEFINITIONS ///.
Definition simUtils.c:57
#define SIM_RANDOM_UNSIGNED
Definition sim.h:158
Abc_NtkType_t ntkType
Definition abc.h:156
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
Abc_NtkFunc_t ntkFunc
Definition abc.h:157
void * pData
Definition abc.h:145
int Id
Definition abc.h:132
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
unsigned Level
Definition abc.h:142
Vec_Ptr_t * vFanoutRoots
Definition abcRr.c:45
Vec_Ptr_t * vLeaves
Definition abcRr.c:47
Abc_Ntk_t * pMiter
Definition abcRr.c:52
Vec_Ptr_t * vCone
Definition abcRr.c:48
Abc_Ntk_t * pWnd
Definition abcRr.c:50
int nLevelsOld
Definition abcRr.c:56
abctime timeProve
Definition abcRr.c:61
abctime timeMiter
Definition abcRr.c:60
abctime timeTotal
Definition abcRr.c:63
abctime timeUpdate
Definition abcRr.c:62
int nFanoutLevels
Definition abcRr.c:38
Prove_Params_t * pParams
Definition abcRr.c:53
Abc_Ntk_t * pNtk
Definition abcRr.c:36
int nNodesOld
Definition abcRr.c:55
int nEdgesRemoved
Definition abcRr.c:58
Abc_Obj_t * pFanin
Definition abcRr.c:41
Abc_Obj_t * pFanout
Definition abcRr.c:42
Vec_Ptr_t * vRoots
Definition abcRr.c:49
int nFaninLevels
Definition abcRr.c:37
Abc_Obj_t * pNode
Definition abcRr.c:40
Vec_Ptr_t * vFaninLeaves
Definition abcRr.c:44
int nEdgesTried
Definition abcRr.c:57
abctime timeWindow
Definition abcRr.c:59
#define assert(ex)
Definition util_old.h:213
char * memset()
#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