ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaCof.c
Go to the documentation of this file.
1
20
21#include <math.h>
22#include "gia.h"
23
25
26
30
31typedef struct Cof_Fan_t_ Cof_Fan_t;
33{
34 unsigned iFan : 31; // ID of the fanin/fanout
35 unsigned fCompl : 1; // complemented attribute
36};
37
38typedef struct Cof_Obj_t_ Cof_Obj_t;
40{
41 unsigned fTerm : 1; // terminal node (CI/CO)
42 unsigned fPhase : 1; // value under 000 pattern
43 unsigned fMark0 : 1; // first user-controlled mark
44 unsigned fMark1 : 1; // second user-controlled mark
45 unsigned nFanins : 4; // the number of fanins
46 unsigned nFanouts : 24; // total number of fanouts
47 unsigned nFanoutsM; // total number of MUX ctrl fanouts
48 unsigned Value; // application specific data
49 int Id; // ID of the node
50 int iNext; // next one in the linked list
51 int iLit; // literal of the node after rehashing
52 Cof_Fan_t Fanios[0]; // the array of fanins/fanouts
53};
54
55typedef struct Cof_Man_t_ Cof_Man_t;
57{
58 Gia_Man_t * pGia; // the original AIG manager
59 Vec_Int_t * vCis; // the vector of CIs (PIs + LOs)
60 Vec_Int_t * vCos; // the vector of COs (POs + LIs)
61 int nObjs; // the number of objects
62 int nNodes; // the number of nodes
63 int nTravIds; // traversal ID of the network
64 int * pObjData; // the logic network defined for the AIG
65 int nObjData; // the size of array to store the logic network
66 int * pLevels; // the linked lists of levels
67 int nLevels; // the max number of logic levels
68};
69
70static inline unsigned Gia_ObjHandle( Gia_Obj_t * pObj ) { return pObj->Value; }
71
72static inline int Cof_ObjLevel( Cof_Man_t * p, Cof_Obj_t * pObj ) { return Gia_ObjLevel(p->pGia, Gia_ManObj(p->pGia,pObj->Id)); }
73
74static inline unsigned Cof_ObjHandle( Cof_Man_t * p, Cof_Obj_t * pObj ) { return (unsigned)(((int *)pObj) - p->pObjData); }
75static inline unsigned Cof_ObjHandleDiff( Cof_Obj_t * pObj, Cof_Obj_t * pFanin ) { return (unsigned)(((int *)pObj) - ((int *)pFanin)); }
76
77static inline int Cof_ObjIsTerm( Cof_Obj_t * pObj ) { return pObj->fTerm; }
78static inline int Cof_ObjIsCi( Cof_Obj_t * pObj ) { return pObj->fTerm && pObj->nFanins == 0; }
79static inline int Cof_ObjIsCo( Cof_Obj_t * pObj ) { return pObj->fTerm && pObj->nFanins == 1; }
80static inline int Cof_ObjIsNode( Cof_Obj_t * pObj ) { return!pObj->fTerm && pObj->nFanins > 0; }
81static inline int Cof_ObjIsConst0( Cof_Obj_t * pObj ) { return!pObj->fTerm && pObj->nFanins == 0; }
82
83static inline int Cof_ObjFaninNum( Cof_Obj_t * pObj ) { return pObj->nFanins; }
84static inline int Cof_ObjFanoutNum( Cof_Obj_t * pObj ) { return pObj->nFanouts; }
85static inline int Cof_ObjSize( Cof_Obj_t * pObj ) { return sizeof(Cof_Obj_t) / 4 + pObj->nFanins + pObj->nFanouts; }
86
87static inline Cof_Obj_t * Cof_ManObj( Cof_Man_t * p, unsigned iHandle ) { return (Cof_Obj_t *)(p->pObjData + iHandle); }
88static inline Cof_Obj_t * Cof_ObjFanin( Cof_Obj_t * pObj, int i ) { return (Cof_Obj_t *)(((int *)pObj) - pObj->Fanios[i].iFan); }
89static inline Cof_Obj_t * Cof_ObjFanout( Cof_Obj_t * pObj, int i ) { return (Cof_Obj_t *)(((int *)pObj) + pObj->Fanios[pObj->nFanins+i].iFan); }
90
91static inline int Cof_ManObjNum( Cof_Man_t * p ) { return p->nObjs; }
92static inline int Cof_ManNodeNum( Cof_Man_t * p ) { return p->nNodes; }
93
94static inline void Cof_ManResetTravId( Cof_Man_t * p ) { extern void Cof_ManCleanValue( Cof_Man_t * p ); Cof_ManCleanValue( p ); p->nTravIds = 1; }
95static inline void Cof_ManIncrementTravId( Cof_Man_t * p ) { p->nTravIds++; }
96static inline void Cof_ObjSetTravId( Cof_Obj_t * pObj, int TravId ) { pObj->Value = TravId; }
97static inline void Cof_ObjSetTravIdCurrent( Cof_Man_t * p, Cof_Obj_t * pObj ) { pObj->Value = p->nTravIds; }
98static inline void Cof_ObjSetTravIdPrevious( Cof_Man_t * p, Cof_Obj_t * pObj ) { pObj->Value = p->nTravIds - 1; }
99static inline int Cof_ObjIsTravIdCurrent( Cof_Man_t * p, Cof_Obj_t * pObj ) { return ((int)pObj->Value == p->nTravIds); }
100static inline int Cof_ObjIsTravIdPrevious( Cof_Man_t * p, Cof_Obj_t * pObj ) { return ((int)pObj->Value == p->nTravIds - 1); }
101
102#define Cof_ManForEachObj( p, pObj, i ) \
103 for ( i = 0; (i < p->nObjData) && (pObj = Cof_ManObj(p,i)); i += Cof_ObjSize(pObj) )
104#define Cof_ManForEachNode( p, pObj, i ) \
105 for ( i = 0; (i < p->nObjData) && (pObj = Cof_ManObj(p,i)); i += Cof_ObjSize(pObj) ) if ( Cof_ObjIsTerm(pObj) ) {} else
106#define Cof_ObjForEachFanin( pObj, pNext, i ) \
107 for ( i = 0; (i < (int)pObj->nFanins) && (pNext = Cof_ObjFanin(pObj,i)); i++ )
108#define Cof_ObjForEachFanout( pObj, pNext, i ) \
109 for ( i = 0; (i < (int)pObj->nFanouts) && (pNext = Cof_ObjFanout(pObj,i)); i++ )
110
114
127{
128 Cof_Man_t * p;
129 Cof_Obj_t * pObjLog, * pFanLog;
130 Gia_Obj_t * pObj;
131 int * pMuxRefs;
132 int i, iHandle = 0;
133 p = ABC_CALLOC( Cof_Man_t, 1 );
134 p->pGia = pGia;
135 p->vCis = Vec_IntAlloc( Gia_ManCiNum(pGia) );
136 p->vCos = Vec_IntAlloc( Gia_ManCoNum(pGia) );
137 p->nObjData = (sizeof(Cof_Obj_t) / 4) * Gia_ManObjNum(pGia) + 4 * Gia_ManAndNum(pGia) + 2 * Gia_ManCoNum(pGia);
138 p->pObjData = ABC_CALLOC( int, p->nObjData );
139 ABC_FREE( pGia->pRefs );
140 Gia_ManCreateRefs( pGia );
141 Gia_ManForEachObj( pGia, pObj, i )
142 {
143 pObj->Value = iHandle;
144 pObjLog = Cof_ManObj( p, iHandle );
145 pObjLog->nFanins = 0;
146 pObjLog->nFanouts = Gia_ObjRefNum( pGia, pObj );
147 pObjLog->Id = i;
148 pObjLog->Value = 0;
149 if ( Gia_ObjIsAnd(pObj) )
150 {
151 pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) );
152 pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan =
153 pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog );
154 pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj);
155
156 pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin1(pObj)) );
157 pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan =
158 pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog );
159 pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC1(pObj);
160 p->nNodes++;
161 }
162 else if ( Gia_ObjIsCo(pObj) )
163 {
164 pFanLog = Cof_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) );
165 pFanLog->Fanios[pFanLog->nFanins + pFanLog->Value++].iFan =
166 pObjLog->Fanios[pObjLog->nFanins].iFan = Cof_ObjHandleDiff( pObjLog, pFanLog );
167 pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj);
168
169 pObjLog->fTerm = 1;
170 Vec_IntPush( p->vCos, iHandle );
171 }
172 else if ( Gia_ObjIsCi(pObj) )
173 {
174 pObjLog->fTerm = 1;
175 Vec_IntPush( p->vCis, iHandle );
176 }
177 iHandle += Cof_ObjSize( pObjLog );
178 p->nObjs++;
179 }
180 assert( iHandle == p->nObjData );
181 pMuxRefs = Gia_ManCreateMuxRefs( pGia );
182 Gia_ManForEachObj( pGia, pObj, i )
183 {
184 pObjLog = Cof_ManObj( p, Gia_ObjHandle(pObj) );
185 assert( pObjLog->nFanouts == pObjLog->Value );
186 pObjLog->nFanoutsM = pMuxRefs[i];
187 }
188 ABC_FREE( pMuxRefs );
189 return p;
190}
191
204{
205 Vec_IntFree( p->vCis );
206 Vec_IntFree( p->vCos );
207 ABC_FREE( p->pObjData );
208 ABC_FREE( p->pLevels );
209 ABC_FREE( p );
210}
211
212
225{
226 Cof_Obj_t * pNext;
227 unsigned i, Counter = 0;
228 if ( Cof_ObjIsTravIdCurrent(p, pObj) )
229 return 0;
230 Cof_ObjSetTravIdCurrent(p, pObj);
231 if ( Cof_ObjIsCo(pObj) )
232 return 0;
233 assert( Cof_ObjIsCi(pObj) || Cof_ObjIsNode(pObj) );
234 Cof_ObjForEachFanout( pObj, pNext, i )
235 Counter += Cof_ManTfoSize_rec( p, pNext );
236 return 1 + Counter;
237}
238
250int Cof_ManTfoSize( Cof_Man_t * p, Cof_Obj_t ** ppObjs, int nObjs )
251{
252 int i, Counter = 0;
253 Cof_ManIncrementTravId( p );
254 for ( i = 0; i < nObjs; i++ )
255 Counter += Cof_ManTfoSize_rec( p, ppObjs[i] ) - 1;
256 return Counter;
257}
258
271{
272 Cof_Obj_t * pNext;
273 unsigned i, Counter = 0;
274 if ( Cof_ObjIsTravIdCurrent(p, pObj) )
275 return 0;
276 Cof_ObjSetTravIdCurrent(p, pObj);
277 if ( Cof_ObjIsCi(pObj) )
278 return 0;
279 assert( Cof_ObjIsNode(pObj) );
280 Cof_ObjForEachFanin( pObj, pNext, i )
281 Counter += Cof_ManTfiSize_rec( p, pNext );
282 return 1 + Counter;
283}
284
296int Cof_ManTfiSize( Cof_Man_t * p, Cof_Obj_t ** ppObjs, int nObjs )
297{
298 int i, Counter = 0;
299 Cof_ManIncrementTravId( p );
300 for ( i = 0; i < nObjs; i++ )
301 if ( Cof_ObjIsCo(ppObjs[i]) )
302 Counter += Cof_ManTfiSize_rec( p, Cof_ObjFanin(ppObjs[i],0) );
303 else
304 Counter += Cof_ManTfiSize_rec( p, ppObjs[i] );
305 return Counter;
306}
307
320{
321 Cof_Obj_t * pNext;
322 unsigned i, Counter = 0;
323 if ( Cof_ObjIsTravIdCurrent(p, pObj) )
324 return 0;
325 Cof_ObjSetTravIdCurrent(p, pObj);
326 if ( Cof_ObjIsCi(pObj) )
327 return 1;
328 assert( Cof_ObjIsNode(pObj) );
329 Cof_ObjForEachFanin( pObj, pNext, i )
330 Counter += Cof_ManSuppSize_rec( p, pNext );
331 return Counter;
332}
333
345int Cof_ManSuppSize( Cof_Man_t * p, Cof_Obj_t ** ppObjs, int nObjs )
346{
347 int i, Counter = 0;
348 Cof_ManIncrementTravId( p );
349 for ( i = 0; i < nObjs; i++ )
350 if ( Cof_ObjIsCo(ppObjs[i]) )
351 Counter += Cof_ManSuppSize_rec( p, Cof_ObjFanin(ppObjs[i],0) );
352 else
353 Counter += Cof_ManSuppSize_rec( p, ppObjs[i] );
354 return Counter;
355}
356
357
370{
371 Cof_Obj_t * pObj;
372 int i;
373 Cof_ManForEachObj( p, pObj, i )
374 pObj->Value = 0;
375}
376
388void Cof_ManInsertEntry_rec( Vec_Ptr_t * vNodes, Cof_Obj_t * pNode, int nNodeMax )
389{
390 Cof_Obj_t * pLast;
391 if ( Vec_PtrSize(vNodes) == 0 )
392 {
393 Vec_PtrPush(vNodes, pNode);
394 return;
395 }
396 pLast = (Cof_Obj_t *)Vec_PtrPop(vNodes);
397 if ( Cof_ObjFanoutNum(pLast) < Cof_ObjFanoutNum(pNode) )
398 {
399 Cof_ManInsertEntry_rec( vNodes, pNode, nNodeMax );
400 if ( Vec_PtrSize(vNodes) < nNodeMax )
401 Vec_PtrPush( vNodes, pLast );
402 }
403 else
404 {
405 Vec_PtrPush( vNodes, pLast );
406 if ( Vec_PtrSize(vNodes) < nNodeMax )
407 Vec_PtrPush( vNodes, pNode );
408 }
409}
410
423{
424 Vec_Ptr_t * vNodes;
425 Cof_Obj_t * pObj;
426 int i;
427 vNodes = Vec_PtrAlloc( nNodes );
428 Cof_ManForEachObj( p, pObj, i )
429 if ( Cof_ObjIsCi(pObj) || Cof_ObjIsNode(pObj) )
430 Cof_ManInsertEntry_rec( vNodes, pObj, nNodes );
431 return vNodes;
432}
433
445int Cof_ManCountRemoved( Cof_Man_t * p, Cof_Obj_t * pRoot, int fConst1 )
446{
447 Gia_Obj_t * pNextGia;
448 Cof_Obj_t * pTemp, * pNext, * pFanin0, * pFanin1;
449 int Counter = 0, LevelStart, LevelNext;
450 int i, k, iHandle, iLit0, iLit1, iNextNew;
451 // restart the trav ids
452 Cof_ManIncrementTravId( p );
453 Cof_ObjSetTravIdCurrent( p, pRoot );
454 // add the node to the queue
455 LevelStart = Cof_ObjLevel(p, pRoot);
456 assert( p->pLevels[LevelStart] == 0 );
457 pRoot->iNext = 0;
458 p->pLevels[LevelStart] = Cof_ObjHandle( p, pRoot );
459 // set the new literal
460 pRoot->iLit = Abc_Var2Lit( 0, fConst1 );
461 // process nodes in the levelized order
462 for ( i = LevelStart; i < p->nLevels; i++ )
463 {
464 for ( iHandle = p->pLevels[i];
465 iHandle && (pTemp = Cof_ManObj(p, iHandle));
466 iHandle = pTemp->iNext )
467 {
468 assert( pTemp->Id != Abc_Lit2Var(pTemp->iLit) );
469 Cof_ObjForEachFanout( pTemp, pNext, k )
470 {
471 if ( Cof_ObjIsCo(pNext) )
472 continue;
473 if ( Cof_ObjIsTravIdCurrent(p, pNext) )
474 continue;
475 pFanin0 = Cof_ObjFanin( pNext, 0 );
476 pFanin1 = Cof_ObjFanin( pNext, 1 );
477 assert( pFanin0 == pTemp || pFanin1 == pTemp );
478 pNextGia = Gia_ManObj( p->pGia, pNext->Id );
479 if ( Cof_ObjIsTravIdCurrent(p, pFanin0) )
480 iLit0 = Abc_LitNotCond( pFanin0->iLit, Gia_ObjFaninC0(pNextGia) );
481 else
482 iLit0 = Gia_ObjFaninLit0( pNextGia, pNext->Id );
483 if ( Cof_ObjIsTravIdCurrent(p, pFanin1) )
484 iLit1 = Abc_LitNotCond( pFanin1->iLit, Gia_ObjFaninC1(pNextGia) );
485 else
486 iLit1 = Gia_ObjFaninLit1( pNextGia, pNext->Id );
487 iNextNew = Gia_ManHashAndTry( p->pGia, iLit0, iLit1 );
488 if ( iNextNew == -1 )
489 continue;
490 Cof_ObjSetTravIdCurrent(p, pNext);
491 // set the new literal
492 pNext->iLit = iNextNew;
493 // add it to be processed
494 LevelNext = Cof_ObjLevel( p, pNext );
495 assert( LevelNext > i && LevelNext < p->nLevels );
496 pNext->iNext = p->pLevels[LevelNext];
497 p->pLevels[LevelNext] = Cof_ObjHandle( p, pNext );
498 Counter++;
499 }
500 }
501 p->pLevels[i] = 0;
502 }
503 return Counter;
504}
505
518{
519 printf( "%7d : ", pObj->Id );
520 printf( "i/o/c =%2d %5d %5d ", Cof_ObjFaninNum(pObj), Cof_ObjFanoutNum(pObj), 2*pObj->nFanoutsM );
521 printf( "l =%4d ", Cof_ObjLevel(p, pObj) );
522 printf( "s =%5d ", Cof_ManSuppSize(p, &pObj, 1) );
523 printf( "TFI =%7d ", Cof_ManTfiSize(p, &pObj, 1) );
524 printf( "TFO =%7d ", Cof_ManTfoSize(p, &pObj, 1) );
525 printf( "C0 =%6d ", Cof_ManCountRemoved(p, pObj, 0) );
526 printf( "C1 =%6d", Cof_ManCountRemoved(p, pObj, 1) );
527 printf( "\n" );
528}
529
541void Cof_ManPrintHighFanout( Cof_Man_t * p, int nNodes )
542{
543 Vec_Ptr_t * vNodes;
544 Cof_Obj_t * pObj;
545 int i;
546 vNodes = Cof_ManCollectHighFanout( p, nNodes );
547 Vec_PtrForEachEntry( Cof_Obj_t *, vNodes, pObj, i )
549 Vec_PtrFree( vNodes );
550}
551
552
565{
566 if ( pNode->nFanins == 0 )
567 return 0;
568 if ( --pNode->nFanouts > 0 )
569 return 0;
570 return 1 + Cof_NodeDeref_rec( Cof_ObjFanin(pNode, 0) )
571 + Cof_NodeDeref_rec( Cof_ObjFanin(pNode, 1) );
572}
574{
575 if ( pNode->nFanins == 0 )
576 return 0;
577 if ( pNode->nFanouts++ > 0 )
578 return 0;
579 return 1 + Cof_NodeRef_rec( Cof_ObjFanin(pNode, 0) )
580 + Cof_NodeRef_rec( Cof_ObjFanin(pNode, 1) );
581}
582static inline int Cof_ObjMffcSize( Cof_Obj_t * pNode )
583{
584 int Count1, Count2, nFanout;
585 nFanout = pNode->nFanouts;
586 pNode->nFanouts = 1;
587 Count1 = Cof_NodeDeref_rec( pNode );
588 Count2 = Cof_NodeRef_rec( pNode );
589 pNode->nFanouts = nFanout;
590 assert( Count1 == Count2 );
591 return Count1;
592}
593
606{
607 char Buffer[100];
608 Cof_Obj_t * pNode;
609 Vec_Int_t * vFanins, * vFanouts, * vMffcs;
610 int nFanins, nFanouts, nMffcs, nFaninsMax, nFanoutsMax, nMffcsMax, nFaninsAll, nFanoutsAll, nMffcsAll;
611 int i, k, nSizeMax, nMffcNodes = 0;
612
613 // determine the largest fanin and fanout
614 nFaninsMax = nFanoutsMax = nMffcsMax = 0;
615 nFaninsAll = nFanoutsAll = nMffcsAll = 0;
616 Cof_ManForEachNode( p, pNode, i )
617 {
618 if ( i == 0 ) continue;
619 nFanins = Cof_ObjFaninNum(pNode);
620 nFanouts = Cof_ObjFanoutNum(pNode);
621 nMffcs = pNode->nFanouts > 1 ? Cof_ObjMffcSize(pNode) : 0;
622 nFaninsAll += nFanins;
623 nFanoutsAll += nFanouts;
624 nMffcsAll += nMffcs;
625 nFaninsMax = Abc_MaxInt( nFaninsMax, nFanins );
626 nFanoutsMax = Abc_MaxInt( nFanoutsMax, nFanouts );
627 nMffcsMax = Abc_MaxInt( nMffcsMax, nMffcs );
628 }
629
630 // allocate storage for fanin/fanout numbers
631 nSizeMax = Abc_MaxInt( 10 * (Abc_Base10Log(nFaninsMax) + 1), 10 * (Abc_Base10Log(nFanoutsMax) + 1) );
632 nSizeMax = Abc_MaxInt( 10 * (Abc_Base10Log(nMffcsMax) + 1), nSizeMax );
633 vFanins = Vec_IntStart( nSizeMax );
634 vFanouts = Vec_IntStart( nSizeMax );
635 vMffcs = Vec_IntStart( nSizeMax );
636
637 // count the number of fanins and fanouts
638 Cof_ManForEachNode( p, pNode, i )
639 {
640 if ( i == 0 ) continue;
641 nFanins = Cof_ObjFaninNum(pNode);
642 nFanouts = Cof_ObjFanoutNum(pNode);
643 nMffcs = pNode->nFanouts > 1 ? Cof_ObjMffcSize(pNode) : 0;
644
645 if ( nFanins < 10 )
646 Vec_IntAddToEntry( vFanins, nFanins, 1 );
647 else if ( nFanins < 100 )
648 Vec_IntAddToEntry( vFanins, 10 + nFanins/10, 1 );
649 else if ( nFanins < 1000 )
650 Vec_IntAddToEntry( vFanins, 20 + nFanins/100, 1 );
651 else if ( nFanins < 10000 )
652 Vec_IntAddToEntry( vFanins, 30 + nFanins/1000, 1 );
653 else if ( nFanins < 100000 )
654 Vec_IntAddToEntry( vFanins, 40 + nFanins/10000, 1 );
655 else if ( nFanins < 1000000 )
656 Vec_IntAddToEntry( vFanins, 50 + nFanins/100000, 1 );
657 else if ( nFanins < 10000000 )
658 Vec_IntAddToEntry( vFanins, 60 + nFanins/1000000, 1 );
659
660 if ( nFanouts < 10 )
661 Vec_IntAddToEntry( vFanouts, nFanouts, 1 );
662 else if ( nFanouts < 100 )
663 Vec_IntAddToEntry( vFanouts, 10 + nFanouts/10, 1 );
664 else if ( nFanouts < 1000 )
665 Vec_IntAddToEntry( vFanouts, 20 + nFanouts/100, 1 );
666 else if ( nFanouts < 10000 )
667 Vec_IntAddToEntry( vFanouts, 30 + nFanouts/1000, 1 );
668 else if ( nFanouts < 100000 )
669 Vec_IntAddToEntry( vFanouts, 40 + nFanouts/10000, 1 );
670 else if ( nFanouts < 1000000 )
671 Vec_IntAddToEntry( vFanouts, 50 + nFanouts/100000, 1 );
672 else if ( nFanouts < 10000000 )
673 Vec_IntAddToEntry( vFanouts, 60 + nFanouts/1000000, 1 );
674
675 if ( nMffcs == 0 )
676 continue;
677 nMffcNodes++;
678
679 if ( nMffcs < 10 )
680 Vec_IntAddToEntry( vMffcs, nMffcs, 1 );
681 else if ( nMffcs < 100 )
682 Vec_IntAddToEntry( vMffcs, 10 + nMffcs/10, 1 );
683 else if ( nMffcs < 1000 )
684 Vec_IntAddToEntry( vMffcs, 20 + nMffcs/100, 1 );
685 else if ( nMffcs < 10000 )
686 Vec_IntAddToEntry( vMffcs, 30 + nMffcs/1000, 1 );
687 else if ( nMffcs < 100000 )
688 Vec_IntAddToEntry( vMffcs, 40 + nMffcs/10000, 1 );
689 else if ( nMffcs < 1000000 )
690 Vec_IntAddToEntry( vMffcs, 50 + nMffcs/100000, 1 );
691 else if ( nMffcs < 10000000 )
692 Vec_IntAddToEntry( vMffcs, 60 + nMffcs/1000000, 1 );
693 }
694
695 printf( "The distribution of fanins, fanouts. and MFFCs in the network:\n" );
696 printf( " Number Nodes with fanin Nodes with fanout Nodes with MFFC\n" );
697
698 for ( k = 0; k < nSizeMax; k++ )
699 {
700 if ( vFanins->pArray[k] == 0 && vFanouts->pArray[k] == 0 && vMffcs->pArray[k] == 0 )
701 continue;
702 if ( k < 10 )
703 printf( "%15d : ", k );
704 else
705 {
706 sprintf( Buffer, "%d - %d", (int)pow((double)10, k/10) * (k%10), (int)pow((double)10, k/10) * (k%10+1) - 1 );
707 printf( "%15s : ", Buffer );
708 }
709 if ( vFanins->pArray[k] == 0 )
710 printf( " " );
711 else
712 printf( "%11d ", vFanins->pArray[k] );
713 printf( " " );
714 if ( vFanouts->pArray[k] == 0 )
715 printf( " " );
716 else
717 printf( "%12d ", vFanouts->pArray[k] );
718 printf( " " );
719 if ( vMffcs->pArray[k] == 0 )
720 printf( " " );
721 else
722 printf( " %12d ", vMffcs->pArray[k] );
723 printf( "\n" );
724 }
725 Vec_IntFree( vFanins );
726 Vec_IntFree( vFanouts );
727 Vec_IntFree( vMffcs );
728
729 printf( "Fanins: Max = %d. Ave = %.2f. Fanouts: Max = %d. Ave = %.2f. MFFCs: Max = %d. Ave = %.2f.\n",
730 nFaninsMax, 1.0*nFaninsAll /Cof_ManNodeNum(p),
731 nFanoutsMax, 1.0*nFanoutsAll/Cof_ManNodeNum(p),
732 nMffcsMax, 1.0*nMffcsAll /nMffcNodes );
733}
734
746void Gia_ManPrintFanio( Gia_Man_t * pGia, int nNodes )
747{
748 Cof_Man_t * p;
749 abctime clk = Abc_Clock();
750 p = Cof_ManCreateLogicSimple( pGia );
751 p->nLevels = 1 + Gia_ManLevelNum( pGia );
752 p->pLevels = ABC_CALLOC( int, p->nLevels );
754
755 if ( nNodes > 0 )
756 {
757 Cof_ManResetTravId( p );
758 Gia_ManHashStart( pGia );
759 Cof_ManPrintHighFanout( p, nNodes );
760 Gia_ManHashStop( pGia );
761ABC_PRMn( "Memory for logic network", 4*p->nObjData );
762ABC_PRT( "Time", Abc_Clock() - clk );
763 }
764
765 Cof_ManStop( p );
766}
767
768
781{
782 Gia_Man_t * pNew;
783 Gia_Obj_t * pObj, * pPivot;
784 int i, iCofVar = -1;
785 if ( !(iVar > 0 && iVar < Gia_ManObjNum(p)) )
786 {
787 printf( "Gia_ManDupCof(): Variable %d is out of range (%d; %d).\n", iVar, 0, Gia_ManObjNum(p) );
788 return NULL;
789 }
790 // find the cofactoring variable
791 pPivot = Gia_ManObj( p, iVar );
792 if ( !Gia_ObjIsCand(pPivot) )
793 {
794 printf( "Gia_ManDupCof(): Variable %d should be a CI or an AND node.\n", iVar );
795 return NULL;
796 }
797 pNew = Gia_ManStart( Gia_ManObjNum(p) );
798 pNew->pName = Abc_UtilStrsav( p->pName );
799 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
800 Gia_ManHashAlloc( pNew );
802 Gia_ManConst0(p)->Value = 0;
803 // compute negative cofactor
804 Gia_ManForEachCi( p, pObj, i )
805 {
806 pObj->Value = Gia_ManAppendCi(pNew);
807 if ( pObj == pPivot )
808 {
809 iCofVar = pObj->Value;
810 pObj->Value = Abc_Var2Lit( 0, 0 );
811 }
812 }
813 Gia_ManForEachAnd( p, pObj, i )
814 {
815 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
816 if ( pObj == pPivot )
817 {
818 iCofVar = pObj->Value;
819 pObj->Value = Abc_Var2Lit( 0, 0 );
820 }
821 }
822 Gia_ManForEachCo( p, pObj, i )
823 pObj->Value = Gia_ObjFanin0Copy(pObj);
824 // compute the positive cofactor
825 Gia_ManForEachCi( p, pObj, i )
826 {
827 pObj->Value = Abc_Var2Lit( Gia_ObjId(pNew, Gia_ManCi(pNew, i)), 0 );
828 if ( pObj == pPivot )
829 pObj->Value = Abc_Var2Lit( 0, 1 );
830 }
831 Gia_ManForEachAnd( p, pObj, i )
832 {
833 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
834 if ( pObj == pPivot )
835 pObj->Value = Abc_Var2Lit( 0, 1 );
836 }
837 // create MUXes
838 assert( iCofVar > 0 );
839 Gia_ManForEachCo( p, pObj, i )
840 {
841 if ( pObj->Value == (unsigned)Gia_ObjFanin0Copy(pObj) )
842 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
843 else
844 pObj->Value = Gia_ManAppendCo( pNew, Gia_ManHashMux(pNew, iCofVar, Gia_ObjFanin0Copy(pObj), pObj->Value) );
845 }
846 Gia_ManHashStop( pNew );
847 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
848 return pNew;
849}
850
863{
864 Gia_Man_t * pNew, * pTemp;
865 pNew = Gia_ManDupCofInt( p, iVar );
866 pNew = Gia_ManCleanup( pTemp = pNew );
867 Gia_ManStop( pTemp );
868 return pNew;
869}
870
871
884{
885 Vec_Int_t * vVars;
886 Gia_Obj_t * pObj;
887 int i;
888 ABC_FREE( p->pRefs );
890 vVars = Vec_IntAlloc( 100 );
891 Gia_ManForEachObj( p, pObj, i )
892 if ( Gia_ObjIsCand(pObj) && Gia_ObjRefNum(p, pObj) >= nFanLim )
893 Vec_IntPush( vVars, i );
894 ABC_FREE( p->pRefs );
895 return vVars;
896}
897
910{
911 Vec_Int_t * vSigsNew;
912 Gia_Obj_t * pObj, * pObjF;
913 int i;
914 vSigsNew = Vec_IntAlloc( 100 );
915 Gia_ManForEachObjVec( vSigs, pAig, pObj, i )
916 {
917 assert( Gia_ObjIsCand(pObj) );
918 pObjF = Gia_ManObj( pCof, Abc_Lit2Var(pObj->Value) );
919 if ( pObjF->Value && ~pObjF->Value )
920 Vec_IntPushUnique( vSigsNew, Abc_Lit2Var(pObjF->Value) );
921 }
922 return vSigsNew;
923}
924
936Gia_Man_t * Gia_ManDupCofAllInt( Gia_Man_t * p, Vec_Int_t * vSigs, int fVerbose )
937{
938 Vec_Int_t * vSigsNew, * vTemp;
939 Gia_Man_t * pAig, * pCof, * pNew;
940 int iVar;
941 if ( fVerbose )
942 {
943 printf( "Cofactoring %d signals.\n", Vec_IntSize(vSigs) );
944 Gia_ManPrintStats( p, NULL );
945 }
946 if ( Vec_IntSize( vSigs ) > 200 )
947 {
948 printf( "Too many signals to cofactor.\n" );
949 return NULL;
950 }
951 pAig = Gia_ManDup( p );
952 vSigsNew = Vec_IntDup( vSigs );
953 while ( Vec_IntSize(vSigsNew) > 0 )
954 {
955 Vec_IntSort( vSigsNew, 0 );
956 iVar = Vec_IntPop( vSigsNew );
957// Gia_ManCreateRefs( pAig );
958// printf( "ref count = %d\n", Gia_ObjRefNum( pAig, Gia_ManObj(pAig, iVar) ) );
959// ABC_FREE( pAig->pRefs );
960 pCof = Gia_ManDupCofInt( pAig, iVar );
961 pNew = Gia_ManCleanup( pCof );
962 vSigsNew = Gia_ManTransfer( pAig, pCof, pNew, vTemp = vSigsNew );
963 Vec_IntFree( vTemp );
964 Gia_ManStop( pAig );
965 Gia_ManStop( pCof );
966 pAig = pNew;
967 if ( fVerbose )
968 printf( "Cofactored variable %d.\n", iVar );
969 if ( fVerbose )
970 Gia_ManPrintStats( pAig, NULL );
971 }
972 Vec_IntFree( vSigsNew );
973 return pAig;
974}
975
987Gia_Man_t * Gia_ManDupCofAll( Gia_Man_t * p, int nFanLim, int fVerbose )
988{
989 Gia_Man_t * pNew;
990 Vec_Int_t * vSigs = Gia_ManCofVars( p, nFanLim );
991 pNew = Gia_ManDupCofAllInt( p, vSigs, fVerbose );
992 Vec_IntFree( vSigs );
993 return pNew;
994}
995
1008{
1009 Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj; int i, j;
1010 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
1011 assert( Gia_ManPoNum(p) == 1 );
1012 assert( iIn >= 0 && iIn < Gia_ManPiNum(p) );
1013 pNew = Gia_ManStart( Gia_ManObjNum(p) );
1014 pNew->pName = Abc_UtilStrsav( p->pName );
1015 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
1016 Gia_ManHashAlloc( pNew );
1018 Gia_ManConst0(p)->Value = 0;
1019 Gia_ManForEachCi( p, pObj, i )
1020 pObj->Value = Gia_ManAppendCi(pNew);
1021 for ( i = 0; i < Gia_ManPiNum(p); i++ ) if ( i != iIn )
1022 for ( j = i+1; j < Gia_ManPiNum(p); j++ ) if ( j != iIn )
1023 {
1024 int pRes[8], k, n;
1025 int iLit0 = Gia_ManPi(p, iIn)->Value;
1026 int iLit1 = Gia_ManPi(p, i)->Value;
1027 int iLit2 = Gia_ManPi(p, j)->Value;
1028 for ( k = 0; k < 8; k++ )
1029 {
1030 Gia_ManPi(p, iIn)->Value = k & 1;
1031 Gia_ManPi(p, i)->Value = (k >> 1) & 1;
1032 Gia_ManPi(p, j)->Value = (k >> 2) & 1;
1033 Gia_ManForEachAnd( p, pObj, n )
1034 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1035 pRes[k] = Gia_ObjFanin0Copy(Gia_ManPo(p, 0));
1036 }
1037 Gia_ManPi(p, iIn)->Value = iLit0;
1038 Gia_ManPi(p, i)->Value = iLit1;
1039 Gia_ManPi(p, j)->Value = iLit2;
1040 for ( k = 0; k < 4; k++ )
1041 pRes[k] = Gia_ManHashXor( pNew, pRes[2*k], pRes[2*k+1] );
1042 Vec_IntPush( vRes, Gia_ManHashXor(pNew, Gia_ManHashAnd(pNew, pRes[0], pRes[3]), Gia_ManHashAnd(pNew, pRes[1], pRes[2])) );
1043 }
1044 Vec_IntForEachEntry( vRes, j, i )
1045 Gia_ManAppendCo( pNew, j );
1046 Vec_IntFree( vRes );
1047 pNew = Gia_ManCleanup( pTemp = pNew );
1048 Gia_ManStop( pTemp );
1049 return pNew;
1050}
1052{
1053 extern Gia_Man_t * Cec4_ManSimulateTest3( Gia_Man_t * p, int nBTLimit, int fVerbose );
1054 Gia_Man_t * pNew = Gia_ManDsdMatrix( p, iIn ); int i, j, fFirst = 1, Count = 0;
1055 Gia_Man_t * pSweep = Cec4_ManSimulateTest3( pNew, 0, 0 );
1056 Gia_ManStop( pNew );
1057 printf( "%4c : ", ' ' );
1058 for ( j = 0; j < Gia_ManPiNum(p); j++ )
1059 printf( "%4d", j );
1060 printf( "\n" );
1061 for ( i = 0; i < Gia_ManPiNum(p); i++, printf("\n"), fFirst = 1 )
1062 for ( j = 0; j < Gia_ManPiNum(p); j++ )
1063 {
1064 if ( fFirst )
1065 printf( "%4d : ", i ), fFirst = 0;
1066 if ( i == iIn )
1067 continue;
1068 if ( j == iIn )
1069 printf( "%4c", ' ' );
1070 else
1071 {
1072 if ( j > i ) {
1073 if ( Gia_ObjFaninLit0p(pSweep, Gia_ManPo(pSweep, Count++)) == 0 )
1074 printf( "%4c", '.' );
1075 else
1076 printf( "%4c", '+' );
1077 }
1078 else
1079 printf( "%4c", ' ' );
1080 }
1081 }
1082 assert( Count == Gia_ManPoNum(pSweep) );
1083 Gia_ManStop( pSweep );
1084}
1085
1086
1090
1091
1093
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_PRMn(a, f)
Definition abc_global.h:261
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#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
Cube * p
Definition exorList.c:222
Vec_Int_t * Gia_ManTransfer(Gia_Man_t *pAig, Gia_Man_t *pCof, Gia_Man_t *pNew, Vec_Int_t *vSigs)
Definition giaCof.c:909
Gia_Man_t * Gia_ManDupCof(Gia_Man_t *p, int iVar)
Definition giaCof.c:862
void Cof_ManInsertEntry_rec(Vec_Ptr_t *vNodes, Cof_Obj_t *pNode, int nNodeMax)
Definition giaCof.c:388
int Cof_ManSuppSize(Cof_Man_t *p, Cof_Obj_t **ppObjs, int nObjs)
Definition giaCof.c:345
void Gia_ManPrintFanio(Gia_Man_t *pGia, int nNodes)
Definition giaCof.c:746
int Cof_ManTfiSize(Cof_Man_t *p, Cof_Obj_t **ppObjs, int nObjs)
Definition giaCof.c:296
Vec_Int_t * Gia_ManCofVars(Gia_Man_t *p, int nFanLim)
Definition giaCof.c:883
struct Cof_Man_t_ Cof_Man_t
Definition giaCof.c:55
Gia_Man_t * Gia_ManDupCofInt(Gia_Man_t *p, int iVar)
Definition giaCof.c:780
void Cof_ManPrintHighFanout(Cof_Man_t *p, int nNodes)
Definition giaCof.c:541
int Cof_ManCountRemoved(Cof_Man_t *p, Cof_Obj_t *pRoot, int fConst1)
Definition giaCof.c:445
void Cof_ManStop(Cof_Man_t *p)
Definition giaCof.c:203
int Cof_NodeDeref_rec(Cof_Obj_t *pNode)
Definition giaCof.c:564
struct Cof_Obj_t_ Cof_Obj_t
Definition giaCof.c:38
void Cof_ManPrintFanio(Cof_Man_t *p)
Definition giaCof.c:605
void Cof_ManCleanValue(Cof_Man_t *p)
Definition giaCof.c:369
Gia_Man_t * Gia_ManDupCofAllInt(Gia_Man_t *p, Vec_Int_t *vSigs, int fVerbose)
Definition giaCof.c:936
int Cof_ManTfoSize(Cof_Man_t *p, Cof_Obj_t **ppObjs, int nObjs)
Definition giaCof.c:250
Gia_Man_t * Gia_ManDsdMatrix(Gia_Man_t *p, int iIn)
Definition giaCof.c:1007
void Cof_ManPrintHighFanoutOne(Cof_Man_t *p, Cof_Obj_t *pObj)
Definition giaCof.c:517
#define Cof_ObjForEachFanout(pObj, pNext, i)
Definition giaCof.c:108
int Cof_NodeRef_rec(Cof_Obj_t *pNode)
Definition giaCof.c:573
typedefABC_NAMESPACE_IMPL_START struct Cof_Fan_t_ Cof_Fan_t
DECLARATIONS ///.
Definition giaCof.c:31
void Gia_ManPrintDsdMatrix(Gia_Man_t *p, int iIn)
Definition giaCof.c:1051
#define Cof_ManForEachNode(p, pObj, i)
Definition giaCof.c:104
Gia_Man_t * Gia_ManDupCofAll(Gia_Man_t *p, int nFanLim, int fVerbose)
Definition giaCof.c:987
int Cof_ManTfoSize_rec(Cof_Man_t *p, Cof_Obj_t *pObj)
Definition giaCof.c:224
#define Cof_ObjForEachFanin(pObj, pNext, i)
Definition giaCof.c:106
Cof_Man_t * Cof_ManCreateLogicSimple(Gia_Man_t *pGia)
FUNCTION DEFINITIONS ///.
Definition giaCof.c:126
int Cof_ManTfiSize_rec(Cof_Man_t *p, Cof_Obj_t *pObj)
Definition giaCof.c:270
#define Cof_ManForEachObj(p, pObj, i)
Definition giaCof.c:102
int Cof_ManSuppSize_rec(Cof_Man_t *p, Cof_Obj_t *pObj)
Definition giaCof.c:319
Vec_Ptr_t * Cof_ManCollectHighFanout(Cof_Man_t *p, int nNodes)
Definition giaCof.c:422
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
int * Gia_ManCreateMuxRefs(Gia_Man_t *p)
Definition giaUtil.c:828
void Gia_ManHashStart(Gia_Man_t *p)
Definition giaHash.c:125
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:668
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Definition giaHash.c:692
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
int Gia_ManHashAndTry(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:637
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition giaMan.c:495
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
unsigned iFan
Definition giaCof.c:34
unsigned fCompl
Definition giaCof.c:35
Vec_Int_t * vCos
Definition giaCof.c:60
int nLevels
Definition giaCof.c:67
int nObjs
Definition giaCof.c:61
int nNodes
Definition giaCof.c:62
int nObjData
Definition giaCof.c:65
Vec_Int_t * vCis
Definition giaCof.c:59
Gia_Man_t * pGia
Definition giaCof.c:58
int * pLevels
Definition giaCof.c:66
int nTravIds
Definition giaCof.c:63
int * pObjData
Definition giaCof.c:64
unsigned Value
Definition giaCof.c:48
unsigned nFanouts
Definition giaCof.c:46
unsigned nFanins
Definition giaCof.c:45
int iLit
Definition giaCof.c:51
unsigned nFanoutsM
Definition giaCof.c:47
Cof_Fan_t Fanios[0]
Definition giaCof.c:52
unsigned fPhase
Definition giaCof.c:42
int Id
Definition giaCof.c:49
unsigned fMark1
Definition giaCof.c:44
int iNext
Definition giaCof.c:50
unsigned fTerm
Definition giaCof.c:41
unsigned fMark0
Definition giaCof.c:43
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
int * pRefs
Definition gia.h:118
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
char * sprintf()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
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
Gia_Man_t * Cec4_ManSimulateTest3(Gia_Man_t *p, int nBTLimit, int fVerbose)
Definition cecSatG2.c:2077