ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaUtil.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "base/main/mainInt.h"
23
25
26
30
31#define NUMBER1 3716960521u
32#define NUMBER2 2174103536u
33
37
49unsigned Gia_ManRandom( int fReset )
50{
51#ifdef _MSC_VER
52 static unsigned int m_z = NUMBER1;
53 static unsigned int m_w = NUMBER2;
54#else
55 static __thread unsigned int m_z = NUMBER1;
56 static __thread unsigned int m_w = NUMBER2;
57#endif
58 if ( fReset )
59 {
60 m_z = NUMBER1;
61 m_w = NUMBER2;
62 }
63 m_z = 36969 * (m_z & 65535) + (m_z >> 16);
64 m_w = 18000 * (m_w & 65535) + (m_w >> 16);
65 return (m_z << 16) + m_w;
66}
67word Gia_ManRandomW( int fReset )
68{
69 return ((word)Gia_ManRandom(fReset) << 32) | ((word)Gia_ManRandom(fReset) << 0);
70}
71
72
73
85void Gia_ManRandomInfo( Vec_Ptr_t * vInfo, int iInputStart, int iWordStart, int iWordStop )
86{
87 unsigned * pInfo;
88 int i, w;
89 Vec_PtrForEachEntryStart( unsigned *, vInfo, pInfo, i, iInputStart )
90 for ( w = iWordStart; w < iWordStop; w++ )
91 pInfo[w] = Gia_ManRandom(0);
92}
93
94
107{
108 static char Buffer[100];
109 char * TimeStamp;
110 time_t ltime;
111 // get the current time
112 time( &ltime );
113 TimeStamp = asctime( localtime( &ltime ) );
114 TimeStamp[ strlen(TimeStamp) - 1 ] = 0;
115 strcpy( Buffer, TimeStamp );
116 return Buffer;
117}
118
130char * Gia_FileNameGenericAppend( char * pBase, char * pSuffix )
131{
132 static char Buffer[1000];
133 char * pDot;
134 strcpy( Buffer, pBase );
135 if ( (pDot = strrchr( Buffer, '.' )) )
136 *pDot = 0;
137 strcat( Buffer, pSuffix );
138 if ( (pDot = strrchr( Buffer, '\\' )) || (pDot = strrchr( Buffer, '/' )) )
139 return pDot+1;
140 return Buffer;
141}
142
154Vec_Ptr_t * Gia_GetFakeNames( int nNames, int fCaps )
155{
156 Vec_Ptr_t * vNames;
157 char Buffer[5];
158 int i;
159
160 vNames = Vec_PtrAlloc( nNames );
161 for ( i = 0; i < nNames; i++ )
162 {
163 if ( nNames < 26 )
164 {
165 Buffer[0] = (fCaps ? 'A' : 'a') + i;
166 Buffer[1] = 0;
167 }
168 else
169 {
170 Buffer[0] = (fCaps ? 'A' : 'a') + i%26;
171 Buffer[1] = '0' + i/26;
172 Buffer[2] = 0;
173 }
174 Vec_PtrPush( vNames, Extra_UtilStrsav(Buffer) );
175 }
176 return vNames;
177}
178
191{
192 if ( p->pTravIds == NULL )
193 {
194 p->nTravIdsAlloc = Gia_ManObjNum(p) + 100;
195 p->pTravIds = ABC_CALLOC( int, p->nTravIdsAlloc );
196 p->nTravIds = 0;
197 }
198 while ( p->nTravIdsAlloc < Gia_ManObjNum(p) )
199 {
200 p->nTravIdsAlloc *= 2;
201 p->pTravIds = ABC_REALLOC( int, p->pTravIds, p->nTravIdsAlloc );
202 memset( p->pTravIds + p->nTravIdsAlloc/2, 0, sizeof(int) * p->nTravIdsAlloc/2 );
203 }
204 p->nTravIds++;
205}
206
219{
220 Gia_Obj_t * pObj;
221 int i;
222 Gia_ManForEachObj( p, pObj, i )
223 pObj->fMark0 = pObj->fMark1 = 0;
224}
225
238{
239 Gia_Obj_t * pObj;
240 int i;
241 Gia_ManForEachObj( p, pObj, i )
242 pObj->fMark0 = 1;
243}
244
257{
258 Gia_Obj_t * pObj;
259 int i;
260 Gia_ManForEachObj( p, pObj, i )
261 pObj->fMark0 = 0;
262}
263
276{
277 Gia_Obj_t * pObj;
278 int i;
279 Gia_ManForEachObj( p, pObj, i )
280 assert( pObj->fMark0 == 0 );
281}
282
295{
296 Gia_Obj_t * pObj;
297 int i;
298 Gia_ManForEachObj( p, pObj, i )
299 pObj->fMark1 = 1;
300}
301
314{
315 Gia_Obj_t * pObj;
316 int i;
317 Gia_ManForEachObj( p, pObj, i )
318 pObj->fMark1 = 0;
319}
320
333{
334 Gia_Obj_t * pObj;
335 int i;
336 Gia_ManForEachObj( p, pObj, i )
337 assert( pObj->fMark1 == 0 );
338}
339
352{
353 int i;
354 for ( i = 0; i < p->nObjs; i++ )
355 p->pObjs[i].Value = 0;
356}
357
370{
371 int i;
372 for ( i = 0; i < p->nObjs; i++ )
373 p->pObjs[i].Value = ~0;
374}
375
388{
389 if ( Gia_ObjIsAnd(pObj) )
390 {
391 int fPhase0 = Gia_ObjPhase(Gia_ObjFanin0(pObj)) ^ Gia_ObjFaninC0(pObj);
392 int fPhase1 = Gia_ObjPhase(Gia_ObjFanin1(pObj)) ^ Gia_ObjFaninC1(pObj);
393 if ( Gia_ObjIsMux(p, pObj) )
394 {
395 int fPhase2 = Gia_ObjPhase(Gia_ObjFanin2(p, pObj)) ^ Gia_ObjFaninC2(p, pObj);
396 pObj->fPhase = (fPhase2 && fPhase1) || (!fPhase2 && fPhase0);
397 }
398 else if ( Gia_ObjIsXor(pObj) )
399 pObj->fPhase = fPhase0 ^ fPhase1;
400 else
401 pObj->fPhase = fPhase0 & fPhase1;
402 }
403 else if ( Gia_ObjIsCo(pObj) )
404 pObj->fPhase = (Gia_ObjPhase(Gia_ObjFanin0(pObj)) ^ Gia_ObjFaninC0(pObj));
405 else
406 pObj->fPhase = 0;
407}
408
421{
422 Gia_Obj_t * pObj;
423 int i;
424 Gia_ManForEachObj( p, pObj, i )
425 Gia_ObjSetPhase( p, pObj );
426}
428{
429 Gia_Obj_t * pObj;
430 int i;
431 assert( Gia_ManCiNum(p) == Vec_IntSize(vCiValues) );
432 Gia_ManForEachObj( p, pObj, i )
433 if ( Gia_ObjIsCi(pObj) )
434 pObj->fPhase = Vec_IntEntry( vCiValues, Gia_ObjCioId(pObj) );
435 else
436 Gia_ObjSetPhase( p, pObj );
437}
438
451{
452 Gia_Obj_t * pObj;
453 int i;
454 Gia_ManForEachCi( p, pObj, i )
455 pObj->fPhase = 1;
456 Gia_ManForEachObj( p, pObj, i )
457 if ( !Gia_ObjIsCi(pObj) )
458 Gia_ObjSetPhase( p, pObj );
459}
460
473{
474 Gia_Obj_t * pObj;
475 int i;
476 Gia_ManForEachObj( p, pObj, i )
477 pObj->fPhase = 0;
478}
479
492{
493 Gia_Obj_t * pObj;
494 int i, Counter = 0;
495 Gia_ManForEachCo( p, pObj, i )
496 Counter += pObj->fPhase;
497 return Counter;
498}
499
511void Gia_ManCleanLevels( Gia_Man_t * p, int Size )
512{
513 if ( p->vLevels == NULL )
514 p->vLevels = Vec_IntAlloc( Size );
515 Vec_IntFill( p->vLevels, Size, 0 );
516}
517
529{
530 if ( p->vTruths == NULL )
531 p->vTruths = Vec_IntAlloc( Gia_ManObjNum(p) );
532 Vec_IntFill( p->vTruths, Gia_ManObjNum(p), -1 );
533}
534
547{
548 Gia_Obj_t * pObj;
549 int i;
550 Gia_ManCleanLevels( p, Gia_ManObjNum(p) );
551 p->nLevels = 0;
552 Gia_ManForEachObj( p, pObj, i )
553 {
554 if ( !p->fGiaSimple && Gia_ObjIsBuf(pObj) )
555 Gia_ObjSetBufLevel( p, pObj );
556 else if ( Gia_ObjIsAnd(pObj) )
557 Gia_ObjSetGateLevel( p, pObj );
558 else if ( Gia_ObjIsCo(pObj) )
559 Gia_ObjSetCoLevel( p, pObj );
560 else
561 Gia_ObjSetLevel( p, pObj, 0 );
562 p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
563 }
564 return p->nLevels;
565}
567{
568 Gia_Obj_t * pObj;
569 int i;
570 Gia_ManCleanLevels( p, Gia_ManObjNum(p) );
571 p->nLevels = 0;
572 Gia_ManForEachObjReverse( p, pObj, i )
573 {
574 if ( !p->fGiaSimple && Gia_ObjIsBuf(pObj) )
575 Gia_ObjUpdateLevelId( p, Gia_ObjFaninId0(pObj, i), Gia_ObjLevel(p, pObj) );
576 else if ( Gia_ObjIsAnd(pObj) )
577 {
578 Gia_ObjUpdateLevelId( p, Gia_ObjFaninId0(pObj, i), 1+Gia_ObjLevel(p, pObj) );
579 Gia_ObjUpdateLevelId( p, Gia_ObjFaninId1(pObj, i), 1+Gia_ObjLevel(p, pObj) );
580 }
581 else if ( Gia_ObjIsCo(pObj) )
582 Gia_ObjUpdateLevelId( p, Gia_ObjFaninId0(pObj, i), 1 );
583 else
584 p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
585 }
586 return p->nLevels;
587}
589{
590 Gia_Obj_t * pObj;
591 int i, Ave = 0;
592 assert( p->vLevels );
593 Gia_ManForEachCo( p, pObj, i )
594 Ave += Gia_ObjLevel(p, pObj);
595 return (float)Ave / Gia_ManCoNum(p);
596}
597
610{
611 Vec_Int_t * vCiLevels;
612 Gia_Obj_t * pObj;
613 int i;
614 if ( p->vLevels == NULL )
615 return NULL;
616 vCiLevels = Vec_IntAlloc( Gia_ManCiNum(p) );
617 Gia_ManForEachCi( p, pObj, i )
618 Vec_IntPush( vCiLevels, Gia_ObjLevel(p, pObj) );
619 return vCiLevels;
620}
621int Gia_ManSetLevels( Gia_Man_t * p, Vec_Int_t * vCiLevels )
622{
623 Gia_Obj_t * pObj;
624 int i;
625 if ( vCiLevels == NULL )
626 return Gia_ManLevelNum( p );
627 assert( Vec_IntSize(vCiLevels) == Gia_ManCiNum(p) );
628 Gia_ManCleanLevels( p, Gia_ManObjNum(p) );
629 p->nLevels = 0;
630 Gia_ManForEachCi( p, pObj, i )
631 {
632 Gia_ObjSetLevel( p, pObj, Vec_IntEntry(vCiLevels, i) );
633 p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
634 }
635 Gia_ManForEachObj( p, pObj, i )
636 {
637 if ( Gia_ObjIsAnd(pObj) )
638 Gia_ObjSetGateLevel( p, pObj );
639 else if ( Gia_ObjIsCo(pObj) )
640 Gia_ObjSetCoLevel( p, pObj );
641 else continue;
642 p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
643 }
644 return p->nLevels;
645}
646
659{
660 Vec_Int_t * vLevelRev;
661 Gia_Obj_t * pObj;
662 int i;
663 vLevelRev = Vec_IntStart( Gia_ManObjNum(p) );
664 Gia_ManForEachAndReverse( p, pObj, i )
665 {
666 int LevelR = Vec_IntEntry( vLevelRev, i );
667 if ( Gia_ObjIsMux(p, pObj) )
668 {
669 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId0(pObj, i), LevelR + 2 );
670 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId1(pObj, i), LevelR + 2 );
671 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId2(p, i), LevelR + 2 );
672 }
673 else if ( Gia_ObjIsXor(pObj) )
674 {
675 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId0(pObj, i), LevelR + 2 );
676 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId1(pObj, i), LevelR + 2 );
677 }
678 else if ( Gia_ObjIsBuf(pObj) )
679 {
680 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId0(pObj, i), LevelR );
681 }
682 else
683 {
684 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId0(pObj, i), LevelR + 1 );
685 Vec_IntUpdateEntry( vLevelRev, Gia_ObjFaninId1(pObj, i), LevelR + 1 );
686 }
687 }
688 return vLevelRev;
689}
690
703{
704 Vec_Int_t * vRequired;
705 Gia_Obj_t * pObj;
706 int i, LevelMax = 0;
707 vRequired = Gia_ManReverseLevel( p );
708 Gia_ManForEachCi( p, pObj, i )
709 LevelMax = Abc_MaxInt( LevelMax, Vec_IntEntry(vRequired, Gia_ObjId(p, pObj)) );
710 Gia_ManForEachObj( p, pObj, i )
711 Vec_IntWriteEntry( vRequired, i, LevelMax - Vec_IntEntry(vRequired, i) );
712 return vRequired;
713}
714
727{
728 Gia_Obj_t * pObj;
729 int i, nLevels = Gia_ManLevelNum( p );
730 Vec_Int_t * vLevelR = Gia_ManReverseLevel( p );
731 Vec_Int_t * vSlacks = Vec_IntAlloc( Gia_ManObjNum(p) );
732 Gia_ManForEachObj( p, pObj, i )
733 Vec_IntPush( vSlacks, nLevels - Gia_ObjLevelId(p, i) - Vec_IntEntry(vLevelR, i) );
734 assert( Vec_IntSize(vSlacks) == Gia_ManObjNum(p) );
735 Vec_IntFree( vLevelR );
736 return vSlacks;
737}
738
751{
752 Gia_Obj_t * pObj;
753 int i;
754 Gia_ManForEachObj( p, pObj, i )
755 {
756 pObj->Value = 0;
757 if ( Gia_ObjIsAnd(pObj) )
758 {
759 Gia_ObjFanin0(pObj)->Value++;
760 if ( !Gia_ObjIsBuf(pObj) )
761 Gia_ObjFanin1(pObj)->Value++;
762 }
763 else if ( Gia_ObjIsCo(pObj) )
764 Gia_ObjFanin0(pObj)->Value++;
765 }
766}
767
780{
781 Gia_Obj_t * pObj;
782 int i;
783 assert( p->pRefs == NULL );
784 p->pRefs = ABC_CALLOC( int, Gia_ManObjNum(p) );
785 Gia_ManForEachObj( p, pObj, i )
786 {
787 if ( Gia_ObjIsAnd(pObj) )
788 {
789 Gia_ObjRefFanin0Inc( p, pObj );
790 if ( !Gia_ObjIsBuf(pObj) )
791 Gia_ObjRefFanin1Inc( p, pObj );
792 if ( Gia_ObjIsMuxId(p, i) )
793 Gia_ObjRefFanin2Inc( p, pObj );
794 }
795 else if ( Gia_ObjIsCo(pObj) )
796 Gia_ObjRefFanin0Inc( p, pObj );
797 }
798}
800{
801 Gia_Obj_t * pObj;
802 int i;
803 assert( p->pRefs == NULL );
804 p->pRefs = ABC_CALLOC( int, 2*Gia_ManObjNum(p) );
805 Gia_ManForEachObj( p, pObj, i )
806 {
807 if ( Gia_ObjIsAnd(pObj) )
808 {
809 p->pRefs[Gia_ObjFaninLit0(pObj, i)]++;
810 p->pRefs[Gia_ObjFaninLit1(pObj, i)]++;
811 }
812 else if ( Gia_ObjIsCo(pObj) )
813 p->pRefs[Gia_ObjFaninLit0(pObj, i)]++;
814 }
815}
816
829{
830 Gia_Obj_t * pObj, * pCtrl, * pFan0, * pFan1;
831 int i, * pMuxRefs;
832 pMuxRefs = ABC_CALLOC( int, Gia_ManObjNum(p) );
833 Gia_ManForEachObj( p, pObj, i )
834 {
835 if ( Gia_ObjRecognizeExor( pObj, &pFan0, &pFan1 ) )
836 continue;
837 if ( !Gia_ObjIsMuxType(pObj) )
838 continue;
839 pCtrl = Gia_ObjRecognizeMux( pObj, &pFan0, &pFan1 );
840 pMuxRefs[ Gia_ObjId(p, Gia_Regular(pCtrl)) ]++;
841 }
842 return pMuxRefs;
843}
844
857{
858 Vec_Int_t * vNodes = Vec_IntAlloc( Gia_ManObjNum(p) );
859 Vec_Vec_t * vLevels = Gia_ManLevelize( p );
860 Vec_Ptr_t * vObjs;
861 Gia_Obj_t * pObj;
862 int i, k;
863 Vec_VecForEachLevel( vLevels, vObjs, i )
864 Vec_PtrForEachEntry( Gia_Obj_t *, vObjs, pObj, k )
865 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
866 Vec_VecFree( vLevels );
867 return vNodes;
868}
869
871{
872 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
873 return;
874 Gia_ObjSetTravIdCurrent(p, pObj);
875 if ( Gia_ObjIsCi(pObj) )
876 {
877 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
878 return;
879 }
880 if ( Gia_ObjIsCo(pObj) )
881 {
882 Gia_ObjFanin0(pObj)->Value++;
883 Gia_ManDfsForCrossCut_rec( p, Gia_ObjFanin0(pObj), vNodes );
884 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
885 return;
886 }
887 assert( Gia_ObjIsAnd(pObj) );
888 Gia_ObjFanin0(pObj)->Value++;
889 Gia_ObjFanin1(pObj)->Value++;
890 Gia_ManDfsForCrossCut_rec( p, Gia_ObjFanin0(pObj), vNodes );
891 Gia_ManDfsForCrossCut_rec( p, Gia_ObjFanin1(pObj), vNodes );
892 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
893}
895{
896 Vec_Int_t * vNodes;
897 Gia_Obj_t * pObj;
898 int i;
900 vNodes = Vec_IntAlloc( Gia_ManObjNum(p) );
902 if ( fReverse )
903 {
904 Gia_ManForEachCoReverse( p, pObj, i )
905 if ( !Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
906 Gia_ManDfsForCrossCut_rec( p, pObj, vNodes );
907 }
908 else
909 {
910 Gia_ManForEachCo( p, pObj, i )
911 if ( !Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
912 Gia_ManDfsForCrossCut_rec( p, pObj, vNodes );
913 }
914 return vNodes;
915}
916int Gia_ManCrossCut( Gia_Man_t * p, int fReverse )
917{
918 Vec_Int_t * vNodes;
919 Gia_Obj_t * pObj;
920 int i, nCutCur = 0, nCutMax = 0;
921 vNodes = Gia_ManDfsForCrossCut( p, fReverse );
922 //vNodes = Gia_ManBfsForCrossCut( p );
923 Gia_ManForEachObjVec( vNodes, p, pObj, i )
924 {
925 if ( pObj->Value )
926 nCutCur++;
927 if ( nCutMax < nCutCur )
928 nCutMax = nCutCur;
929 if ( Gia_ObjIsAnd(pObj) )
930 {
931 if ( --Gia_ObjFanin0(pObj)->Value == 0 )
932 nCutCur--;
933 if ( --Gia_ObjFanin1(pObj)->Value == 0 )
934 nCutCur--;
935 }
936 else if ( Gia_ObjIsCo(pObj) )
937 {
938 if ( --Gia_ObjFanin0(pObj)->Value == 0 )
939 nCutCur--;
940 }
941 }
942 Vec_IntFree( vNodes );
943 Gia_ManForEachObj( p, pObj, i )
944 assert( pObj->Value == 0 );
945 return nCutMax;
946}
947
948
961{
962 Vec_Int_t * vStart;
963 int Entry, i;
964 vStart = Vec_IntAlloc( Gia_ManPoNum(p) );
965 Vec_IntForEachEntryStop( p->vCos, Entry, i, Gia_ManPoNum(p) )
966 Vec_IntPush( vStart, Entry );
967 return vStart;
968}
969
970
983{
984 Gia_Obj_t * pNode0, * pNode1;
985 // check that the node is regular
986 assert( !Gia_IsComplement(pNode) );
987 // if the node is not AND, this is not MUX
988 if ( !Gia_ObjIsAnd(pNode) || Gia_ObjIsBuf(pNode) )
989 return 0;
990 // if the children are not complemented, this is not MUX
991 if ( !Gia_ObjFaninC0(pNode) || !Gia_ObjFaninC1(pNode) )
992 return 0;
993 // get children
994 pNode0 = Gia_ObjFanin0(pNode);
995 pNode1 = Gia_ObjFanin1(pNode);
996 // if the children are not ANDs, this is not MUX
997 if ( !Gia_ObjIsAnd(pNode0) || !Gia_ObjIsAnd(pNode1) )
998 return 0;
999 // otherwise the node is MUX iff it has a pair of equal grandchildren
1000 return (Gia_ObjFanin0(pNode0) == Gia_ObjFanin0(pNode1) && (Gia_ObjFaninC0(pNode0) ^ Gia_ObjFaninC0(pNode1))) ||
1001 (Gia_ObjFanin0(pNode0) == Gia_ObjFanin1(pNode1) && (Gia_ObjFaninC0(pNode0) ^ Gia_ObjFaninC1(pNode1))) ||
1002 (Gia_ObjFanin1(pNode0) == Gia_ObjFanin0(pNode1) && (Gia_ObjFaninC1(pNode0) ^ Gia_ObjFaninC0(pNode1))) ||
1003 (Gia_ObjFanin1(pNode0) == Gia_ObjFanin1(pNode1) && (Gia_ObjFaninC1(pNode0) ^ Gia_ObjFaninC1(pNode1)));
1004}
1005
1006
1018int Gia_ObjRecognizeExor( Gia_Obj_t * pObj, Gia_Obj_t ** ppFan0, Gia_Obj_t ** ppFan1 )
1019{
1020 Gia_Obj_t * p0, * p1;
1021 assert( !Gia_IsComplement(pObj) );
1022 if ( !Gia_ObjIsAnd(pObj) || Gia_ObjIsBuf(pObj) )
1023 return 0;
1024 assert( Gia_ObjIsAnd(pObj) );
1025 p0 = Gia_ObjChild0(pObj);
1026 p1 = Gia_ObjChild1(pObj);
1027 if ( !Gia_IsComplement(p0) || !Gia_IsComplement(p1) )
1028 return 0;
1029 p0 = Gia_Regular(p0);
1030 p1 = Gia_Regular(p1);
1031 if ( !Gia_ObjIsAnd(p0) || !Gia_ObjIsAnd(p1) )
1032 return 0;
1033 if ( Gia_ObjFanin0(p0) != Gia_ObjFanin0(p1) || Gia_ObjFanin1(p0) != Gia_ObjFanin1(p1) )
1034 return 0;
1035 if ( Gia_ObjFaninC0(p0) == Gia_ObjFaninC0(p1) || Gia_ObjFaninC1(p0) == Gia_ObjFaninC1(p1) )
1036 return 0;
1037 if ( ppFan0 ) *ppFan0 = Gia_ObjChild0(p0);
1038 if ( ppFan1 ) *ppFan1 = Gia_ObjChild1(p0);
1039 return 1;
1040}
1041
1056Gia_Obj_t * Gia_ObjRecognizeMux( Gia_Obj_t * pNode, Gia_Obj_t ** ppNodeT, Gia_Obj_t ** ppNodeE )
1057{
1058 Gia_Obj_t * pNode0, * pNode1;
1059 assert( !Gia_IsComplement(pNode) );
1060 assert( Gia_ObjIsMuxType(pNode) );
1061 // get children
1062 pNode0 = Gia_ObjFanin0(pNode);
1063 pNode1 = Gia_ObjFanin1(pNode);
1064
1065 // find the control variable
1066 if ( Gia_ObjFanin1(pNode0) == Gia_ObjFanin1(pNode1) && (Gia_ObjFaninC1(pNode0) ^ Gia_ObjFaninC1(pNode1)) )
1067 {
1068// if ( FrGia_IsComplement(pNode1->p2) )
1069 if ( Gia_ObjFaninC1(pNode0) )
1070 { // pNode2->p2 is positive phase of C
1071 *ppNodeT = Gia_Not(Gia_ObjChild0(pNode1));//pNode2->p1);
1072 *ppNodeE = Gia_Not(Gia_ObjChild0(pNode0));//pNode1->p1);
1073 return Gia_ObjChild1(pNode1);//pNode2->p2;
1074 }
1075 else
1076 { // pNode1->p2 is positive phase of C
1077 *ppNodeT = Gia_Not(Gia_ObjChild0(pNode0));//pNode1->p1);
1078 *ppNodeE = Gia_Not(Gia_ObjChild0(pNode1));//pNode2->p1);
1079 return Gia_ObjChild1(pNode0);//pNode1->p2;
1080 }
1081 }
1082 else if ( Gia_ObjFanin0(pNode0) == Gia_ObjFanin0(pNode1) && (Gia_ObjFaninC0(pNode0) ^ Gia_ObjFaninC0(pNode1)) )
1083 {
1084// if ( FrGia_IsComplement(pNode1->p1) )
1085 if ( Gia_ObjFaninC0(pNode0) )
1086 { // pNode2->p1 is positive phase of C
1087 *ppNodeT = Gia_Not(Gia_ObjChild1(pNode1));//pNode2->p2);
1088 *ppNodeE = Gia_Not(Gia_ObjChild1(pNode0));//pNode1->p2);
1089 return Gia_ObjChild0(pNode1);//pNode2->p1;
1090 }
1091 else
1092 { // pNode1->p1 is positive phase of C
1093 *ppNodeT = Gia_Not(Gia_ObjChild1(pNode0));//pNode1->p2);
1094 *ppNodeE = Gia_Not(Gia_ObjChild1(pNode1));//pNode2->p2);
1095 return Gia_ObjChild0(pNode0);//pNode1->p1;
1096 }
1097 }
1098 else if ( Gia_ObjFanin0(pNode0) == Gia_ObjFanin1(pNode1) && (Gia_ObjFaninC0(pNode0) ^ Gia_ObjFaninC1(pNode1)) )
1099 {
1100// if ( FrGia_IsComplement(pNode1->p1) )
1101 if ( Gia_ObjFaninC0(pNode0) )
1102 { // pNode2->p2 is positive phase of C
1103 *ppNodeT = Gia_Not(Gia_ObjChild0(pNode1));//pNode2->p1);
1104 *ppNodeE = Gia_Not(Gia_ObjChild1(pNode0));//pNode1->p2);
1105 return Gia_ObjChild1(pNode1);//pNode2->p2;
1106 }
1107 else
1108 { // pNode1->p1 is positive phase of C
1109 *ppNodeT = Gia_Not(Gia_ObjChild1(pNode0));//pNode1->p2);
1110 *ppNodeE = Gia_Not(Gia_ObjChild0(pNode1));//pNode2->p1);
1111 return Gia_ObjChild0(pNode0);//pNode1->p1;
1112 }
1113 }
1114 else if ( Gia_ObjFanin1(pNode0) == Gia_ObjFanin0(pNode1) && (Gia_ObjFaninC1(pNode0) ^ Gia_ObjFaninC0(pNode1)) )
1115 {
1116// if ( FrGia_IsComplement(pNode1->p2) )
1117 if ( Gia_ObjFaninC1(pNode0) )
1118 { // pNode2->p1 is positive phase of C
1119 *ppNodeT = Gia_Not(Gia_ObjChild1(pNode1));//pNode2->p2);
1120 *ppNodeE = Gia_Not(Gia_ObjChild0(pNode0));//pNode1->p1);
1121 return Gia_ObjChild0(pNode1);//pNode2->p1;
1122 }
1123 else
1124 { // pNode1->p2 is positive phase of C
1125 *ppNodeT = Gia_Not(Gia_ObjChild0(pNode0));//pNode1->p1);
1126 *ppNodeE = Gia_Not(Gia_ObjChild1(pNode1));//pNode2->p2);
1127 return Gia_ObjChild1(pNode0);//pNode1->p2;
1128 }
1129 }
1130 assert( 0 ); // this is not MUX
1131 return NULL;
1132}
1133int Gia_ObjRecognizeMuxLits( Gia_Man_t * p, Gia_Obj_t * pNode, int * iLitT, int * iLitE )
1134{
1135 Gia_Obj_t * pNodeT, * pNodeE;
1136 Gia_Obj_t * pCtrl = Gia_ObjRecognizeMux( pNode, &pNodeT, &pNodeE );
1137 assert( pCtrl != NULL );
1138 *iLitT = Gia_Obj2Lit( p, pNodeT );
1139 *iLitE = Gia_Obj2Lit( p, pNodeE );
1140 return Gia_Obj2Lit( p, pCtrl );
1141}
1142
1143
1156{
1157 Gia_Obj_t * pFanin;
1158 int Counter = 0;
1159 if ( Gia_ObjIsCi(pNode) )
1160 return 0;
1161 assert( Gia_ObjIsAnd(pNode) );
1162 pFanin = Gia_ObjFanin0(pNode);
1163 assert( Gia_ObjRefNum(p, pFanin) > 0 );
1164 if ( Gia_ObjRefDec(p, pFanin) == 0 )
1165 Counter += Gia_NodeDeref_rec( p, pFanin );
1166 pFanin = Gia_ObjFanin1(pNode);
1167 assert( Gia_ObjRefNum(p, pFanin) > 0 );
1168 if ( Gia_ObjRefDec(p, pFanin) == 0 )
1169 Counter += Gia_NodeDeref_rec( p, pFanin );
1170 return Counter + 1;
1171}
1172
1184int Gia_NodeRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode, int fMark )
1185{
1186 Gia_Obj_t * pFanin;
1187 int Counter = 0;
1188 if ( Gia_ObjIsCi(pNode) )
1189 return 0;
1190 assert( Gia_ObjIsAnd(pNode) );
1191 if ( fMark ) Gia_ObjSetTravIdCurrent(p, pNode);
1192 pFanin = Gia_ObjFanin0(pNode);
1193 if ( Gia_ObjRefInc(p, pFanin) == 0 )
1194 Counter += Gia_NodeRef_rec( p, pFanin, fMark );
1195 pFanin = Gia_ObjFanin1(pNode);
1196 if ( Gia_ObjRefInc(p, pFanin) == 0 )
1197 Counter += Gia_NodeRef_rec( p, pFanin, fMark );
1198 return Counter + 1;
1199}
1200
1201
1214{
1216 return Gia_NodeDeref_rec( p, Gia_ObjFanin0(Gia_ManPo(p, 0)) );
1217}
1218
1231{
1232 int ConeSize1, ConeSize2;
1233 assert( !Gia_IsComplement(pNode) );
1234 assert( Gia_ObjIsCand(pNode) );
1235 ConeSize1 = Gia_NodeDeref_rec( p, pNode );
1236 ConeSize2 = Gia_NodeRef_rec( p, pNode, 0 );
1237 assert( ConeSize1 == ConeSize2 );
1238 assert( ConeSize1 >= 0 );
1239 return ConeSize1;
1240}
1242{
1243 int ConeSize1, ConeSize2;
1244 assert( !Gia_IsComplement(pNode) );
1245 assert( Gia_ObjIsCand(pNode) );
1246 ConeSize1 = Gia_NodeDeref_rec( p, pNode );
1248 ConeSize2 = Gia_NodeRef_rec( p, pNode, 1 );
1249 assert( ConeSize1 == ConeSize2 );
1250 assert( ConeSize1 >= 0 );
1251 return ConeSize1;
1252}
1253
1266{
1267 if ( Gia_ObjIsTravIdCurrent(p, pNode) )
1268 return;
1269 Gia_ObjSetTravIdCurrent(p, pNode);
1270 if ( Gia_ObjRefNum(p, pNode) || Gia_ObjIsCi(pNode) )
1271 {
1272 Vec_IntPush( vSupp, Gia_ObjId(p, pNode) );
1273 return;
1274 }
1275 assert( Gia_ObjIsAnd(pNode) );
1276 Gia_NodeCollect_rec( p, Gia_ObjFanin0(pNode), vSupp );
1277 Gia_NodeCollect_rec( p, Gia_ObjFanin1(pNode), vSupp );
1278}
1280{
1281 int ConeSize1, ConeSize2;
1282 assert( !Gia_IsComplement(pNode) );
1283 assert( Gia_ObjIsAnd(pNode) );
1284 Vec_IntClear( vSupp );
1286 ConeSize1 = Gia_NodeDeref_rec( p, pNode );
1287 Gia_NodeCollect_rec( p, Gia_ObjFanin0(pNode), vSupp );
1288 Gia_NodeCollect_rec( p, Gia_ObjFanin1(pNode), vSupp );
1289 ConeSize2 = Gia_NodeRef_rec( p, pNode, 0 );
1290 assert( ConeSize1 == ConeSize2 );
1291 assert( ConeSize1 >= 0 );
1292 return ConeSize1;
1293}
1294
1306int Gia_NodeMffcMapping_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vMapping, Vec_Int_t * vSupp )
1307{
1308 Gia_Obj_t * pObj; int i, iNode, Count = 1;
1309 if ( !iObj || Vec_IntEntry(vMapping, iObj) )
1310 return 0;
1311 pObj = Gia_ManObj( p, iObj );
1312 if ( Gia_ObjIsCi(pObj) )
1313 return 0;
1314 Gia_NodeMffcSizeSupp( p, pObj, vSupp );
1315 Vec_IntSort( vSupp, 0 );
1316 Vec_IntWriteEntry( vMapping, iObj, Vec_IntSize(vMapping) );
1317 Vec_IntPush( vMapping, Vec_IntSize(vSupp) );
1318 Vec_IntAppend( vMapping, vSupp );
1319 Vec_IntPush( vMapping, iObj );
1320 Vec_IntForEachEntry( vSupp, iNode, i )
1321 Count += Gia_NodeMffcMapping_rec( p, iNode, vMapping, vSupp );
1322 return Count;
1323}
1325{
1326 int i, Id, Count = 0;
1327 int * pRefsOld;
1328 Vec_Int_t * vMapping, * vSupp = Vec_IntAlloc( 100 );
1329 vMapping = Vec_IntAlloc( 2 * Gia_ManObjNum(p) );
1330 Vec_IntFill( vMapping, Gia_ManObjNum(p), 0 );
1331 pRefsOld = p->pRefs; p->pRefs = NULL;
1332 Gia_ManCreateRefs( p );
1333 Gia_ManForEachCoDriverId( p, Id, i )
1334 Count += Gia_NodeMffcMapping_rec( p, Id, vMapping, vSupp );
1335 p->pRefs = pRefsOld;
1336 Vec_IntFree( vSupp );
1337 p->vMapping = vMapping;
1338 //printf( "Mapping is %.2fx larger than AIG manager.\n", 1.0*Vec_IntSize(vMapping)/Gia_ManObjNum(p) );
1339 return Count;
1340}
1341
1354{
1355 Gia_Obj_t * pObj;
1356 int i, Counter = 0;
1357 Gia_ManForEachObj( p, pObj, i )
1358 {
1359 pObj->fMark0 = 0;
1360 if ( Gia_ObjIsCo(pObj) )
1361 Gia_ObjFanin0(pObj)->fMark0 = 1;
1362 else if ( Gia_ObjIsMux(p, pObj) )
1363 {
1364 Gia_ObjFanin0(pObj)->fMark0 = 1;
1365 Gia_ObjFanin1(pObj)->fMark0 = 1;
1366 Gia_ObjFanin2(p, pObj)->fMark0 = 1;
1367 }
1368 else if ( Gia_ObjIsAnd(pObj) )
1369 {
1370 Gia_ObjFanin0(pObj)->fMark0 = 1;
1371 Gia_ObjFanin1(pObj)->fMark0 = 1;
1372 }
1373 }
1374 Gia_ManForEachAnd( p, pObj, i )
1375 Counter += !pObj->fMark0;
1377 return Counter;
1378}
1379
1392{
1393 Gia_Obj_t * pObj;
1394 int i, Counter = 0;
1395 Gia_ManForEachObj( p, pObj, i )
1396 {
1397 pObj->fMark0 = 0;
1398 if ( Gia_ObjIsAnd(pObj) )
1399 {
1400 Gia_ObjFanin0(pObj)->fMark0 = 1;
1401 Gia_ObjFanin1(pObj)->fMark0 = 1;
1402 }
1403 else if ( Gia_ObjIsCo(pObj) )
1404 Gia_ObjFanin0(pObj)->fMark0 = 1;
1405 }
1406 Gia_ManForEachAnd( p, pObj, i )
1407 Counter += !pObj->fMark0;
1408 return Counter;
1409}
1410
1423{
1424 Vec_Int_t * vDangles;
1425 Gia_Obj_t * pObj;
1426 int i;
1427 Gia_ManForEachObj( p, pObj, i )
1428 {
1429 pObj->fMark0 = 0;
1430 if ( Gia_ObjIsAnd(pObj) )
1431 {
1432 Gia_ObjFanin0(pObj)->fMark0 = 1;
1433 Gia_ObjFanin1(pObj)->fMark0 = 1;
1434 }
1435 else if ( Gia_ObjIsCo(pObj) )
1436 Gia_ObjFanin0(pObj)->fMark0 = 1;
1437 }
1438 vDangles = Vec_IntAlloc( 100 );
1439 Gia_ManForEachAnd( p, pObj, i )
1440 if ( !pObj->fMark0 )
1441 Vec_IntPush( vDangles, i );
1443 return vDangles;
1444}
1445
1457{
1458 if ( pObj == NULL )
1459 {
1460 printf( "Object is NULL." );
1461 return;
1462 }
1463 if ( Gia_IsComplement(pObj) )
1464 {
1465 printf( "Compl " );
1466 pObj = Gia_Not(pObj);
1467 }
1468 assert( !Gia_IsComplement(pObj) );
1469 printf( "Obj %4d : ", Gia_ObjId(p, pObj) );
1470 if ( Gia_ObjIsConst0(pObj) )
1471 printf( "constant 0" );
1472 else if ( Gia_ObjIsPi(p, pObj) )
1473 printf( "PI" );
1474 else if ( Gia_ObjIsPo(p, pObj) )
1475 printf( "PO( %4d%s )", Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " ") );
1476 else if ( Gia_ObjIsCi(pObj) )
1477 printf( "RO( %4d%s )", Gia_ObjFaninId0p(p, Gia_ObjRoToRi(p, pObj)), (Gia_ObjFaninC0(Gia_ObjRoToRi(p, pObj))? "\'" : " ") );
1478 else if ( Gia_ObjIsCo(pObj) )
1479 printf( "RI( %4d%s )", Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " ") );
1480// else if ( Gia_ObjIsBuf(pObj) )
1481// printf( "BUF( %d%s )", Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " ") );
1482 else if ( Gia_ObjIsXor(pObj) )
1483 printf( "XOR( %4d%s, %4d%s )",
1484 Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " "),
1485 Gia_ObjFaninId1p(p, pObj), (Gia_ObjFaninC1(pObj)? "\'" : " ") );
1486 else if ( Gia_ObjIsMuxId(p, Gia_ObjId(p, pObj)) )
1487 printf( "MUX( %4d%s, %4d%s, %4d%s )",
1488 Gia_ObjFaninId2p(p, pObj), (Gia_ObjFaninC2(p, pObj)? "\'" : " "),
1489 Gia_ObjFaninId1p(p, pObj), (Gia_ObjFaninC1(pObj)? "\'" : " "),
1490 Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " ") );
1491 else
1492 printf( "AND( %4d%s, %4d%s )",
1493 Gia_ObjFaninId0p(p, pObj), (Gia_ObjFaninC0(pObj)? "\'" : " "),
1494 Gia_ObjFaninId1p(p, pObj), (Gia_ObjFaninC1(pObj)? "\'" : " ") );
1495 if ( p->pRefs )
1496 printf( " (refs = %3d)", Gia_ObjRefNum(p, pObj) );
1497 if ( pObj->fMark0 )
1498 printf( " mark0" );
1499 if ( pObj->fMark1 )
1500 printf( " mark1" );
1501 if ( Gia_ManHasMapping(p) && Gia_ObjIsLut(p, Gia_ObjId(p, pObj)) )
1502 {
1503 int i, iFan;
1504 printf( " Cut = { " );
1505 Gia_LutForEachFanin( p, Gia_ObjId(p, pObj), iFan, i )
1506 printf( "%d ", iFan );
1507 printf( "}" );
1508 }
1509 if ( Gia_ManHasMapping2(p) && Gia_ObjIsLut2(p, Gia_ObjId(p, pObj)) )
1510 {
1511 int i, iFan;
1512 printf( " Cut = { " );
1513 Gia_LutForEachFanin2( p, Gia_ObjId(p, pObj), iFan, i )
1514 printf( "%d ", iFan );
1515 printf( "}" );
1516 }
1517 printf( "\n" );
1518/*
1519 if ( p->pRefs )
1520 {
1521 Gia_Obj_t * pFanout;
1522 int i;
1523 int iFan = -1; // Suppress "might be used uninitialized"
1524 printf( "\nFanouts:\n" );
1525 Gia_ObjForEachFanout( p, pObj, pFanout, iFan, i )
1526 {
1527 printf( " " );
1528 printf( "Node %4d : ", Gia_ObjId(pFanout) );
1529 if ( Gia_ObjIsPo(pFanout) )
1530 printf( "PO( %4d%s )", Gia_ObjFanin0(pFanout)->Id, (Gia_ObjFaninC0(pFanout)? "\'" : " ") );
1531 else if ( Gia_ObjIsBuf(pFanout) )
1532 printf( "BUF( %d%s )", Gia_ObjFanin0(pFanout)->Id, (Gia_ObjFaninC0(pFanout)? "\'" : " ") );
1533 else
1534 printf( "AND( %4d%s, %4d%s )",
1535 Gia_ObjFanin0(pFanout)->Id, (Gia_ObjFaninC0(pFanout)? "\'" : " "),
1536 Gia_ObjFanin1(pFanout)->Id, (Gia_ObjFaninC1(pFanout)? "\'" : " ") );
1537 printf( "\n" );
1538 }
1539 return;
1540 }
1541*/
1542}
1544{
1545 Gia_Obj_t * pObj;
1546 int i;
1547 printf( "GIA manager has %d ANDs, %d XORs, %d MUXes.\n",
1548 Gia_ManAndNum(p) - Gia_ManXorNum(p) - Gia_ManMuxNum(p), Gia_ManXorNum(p), Gia_ManMuxNum(p) );
1549 Gia_ManForEachObj( p, pObj, i )
1550 Gia_ObjPrint( p, pObj );
1551}
1553{
1554 if ( Gia_ObjIsAnd(pObj) )
1555 {
1556 Gia_ManPrintCo_rec( p, Gia_ObjFanin0(pObj) );
1557 Gia_ManPrintCo_rec( p, Gia_ObjFanin1(pObj) );
1558 if ( Gia_ObjIsMux(p, pObj) )
1559 Gia_ManPrintCo_rec( p, Gia_ObjFanin2(p, pObj) );
1560 }
1561 Gia_ObjPrint( p, pObj );
1562}
1564{
1565 assert( Gia_ObjIsCo(pObj) );
1566 printf( "TFI cone of CO number %d:\n", Gia_ObjCioId(pObj) );
1567 Gia_ManPrintCo_rec( p, Gia_ObjFanin0(pObj) );
1568 Gia_ObjPrint( p, pObj );
1569}
1570
1572{
1573 if ( Vec_IntFind(vNodes, Gia_ObjId(p, pObj)) >= 0 )
1574 return;
1575 assert( Gia_ObjIsAnd(pObj) );
1576 Gia_ManPrintCollect_rec( p, Gia_ObjFanin0(pObj), vNodes );
1577 Gia_ManPrintCollect_rec( p, Gia_ObjFanin1(pObj), vNodes );
1578 if ( Gia_ObjIsMux(p, pObj) )
1579 Gia_ManPrintCollect_rec( p, Gia_ObjFanin2(p, pObj), vNodes );
1580 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
1581}
1582void Gia_ManPrintCone( Gia_Man_t * p, Gia_Obj_t * pObj, int * pLeaves, int nLeaves, Vec_Int_t * vNodes )
1583{
1584 int i;
1585 Vec_IntClear( vNodes );
1586 for ( i = 0; i < nLeaves; i++ )
1587 Vec_IntPush( vNodes, pLeaves[i] );
1588 Gia_ManPrintCollect_rec( p, pObj, vNodes );
1589 printf( "GIA logic cone for node %d:\n", Gia_ObjId(p, pObj) );
1590 Gia_ManForEachObjVec( vNodes, p, pObj, i )
1591 Gia_ObjPrint( p, pObj );
1592}
1593void Gia_ManPrintConeMulti( Gia_Man_t * p, Vec_Int_t * vObjs, Vec_Int_t * vLeaves, Vec_Int_t * vNodes )
1594{
1595 Gia_Obj_t * pObj;
1596 int i;
1597 Vec_IntClear( vNodes );
1598 Vec_IntAppend( vNodes, vLeaves );
1599 Gia_ManForEachObjVec( vObjs, p, pObj, i )
1600 Gia_ManPrintCollect_rec( p, pObj, vNodes );
1601 printf( "GIA logic cone for %d nodes:\n", Vec_IntSize(vObjs) );
1602 Gia_ManForEachObjVec( vNodes, p, pObj, i )
1603 Gia_ObjPrint( p, pObj );
1604}
1605
1607{
1608 if ( Vec_IntFind(vNodes, Gia_ObjId(p, pObj)) >= 0 )
1609 return;
1610 if ( Gia_ObjIsCo(pObj) || Gia_ObjIsAnd(pObj) )
1611 Gia_ManPrintCollect2_rec( p, Gia_ObjFanin0(pObj), vNodes );
1612 if ( Gia_ObjIsAnd(pObj) )
1613 Gia_ManPrintCollect2_rec( p, Gia_ObjFanin1(pObj), vNodes );
1614 if ( Gia_ObjIsMux(p, pObj) )
1615 Gia_ManPrintCollect2_rec( p, Gia_ObjFanin2(p, pObj), vNodes );
1616 Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
1617}
1619{
1620 Vec_Int_t * vNodes;
1621 int i;
1622 vNodes = Vec_IntAlloc( 100 );
1623 Gia_ManPrintCollect2_rec( p, pObj, vNodes );
1624 printf( "GIA logic cone for node %d:\n", Gia_ObjId(p, pObj) );
1625 Gia_ManForEachObjVec( vNodes, p, pObj, i )
1626 Gia_ObjPrint( p, pObj );
1627 Vec_IntFree( vNodes );
1628}
1629
1642{
1643 Gia_Obj_t * pObj;
1644 int i;
1645 if ( Gia_ManConstrNum(pAig) == 0 )
1646 return;
1647 Gia_ManForEachPo( pAig, pObj, i )
1648 if ( i >= Gia_ManPoNum(pAig) - Gia_ManConstrNum(pAig) )
1649 Gia_ObjFlipFaninC0( pObj );
1650}
1652{
1653 Gia_Obj_t * pObj;
1654 int i;
1655 Gia_ManForEachPo( pAig, pObj, i )
1656 Gia_ObjFlipFaninC0( pObj );
1657}
1658
1670void Gia_ManCollectObjs_rec( Gia_Man_t * p, int iObjId, Vec_Int_t * vObjs, int Limit )
1671{
1672 Gia_Obj_t * pObj;
1673 if ( Vec_IntSize(vObjs) == Limit )
1674 return;
1675 if ( Gia_ObjIsTravIdCurrentId(p, iObjId) )
1676 return;
1677 Gia_ObjSetTravIdCurrentId(p, iObjId);
1678 pObj = Gia_ManObj( p, iObjId );
1679 if ( Gia_ObjIsAnd(pObj) )
1680 {
1681 Gia_ManCollectObjs_rec( p, Gia_ObjFaninId0p(p, pObj), vObjs, Limit );
1682 if ( Vec_IntSize(vObjs) == Limit )
1683 return;
1684 Gia_ManCollectObjs_rec( p, Gia_ObjFaninId1p(p, pObj), vObjs, Limit );
1685 if ( Vec_IntSize(vObjs) == Limit )
1686 return;
1687 }
1688 Vec_IntPush( vObjs, iObjId );
1689}
1690unsigned * Gia_ManComputePoTruthTables( Gia_Man_t * p, int nBytesMax )
1691{
1692 int nVars = Gia_ManPiNum(p);
1693 int nTruthWords = Abc_TruthWordNum( nVars );
1694 int nTruths = nBytesMax / (sizeof(unsigned) * nTruthWords);
1695 int nTotalNodes = 0, nRounds = 0;
1696 Vec_Int_t * vObjs;
1697 Gia_Obj_t * pObj;
1698 abctime clk = Abc_Clock();
1699 int i;
1700 printf( "Var = %d. Words = %d. Truths = %d.\n", nVars, nTruthWords, nTruths );
1701 vObjs = Vec_IntAlloc( nTruths );
1703 Gia_ManForEachPo( p, pObj, i )
1704 {
1705 Gia_ManCollectObjs_rec( p, Gia_ObjFaninId0p(p, pObj), vObjs, nTruths );
1706 if ( Vec_IntSize(vObjs) == nTruths )
1707 {
1708 nRounds++;
1709// printf( "%d ", i );
1710 nTotalNodes += Vec_IntSize( vObjs );
1711 Vec_IntClear( vObjs );
1713 }
1714 }
1715// printf( "\n" );
1716 nTotalNodes += Vec_IntSize( vObjs );
1717 Vec_IntFree( vObjs );
1718
1719 printf( "Rounds = %d. Objects = %d. Total = %d. ", nRounds, Gia_ManObjNum(p), nTotalNodes );
1720 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
1721
1722 return NULL;
1723}
1724
1725
1738{
1739 Gia_Obj_t * pObj1, * pObj2;
1740 int i;
1741 if ( Gia_ManObjNum(p1) != Gia_ManObjNum(p2) )
1742 {
1743 printf( "AIGs have different number of objects.\n" );
1744 return 0;
1745 }
1746 Gia_ManCleanValue( p1 );
1747 Gia_ManCleanValue( p2 );
1748 Gia_ManForEachObj( p1, pObj1, i )
1749 {
1750 pObj2 = Gia_ManObj( p2, i );
1751 if ( memcmp( pObj1, pObj2, sizeof(Gia_Obj_t) ) )
1752 {
1753 printf( "Objects %d are different.\n", i );
1754 return 0;
1755 }
1756 if ( p1->pReprs && p2->pReprs )
1757 {
1758 if ( memcmp( &p1->pReprs[i], &p2->pReprs[i], sizeof(Gia_Rpr_t) ) )
1759 {
1760 printf( "Representatives of objects %d are different.\n", i );
1761 return 0;
1762 }
1763 }
1764 }
1765 return 1;
1766}
1767
1780{
1781 Gia_Obj_t * pObj;
1782 int i;
1783 Gia_ManForEachObj( p, pObj, i )
1784 {
1785 pObj->fMark0 = 0;
1786 if ( Gia_ObjIsAnd(pObj) )
1787 {
1788 Gia_ObjFanin0(pObj)->fMark0 = 1;
1789 Gia_ObjFanin1(pObj)->fMark0 = 1;
1790 }
1791 else if ( Gia_ObjIsCo(pObj) )
1792 Gia_ObjFanin0(pObj)->fMark0 = 1;
1793 }
1794}
1795
1796
1809{
1810 int Lit0, LitI;
1811 assert( i >= 0 && i < Gia_ManPoNum(p) );
1812 if ( i == 0 )
1813 return;
1814 Lit0 = Gia_ObjFaninLit0p( p, Gia_ManPo(p, 0) );
1815 LitI = Gia_ObjFaninLit0p( p, Gia_ManPo(p, i) );
1816 Gia_ManPatchCoDriver( p, 0, LitI );
1817 Gia_ManPatchCoDriver( p, i, Lit0 );
1818}
1819
1832{
1833 Vec_Int_t * vValues;
1834 Gia_Obj_t * pObj;
1835 int i;
1836 vValues = Vec_IntAlloc( Gia_ManObjNum(p) );
1837 Gia_ManForEachObj( p, pObj, i )
1838 Vec_IntPush( vValues, pObj->Value );
1839 return vValues;
1840}
1842{
1843 Gia_Obj_t * pObj;
1844 int i;
1845 Gia_ManForEachObj( p, pObj, i )
1846 pObj->Value = Vec_IntEntry(vValues, i);
1847}
1848
1849
1862{
1863 Vec_Int_t * vFans = Vec_IntStart( Gia_ManObjNum(p) );
1864 Gia_Obj_t * pObj;
1865 int i;
1866 Gia_ManForEachObj( p, pObj, i )
1867 {
1868 if ( Gia_ObjIsAnd(pObj) )
1869 {
1870 if ( Vec_IntEntry(vFans, Gia_ObjFaninId0p(p, pObj)) == 0 )
1871 Vec_IntWriteEntry(vFans, Gia_ObjFaninId0p(p, pObj), i);
1872 if ( Vec_IntEntry(vFans, Gia_ObjFaninId1p(p, pObj)) == 0 )
1873 Vec_IntWriteEntry(vFans, Gia_ObjFaninId1p(p, pObj), i);
1874 if ( Gia_ObjIsMuxId(p, i) && Vec_IntEntry(vFans, Gia_ObjFaninId2p(p, pObj)) == 0 )
1875 Vec_IntWriteEntry(vFans, Gia_ObjFaninId2p(p, pObj), i);
1876 }
1877 else if ( Gia_ObjIsCo(pObj) )
1878 {
1879 if ( Vec_IntEntry(vFans, Gia_ObjFaninId0p(p, pObj)) == 0 )
1880 Vec_IntWriteEntry(vFans, Gia_ObjFaninId0p(p, pObj), i);
1881 }
1882 }
1883 return vFans;
1884}
1885
1898{
1899 Gia_Obj_t * pObj;
1900 int i, Counter1 = 0, Counter2 = 0;
1901 int nFailNoRepr = 0;
1902 int nFailHaveRepr = 0;
1903 int nChoiceNodes = 0;
1904 int nChoices = 0;
1905 if ( p->pReprs == NULL || p->pNexts == NULL )
1906 return 0;
1907 // check if there are any representatives
1908 Gia_ManForEachObj( p, pObj, i )
1909 {
1910 if ( Gia_ObjReprObj( p, Gia_ObjId(p, pObj) ) )
1911 {
1912// printf( "%d ", i );
1913 Counter1++;
1914 }
1915// if ( Gia_ObjNext( p, Gia_ObjId(p, pObj) ) )
1916// Counter2++;
1917 }
1918// printf( "\n" );
1919 Gia_ManForEachObj( p, pObj, i )
1920 {
1921// if ( Gia_ObjReprObj( p, Gia_ObjId(p, pObj) ) )
1922// Counter1++;
1923 if ( Gia_ObjNext( p, Gia_ObjId(p, pObj) ) )
1924 {
1925// printf( "%d ", i );
1926 Counter2++;
1927 }
1928 }
1929// printf( "\n" );
1930 if ( Counter1 == 0 )
1931 {
1932 printf( "Warning: AIG has repr data-strucure but not reprs.\n" );
1933 return 0;
1934 }
1935 printf( "%d nodes have reprs.\n", Counter1 );
1936 printf( "%d nodes have nexts.\n", Counter2 );
1937 // check if there are any internal nodes without fanout
1938 // make sure all nodes without fanout have representatives
1939 // make sure all nodes with fanout have no representatives
1940 ABC_FREE( p->pRefs );
1942 Gia_ManForEachAnd( p, pObj, i )
1943 {
1944 if ( Gia_ObjRefNum(p, pObj) == 0 )
1945 {
1946 if ( Gia_ObjReprObj( p, Gia_ObjId(p, pObj) ) == NULL )
1947 nFailNoRepr++;
1948 else
1949 nChoices++;
1950 }
1951 else
1952 {
1953 if ( Gia_ObjReprObj( p, Gia_ObjId(p, pObj) ) != NULL )
1954 nFailHaveRepr++;
1955 if ( Gia_ObjNextObj( p, Gia_ObjId(p, pObj) ) != NULL )
1956 nChoiceNodes++;
1957 }
1958 if ( Gia_ObjReprObj( p, i ) )
1959 assert( Gia_ObjRepr(p, i) < i );
1960 }
1961 if ( nChoices == 0 )
1962 return 0;
1963 if ( nFailNoRepr )
1964 {
1965 printf( "Gia_ManHasChoices_very_old(): Error: %d internal nodes have no fanout and no repr.\n", nFailNoRepr );
1966// return 0;
1967 }
1968 if ( nFailHaveRepr )
1969 {
1970 printf( "Gia_ManHasChoices_very_old(): Error: %d internal nodes have both fanout and repr.\n", nFailHaveRepr );
1971// return 0;
1972 }
1973// printf( "Gia_ManHasChoices_very_old(): AIG has %d choice nodes with %d choices.\n", nChoiceNodes, nChoices );
1974 return 1;
1975}
1976
1977
1989Vec_Int_t * Gia_ManGroupProve( Gia_Man_t * pInit, char * pCommLine, int nGroupSize, int fVerbose )
1990{
1992 Gia_Man_t * p = Gia_ManDup( pInit );
1993 Gia_Man_t * pGroup;
1994 Vec_Int_t * vOuts;
1995 Vec_Int_t * vOutMap;
1996 Vec_Ptr_t * vCexes;
1997 int i, k, nGroupCur, nGroups;
1998 abctime clk, timeComm = 0;
1999 abctime timeStart = Abc_Clock();
2000 // pre-conditions
2001 assert( nGroupSize > 0 );
2002 assert( pCommLine != NULL );
2003 assert( p->nConstrs == 0 );
2004 Abc_Print( 1, "RUNNING MultiProve: Group size = %d. Command line = \"%s\".\n", nGroupSize, pCommLine );
2005 // create output map
2006 vOuts = Vec_IntStartNatural( Gia_ManPoNum(p) );
2007 vOutMap = Vec_IntAlloc( Gia_ManPoNum(p) );
2008 vCexes = Vec_PtrAlloc( Gia_ManPoNum(p) );
2009 nGroups = Gia_ManPoNum(p) / nGroupSize + (int)((Gia_ManPoNum(p) % nGroupSize) > 0);
2010 for ( i = 0; i < nGroups; i++ )
2011 {
2012 // derive the group
2013 nGroupCur = ((i + 1) * nGroupSize < Gia_ManPoNum(p)) ? nGroupSize : Gia_ManPoNum(p) - i * nGroupSize;
2014 pGroup = Gia_ManDupCones( p, Vec_IntArray(vOuts) + i * nGroupSize, nGroupCur, 0 );
2015 Abc_Print( 1, "GROUP %4d : %4d <= PoId < %4d : ", i, i * nGroupSize, i * nGroupSize + nGroupCur );
2016 // set the current GIA
2017 Abc_FrameUpdateGia( pAbc, pGroup );
2018 // solve the group
2019 clk = Abc_Clock();
2020 Cmd_CommandExecute( pAbc, pCommLine );
2021 timeComm += Abc_Clock() - clk;
2022 // get the solution status
2023 if ( nGroupSize == 1 )
2024 {
2025 Vec_IntPush( vOutMap, Abc_FrameReadProbStatus(pAbc) );
2026 Vec_PtrPush( vCexes, Abc_FrameReadCex(pAbc) );
2027 }
2028 else // if ( nGroupSize > 1 )
2029 {
2030 Vec_Int_t * vStatusCur = Abc_FrameReadPoStatuses( pAbc );
2031 Vec_Ptr_t * vCexesCur = Abc_FrameReadCexVec( pAbc );
2032 assert( vStatusCur != NULL ); // only works for "bmc3" and "pdr"
2033// assert( vCexesCur != NULL );
2034 for ( k = 0; k < nGroupCur; k++ )
2035 {
2036 Vec_IntPush( vOutMap, Vec_IntEntry(vStatusCur, k) );
2037 Vec_PtrPush( vCexes, vCexesCur ? Vec_PtrEntry(vCexesCur, k) : NULL );
2038 }
2039 }
2040 }
2041 assert( Vec_PtrSize(vCexes) == Gia_ManPoNum(p) );
2042 assert( Vec_IntSize(vOutMap) == Gia_ManPoNum(p) );
2043 // set CEXes
2044 if ( Vec_PtrCountZero(vCexes) < Vec_PtrSize(vCexes) )
2045 Abc_FrameReplaceCexVec( pAbc, &vCexes );
2046 else // there is no CEXes
2047 Vec_PtrFree( vCexes );
2048 // report the result
2049 Abc_Print( 1, "SUMMARY: " );
2050 Abc_Print( 1, "Properties = %6d. ", Gia_ManPoNum(p) );
2051 Abc_Print( 1, "UNSAT = %6d. ", Vec_IntCountEntry(vOutMap, 1) );
2052 Abc_Print( 1, "SAT = %6d. ", Vec_IntCountEntry(vOutMap, 0) );
2053 Abc_Print( 1, "UNDEC = %6d. ", Vec_IntCountEntry(vOutMap, -1) );
2054 Abc_Print( 1, "\n" );
2055 Abc_PrintTime( 1, "Command time", timeComm );
2056 Abc_PrintTime( 1, "Total time ", Abc_Clock() - timeStart );
2057 // cleanup
2058 Vec_IntFree( vOuts );
2059 Gia_ManStop( p );
2060 return vOutMap;
2061}
2062
2063
2075Vec_Int_t * Gia_ManPoXSim( Gia_Man_t * p, int nFrames, int fVerbose )
2076{
2077 Vec_Int_t * vRes;
2078 Gia_Obj_t * pObj;
2079 int f, k, nLeft = Gia_ManPoNum(p);
2080 vRes = Vec_IntAlloc( Gia_ManPoNum(p) );
2081 Vec_IntFill( vRes, Gia_ManPoNum(p), nFrames );
2082 Gia_ObjTerSimSet0( Gia_ManConst0(p) );
2083 Gia_ManForEachRi( p, pObj, k )
2084 Gia_ObjTerSimSet0( pObj );
2085 for ( f = 0; f < nFrames; f++ )
2086 {
2087 Gia_ManForEachPi( p, pObj, k )
2088 Gia_ObjTerSimSetX( pObj );
2089 Gia_ManForEachRo( p, pObj, k )
2090 Gia_ObjTerSimRo( p, pObj );
2091 Gia_ManForEachAnd( p, pObj, k )
2092 Gia_ObjTerSimAnd( pObj );
2093 Gia_ManForEachCo( p, pObj, k )
2094 Gia_ObjTerSimCo( pObj );
2095 if ( fVerbose )
2096 {
2097 Gia_ManForEachPo( p, pObj, k )
2098 Gia_ObjTerSimPrint( pObj );
2099 printf( "\n" );
2100 }
2101 Gia_ManForEachPo( p, pObj, k )
2102 if ( Vec_IntEntry(vRes, k) == nFrames && Gia_ObjTerSimGetX(pObj) )
2103 Vec_IntWriteEntry(vRes, k, f), nLeft--;
2104 if ( nLeft == 0 )
2105 break;
2106 }
2107 if ( fVerbose )
2108 {
2109 if ( nLeft == 0 )
2110 printf( "Simulation converged after %d frames.\n", f+1 );
2111 else
2112 printf( "Simulation terminated after %d frames.\n", nFrames );
2113 }
2114// Vec_IntPrint( vRes );
2115 return vRes;
2116}
2117
2118#define MAX_LUT_SIZE 8
2119typedef struct Gia_MapLut_t_
2120{
2121 int Type; // node type: PI=1, PO=2, LUT=3
2122 int Out; // ID
2123 int StartId; // -1
2124 int nFans; // fanin count
2125 float Delay; // 0.0
2126 int pFans[MAX_LUT_SIZE]; // fanin IDs
2127 unsigned pTruth[MAX_LUT_SIZE<6?1:(1<<(MAX_LUT_SIZE-5))]; // the truth table
2129
2141void Gia_AigerWriteLut( Gia_Man_t * p, char * pFileName )
2142{
2143 Gia_Obj_t * pObj;
2144 int i, k, iFan, iLut = 0;
2145 int LutSizeMax = Gia_ManLutSizeMax( p );
2146 int nUints = Abc_TruthWordNum(LutSizeMax);
2147 int nLuts = 1 + Gia_ManCiNum(p) + Gia_ManCoNum(p) + Gia_ManLutNum(p);
2148 Gia_MapLut_t * pLuts = ABC_CALLOC( Gia_MapLut_t, nLuts );
2149 Vec_Wrd_t * vTruths = Vec_WrdStart( Gia_ManObjNum(p) );
2150 assert( LutSizeMax <= 6 );
2151 // set obj numbers
2152 // constant
2153 pLuts->Type = 3;
2154 memset( pLuts->pTruth, 0xFF, sizeof(unsigned) * nUints );
2156 Gia_ManConst0(p)->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
2157 iLut++;
2158 // inputs
2159 Gia_ManForEachCi( p, pObj, i )
2160 {
2161 pLuts[iLut].Type = 1;
2162 memset( pLuts[iLut].pTruth, 0xAA, sizeof(unsigned) * nUints );
2163 pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
2164 iLut++;
2165 }
2166 // nodes
2167 Gia_ManForEachObj( p, pObj, i )
2168 if ( i && Gia_ObjIsLut(p, i) )
2169 {
2170 word truth;
2171 pLuts[iLut].Type = 3;
2172 Gia_LutForEachFanin( p, i, iFan, k )
2173 pLuts[iLut].pFans[k] = Gia_ManObj(p, iFan)->Value;
2174 pLuts[iLut].nFans = k;
2175 truth = Gia_LutComputeTruth6(p, i, vTruths);
2176 memcpy( pLuts[iLut].pTruth, &truth, sizeof(word) );
2177 pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
2178 iLut++;
2179 }
2180 // outputs
2181 Gia_ManForEachCo( p, pObj, i )
2182 {
2183 pLuts[iLut].Type = 2;
2184 pLuts[iLut].pFans[0] = Gia_ObjFanin0(pObj)->Value;
2185 if ( Gia_ObjFaninC0(pObj) ^ Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
2186 memset( pLuts[iLut].pTruth, 0x55, sizeof(unsigned) * nUints );
2187 else
2188 memset( pLuts[iLut].pTruth, 0xAA, sizeof(unsigned) * nUints );
2189 pLuts[iLut].nFans = 1;
2190 pObj->Value = pLuts[iLut].Out = Abc_Var2Lit( iLut, 0 );
2191 iLut++;
2192 }
2193 assert( iLut == nLuts );
2194 // dump into a file
2195 {
2196 FILE * pFile = fopen( pFileName, "wb" );
2197 if ( pFile == NULL )
2198 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
2199 else
2200 {
2201 int nSize1 = nLuts * sizeof(Gia_MapLut_t);
2202 int nSize2 = fwrite( pLuts, 1, nSize1, pFile );
2203 assert( nSize1 == nSize2 );
2204 printf( "Successfully dumped %d bytes of binary data.\n", nSize1 );
2205 }
2206 fclose( pFile );
2207 }
2208 ABC_FREE( pLuts );
2209 Vec_WrdFree( vTruths );
2210}
2211
2223void Gia_DumpLutSizeDistrib( Gia_Man_t * p, char * pFileName )
2224{
2225 FILE * pTable = fopen( pFileName, "a+" );
2226 int i, Counts[10] = {0};
2227 Gia_ManForEachLut( p, i )
2228 if ( Gia_ObjLutSize(p, i) > 0 && Gia_ObjLutSize(p, i) < 10 )
2229 Counts[ Gia_ObjLutSize(p, i) ]++;
2230 fprintf( pTable, "%s", p->pName );
2231 for ( i = 1; i < 10; i++ )
2232 fprintf( pTable, " %d", Counts[i] );
2233 fprintf( pTable, "\n" );
2234 fclose( pTable );
2235}
2236
2249{
2250 if ( pObj->fMark0 )
2251 return;
2252 pObj->fMark0 = 1;
2253 if ( Gia_ObjIsCi(pObj) )
2254 return;
2255 Gia_ManCheckSuppMark_rec( p, Gia_ObjFanin0(pObj) );
2256 Gia_ManCheckSuppMark_rec( p, Gia_ObjFanin1(pObj) );
2257}
2259{
2260 if ( !pObj->fMark0 )
2261 return;
2262 pObj->fMark0 = 0;
2263 if ( Gia_ObjIsCi(pObj) )
2264 return;
2265 Gia_ManCheckSuppUnmark_rec( p, Gia_ObjFanin0(pObj) );
2266 Gia_ManCheckSuppUnmark_rec( p, Gia_ObjFanin1(pObj) );
2267}
2269{
2270 if ( pObj->fMark0 )
2271 return 1;
2272 if ( Gia_ObjIsCi(pObj) )
2273 return 0;
2274 if ( Gia_ManCheckSupp_rec( p, Gia_ObjFanin0(pObj) ) )
2275 return 1;
2276 return Gia_ManCheckSupp_rec( p, Gia_ObjFanin1(pObj) );
2277}
2278int Gia_ManCheckSuppOverlap( Gia_Man_t * p, int iNode1, int iNode2 )
2279{
2280 int Result;
2281 if ( iNode1 == 0 || iNode2 == 0 )
2282 return 0;
2283 Gia_ManCheckSuppMark_rec( p, Gia_ManObj(p, iNode1) );
2284 Result = Gia_ManCheckSupp_rec( p, Gia_ManObj(p, iNode2) );
2285 Gia_ManCheckSuppUnmark_rec( p, Gia_ManObj(p, iNode1) );
2286 return Result;
2287}
2288
2289
2302{
2303 Gia_Obj_t * pObj;
2304 int i, Count = 0;
2305 Gia_ManForEachCi( p, pObj, i )
2306 pObj->fMark0 = 0;
2307 Gia_ManForEachAnd( p, pObj, i )
2308 {
2309 Gia_ObjFanin0(pObj)->fMark0 = 1;
2310 Gia_ObjFanin1(pObj)->fMark0 = 1;
2311 }
2312 Gia_ManForEachCo( p, pObj, i )
2313 Gia_ObjFanin0(pObj)->fMark0 = 1;
2314 Gia_ManForEachCi( p, pObj, i )
2315 Count += pObj->fMark0;
2316 Gia_ManForEachObj( p, pObj, i )
2317 pObj->fMark0 = 0;
2318 return Count;
2319}
2320
2333{
2334 Gia_Obj_t * pObj;
2335 int i, Count = 0;
2336 Gia_ManForEachCo( p, pObj, i )
2337 Count += Gia_ObjFaninLit0(pObj, Gia_ObjId(p, pObj)) != 0;
2338 return Count;
2339}
2340
2353{
2354 Gia_Obj_t * pObj;
2355 int i, iLit;
2356 Vec_IntForEachEntry( vCopy, iLit, i )
2357 {
2358 if ( iLit == -1 )
2359 continue;
2360 pObj = Gia_ManObj( p, Abc_Lit2Var(iLit) );
2361 if ( !~pObj->Value )
2362 Vec_IntWriteEntry( vCopy, i, -1 );
2363 else
2364 Vec_IntWriteEntry( vCopy, i, Abc_LitNotCond(pObj->Value, Abc_LitIsCompl(iLit)) );
2365 }
2366}
2367
2380{
2381 Vec_Int_t * vPoints = Vec_IntAlloc( 1000 );
2382 Vec_Int_t * vQuads = Vec_IntAlloc( 1000 );
2383 Vec_Bit_t * vHeads = Vec_BitStart( Gia_ManObjNum(p) );
2384 Vec_Bit_t * vDatas = Vec_BitStart( Gia_ManObjNum(p) );
2385 Gia_Obj_t * pObj, * pCtrl, * pData0, * pData1;
2386 Gia_Man_t * pNew = Gia_ManDup( p ); int i, iObj;
2387 assert( Gia_ManRegNum(pNew) == 0 );
2388 Gia_ManForEachAnd( pNew, pObj, i )
2389 {
2390 if ( !Gia_ObjIsMuxType(pObj) )
2391 continue;
2392 pCtrl = Gia_ObjRecognizeMux( pObj, &pData1, &pData0 );
2393 pCtrl = Gia_Regular(pCtrl);
2394 pData0 = Gia_Regular(pData0);
2395 pData1 = Gia_Regular(pData1);
2396 Vec_IntPushTwo( vQuads, Gia_ObjId(pNew, pObj), Gia_ObjId(pNew, pCtrl) );
2397 Vec_IntPushTwo( vQuads, Gia_ObjId(pNew, pData0), Gia_ObjId(pNew, pData1) );
2398 Vec_BitWriteEntry( vHeads, Gia_ObjId(pNew, pObj), 1 );
2399 Vec_BitWriteEntry( vDatas, Gia_ObjId(pNew, pData0), 1 );
2400 Vec_BitWriteEntry( vDatas, Gia_ObjId(pNew, pData1), 1 );
2401 }
2402 Gia_ManForEachCo( pNew, pObj, i )
2403 Gia_ObjFanin0(pObj)->fMark0 = 1;
2404 for ( i = 0; i < Vec_IntSize(vQuads)/4; i++ )
2405 {
2406 int iObj = Vec_IntEntry( vQuads, 4*i+0 );
2407 int iCtrl = Vec_IntEntry( vQuads, 4*i+1 );
2408 int iData0 = Vec_IntEntry( vQuads, 4*i+2 );
2409 int iData1 = Vec_IntEntry( vQuads, 4*i+3 );
2410 if ( (Vec_BitEntry(vHeads, iObj) && Vec_BitEntry(vDatas, iObj)) ||
2411 (Vec_BitEntry(vHeads, iData0) && Vec_BitEntry(vDatas, iData0)) ||
2412 (Vec_BitEntry(vHeads, iData1) && Vec_BitEntry(vDatas, iData1)) )
2413 {
2414 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
2415 Gia_Obj_t * pCtrl = Gia_ManObj( p, iCtrl );
2416 Gia_Obj_t * pData0 = Gia_ManObj( p, iData0 );
2417 Gia_Obj_t * pData1 = Gia_ManObj( p, iData1 );
2418 if ( Gia_ObjIsAnd(pObj) && !pObj->fMark0 ) Vec_IntPush( vPoints, iObj );
2419 if ( Gia_ObjIsAnd(pCtrl) && !pCtrl->fMark0 ) Vec_IntPush( vPoints, iCtrl );
2420 if ( Gia_ObjIsAnd(pData0) && !pData0->fMark0 ) Vec_IntPush( vPoints, iData0 );
2421 if ( Gia_ObjIsAnd(pData1) && !pData1->fMark0 ) Vec_IntPush( vPoints, iData1 );
2422 }
2423 }
2424 Gia_ManCleanMark0( pNew );
2425 Vec_IntUniqify( vPoints );
2426 Vec_IntForEachEntry( vPoints, iObj, i )
2427 Gia_ManAppendCo( pNew, Abc_Var2Lit(iObj, 0) );
2428 Vec_IntFree( vPoints );
2429 Vec_IntFree( vQuads );
2430 Vec_BitFree( vHeads );
2431 Vec_BitFree( vDatas );
2432 return pNew;
2433}
2434
2446void Gia_ManRingAdd( Gia_Man_t * p, int iObj, Vec_Int_t * vRes, Vec_Int_t * vDists, int Dist )
2447{
2448 if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
2449 return;
2450 Gia_ObjSetTravIdCurrentId(p, iObj);
2451 Vec_IntWriteEntry( vDists, iObj, Dist );
2452 Vec_IntPush( vRes, iObj );
2453}
2454void Gia_ManCollectRing( Gia_Man_t * p, Vec_Int_t * vStart, Vec_Int_t * vRes, Vec_Int_t * vDists )
2455{
2456 int i, k, iObj, iFan;
2457 Vec_IntForEachEntry( vStart, iObj, i )
2458 {
2459 int Weight = Vec_IntEntry( vDists, iObj );
2460 Gia_Obj_t * pObj = Gia_ManObj(p, iObj);
2461 assert( Weight > 0 );
2462 if ( Gia_ObjIsAnd(pObj) )
2463 {
2464 Gia_ManRingAdd( p, Gia_ObjFaninId0(pObj, iObj), vRes, vDists, Weight + 1*!Gia_ObjIsBuf(Gia_ObjFanin0(pObj)) );
2465 Gia_ManRingAdd( p, Gia_ObjFaninId1(pObj, iObj), vRes, vDists, Weight + 1*!Gia_ObjIsBuf(Gia_ObjFanin1(pObj)) );
2466 }
2467 Gia_ObjForEachFanoutStaticId( p, iObj, iFan, k )
2468 Gia_ManRingAdd( p, iFan, vRes, vDists, Weight + 1*!Gia_ObjIsBuf(Gia_ManObj(p, iFan)) );
2469 }
2470}
2471Vec_Int_t * Gia_ManComputeDistanceInt( Gia_Man_t * p, int iTarg, Vec_Int_t * vObjs, int fVerbose )
2472{
2473 int i, iObj;
2474 Vec_Int_t * vDists, * vStart, * vNexts;
2475 vStart = Vec_IntAlloc( 100 );
2476 vNexts = Vec_IntAlloc( 100 );
2477 vDists = Vec_IntStart( Gia_ManObjNum(p) );
2479 if ( vObjs )
2480 {
2481 Vec_IntForEachEntry( vObjs, iObj, i )
2482 {
2483 Gia_ObjSetTravIdCurrentId(p, iObj);
2484 Vec_IntWriteEntry( vDists, iObj, 1 );
2485 Vec_IntPush( vStart, iObj );
2486 }
2487 }
2488 else
2489 {
2490 Gia_ObjSetTravIdCurrentId(p, iTarg);
2491 Vec_IntWriteEntry( vDists, iTarg, 1 );
2492 Vec_IntPush( vStart, iTarg );
2493 }
2494 for ( i = 0; ; i++ )
2495 {
2496 if ( fVerbose )
2497 printf( "Ring %2d : %6d\n", i, Vec_IntSize(vDists)-Vec_IntCountZero(vDists) );
2498 Gia_ManCollectRing( p, vStart, vNexts, vDists );
2499 if ( Vec_IntSize(vNexts) == 0 )
2500 break;
2501 Vec_IntClear( vStart );
2502 ABC_SWAP( Vec_Int_t, *vStart, *vNexts );
2503 }
2504 Vec_IntFree( vStart );
2505 Vec_IntFree( vNexts );
2506 return vDists;
2507}
2508Vec_Int_t * Gia_ManComputeDistance( Gia_Man_t * p, int iObj, Vec_Int_t * vObjs, int fVerbose )
2509{
2510 Vec_Int_t * vDists;
2511 if ( p->vFanoutNums )
2512 vDists = Gia_ManComputeDistanceInt( p, iObj, vObjs, fVerbose );
2513 else
2514 {
2516 vDists = Gia_ManComputeDistanceInt( p, iObj, vObjs, fVerbose );
2518 }
2519 return vDists;
2520}
2521
2522
2535{
2536 char * pStart, Line [1000]; float Total = 0;
2537 char * pFileName = "data.txt";
2538 FILE * pFile = fopen( pFileName, "r" );
2539 if ( pFile == NULL )
2540 { printf( "Input file \"%s\" cannot be opened.\n", pFileName ); return; }
2541 while ( fgets( Line, 1000, pFile ) != NULL )
2542 {
2543 if ( !strstr(Line, "xxx") )
2544 continue;
2545 if ( !strstr(Line, "yyy") )
2546 continue;
2547 //printf( "%s", Line );
2548 pStart = strstr(Line, "zzz");
2549 if ( pStart == NULL )
2550 continue;
2551 //printf( "%s", pStart + 4 );
2552 Total += -atof( pStart + 4 );
2553 }
2554 printf( "Total = %.2f\n", Total );
2555 fclose( pFile );
2556}
2557
2558
2571{
2572 Gia_Obj_t * pObj;
2573 Vec_Wec_t * vSupps = Vec_WecStart( Gia_ManObjNum(p) );
2574 int i, nResult = 0;
2575 for ( i = 0; i < Gia_ManCiNum(p); i++ )
2576 Vec_IntPush( Vec_WecEntry(vSupps, 1+i), i );
2577 Gia_ManForEachAnd( p, pObj, i )
2578 Vec_IntTwoMerge2( Vec_WecEntry(vSupps, Gia_ObjFaninId0(pObj, i)), Vec_WecEntry(vSupps, Gia_ObjFaninId1(pObj, i)), Vec_WecEntry(vSupps, i) );
2579 Gia_ManForEachCo( p, pObj, i )
2580 nResult += Vec_IntSize( Vec_WecEntry(vSupps, Gia_ObjFaninId0p(p, pObj)) );
2581 Vec_WecFree( vSupps );
2582 return nResult;
2583}
2584
2597{
2598 Vec_Wrd_t * vSims = Vec_WrdStart( Gia_ManObjNum(p) );
2599 int r, nResult = 0, nRounds = (Gia_ManCiNum(p) + 63)/64;
2600 for ( r = 0; r < nRounds; r++ )
2601 {
2602 Gia_Obj_t * pObj;
2603 int i, Limit = r == nRounds-1 ? Gia_ManCiNum(p) % 64 : 64;
2604 for ( i = 0; i < Limit; i++ )
2605 Vec_WrdWriteEntry( vSims, 1+64*r+i, (word)1 << i );
2606 Gia_ManForEachAnd( p, pObj, i )
2607 Vec_WrdWriteEntry( vSims, i, Vec_WrdEntry(vSims, Gia_ObjFaninId0(pObj, i)) | Vec_WrdEntry(vSims, Gia_ObjFaninId1(pObj, i)) );
2608 Gia_ManForEachCo( p, pObj, i )
2609 nResult += Abc_TtCountOnes( Vec_WrdEntry(vSims, Gia_ObjFaninId0p(p, pObj)) );
2610 for ( i = 0; i < Limit; i++ )
2611 Vec_WrdWriteEntry( vSims, 1+64*r+i, 0 );
2612 }
2613 Vec_WrdFree( vSims );
2614 return nResult;
2615}
2616
2629{
2630 Gia_Man_t * pNew, * pTemp;
2631 Gia_Obj_t * pObj; int i, m;
2632 Gia_Obj_t * pSink = Gia_ManCo(p, 0);
2633 Vec_Int_t * vRoots = Vec_IntAlloc( 1 );
2634 Vec_Int_t * vNodes = Vec_IntAlloc( 1000 );
2635 Vec_IntPush( vRoots, Gia_ObjFaninId0p(p, pSink) );
2636 Gia_ManCollectTfi( p, vRoots, vNodes );
2637 pNew = Gia_ManStart( Gia_ManObjNum(p) );
2638 pNew->pName = Abc_UtilStrsav( p->pName );
2639 Gia_ManForEachCi( p, pObj, i )
2640 pObj->Value = Gia_ManAppendCi(pNew);
2641 Gia_ManHashAlloc( pNew );
2642 for ( m = 0; m < (1 << nVars); m++ )
2643 {
2644 for ( i = 0; i < nVars; i++ )
2645 Gia_ManCi(p, Gia_ManCiNum(p)-nVars+i)->Value = (m >> i) & 1;
2646 Gia_ManForEachObjVec( vNodes, p, pObj, i )
2647 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2648 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pSink) );
2649 }
2650 pNew = Gia_ManCleanup( pTemp = pNew );
2651 Gia_ManStop( pTemp );
2652 Vec_IntFree( vRoots );
2653 Vec_IntFree( vNodes );
2654 return pNew;
2655}
2656
2669{
2670 Gia_Man_t * pNew, * pTemp;
2671 Gia_Obj_t * pObj, * pSink; int i, o, m;
2672 Vec_Int_t * vSupp = Vec_IntAlloc( 1000 );
2673 Vec_Int_t * vAnds = Vec_IntAlloc( 1000 );
2674 pNew = Gia_ManStart( Gia_ManObjNum(p) );
2675 pNew->pName = Abc_UtilStrsav( p->pName );
2676 Gia_ManForEachCi( p, pObj, i )
2677 {
2678 pObj->Value = Gia_ManAppendCi(pNew);
2679 assert( (int)pObj->Value == Abc_Var2Lit( 1 + Gia_ObjCioId(pObj), 0 ) );
2680 }
2681 Gia_ManHashAlloc( pNew );
2682 Gia_ManForEachRi( p, pSink, o )
2683 {
2684 int Fanin = Gia_ObjFaninId0p( p, pSink );
2685 Vec_Int_t * vNodes = Gia_ManCollectNodesCis( p, &Fanin, 1 );
2686 Vec_IntClear( vSupp );
2687 Vec_IntClear( vAnds );
2688 Gia_ManForEachObjVec( vNodes, p, pObj, i )
2689 Vec_IntPush( Gia_ObjIsAnd(pObj) ? vAnds : vSupp, Gia_ObjId(p, pObj) );
2690 Vec_IntFree( vNodes );
2691 Vec_IntSort( vSupp, 0 );
2692 for ( m = 0; m < 5; m++ )
2693 {
2694 Gia_ManForEachObjVec( vSupp, p, pObj, i )
2695 if ( i >= Vec_IntSize(vSupp)-5 )
2696 pObj->Value = (i == Vec_IntSize(vSupp)-5+m) ? 1 : 0;
2697 Gia_ManForEachObjVec( vAnds, p, pObj, i )
2698 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2699 //if ( m == 4 )
2700 // Gia_ManAppendCo( pNew, 0 );
2701 //else
2702 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pSink) );
2703 Gia_ManAppendCo( pNew, Abc_Var2Lit( Vec_IntEntry(vSupp, Vec_IntSize(vSupp)-5+m), 0 ) );
2704 Gia_ManForEachObjVec( vSupp, p, pObj, i )
2705 if ( i >= Vec_IntSize(vSupp)-5 )
2706 pObj->Value = Abc_Var2Lit( 1 + Gia_ObjCioId(pObj), 0 );
2707 }
2708 }
2709 pNew = Gia_ManCleanup( pTemp = pNew );
2710 Gia_ManStop( pTemp );
2711 Vec_IntFree( vSupp );
2712 Vec_IntFree( vAnds );
2713 return pNew;
2714}
2715
2728{
2729 Gia_Man_t * pNew, * pTemp;
2730 Gia_Obj_t * pObj; int i, n, iLits[2];
2731 Gia_Obj_t * pPivot = Gia_ManCi(p, iIn);
2732 Gia_Obj_t * pSink = Gia_ManCo(p, iOut);
2733 Vec_Int_t * vRoots = Vec_IntAlloc( 1 );
2734 Vec_Int_t * vNodes = Vec_IntAlloc( 1000 );
2735 Vec_IntPush( vRoots, Gia_ObjFaninId0p(p, pSink) );
2736 Gia_ManCollectTfi( p, vRoots, vNodes );
2737 pNew = Gia_ManStart( Gia_ManObjNum(p) );
2738 pNew->pName = Abc_UtilStrsav( p->pName );
2739 Gia_ManForEachCi( p, pObj, i )
2740 pObj->Value = Gia_ManAppendCi(pNew);
2741 Gia_ManHashAlloc( pNew );
2742 for ( n = 0; n < 2; n++ )
2743 {
2744 pPivot->Value = n;
2745 Gia_ManForEachObjVec( vNodes, p, pObj, i )
2746 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2747 iLits[n] = Gia_ObjFanin0Copy(pSink);
2748 }
2749 Gia_ManAppendCo( pNew, Gia_ManHashAnd(pNew, iLits[1], Abc_LitNot(iLits[0])) );
2750 Gia_ManAppendCo( pNew, Gia_ManHashAnd(pNew, iLits[0], Abc_LitNot(iLits[1])) );
2751 pNew = Gia_ManCleanup( pTemp = pNew );
2752 Gia_ManStop( pTemp );
2753 Vec_IntFree( vRoots );
2754 Vec_IntFree( vNodes );
2755 return pNew;
2756}
2757int Gia_ManComputeDep( Gia_Man_t * p, int iIn, int iOut )
2758{
2759 extern Gia_Man_t * Cec4_ManSimulateTest3( Gia_Man_t * p, int nBTLimit, int fVerbose );
2760 Gia_Man_t * pNew = Gia_ManComputeDepAig( p, iIn, iOut );
2761 Gia_Man_t * pSwp = Cec4_ManSimulateTest3( pNew, 100000, 0 );
2762 int iLit[2] = { Gia_ObjFaninId0p( pSwp, Gia_ManCo(pSwp, 0) ), Gia_ObjFaninId0p( pSwp, Gia_ManCo(pSwp, 1) ) };
2763 Gia_ManStop( pNew );
2764 Gia_ManStop( pSwp );
2765 if ( iLit[0] == 0 && iLit[1] == 0 )
2766 return 2;
2767 if ( iLit[1] == 0 )
2768 return 1;
2769 if ( iLit[0] == 0 )
2770 return 0;
2771 return -1;
2772}
2774{
2775 abctime clk = Abc_Clock();
2776 int i;
2777 for ( i = 0; i < Gia_ManCiNum(p); i++ )
2778 printf( "%3d : %3d\n", i, Gia_ManComputeDep(p, i, 0) );
2779 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
2780 return Gia_ManDup(p);
2781}
2782
2795{
2796 Vec_Wec_t * vRes = Vec_WecStart( Gia_ManCoNum(p) );
2797 Vec_Wec_t * vSupps = Vec_WecStart( Gia_ManObjNum(p) );
2798 Gia_Obj_t * pObj; int i;
2799 for ( i = 0; i < Gia_ManCiNum(p); i++ )
2800 Vec_IntPush( Vec_WecEntry(vSupps, 1+i), i );
2801 Gia_ManForEachAnd( p, pObj, i )
2802 Vec_IntTwoMerge2( Vec_WecEntry(vSupps, Gia_ObjFaninId0(pObj, i)), Vec_WecEntry(vSupps, Gia_ObjFaninId1(pObj, i)), Vec_WecEntry(vSupps, i) );
2803 Gia_ManForEachCo( p, pObj, i )
2804 Vec_IntAppend( Vec_WecEntry(vRes, i), Vec_WecEntry(vSupps, Gia_ObjFaninId0p(p, pObj)) );
2805 Vec_WecFree( vSupps );
2806 return vRes;
2807}
2809{
2810 Vec_Wec_t * vDiffs = Vec_WecStart( Vec_WecSize(vSupps) );
2811 Vec_Int_t * vNew, * vOld; int i;
2812 Vec_WecForEachLevelTwo( vDiffs, vSupps, vNew, vOld, i ) if ( i )
2813 Vec_IntTwoFindCommon( Vec_WecEntry(vSupps, i-1), vOld, vNew );
2814 return vDiffs;
2815}
2817{
2818 int fPrintDep = 1;
2819 int nSize = Gia_ManCoNum(p) * (Gia_ManCiNum(p) + 1) + 1;
2820 Vec_Str_t * vRes = Vec_StrAlloc( nSize );
2821 Vec_Int_t * vLevel; int i, k, Obj;
2822 assert( Gia_ManCoNum(p) == Vec_WecSize(vSupps) );
2823 Vec_StrFill( vRes, nSize-1, '_' );
2824 Vec_StrPush( vRes, '\0' );
2825 Vec_WecForEachLevel( vSupps, vLevel, i )
2826 {
2827 Vec_IntForEachEntry( vLevel, Obj, k )
2828 {
2829 if ( !fPrintDep )
2830 Vec_StrWriteEntry( vRes, i * (Gia_ManCiNum(p) + 1) + Obj, '*' );
2831 else
2832 {
2833 int Value = Gia_ManComputeDep( p, Obj, i );
2834 if ( Value == -1 )
2835 Vec_StrWriteEntry( vRes, i * (Gia_ManCiNum(p) + 1) + Obj, '*' );
2836 else
2837 Vec_StrWriteEntry( vRes, i * (Gia_ManCiNum(p) + 1) + Obj, (char)('0'+Value) );
2838 }
2839 }
2840 Vec_StrWriteEntry( vRes, i * (Gia_ManCiNum(p) + 1) + Gia_ManCiNum(p), '\n' );
2841 //printf( "Output %d\n", i );
2842 }
2843 return vRes;
2844}
2845void Gia_ManDumpSuppFile( Vec_Str_t * p, char * pFileName )
2846{
2847 FILE * pFile = fopen( pFileName, "wb" );
2848 if ( pFile == NULL )
2849 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
2850 else
2851 {
2852 int nOuts = Vec_StrCountEntry(p, '\n');
2853 int nIns = Vec_StrSize(p)/Vec_StrCountEntry(p, '\n') - 1;
2854 int nSize1 = Vec_StrSize(p) - 1;
2855 int nSize2 = fwrite( Vec_StrArray(p), 1, nSize1, pFile );
2856 assert( nSize1 == nSize2 );
2857 printf( "Successfully dumped file \"%s\" with support data for %d outputs and %d inputs.\n", pFileName, nOuts, nIns );
2858 }
2859 fclose( pFile );
2860}
2861void Gia_ManDumpSuppFileTest3( Gia_Man_t * p, char * pFileName )
2862{
2863 Vec_Wec_t * vSupps = Gia_ManComputeSupports( p );
2864 Vec_Wec_t * vDiffs = Gia_ManComputeSharing( vSupps );
2865 Vec_Wec_t * vDiffs2 = Gia_ManComputeSharing( vDiffs );
2866 Vec_Str_t * vRes = Gia_ManConvertDump( p, vDiffs2 );
2867 Gia_ManDumpSuppFile( vRes, pFileName );
2868 Vec_WecFree( vDiffs2 );
2869 Vec_WecFree( vDiffs );
2870 Vec_WecFree( vSupps );
2871 Vec_StrFree( vRes );
2872}
2873void Gia_ManDumpSuppFileTest( Gia_Man_t * p, char * pFileName )
2874{
2875 Vec_Wec_t * vSupps = Gia_ManComputeSupports( p );
2876 Vec_Str_t * vRes = Gia_ManConvertDump( p, vSupps );
2877 Gia_ManDumpSuppFile( vRes, pFileName );
2878 Vec_WecFree( vSupps );
2879 Vec_StrFree( vRes );
2880}
2881
2882
2895{
2896 if ( !Gia_ObjIsAnd(pObj) )
2897 return;
2898 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
2899 return;
2900 Gia_ObjSetTravIdCurrent(p, pObj);
2901 Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin0(pObj) );
2902 Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin1(pObj) );
2903 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2904}
2906{
2907 int fOnly1 = 0;
2908 int fVerbose = 1;
2909 abctime clk = Abc_Clock();
2910 Gia_Man_t * pNew, * pTemp;
2911 Gia_Obj_t * pObjPi, * pObjRi, * pObjRo;
2912 Vec_Int_t * vSupp = Vec_IntAlloc( 100 );
2913 Vec_Int_t * vAnds = Vec_IntAlloc( 100 );
2914 int i, n, iLits[2];
2915 assert( Gia_ManRegNum(p) && Gia_ManRegNum(p) % 8 == 0 );
2916 pNew = Gia_ManStart( Gia_ManObjNum(p) );
2917 pNew->pName = Abc_UtilStrsav( p->pName );
2918 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
2920 Gia_ManConst0(p)->Value = 0;
2921 Gia_ManForEachPi( p, pObjPi, i )
2922 pObjPi->Value = Gia_ManAppendCi( pNew );
2923 Gia_ManHashAlloc( pNew );
2924 Gia_ManForEachRi( p, pObjRi, i )
2925 {
2926 pObjRo = Gia_ObjRiToRo(p, pObjRi);
2927 if ( (i - Gia_ManPoNum(p)) % 8 != 0 )
2928 continue;
2929 if ( fOnly1 )
2930 {
2931 assert( pObjRo->Value == ~0 );
2932 for ( n = 0; n < 2; n++ )
2933 {
2934 pObjRo->Value = n;
2936 Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin0(pObjRi) );
2937 iLits[n] = Gia_ObjFanin0Copy(pObjRi);
2938 }
2939 pObjRo->Value = ~0;
2940 Gia_ManAppendCo( pNew, Abc_LitNot(Gia_ManHashAnd( pNew, iLits[1], Abc_LitNot(iLits[0]) )) );
2941 }
2942 else
2943 {
2944 int Fanin = Gia_ObjFaninId0p( p, pObjRi );
2945 Vec_Int_t * vNodes = Gia_ManCollectNodesCis( p, &Fanin, 1 );
2946 Gia_Obj_t * pObj; int i, m;
2947 Vec_IntClear( vSupp );
2948 Vec_IntClear( vAnds );
2949 Gia_ManForEachObjVec( vNodes, p, pObj, i )
2950 Vec_IntPush( Gia_ObjIsAnd(pObj) ? vAnds : vSupp, Gia_ObjId(p, pObj) );
2951 Vec_IntFree( vNodes );
2952 Vec_IntSort( vSupp, 0 );
2953 for ( m = 0; m < 4; m++ )
2954 {
2955 Gia_ManForEachObjVec( vSupp, p, pObj, i )
2956 if ( i >= Vec_IntSize(vSupp)-5 )
2957 pObj->Value = (i == Vec_IntSize(vSupp)-5+m) ? 1 : 0;
2958 Gia_ManForEachObjVec( vAnds, p, pObj, i )
2959 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2960 //if ( m == 4 )
2961 // Gia_ManAppendCo( pNew, 0 );
2962 //else
2963 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObjRi) );
2964 //Gia_ManAppendCo( pNew, Abc_Var2Lit( Vec_IntEntry(vSupp, Vec_IntSize(vSupp)-5+m), 0 ) );
2965 Gia_ManForEachObjVec( vSupp, p, pObj, i )
2966 if ( i >= Vec_IntSize(vSupp)-5 )
2967 pObj->Value = Abc_Var2Lit( 1 + Gia_ObjCioId(pObj), 0 );
2968 }
2969 }
2970 }
2971 Vec_IntFree( vSupp );
2972 Vec_IntFree( vAnds );
2973 Gia_ManHashStop( pNew );
2974 //Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
2975 pNew = Gia_ManCleanup( pTemp = pNew );
2976 Gia_ManStop( pTemp );
2977 if ( fVerbose )
2978 printf( "Transformed %d outputs, ", Gia_ManPoNum(pNew) );
2979 if ( fVerbose )
2980 Abc_PrintTime( 0, "Time", Abc_Clock() - clk );
2981 return pNew;
2982}
2983
2984
2997{
2998 int fVerbose = 1;
2999 abctime clk = Abc_Clock();
3000 Gia_Man_t * pNew, * pTemp;
3001 Gia_Obj_t * pObjPi, * pObjRi, * pObjRo;
3002 int i, n, iTempLit, iLits[2];
3003 assert( Gia_ManRegNum(p) > 0 );
3004 pNew = Gia_ManStart( Gia_ManObjNum(p) );
3005 pNew->pName = Abc_UtilStrsav( p->pName );
3006 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
3008 Gia_ManConst0(p)->Value = 0;
3009 Gia_ManForEachCi( p, pObjPi, i )
3010 pObjPi->Value = Gia_ManAppendCi( pNew );
3011 Gia_ManHashAlloc( pNew );
3012 Gia_ManForEachRi( p, pObjRi, i )
3013 {
3014 //if ( (i - Gia_ManPoNum(p)) % 8 != 0 )
3015 // continue;
3016 pObjRo = Gia_ObjRiToRo(p, pObjRi);
3017 iTempLit = pObjRo->Value;
3018 for ( n = 0; n < 2; n++ )
3019 {
3020 pObjRo->Value = n;
3022 Gia_ManConvertSupp_rec( pNew, p, Gia_ObjFanin0(pObjRi) );
3023 iLits[n] = Gia_ObjFanin0Copy(pObjRi);
3024 }
3025 pObjRo->Value = iTempLit;
3026 Gia_ManAppendCo( pNew, Abc_LitNot(Gia_ManHashAnd( pNew, iLits[1], Abc_LitNot(iLits[0]) )) );
3027 Gia_ManAppendCo( pNew, Abc_LitNot(Gia_ManHashAnd( pNew, iLits[0], Abc_LitNot(iLits[1]) )) );
3028 }
3029 Gia_ManHashStop( pNew );
3030 //Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
3031 pNew = Gia_ManCleanup( pTemp = pNew );
3032 Gia_ManStop( pTemp );
3033 if ( fVerbose )
3034 printf( "Created %d outputs. ", Gia_ManPoNum(pNew) );
3035 if ( fVerbose )
3036 Abc_PrintTime( 0, "Time", Abc_Clock() - clk );
3037 return pNew;
3038}
3039
3052{
3053 extern int Cec4_ManGeneratePatterns_rec( Gia_Man_t * p, Gia_Obj_t * pObj, int Value, Vec_Int_t * vPat, Vec_Int_t * vVisit );
3054 Vec_Wrd_t * vSim = Vec_WrdStart( nWords * Gia_ManCiNum(p) );
3055 Vec_Int_t * vPat = Vec_IntAlloc( Gia_ManCiNum(p) );
3056 Vec_Int_t * vVis = Vec_IntAlloc( Gia_ManAndNum(p) );
3057 Gia_Obj_t * pObj = Gia_ManCo( p, iCo ), * pTemp; int iLit, i, k, nTries = 0;
3058 if ( Gia_ObjFanin0(pObj) == Gia_ManConst0(p) )
3059 return NULL;
3060 Gia_ManForEachObj( p, pTemp, k )
3061 assert( !pTemp->fMark0 && !pTemp->fMark1 );
3062 for ( i = 0; i < 64*nWords; )
3063 {
3064 int Res = Cec4_ManGeneratePatterns_rec( p, Gia_ObjFanin0(pObj), !Gia_ObjFaninC0(pObj), vPat, vVis );
3065 if ( Res )
3066 {
3067 Vec_IntForEachEntry( vPat, iLit, k )
3068 {
3069 if ( Abc_LitIsCompl(iLit) )
3070 continue;
3071 pTemp = Gia_ManObj( p, Abc_Lit2Var(iLit) );
3072 assert( Gia_ObjIsCi(pTemp) );
3073 Abc_InfoSetBit( (unsigned *)Vec_WrdEntryP(vSim, nWords*Gia_ObjCioId(pTemp)), i );
3074 }
3075 i++;
3076 }
3077 Gia_ManForEachObjVec( vVis, p, pTemp, k )
3078 pTemp->fMark0 = pTemp->fMark1 = 0;
3079 nTries++;
3080 }
3081 //printf( "%d ", nTries );
3082 Vec_IntFree( vPat );
3083 Vec_IntFree( vVis );
3084 return vSim;
3085}
3087{
3088 Vec_Wrd_t * p = Vec_WrdAlloc( Vec_WrdSize(p1)+Vec_WrdSize(p2) );
3089 int i, k;
3090 assert( Vec_WrdSize(p1) == nWords*nIns );
3091 assert( Vec_WrdSize(p2) == nWords*nIns );
3092 for ( i = 0; i < nIns; i++ )
3093 {
3094 for ( k = 0; k < nWords; k++ )
3095 Vec_WrdPush( p, Vec_WrdEntry(p1, i*nWords+k) );
3096 for ( k = 0; k < nWords; k++ )
3097 Vec_WrdPush( p, Vec_WrdEntry(p2, i*nWords+k) );
3098 }
3099 return p;
3100}
3102{
3103 extern void Gia_ManResubPair( Vec_Wrd_t * vOn, Vec_Wrd_t * vOff, int nWords, int nIns );
3104 abctime clk = Abc_Clock();
3105 Vec_Wrd_t * vSims;
3106 Vec_Wrd_t * vSim[4];
3107 Vec_Wrd_t * vInt[6];
3108 int i;
3109 for ( i = 0; i < Gia_ManCoNum(p); i++ )
3110 {
3111 vSims = Gia_ManDetectSims( p, i, 1 );
3112 if ( i >= Gia_ManCoNum(p)-4 )
3113 vSim[i-(Gia_ManCoNum(p)-4)] = vSims;
3114 else
3115 Vec_WrdFreeP( &vSims );
3116 //Vec_PtrPush( vAll, vSims );
3117 }
3118 vInt[0] = Vec_WrdInterleave( vSim[0], vSim[1], 1, Gia_ManCiNum(p) );
3119 vInt[1] = Vec_WrdInterleave( vSim[0], vSim[2], 1, Gia_ManCiNum(p) );
3120 vInt[2] = Vec_WrdInterleave( vSim[0], vSim[3], 1, Gia_ManCiNum(p) );
3121 vInt[3] = Vec_WrdInterleave( vSim[1], vSim[2], 1, Gia_ManCiNum(p) );
3122 vInt[4] = Vec_WrdInterleave( vSim[1], vSim[3], 1, Gia_ManCiNum(p) );
3123 vInt[5] = Vec_WrdInterleave( vSim[2], vSim[3], 1, Gia_ManCiNum(p) );
3124
3125 Gia_ManResubPair( vInt[0], vInt[5], 2, Gia_ManCiNum(p) );
3126 Gia_ManResubPair( vInt[1], vInt[4], 2, Gia_ManCiNum(p) );
3127 Gia_ManResubPair( vInt[2], vInt[3], 2, Gia_ManCiNum(p) );
3128
3129 Gia_ManResubPair( vInt[5], vInt[0], 2, Gia_ManCiNum(p) );
3130 Gia_ManResubPair( vInt[4], vInt[1], 2, Gia_ManCiNum(p) );
3131 Gia_ManResubPair( vInt[3], vInt[2], 2, Gia_ManCiNum(p) );
3132
3133/*
3134 for ( i = 0; i < 4; i++ )
3135 for ( k = i+1; k < 4; k++ )
3136 Gia_ManResubPair( vSim[i], vSim[k], 1, Gia_ManCiNum(p) );
3137*/
3138 Abc_PrintTime( 0, "Time", Abc_Clock() - clk );
3139 return NULL;
3140}
3141void Gia_ManWriteSol( Gia_Man_t * p, char * pFileName )
3142{
3143 char * pBasicName = Extra_FileNameGeneric( pFileName );
3144 char * pFileName2 = Abc_UtilStrsavTwo( pBasicName, ".sol" );
3145 FILE * pFile = fopen( pFileName2, "wb" );
3146 ABC_FREE( pBasicName );
3147 if ( pFile == NULL )
3148 printf( "Cannot open output file \"%s\".\n", pFileName2 );
3149 else
3150 {
3151 Gia_Obj_t * pObj; int i;
3152 Gia_ManForEachAnd( p, pObj, i )
3153 fprintf( pFile, "%d %d ", Gia_ObjFaninLit0(pObj, i), Gia_ObjFaninLit1(pObj, i) );
3154 Gia_ManForEachCo( p, pObj, i )
3155 fprintf( pFile, "%d %d ", Gia_ObjFaninLit0p(p, pObj), Gia_ObjFaninLit0p(p, pObj) );
3156 fclose( pFile );
3157 printf( "Finished writing solution file \"%s\".\n", pFileName2 );
3158 }
3159 ABC_FREE( pFileName2 );
3160}
3161void Gia_ManWriteResub( Gia_Man_t * p, char * pFileName )
3162{
3163 FILE * pFile = fopen( pFileName, "wb" );
3164 if ( pFile == NULL )
3165 printf( "Cannot open output file \"%s\".\n", pFileName );
3166 else
3167 {
3168 Vec_Wrd_t * vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
3169 Vec_Wrd_t * vSimsPo = Gia_ManSimPatSimOut( p, vSimsPi, 1 );
3170 int i, k, nWords = Vec_WrdSize(vSimsPi) / Gia_ManCiNum(p);
3171 word * pTemp = ABC_ALLOC( word, nWords );
3172 fprintf( pFile, "%d %d %d %d\n", Gia_ManCiNum(p), 0, Gia_ManCoNum(p), 1 << Gia_ManCiNum(p) );
3173 for ( i = 0; i < Gia_ManCiNum(p); i++ )
3174 Abc_TtPrintBinary1( pFile, Vec_WrdEntryP(vSimsPi, i*nWords), Gia_ManCiNum(p) ), fprintf(pFile, "\n");
3175 for ( i = 0; i < (1 << Gia_ManCoNum(p)); i++ )
3176 {
3177 Abc_TtFill( pTemp, nWords );
3178 for ( k = 0; k < Gia_ManCoNum(p); k++ )
3179 Abc_TtAndCompl( pTemp, pTemp, 0, Vec_WrdEntryP(vSimsPo, k*nWords), !((i>>k)&1), nWords );
3180 Abc_TtPrintBinary1( pFile, pTemp, Gia_ManCiNum(p) ), fprintf(pFile, "\n");
3181 }
3182 ABC_FREE( pTemp );
3183 fclose( pFile );
3184 Vec_WrdFree( vSimsPi );
3185 Vec_WrdFree( vSimsPo );
3186 printf( "Finished writing resub file \"%s\".\n", pFileName );
3187 Gia_ManWriteSol( p, pFileName );
3188 }
3189}
3190
3191
3204{
3205 Gia_Obj_t * pObj; int i, nSize = Gia_ManObjNum(p);
3206 printf( "static int s_ArraySize = %d;\n", nSize );
3207 printf( "static int s_ArrayData[%d] = {\n", 2*nSize );
3208 printf( " 0, 0," );
3209 printf( "\n " );
3210 Gia_ManForEachCi( p, pObj, i )
3211 printf( "0, 0, " );
3212 printf( "\n " );
3213 Gia_ManForEachAnd( p, pObj, i )
3214 printf( "%d, %d, ", Gia_ObjFaninLit0p(p, pObj), Gia_ObjFaninLit1p(p, pObj) );
3215 printf( "\n " );
3216 Gia_ManForEachCo( p, pObj, i )
3217 printf( "%d, %d, ", Gia_ObjFaninLit0p(p, pObj), Gia_ObjFaninLit0p(p, pObj) );
3218 printf( "\n" );
3219 printf( "};\n" );
3220
3221}
3222
3223
3235int Gia_GetMValue( int i, int nIns, int Mint, unsigned Truth )
3236{
3237 assert( i >= 0 && i < 16 );
3238 if ( i < nIns )
3239 return (Mint >> i) & 1;
3240 if ( i == nIns )
3241 {
3242 if ( Mint < (1 << nIns) )
3243 return (Truth >> Mint) & 1;
3244 else
3245 return ((Truth >> (Mint-(1 << nIns))) & 1) == 0;
3246 }
3247 else
3248 return 1;
3249}
3251{
3252 unsigned Truth = 0xFE;
3253 int i, j, k, c, nIns = 3, nAux = 3;
3254 int nTotal = nIns + 1 + nAux;
3255 int nPairs = nTotal * (nTotal - 1) / 2;
3256 int nMints = (1 << (nIns+1));
3257 int M[64][100] = {{0}};
3258 float Value[64] = {0};
3259 float Solution[100] = {0};
3260 assert( nMints <= 64 );
3261 assert( nPairs <= 100 );
3262 // 7 nodes: 3 inputs + 1 output + 3 aux
3263 // 7*6/2 = 21 pairs
3264 // 16 minterms
3265 for ( k = 0; k < nMints; k++ )
3266 {
3267 for ( i = c = 0; i < nTotal; i++ )
3268 for ( j = i+1; j < nTotal; j++ )
3269 {
3270 int iVal = Gia_GetMValue( i, nIns, k, Truth );
3271 int jVal = Gia_GetMValue( j, nIns, k, Truth );
3272 M[k][c++] = iVal == jVal ? 1 : -1;
3273 }
3274 Value[k] = k < (1 << nIns) ? -1 : 1;
3275 assert( c == nPairs );
3276 }
3277
3278 for ( k = 0; k < nMints; k++ )
3279 {
3280 for ( c = 0; c < nPairs; c++ )
3281 printf( "%2d ", M[k][c] );
3282 printf( "%3f\n", Value[k] );
3283 }
3284
3285 // solve
3286 float Delta = 0.02;
3287 for ( i = 0; i < 100; i++ )
3288 {
3289 float Error = 0;
3290 for ( k = 0; k < nMints; k++ )
3291 Error += Value[k] > 0 ? Value[k] : -Value[k];
3292 printf( "Round %3d : Error = %5f ", i, Error );
3293 for ( c = 0; c < nPairs; c++ )
3294 printf( "%2f ", Solution[c] );
3295 printf( "\n" );
3296
3297 //if ( Error < 1 )
3298 // Delta /= 10;
3299
3300 for ( c = 0; c < nPairs; c++ )
3301 {
3302 int Count = 0;
3303 for ( k = 0; k < nMints; k++ )
3304 if ( (M[k][c] > 0 && Value[k] > 0) || (M[k][c] < 0 && Value[k] < 0) )
3305 Count++;
3306 else
3307 Count--;
3308 if ( Count == 0 )
3309 continue;
3310 printf( "Count = %3d ", Count );
3311 if ( Count > 0 )
3312 {
3313 printf( "Increasing %d by %f\n", c, Delta );
3314 Solution[c] += Delta;
3315 for ( k = 0; k < nMints; k++ )
3316 if ( M[k][c] > 0 )
3317 Value[k] -= Delta;
3318 else
3319 Value[k] -= Delta;
3320 }
3321 else
3322 {
3323 printf( "Reducing %d by %f\n", c, Delta );
3324 Solution[c] -= Delta;
3325 for ( k = 0; k < nMints; k++ )
3326 if ( M[k][c] > 0 )
3327 Value[k] += Delta;
3328 else
3329 Value[k] += Delta;
3330 }
3331 }
3332 }
3333}
3334
3347{
3348 if ( !Gia_ObjIsAnd(pObj) )
3349 return 0;
3350 if ( Gia_ObjIsTravIdPrevious(p, pObj) )
3351 return 1; // there is an error
3352 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
3353 return 0; // there is no error; visited this node before
3354 Gia_ObjSetTravIdPrevious(p, pObj);
3355 if ( Gia_ManWindowCheckTopoError_rec(p, Gia_ObjFanin0(pObj)) || Gia_ManWindowCheckTopoError_rec(p, Gia_ObjFanin1(pObj)) )
3356 return 1;
3357 Gia_ObjSetTravIdCurrent(p, pObj);
3358 return 0;
3359}
3361{
3362 Gia_Obj_t * pObj; int i, fError = 0;
3363 // outputs should be internal nodes
3364 Gia_ManForEachObjVec( vOuts, p, pObj, i )
3365 assert(Gia_ObjIsAnd(pObj));
3366 // mark outputs
3368 Gia_ManForEachObjVec( vOuts, p, pObj, i )
3369 Gia_ObjSetTravIdCurrent(p, pObj);
3370 // start from inputs and make sure we do not reach any of the outputs
3372 Gia_ManForEachObjVec( vIns, p, pObj, i )
3373 fError |= Gia_ManWindowCheckTopoError_rec(p, pObj);
3374 return fError;
3375}
3376
3388int Gia_ManDupInsertWindows_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vMap, Vec_Ptr_t * vvIns, Vec_Ptr_t * vvOuts, Vec_Ptr_t * vWins )
3389{
3390 if ( ~pObj->Value )
3391 return pObj->Value;
3392 assert( Gia_ObjIsAnd(pObj) );
3393 if ( Vec_IntEntry(vMap, Gia_ObjId(p, pObj)) == -1 ) // this is a regular node
3394 {
3395 Gia_ManDupInsertWindows_rec( pNew, p, Gia_ObjFanin0(pObj), vMap, vvIns, vvOuts, vWins );
3396 Gia_ManDupInsertWindows_rec( pNew, p, Gia_ObjFanin1(pObj), vMap, vvIns, vvOuts, vWins );
3397 return pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
3398 }
3399 // this node is an output of a window
3400 int iWin = Vec_IntEntry(vMap, Gia_ObjId(p, pObj));
3401 Vec_Int_t * vIns = (Vec_Int_t *)Vec_PtrEntry(vvIns, iWin);
3402 Vec_Int_t * vOuts = (Vec_Int_t *)Vec_PtrEntry(vvOuts, iWin);
3403 Gia_Man_t * pWin = (Gia_Man_t *)Vec_PtrEntry(vWins, iWin);
3404 // build transinvite fanins of window inputs
3405 Gia_Obj_t * pNode; int i;
3406 Gia_ManConst0(pWin)->Value = 0;
3407 Gia_ManForEachObjVec( vIns, p, pNode, i )
3408 Gia_ManPi(pWin, i)->Value = Gia_ManDupInsertWindows_rec( pNew, p, pNode, vMap, vvIns, vvOuts, vWins );
3409 // add window nodes
3410 Gia_ManForEachAnd( pWin, pNode, i )
3411 pNode->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pNode), Gia_ObjFanin1Copy(pNode) );
3412 // transfer to window outputs
3413 Gia_ManForEachObjVec( vOuts, p, pNode, i )
3414 pNode->Value = Gia_ObjFanin0Copy(Gia_ManPo(pWin, i));
3415 assert( ~pObj->Value );
3416 return pObj->Value;
3417}
3419{
3420 // check consistency of input data
3421 Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj; int i, k, iNode;
3422 Vec_PtrForEachEntry( Gia_Man_t *, vWins, pTemp, i ) {
3423 Vec_Int_t * vIns = (Vec_Int_t *)Vec_PtrEntry(vvIns, i);
3424 Vec_Int_t * vOuts = (Vec_Int_t *)Vec_PtrEntry(vvOuts, i);
3425 assert( Vec_IntSize(vIns) == Gia_ManPiNum(pTemp) );
3426 assert( Vec_IntSize(vOuts) == Gia_ManPoNum(pTemp) );
3427 assert( !Gia_ManWindowCheckTopoError(p, vIns, vOuts) );
3428 }
3429 // create mapping of window outputs into window IDs
3430 Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(p) ), * vOuts;
3431 Vec_PtrForEachEntry( Vec_Int_t *, vvOuts, vOuts, i )
3432 Vec_IntForEachEntry( vOuts, iNode, k )
3433 Vec_IntWriteEntry( vMap, iNode, i );
3434 // create the resulting AIG by performing DFS from the POs of the original AIG
3435 // it goes recursively through original nodes and windows until it reaches the PIs of the original AIG
3436 pNew = Gia_ManStart( Gia_ManObjNum(p) );
3437 pNew->pName = Abc_UtilStrsav( p->pName );
3438 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
3439 Gia_ManHashAlloc( pNew );
3441 Gia_ManConst0(p)->Value = 0;
3442 Gia_ManForEachCi( p, pObj, i )
3443 pObj->Value = Gia_ManAppendCi(pNew);
3444 Gia_ManForEachCo( p, pObj, i )
3445 Gia_ManDupInsertWindows_rec( pNew, p, Gia_ObjFanin0(pObj), vMap, vvIns, vvOuts, vWins );
3446 Gia_ManForEachCo( p, pObj, i )
3447 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
3448 // cleanup and return
3449 Vec_IntFree( vMap );
3450 pNew = Gia_ManCleanup( pTemp = pNew );
3451 Gia_ManStop( pTemp );
3452 //Gia_ManPrint( pNew );
3453 return pNew;
3454}
3455
3468{
3469 Gia_Man_t * pNew; Gia_Obj_t * pObj; int i;
3470 assert( Gia_ManCiNum(p0) == Gia_ManCiNum(p1) );
3471 assert( Gia_ManCoNum(p0) == Gia_ManCoNum(p1) );
3472 // start the manager
3473 pNew = Gia_ManStart( Gia_ManObjNum(p0) + Gia_ManObjNum(p1) );
3474 pNew->pName = Abc_UtilStrsav( "miter" );
3475 Gia_ManFillValue( p0 );
3476 Gia_ManFillValue( p1 );
3477 // map combinational inputs
3478 Gia_ManConst0(p0)->Value = 0;
3479 Gia_ManConst0(p1)->Value = 0;
3480 Gia_ManForEachCi( p0, pObj, i )
3481 Gia_ManCi(p1, i)->Value = pObj->Value = Gia_ManAppendCi( pNew );
3482 // map internal nodes and outputs
3483 Gia_ManHashAlloc( pNew );
3484 Gia_ManForEachAnd( p0, pObj, i )
3485 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
3486 assert( Gia_ManAndNum(pNew) == Gia_ManAndNum(p0) ); // the input AIG p0 is structurally hashed
3487 Gia_ManForEachAnd( p1, pObj, i )
3488 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
3489 // add the outputs
3490 Gia_ManForEachCo( p0, pObj, i )
3491 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
3492 Gia_ManForEachCo( p1, pObj, i )
3493 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
3494 printf( "The two AIGs have %d structurally equivalent nodes.\n", Gia_ManAndNum(p0) + Gia_ManAndNum(p1) - Gia_ManAndNum(pNew) );
3495 // there should be no dangling nodes (otherwise, the second AIG may not be structurally hashed)
3496 int nDangling = Gia_ManMarkDangling(pNew);
3497 assert( nDangling == 0 );
3498 Gia_ManCleanMark01(pNew);
3499 return pNew;
3500}
3501Vec_Int_t * Gia_ManFindMutualEquivs( Gia_Man_t * p0, Gia_Man_t * p1, int nConflictLimit, int fVerbose )
3502{
3503 Vec_Int_t * vPairs = Vec_IntAlloc( 100 );
3504 // derive the miter
3505 Gia_Man_t * pMiter = Gia_ManCreateDualOutputMiter( p0, p1 );
3506 //Gia_ManPrintStats( pMiter, NULL );
3507 //Gia_AigerWrite( pMiter, "out.aig", 0, 0, 0 );
3508 // perform SAT sweeping
3509 extern Gia_Man_t * Cec4_ManSimulateTest3( Gia_Man_t * p, int nBTLimit, int fVerbose );
3510 Gia_Man_t * pNew = Cec4_ManSimulateTest3( pMiter, nConflictLimit, fVerbose );
3511 Gia_ManStop( pNew );
3512 // now, pMiter is annotated with the equiv class info
3513
3514 // here we collect AIG node pairs with the following properties:
3515 // - the first node belongs to p0; the second node belongs to p1
3516 // - both nodes are internal nodes of p0 and p1 (not primary inputs/outputs)
3517 // - these nodes are combinationally equivalent (possibly up to the complement)
3518 // - these nodes are "singleton" equivalences (no other nodes in p0 and p1 are equivalent to them)
3519 // - these nodes are not structurally equivalent (that is, they have structurally different TFI logic cones)
3520
3521 // count the number of nodes in each equivalence class
3522 Vec_Int_t * vCounts = Vec_IntStart( Gia_ManObjNum(pMiter) );
3523 Gia_Obj_t * pObj; int i, k;
3524 Gia_ManForEachClass( pMiter, i )
3525 Gia_ClassForEachObj( pMiter, i, k )
3526 Vec_IntAddToEntry( vCounts, i, 1 );
3527
3528 // map each miter node coming from p1 into the corresponding node in p1
3529 Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(pMiter) );
3530 int iStartP1 = 1 + Gia_ManPiNum(p0) + Gia_ManAndNum(p0);
3531 Gia_ManForEachAnd( p1, pObj, i )
3532 if ( Abc_Lit2Var(pObj->Value) >= iStartP1 ) // node from p1 (not from p0)
3533 Vec_IntWriteEntry( vMap, Abc_Lit2Var(pObj->Value), i );
3534
3535 // go through functionally (not structurally!) equivalent nodes in the second AIG
3536 // and collect those node pairs from p0 and p1 whose equivalence class contains exactly two nodes
3537 for ( i = iStartP1; i < Gia_ManObjNum(pMiter) - Gia_ManCoNum(pMiter); i++ ) {
3538 assert( Gia_ObjIsAnd(Gia_ManObj(pMiter, i)) );
3539 int Repr = Gia_ObjRepr(pMiter, i);
3540 if ( Repr == GIA_VOID || Repr >= iStartP1 || Vec_IntEntry(vCounts, Repr) != 2 )
3541 continue;
3542 assert( Repr < iStartP1 ); // node in p0
3543 assert( Vec_IntEntry(vMap, i) > 0 ); // node in p1
3544 Vec_IntPushTwo( vPairs, Repr, Vec_IntEntry(vMap, i) );
3545 }
3546 // cleanup
3547 Vec_IntFree( vMap );
3548 Vec_IntFree( vCounts );
3549 Gia_ManStop( pMiter );
3550 return vPairs;
3551}
3553{
3554 Gia_Man_t * p0 = Gia_AigerRead( "p0.aig", 0, 0, 0 );
3555 Gia_Man_t * p1 = Gia_AigerRead( "p1.aig", 0, 0, 0 );
3556 Vec_Int_t * vPairs = Gia_ManFindMutualEquivs( p0, p1, 0, 0 );
3557 printf( "Pair Aig0 node Aig1 node\n" );
3558 int i, Obj0, Obj1;
3559 Vec_IntForEachEntryDouble( vPairs, Obj0, Obj1, i )
3560 printf( "%3d %6d %6d\n", i/2, Obj0, Obj1 );
3561 Gia_ManStop( p0 );
3562 Gia_ManStop( p1 );
3563 Vec_IntFree( vPairs );
3564}
3565
3566
3570
3571
3573
int nWords
Definition abcNpn.c:127
void Abc_FrameUpdateGia(Abc_Frame_t *pAbc, Gia_Man_t *pNew)
Definition abc.c:824
void Abc_FrameReplaceCexVec(Abc_Frame_t *pAbc, Vec_Ptr_t **pvCexVec)
Definition abc.c:704
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#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
ABC_DLL int Abc_FrameReadProbStatus(Abc_Frame_t *pAbc)
Definition mainFrame.c:74
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL void * Abc_FrameReadCex(Abc_Frame_t *pAbc)
Definition mainFrame.c:75
#define NUMBER2
Definition aigUtil.c:1157
#define NUMBER1
Definition aigUtil.c:1156
int nTotal
DECLARATIONS ///.
Definition cutTruth.c:37
ABC_DLL Abc_Frame_t * Abc_FrameReadGlobalFrame()
Definition mainFrame.c:666
ABC_DLL Vec_Int_t * Abc_FrameReadPoStatuses(Abc_Frame_t *p)
Definition mainFrame.c:79
ABC_DLL Vec_Ptr_t * Abc_FrameReadCexVec(Abc_Frame_t *p)
Definition mainFrame.c:76
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
int Cec4_ManGeneratePatterns_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int Value, Vec_Int_t *vPat, Vec_Int_t *vVisit)
Definition cecSatG2.c:1307
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition cmdApi.c:193
Cube * p
Definition exorList.c:222
cubedist Dist
Definition exorList.c:1012
char * Extra_UtilStrsav(const char *s)
char * Extra_FileNameGeneric(char *FileName)
void Gia_ManResubPair(Vec_Wrd_t *vOn, Vec_Wrd_t *vOff, int nWords, int nIns)
Definition giaResub.c:1689
void Gia_ManWriteSol(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:3141
int Gia_ManCountPisWithFanout(Gia_Man_t *p)
Definition giaUtil.c:2301
Gia_Man_t * Gia_ManDupWithMuxPos(Gia_Man_t *p)
Definition giaUtil.c:2379
Gia_Man_t * Gia_ManConvertSupp(Gia_Man_t *p)
Definition giaUtil.c:2905
void Gia_ManPrintArray(Gia_Man_t *p)
Definition giaUtil.c:3203
int Gia_NodeDeref_rec(Gia_Man_t *p, Gia_Obj_t *pNode)
Definition giaUtil.c:1155
int * Gia_ManCreateMuxRefs(Gia_Man_t *p)
Definition giaUtil.c:828
void Gia_ObjSetPhase(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:387
void Gia_AigerWriteLut(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:2141
void Gia_ManCheckSuppMark_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:2248
void Gia_ManSwapPos(Gia_Man_t *p, int i)
Definition giaUtil.c:1808
int Gia_ManDupInsertWindows_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vMap, Vec_Ptr_t *vvIns, Vec_Ptr_t *vvOuts, Vec_Ptr_t *vWins)
Definition giaUtil.c:3388
#define MAX_LUT_SIZE
Definition giaUtil.c:2118
struct Gia_MapLut_t_ Gia_MapLut_t
int Gia_NodeMffcSizeSupp(Gia_Man_t *p, Gia_Obj_t *pNode, Vec_Int_t *vSupp)
Definition giaUtil.c:1279
void Gia_ManCreateLitRefs(Gia_Man_t *p)
Definition giaUtil.c:799
void Gia_ManCollectRing(Gia_Man_t *p, Vec_Int_t *vStart, Vec_Int_t *vRes, Vec_Int_t *vDists)
Definition giaUtil.c:2454
int Gia_ManHasDangling(Gia_Man_t *p)
Definition giaUtil.c:1353
float Gia_ManLevelAve(Gia_Man_t *p)
Definition giaUtil.c:588
int Gia_ManComputeDep(Gia_Man_t *p, int iIn, int iOut)
Definition giaUtil.c:2757
void Gia_ManPrintCone2(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1618
void Gia_ManFindMutualEquivsTest()
Definition giaUtil.c:3552
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition giaUtil.c:1056
void Gia_ManSetPhasePattern(Gia_Man_t *p, Vec_Int_t *vCiValues)
Definition giaUtil.c:427
Vec_Int_t * Gia_ManComputeDistance(Gia_Man_t *p, int iObj, Vec_Int_t *vObjs, int fVerbose)
Definition giaUtil.c:2508
Vec_Int_t * Gia_ManComputeSlacks(Gia_Man_t *p)
Definition giaUtil.c:726
int Gia_ManPoMffcSize(Gia_Man_t *p)
Definition giaUtil.c:1213
Gia_Man_t * Gia_ManTransformCond2(Gia_Man_t *p)
Definition giaUtil.c:2996
unsigned * Gia_ManComputePoTruthTables(Gia_Man_t *p, int nBytesMax)
Definition giaUtil.c:1690
Vec_Int_t * Gia_ManCollectPoIds(Gia_Man_t *p)
Definition giaUtil.c:960
int Gia_GetMValue(int i, int nIns, int Mint, unsigned Truth)
Definition giaUtil.c:3235
void Gia_ManWriteResub(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:3161
Vec_Int_t * Gia_ManRequiredLevel(Gia_Man_t *p)
Definition giaUtil.c:702
Vec_Wec_t * Gia_ManComputeSharing(Vec_Wec_t *vSupps)
Definition giaUtil.c:2808
word Gia_ManRandomW(int fReset)
Definition giaUtil.c:67
void Gia_ManSetPhase1(Gia_Man_t *p)
Definition giaUtil.c:450
void Gia_ManRandomInfo(Vec_Ptr_t *vInfo, int iInputStart, int iWordStart, int iWordStop)
Definition giaUtil.c:85
void Gia_ManCreateValueRefs(Gia_Man_t *p)
Definition giaUtil.c:750
void Gia_ManSetMark1(Gia_Man_t *p)
Definition giaUtil.c:294
Vec_Int_t * Gia_ManGetCiLevels(Gia_Man_t *p)
Definition giaUtil.c:609
void Gia_ManDfsForCrossCut_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vNodes)
Definition giaUtil.c:870
void Gia_ManPrintCo(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1563
Gia_Man_t * Gia_ManComputeCofs2(Gia_Man_t *p)
Definition giaUtil.c:2668
int Gia_ManMarkDangling(Gia_Man_t *p)
Definition giaUtil.c:1391
Vec_Wec_t * Gia_ManComputeSupports(Gia_Man_t *p)
Definition giaUtil.c:2794
int Gia_NodeMffcMapping(Gia_Man_t *p)
Definition giaUtil.c:1324
void Gia_ManDumpSuppFileTest(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:2873
Vec_Str_t * Gia_ManConvertDump(Gia_Man_t *p, Vec_Wec_t *vSupps)
Definition giaUtil.c:2816
int Gia_ManCountPosWithNonZeroDrivers(Gia_Man_t *p)
Definition giaUtil.c:2332
Vec_Int_t * Gia_ManBfsForCrossCut(Gia_Man_t *p)
Definition giaUtil.c:856
Gia_Man_t * Gia_ManComputeDepTest(Gia_Man_t *p)
Definition giaUtil.c:2773
void Gia_ManCollectObjs_rec(Gia_Man_t *p, int iObjId, Vec_Int_t *vObjs, int Limit)
Definition giaUtil.c:1670
int Gia_ObjRecognizeMuxLits(Gia_Man_t *p, Gia_Obj_t *pNode, int *iLitT, int *iLitE)
Definition giaUtil.c:1133
int Gia_ManLevelRNum(Gia_Man_t *p)
Definition giaUtil.c:566
void Gia_ManUpdateCopy(Vec_Int_t *vCopy, Gia_Man_t *p)
Definition giaUtil.c:2352
int Gia_ManCompare(Gia_Man_t *p1, Gia_Man_t *p2)
Definition giaUtil.c:1737
void Gia_ManPrint(Gia_Man_t *p)
Definition giaUtil.c:1543
void Gia_ManLoadValue(Gia_Man_t *p, Vec_Int_t *vValues)
Definition giaUtil.c:1841
Vec_Wrd_t * Vec_WrdInterleave(Vec_Wrd_t *p1, Vec_Wrd_t *p2, int nWords, int nIns)
Definition giaUtil.c:3086
void Gia_ManCheckMark0(Gia_Man_t *p)
Definition giaUtil.c:275
int Gia_ManSumTotalOfSupportSizes2(Gia_Man_t *p)
Definition giaUtil.c:2596
void Gia_ManPrintCollect2_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vNodes)
Definition giaUtil.c:1606
Vec_Int_t * Gia_ManComputeDistanceInt(Gia_Man_t *p, int iTarg, Vec_Int_t *vObjs, int fVerbose)
Definition giaUtil.c:2471
void Gia_ManInvertPos(Gia_Man_t *pAig)
Definition giaUtil.c:1651
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
Definition giaUtil.c:982
Gia_Man_t * Gia_ManDupInsertWindows(Gia_Man_t *p, Vec_Ptr_t *vvIns, Vec_Ptr_t *vvOuts, Vec_Ptr_t *vWins)
Definition giaUtil.c:3418
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1456
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
int Gia_ManCheckCoPhase(Gia_Man_t *p)
Definition giaUtil.c:491
int Gia_ManHasChoices_very_old(Gia_Man_t *p)
Definition giaUtil.c:1897
void Gia_ManDumpSuppFile(Vec_Str_t *p, char *pFileName)
Definition giaUtil.c:2845
int Gia_NodeMffcSize(Gia_Man_t *p, Gia_Obj_t *pNode)
Definition giaUtil.c:1230
char * Gia_TimeStamp()
Definition giaUtil.c:106
Vec_Int_t * Gia_ManGroupProve(Gia_Man_t *pInit, char *pCommLine, int nGroupSize, int fVerbose)
Definition giaUtil.c:1989
Vec_Int_t * Gia_ManDfsForCrossCut(Gia_Man_t *p, int fReverse)
Definition giaUtil.c:894
Gia_Man_t * Gia_ManComputeCofs(Gia_Man_t *p, int nVars)
Definition giaUtil.c:2628
void Gia_ManCleanValue(Gia_Man_t *p)
Definition giaUtil.c:351
void Gia_ManCleanPhase(Gia_Man_t *p)
Definition giaUtil.c:472
int Gia_ManCheckSuppOverlap(Gia_Man_t *p, int iNode1, int iNode2)
Definition giaUtil.c:2278
void Gia_ManPrintCollect_rec(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vNodes)
Definition giaUtil.c:1571
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition giaUtil.c:256
int Gia_ManCheckSupp_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:2268
void Gia_ManCleanTruth(Gia_Man_t *p)
Definition giaUtil.c:528
int Gia_ManCrossCut(Gia_Man_t *p, int fReverse)
Definition giaUtil.c:916
int Gia_ManWindowCheckTopoError_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:3346
Vec_Wrd_t * Gia_ManDetectSims(Gia_Man_t *p, int iCo, int nWords)
Definition giaUtil.c:3051
int Gia_ManSetLevels(Gia_Man_t *p, Vec_Int_t *vCiLevels)
Definition giaUtil.c:621
int Gia_NodeMffcMapping_rec(Gia_Man_t *p, int iObj, Vec_Int_t *vMapping, Vec_Int_t *vSupp)
Definition giaUtil.c:1306
void Gia_DumpLutSizeDistrib(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:2223
Gia_Man_t * Gia_ManComputeDepAig(Gia_Man_t *p, int iIn, int iOut)
Definition giaUtil.c:2727
int Gia_ObjRecognizeExor(Gia_Obj_t *pObj, Gia_Obj_t **ppFan0, Gia_Obj_t **ppFan1)
Definition giaUtil.c:1018
Vec_Int_t * Gia_ManGetDangling(Gia_Man_t *p)
Definition giaUtil.c:1422
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
Definition giaUtil.c:511
void Gia_ManConvertSupp_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:2894
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
void Gia_ManCheckMark1(Gia_Man_t *p)
Definition giaUtil.c:332
int Gia_ManWindowCheckTopoError(Gia_Man_t *p, Vec_Int_t *vIns, Vec_Int_t *vOuts)
Definition giaUtil.c:3360
void Gia_ManPrintCo_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:1552
Vec_Int_t * Gia_ManReverseLevel(Gia_Man_t *p)
Definition giaUtil.c:658
Gia_Man_t * Gia_ManCreateDualOutputMiter(Gia_Man_t *p0, Gia_Man_t *p1)
Definition giaUtil.c:3467
void Gia_NodeCollect_rec(Gia_Man_t *p, Gia_Obj_t *pNode, Vec_Int_t *vSupp)
Definition giaUtil.c:1265
Vec_Int_t * Gia_ManPoXSim(Gia_Man_t *p, int nFrames, int fVerbose)
Definition giaUtil.c:2075
void Gia_ComputeTest()
Definition giaUtil.c:2534
void Gia_ManInvertConstraints(Gia_Man_t *pAig)
Definition giaUtil.c:1641
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
Vec_Int_t * Gia_ManFirstFanouts(Gia_Man_t *p)
Definition giaUtil.c:1861
void Gia_ManRingAdd(Gia_Man_t *p, int iObj, Vec_Int_t *vRes, Vec_Int_t *vDists, int Dist)
Definition giaUtil.c:2446
void Gia_ManCheckSuppUnmark_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaUtil.c:2258
int Gia_ManSumTotalOfSupportSizes(Gia_Man_t *p)
Definition giaUtil.c:2570
void Gia_ManPrintCone(Gia_Man_t *p, Gia_Obj_t *pObj, int *pLeaves, int nLeaves, Vec_Int_t *vNodes)
Definition giaUtil.c:1582
void Gia_ManTestProblem()
Definition giaUtil.c:3250
void Gia_ManCleanMark01(Gia_Man_t *p)
Definition giaUtil.c:218
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
char * Gia_FileNameGenericAppend(char *pBase, char *pSuffix)
Definition giaUtil.c:130
Vec_Int_t * Gia_ManFindMutualEquivs(Gia_Man_t *p0, Gia_Man_t *p1, int nConflictLimit, int fVerbose)
Definition giaUtil.c:3501
void Gia_ManPrintConeMulti(Gia_Man_t *p, Vec_Int_t *vObjs, Vec_Int_t *vLeaves, Vec_Int_t *vNodes)
Definition giaUtil.c:1593
Gia_Man_t * Gia_ManTransformCond(Gia_Man_t *p)
Definition giaUtil.c:3101
void Gia_ManDumpSuppFileTest3(Gia_Man_t *p, char *pFileName)
Definition giaUtil.c:2861
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
Vec_Ptr_t * Gia_GetFakeNames(int nNames, int fCaps)
Definition giaUtil.c:154
void Gia_ManSetMark0(Gia_Man_t *p)
Definition giaUtil.c:237
int Gia_NodeMffcSizeMark(Gia_Man_t *p, Gia_Obj_t *pNode)
Definition giaUtil.c:1241
void Gia_ManMarkFanoutDrivers(Gia_Man_t *p)
Definition giaUtil.c:1779
int Gia_NodeRef_rec(Gia_Man_t *p, Gia_Obj_t *pNode, int fMark)
Definition giaUtil.c:1184
Vec_Int_t * Gia_ManSaveValue(Gia_Man_t *p)
Definition giaUtil.c:1831
void Gia_ManCleanMark1(Gia_Man_t *p)
Definition giaUtil.c:313
struct Gia_Rpr_t_ Gia_Rpr_t
Definition gia.h:57
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
Vec_Wrd_t * Gia_ManSimPatSimOut(Gia_Man_t *pGia, Vec_Wrd_t *vSimsPi, int fOuts)
Definition giaSimBase.c:138
#define Gia_ManForEachRo(p, pObj, i)
Definition gia.h:1252
void Gia_ManStaticFanoutStart(Gia_Man_t *p)
Definition giaFanout.c:238
void Gia_ManStaticFanoutStop(Gia_Man_t *p)
Definition giaFanout.c:393
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition gia.h:1222
#define Gia_ManForEachCoReverse(p, pObj, i)
Definition gia.h:1242
Gia_Man_t * Gia_AigerRead(char *pFileName, int fGiaSimple, int fSkipStrash, int fCheck)
Definition giaAiger.c:1017
#define Gia_LutForEachFanin2(p, i, iFan, k)
Definition gia.h:1176
#define Gia_ManForEachCoDriverId(p, DriverId, i)
Definition gia.h:1246
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
#define Gia_ManForEachObjReverse(p, pObj, i)
Definition gia.h:1206
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
#define Gia_ManForEachLut(p, i)
Definition gia.h:1157
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
#define Gia_ClassForEachObj(p, i, iObj)
Definition gia.h:1107
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
word Gia_LutComputeTruth6(Gia_Man_t *p, int iObj, Vec_Wrd_t *vTruths)
Definition giaTruth.c:249
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
Gia_Man_t * Gia_ManDupCones(Gia_Man_t *p, int *pPos, int nPos, int fTrimPis)
Definition giaDup.c:3880
#define Gia_ManForEachClass(p, i)
Definition gia.h:1101
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
Vec_Vec_t * Gia_ManLevelize(Gia_Man_t *p)
Definition giaDfs.c:403
int Gia_ManLutSizeMax(Gia_Man_t *p)
Definition giaIf.c:127
int Gia_ManLutNum(Gia_Man_t *p)
Definition giaIf.c:146
void Gia_ManCollectTfi(Gia_Man_t *p, Vec_Int_t *vRoots, Vec_Int_t *vNodes)
Definition giaDfs.c:581
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
#define Gia_ObjForEachFanoutStaticId(p, Id, FanId, i)
Definition gia.h:1127
#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
#define GIA_VOID
Definition gia.h:46
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
Vec_Int_t * Gia_ManCollectNodesCis(Gia_Man_t *p, int *pNodes, int nNodes)
Definition giaDfs.c:202
#define Gia_ManForEachRi(p, pObj, i)
Definition gia.h:1254
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
word M(word f1, word f2, int n)
Definition kitPerm.c:240
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
int pFans[MAX_LUT_SIZE]
Definition giaUtil.c:2126
unsigned pTruth[MAX_LUT_SIZE< 6?1:(1<<(MAX_LUT_SIZE-5))]
Definition giaUtil.c:2127
unsigned fMark1
Definition gia.h:86
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
unsigned fMark0
Definition gia.h:81
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * strrchr()
char * memset()
int strlen()
int memcmp()
char * strstr()
char * strcpy()
double atof()
char * strcat()
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.
Definition vecBit.h:42
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
Definition vecInt.h:58
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
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
#define Vec_VecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecVec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition vecVec.h:42
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
#define Vec_WecForEachLevelTwo(vGlob1, vGlob2, vVec1, vVec2, i)
Definition vecWec.h:69
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
Gia_Man_t * Cec4_ManSimulateTest3(Gia_Man_t *p, int nBTLimit, int fVerbose)
Definition cecSatG2.c:2077