74#define Abc_AigBinForEachEntry( pBin, pEnt ) \
78#define Abc_AigBinForEachEntrySafe( pBin, pEnt, pEnt2 ) \
80 pEnt2 = pEnt? pEnt->pNext: NULL; \
83 pEnt2 = pEnt? pEnt->pNext: NULL )
93 Key ^= Abc_ObjRegular(p0)->Id * 7937;
94 Key ^= Abc_ObjRegular(p1)->Id * 2971;
95 Key ^= Abc_ObjIsComplement(p0) * 911;
96 Key ^= Abc_ObjIsComplement(p1) * 353;
97 return Key % TableSize;
104static void Abc_AigResize(
Abc_Aig_t * pMan );
107static void Abc_AigUpdateLevel_int(
Abc_Aig_t * pMan );
108static void Abc_AigUpdateLevelR_int(
Abc_Aig_t * pMan );
110static void Abc_AigRemoveFromLevelStructureR(
Vec_Vec_t * vStruct,
Abc_Obj_t * pNode );
135 pMan->
nBins = Abc_PrimeCudd( 10000 );
138 pMan->
vNodes = Vec_PtrAlloc( 100 );
139 pMan->
vLevels = Vec_VecAlloc( 100 );
140 pMan->
vLevelsR = Vec_VecAlloc( 100 );
178 Vec_PtrFree( pMan->
vNodes );
203 vDangles = Vec_PtrAlloc( 100 );
204 for ( i = 0; i < pMan->
nBins; i++ )
206 if ( Abc_ObjFanoutNum(pAnd) == 0 )
207 Vec_PtrPush( vDangles, pAnd );
211 Vec_PtrFree( vDangles );
229 int i, nFanins, Counter;
232 nFanins = Abc_ObjFaninNum(pObj);
235 if ( !Abc_AigNodeIsConst(pObj) )
237 printf(
"Abc_AigCheck: The AIG has non-standard constant nodes.\n" );
244 printf(
"Abc_AigCheck: The AIG has single input nodes.\n" );
249 printf(
"Abc_AigCheck: The AIG has non-standard nodes.\n" );
252 if ( pObj->
Level != 1 + (
unsigned)Abc_MaxInt( Abc_ObjFanin0(pObj)->Level, Abc_ObjFanin1(pObj)->Level ) )
253 printf(
"Abc_AigCheck: Node \"%s\" has level that does not agree with the fanin levels.\n",
Abc_ObjName(pObj) );
256 printf(
"Abc_AigCheck: Node \"%s\" is not in the structural hashing table.\n",
Abc_ObjName(pObj) );
260 for ( i = 0; i < pMan->
nBins; i++ )
263 if ( Counter != Abc_NtkNodeNum(pMan->
pNtkAig) )
265 printf(
"Abc_AigCheck: The number of nodes in the structural hashing table is wrong.\n" );
270 if ( Abc_AigNodeIsChoice(pObj) )
272 if ( Abc_ObjFanoutNum(pAnd) > 0 )
274 printf(
"Abc_AigCheck: Representative %s",
Abc_ObjName(pAnd) );
275 printf(
" of choice node %s has %d fanouts.\n",
Abc_ObjName(pObj), Abc_ObjFanoutNum(pAnd) );
296 assert( Abc_NtkIsStrash(pNtk) );
302 if ( LevelsMax < (
int)Abc_ObjFanin0(pNode)->Level )
303 LevelsMax = (int)Abc_ObjFanin0(pNode)->Level;
325 Abc_AigResize( pMan );
327 if ( Abc_ObjRegular(p0)->Id > Abc_ObjRegular(p1)->Id )
328 pAnd = p0, p0 = p1, p1 = pAnd;
330 pAnd = Abc_NtkCreateNode( pMan->
pNtkAig );
334 pAnd->
Level = 1 + Abc_MaxInt( Abc_ObjRegular(p0)->Level, Abc_ObjRegular(p1)->Level );
336 pAnd->
fPhase = (Abc_ObjIsComplement(p0) ^ Abc_ObjRegular(p0)->fPhase) & (Abc_ObjIsComplement(p1) ^ Abc_ObjRegular(p1)->fPhase);
338 Key = Abc_HashKey2( p0, p1, pMan->
nBins );
340 pMan->
pBins[Key] = pAnd;
367 assert( !Abc_ObjIsComplement(pAnd) );
369 if ( Abc_ObjRegular(p0)->Id > Abc_ObjRegular(p1)->Id )
370 pTemp = p0, p0 = p1, p1 = pTemp;
375 pAnd->
Level = 1 + Abc_MaxInt( Abc_ObjRegular(p0)->Level, Abc_ObjRegular(p1)->Level );
378 Key = Abc_HashKey2( p0, p1, pMan->
nBins );
380 pMan->
pBins[Key] = pAnd;
407 assert( Abc_ObjRegular(p0)->pNtk->pManFunc == pMan );
408 assert( Abc_ObjRegular(p1)->pNtk->pManFunc == pMan );
413 if ( p0 == Abc_ObjNot(p1) )
414 return Abc_ObjNot(pConst1);
415 if ( Abc_ObjRegular(p0) == pConst1 )
419 return Abc_ObjNot(pConst1);
421 if ( Abc_ObjRegular(p1) == pConst1 )
425 return Abc_ObjNot(pConst1);
442 int nFans0 = Abc_ObjFanoutNum( Abc_ObjRegular(p0) );
443 int nFans1 = Abc_ObjFanoutNum( Abc_ObjRegular(p1) );
444 if ( nFans0 == 0 || nFans1 == 0 )
449 if ( Abc_ObjRegular(p0)->Id > Abc_ObjRegular(p1)->Id )
450 pAnd = p0, p0 = p1, p1 = pAnd;
452 Key = Abc_HashKey2( p0, p1, pMan->
nBins );
455 if ( p0 == Abc_ObjChild0(pAnd) && p1 == Abc_ObjChild1(pAnd) )
478 if ( pType ) *pType = 0;
484 if ( pNode && pType ) *pType = 1;
492 return pNode? Abc_ObjNot(pNode) : NULL;
512 if ( pType ) *pType = 0;
518 if ( pNode && pType ) *pType = 1;
526 return pNode? Abc_ObjNot(pNode) : NULL;
544 Abc_Obj_t * pAnd, * pAnd0, * pAnd1, ** ppPlace;
546 assert( !Abc_ObjIsComplement(pThis) );
547 assert( Abc_ObjIsNode(pThis) );
548 assert( Abc_ObjFaninNum(pThis) == 2 );
551 pAnd0 = Abc_ObjRegular( Abc_ObjChild0(pThis) );
552 pAnd1 = Abc_ObjRegular( Abc_ObjChild1(pThis) );
553 Key = Abc_HashKey2( Abc_ObjChild0(pThis), Abc_ObjChild1(pThis), pMan->
nBins );
555 ppPlace = pMan->
pBins + Key;
560 ppPlace = &pAnd->
pNext;
563 *ppPlace = pAnd->
pNext;
588 int nBinsNew, Counter, i;
594 nBinsNew = Abc_PrimeCudd( 3 * pMan->
nBins );
600 for ( i = 0; i < pMan->
nBins; i++ )
603 Key = Abc_HashKey2( Abc_ObjChild0(pEnt), Abc_ObjChild1(pEnt), nBinsNew );
604 pEnt->
pNext = pBinsNew[Key];
605 pBinsNew[Key] = pEnt;
613 pMan->
pBins = pBinsNew;
614 pMan->
nBins = nBinsNew;
634 int Counter, Temp, i;
641 for ( i = 0; i < pMan->
nBins; i++ )
646 if ( pArray[0] > pArray[1] )
649 pArray[0] = pArray[1];
656 Key = Abc_HashKey2( Abc_ObjChild0(pEnt), Abc_ObjChild1(pEnt), pMan->
nBins );
657 pEnt->
pNext = pBinsNew[Key];
658 pBinsNew[Key] = pEnt;
664 pMan->
pBins = pBinsNew;
685 assert( Abc_NtkIsStrash(pNtk) );
705 return Abc_AigAndCreate( pMan, p0, p1 );
721 return Abc_ObjNot(
Abc_AigAnd( pMan, Abc_ObjNot(p0), Abc_ObjNot(p1) ) );
792 if ( vPairs->nSize == 0 )
794 assert( vPairs->nSize % 2 == 0 );
798 for ( i = 0; i < vPairs->nSize; i += 2 )
803 for ( i = 0; i < vPairs->nSize; i += 2 )
806 vPairs->nSize = vPairs->nSize/2;
825 assert( vPairs->nSize % 2 == 0 );
828 for ( i = 0; i < vPairs->nSize; i += 2 )
831 pMiter =
Abc_AigOr( pMan, pMiter, pXor );
856 assert( !Abc_ObjIsComplement(pOld) );
862 if ( Abc_ObjFanoutNum(pOld) == 0 )
865 Abc_AigReplace_int( pMan, pOld, pNew, fUpdateLevel );
869 Abc_AigUpdateLevel_int( pMan );
871 Abc_AigUpdateLevelR_int( pMan );
889 Abc_Obj_t * pFanin1, * pFanin2, * pFanout, * pFanoutNew, * pFanoutFanout;
893 assert( !Abc_ObjIsComplement(pOld) );
894 assert( Abc_ObjFanoutNum(pOld) > 0 );
899 if ( Abc_ObjIsCo(pFanout) )
901 pFanin1 = Abc_ObjRegular( pNew );
903 Abc_AigRemoveFromLevelStructureR( pMan->
vLevelsR, pFanin1 );
908 if ( !Abc_ObjIsCi(pFanin1) )
918 iFanin = Vec_IntFind( &pFanout->
vFanins, pOld->
Id );
919 assert( iFanin == 0 || iFanin == 1 );
921 pFanin1 = Abc_ObjNotCond( pNew, Abc_ObjFaninC(pFanout, iFanin) );
922 assert( Abc_ObjRegular(pFanin1) != pFanout );
924 pFanin2 = Abc_ObjChild( pFanout, iFanin ^ 1 );
925 assert( Abc_ObjRegular(pFanin2) != pFanout );
936 assert( Abc_ObjRegular(pFanin1) != Abc_ObjRegular(pFanin2) );
940 Abc_AigRemoveFromLevelStructure( pMan->
vLevels, pFanout );
943 Abc_AigRemoveFromLevelStructureR( pMan->
vLevelsR, pFanout );
946 Abc_AigAndDelete( pMan, pFanout );
950 Abc_AigAndCreateFrom( pMan, pFanin1, pFanin2, pFanout );
970 if ( Abc_AigNodeIsAnd(pFanoutFanout) )
974 if ( Abc_ObjFanoutNum(pOld) == 0 )
995 assert( !Abc_ObjIsComplement(pNode) );
996 assert( Abc_ObjIsNode(pNode) );
997 assert( Abc_ObjFaninNum(pNode) == 2 );
998 assert( Abc_ObjFanoutNum(pNode) == 0 );
1002 if ( pNode == pTemp )
1016 if ( pNode == Abc_ObjRegular(pTemp) )
1020 pNode0 = Abc_ObjFanin0( pNode );
1021 pNode1 = Abc_ObjFanin1( pNode );
1031 Abc_AigAndDelete( pMan, pNode );
1034 Abc_AigRemoveFromLevelStructure( pMan->
vLevels, pNode );
1036 Abc_AigRemoveFromLevelStructureR( pMan->
vLevelsR, pNode );
1041 if ( Abc_ObjIsNode(pNode0) && pNode0->
vFanouts.nSize == 0 )
1043 if ( Abc_ObjIsNode(pNode1) && pNode1->
vFanouts.nSize == 0 )
1063void Abc_AigUpdateLevel_int(
Abc_Aig_t * pMan )
1067 int LevelNew, i, k, v;
1072 if ( Vec_PtrSize(vVec) == 0 )
1076 if ( pNode == NULL )
1078 assert( Abc_ObjIsNode(pNode) );
1086 if ( Abc_ObjIsCo(pFanout) )
1089 LevelNew = 1 + Abc_MaxInt( Abc_ObjFanin0(pFanout)->Level, Abc_ObjFanin1(pFanout)->Level );
1091 if ( (
int)pFanout->
Level == LevelNew )
1095 Abc_AigRemoveFromLevelStructure( pMan->
vLevels, pFanout );
1097 pFanout->
Level = LevelNew;
1104 Vec_PtrClear( vVec );
1119void Abc_AigUpdateLevelR_int(
Abc_Aig_t * pMan )
1123 int LevelNew, i, k, v, j;
1128 if ( Vec_PtrSize(vVec) == 0 )
1132 if ( pNode == NULL )
1134 assert( Abc_ObjIsNode(pNode) );
1142 if ( Abc_ObjIsCi(pFanin) )
1155 Abc_AigRemoveFromLevelStructureR( pMan->
vLevelsR, pFanin );
1161 Vec_VecPush( pMan->
vLevelsR, LevelNew, pFanin );
1164 Vec_PtrClear( vVec );
1185 vVecTemp = Vec_VecEntry( vStruct, pNode->
Level );
1188 if ( pTemp != pNode )
1190 Vec_PtrWriteEntry( vVecTemp, m, NULL );
1193 assert( m < Vec_PtrSize(vVecTemp) );
1217 if ( pTemp != pNode )
1219 Vec_PtrWriteEntry( vVecTemp, m, NULL );
1222 assert( m < Vec_PtrSize(vVecTemp) );
1247 iFanin = Vec_IntFind( &pFanout->
vFanins, pNode->
Id );
1249 if ( Abc_ObjFaninC( pFanout, iFanin ) )
1274 if ( !Abc_NodeIsTravIdCurrent(pFanout) )
1276 iFanin = Vec_IntFind( &pFanout->
vFanins, pNode->
Id );
1278 if ( Abc_ObjFaninC( pFanout, iFanin ) )
1298 Abc_Obj_t * pNodeR = Abc_ObjRegular(pNode);
1299 if ( Abc_ObjIsCi(pNodeR) )
1301 printf(
"CI %4s%s.\n",
Abc_ObjName(pNodeR), Abc_ObjIsComplement(pNode)?
"\'" :
"" );
1304 if ( Abc_AigNodeIsConst(pNodeR) )
1306 printf(
"Constant 1 %s.\n", Abc_ObjIsComplement(pNode)?
"(complemented)" :
"" );
1310 printf(
"%7s%s",
Abc_ObjName(pNodeR), Abc_ObjIsComplement(pNode)?
"\'" :
"" );
1312 printf(
"%7s%s",
Abc_ObjName(Abc_ObjFanin0(pNodeR)), Abc_ObjFaninC0(pNodeR)?
"\'" :
"" );
1314 printf(
"%7s%s",
Abc_ObjName(Abc_ObjFanin1(pNodeR)), Abc_ObjFaninC1(pNodeR)?
"\'" :
"" );
1335 if ( !Abc_AigNodeIsAnd(pNode) )
1337 pFanin0 = Abc_ObjFanin0(pNode);
1338 pFanin1 = Abc_ObjFanin1(pNode);
1339 if ( pRoot == pFanin0 || pRoot == pFanin1 )
1341 if ( Abc_ObjIsCi(pFanin0) )
1348 pChild00 = Abc_ObjFanin0(pFanin0);
1349 pChild01 = Abc_ObjFanin1(pFanin0);
1350 if ( pRoot == pChild00 || pRoot == pChild01 )
1353 if ( Abc_ObjIsCi(pFanin1) )
1360 pChild10 = Abc_ObjFanin0(pFanin1);
1361 pChild11 = Abc_ObjFanin1(pFanin1);
1362 if ( pRoot == pChild10 || pRoot == pChild11 )
1383 for ( i = 0; i < pMan->
nBins; i++ )
1386 if ( Abc_ObjRegular(Abc_ObjChild0(pEnt))->Id > Abc_ObjRegular(Abc_ObjChild1(pEnt))->Id )
1390 printf(
"Node %d has incorrect ordering of fanins.\n", pEnt->
Id );
1415 pObj->
fPhase = Abc_LatchIsInit1(pObj);
1417 pObj->
fPhase = (Abc_ObjFanin0(pObj)->fPhase ^ Abc_ObjFaninC0(pObj)) & (Abc_ObjFanin1(pObj)->fPhase ^ Abc_ObjFaninC1(pObj));
1419 pObj->
fPhase = (Abc_ObjFanin0(pObj)->fPhase ^ Abc_ObjFaninC0(pObj));
1421 pObj->
fPhase = (Abc_ObjFanin0(pObj)->fPhase ^ Abc_ObjFaninC0(pObj));
1498 int i, Counter = 0, CounterTotal = 0;
1500 for ( i = 0; i < pMan->
nBins; i++ )
1503 Counter += (pAnd->
pNext != NULL);
1506 printf(
"Counter = %d. Nodes = %d. Ave = %6.2f\n", Counter, CounterTotal, 1.0 * CounterTotal/pMan->
nBins );
1517 printf(
"Hello, World!\n" );
Abc_Obj_t * Abc_AigMiter2(Abc_Aig_t *pMan, Vec_Ptr_t *vPairs)
int Abc_AigCheck(Abc_Aig_t *pMan)
Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
#define Abc_AigBinForEachEntry(pBin, pEnt)
Abc_Aig_t * Abc_AigAlloc(Abc_Ntk_t *pNtkAig)
FUNCTION DEFINITIONS ///.
void Abc_AigRehash(Abc_Aig_t *pMan)
void Abc_AigUpdateReset(Abc_Aig_t *pMan)
Vec_Ptr_t * Abc_AigUpdateStart(Abc_Aig_t *pMan, Vec_Ptr_t **pvUpdatedNets)
Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_AigBinForEachEntrySafe(pBin, pEnt, pEnt2)
void Abc_AigPrintNode(Abc_Obj_t *pNode)
int Abc_AigLevel(Abc_Ntk_t *pNtk)
void Abc_AigUpdateStop(Abc_Aig_t *pMan)
void Abc_AigSetNodePhases(Abc_Ntk_t *pNtk)
void Abc_AigCheckFaninOrder(Abc_Aig_t *pMan)
Abc_Obj_t * Abc_AigMiter(Abc_Aig_t *pMan, Vec_Ptr_t *vPairs, int fImplic)
int Abc_AigNodeIsAcyclic(Abc_Obj_t *pNode, Abc_Obj_t *pRoot)
int Abc_AigNodeHasComplFanoutEdge(Abc_Obj_t *pNode)
Abc_Obj_t * Abc_AigOr(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Abc_Obj_t * Abc_AigMuxLookup(Abc_Aig_t *pMan, Abc_Obj_t *pC, Abc_Obj_t *pT, Abc_Obj_t *pE, int *pType)
int Abc_AigReplace(Abc_Aig_t *pMan, Abc_Obj_t *pOld, Abc_Obj_t *pNew, int fUpdateLevel)
void Abc_NtkHelloWorld(Abc_Ntk_t *pNtk)
END OF FILE ///.
Abc_Obj_t * Abc_AigXor(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
int Abc_AigCleanup(Abc_Aig_t *pMan)
int Abc_AigNodeHasComplFanoutEdgeTrav(Abc_Obj_t *pNode)
void Abc_AigDeleteNode(Abc_Aig_t *pMan, Abc_Obj_t *pNode)
Abc_Obj_t * Abc_AigMiter_rec(Abc_Aig_t *pMan, Abc_Obj_t **ppObjs, int nObjs)
Abc_Obj_t * Abc_AigMux(Abc_Aig_t *pMan, Abc_Obj_t *pC, Abc_Obj_t *p1, Abc_Obj_t *p0)
Abc_Obj_t * Abc_AigXorLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1, int *pType)
Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
int Abc_AigCountNext(Abc_Aig_t *pMan)
void Abc_AigFree(Abc_Aig_t *pMan)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL int Abc_NtkIsDfsOrdered(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL Abc_Obj_t * Abc_AigXor(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
#define Abc_AigForEachAnd(pNtk, pNode, i)
#define Abc_NtkForEachPo(pNtk, pPo, i)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
struct Abc_Aig_t_ Abc_Aig_t
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
#define Abc_NtkForEachLatchOutput(pNtk, pObj, i)
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_NtkForEachLatchInput(pNtk, pObj, i)
ABC_DLL void Abc_ObjSetReverseLevel(Abc_Obj_t *pObj, int LevelR)
#define Abc_NtkForEachPi(pNtk, pPi, i)
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
ABC_DLL Abc_Obj_t * Abc_NtkCreateObj(Abc_Ntk_t *pNtk, Abc_ObjType_t Type)
ABC_DLL void Abc_NodeFreeCuts(void *p, Abc_Obj_t *pObj)
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
ABC_DLL int Abc_ObjReverseLevel(Abc_Obj_t *pObj)
#define Abc_NtkForEachNode(pNtk, pNode, i)
ABC_DLL int Abc_NodeIsExorType(Abc_Obj_t *pNode)
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Vec_Ptr_t * vStackReplaceOld
Vec_Ptr_t * vStackReplaceNew
int nObjCounts[ABC_OBJ_NUMBER]
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
#define Vec_VecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.