30#define ABC_DC_MAX_NODES (1<<15)
102static inline int Odc_PiNum(
Odc_Man_t *
p ) {
return p->nPis; }
103static inline int Odc_NodeNum(
Odc_Man_t *
p ) {
return p->nObjs -
p->nPis - 1; }
104static inline int Odc_ObjNum(
Odc_Man_t *
p ) {
return p->nObjs; }
113static inline Odc_Lit_t Odc_Const0() {
return 1; }
114static inline Odc_Lit_t Odc_Const1() {
return 0; }
117static inline int Odc_IsTerm(
Odc_Man_t *
p,
Odc_Lit_t Lit ) {
return (
int)(Lit>>1) <=
p->nPis; }
129static inline int Odc_ObjFaninC0(
Odc_Obj_t * pObj ) {
return Odc_IsComplement(pObj->
iFan0); }
130static inline int Odc_ObjFaninC1(
Odc_Obj_t * pObj ) {
return Odc_IsComplement(pObj->
iFan1); }
133static inline void Odc_ManIncrementTravId(
Odc_Man_t *
p ) {
p->nTravIds++; }
135static inline int Odc_ObjIsTravIdCurrent(
Odc_Man_t *
p,
Odc_Obj_t * pObj ) {
return (
int )((int)pObj->
TravId ==
p->nTravIds); }
138static inline unsigned * Odc_ObjTruth(
Odc_Man_t *
p,
Odc_Lit_t Lit ) {
assert( !(Lit & 1) );
return (
unsigned *) Vec_PtrEntry(
p->vTruths, Lit >> 1); }
141#define Odc_ForEachPi( p, Lit, i ) \
142 for ( i = 0; (i < Odc_PiNum(p)) && (((Lit) = Odc_Var(p, i)), 1); i++ )
143#define Odc_ForEachAnd( p, pObj, i ) \
144 for ( i = 1 + Odc_CiNum(p); (i < Odc_ObjNum(p)) && ((pObj) = (p)->pObjs + i); i++ )
170 assert( nVarsMax > 4 && nVarsMax < 16 );
171 assert( nLevels > 0 && nLevels < 10 );
176 p->nVarsMax = nVarsMax;
177 p->nLevels = nLevels;
178 p->fVerbose = fVerbose;
179 p->fVeryVerbose = fVeryVerbose;
184 p->vRoots = Vec_PtrAlloc( 128 );
185 p->vBranches = Vec_PtrAlloc( 128 );
191 p->nPis = nVarsMax + 32;
192 p->nObjs = 1 +
p->nPis;
195 for ( i = 0; i < 32; i++ )
196 p->pObjs[1 +
p->nVarsMax + i].uMask = (1 << i);
198 p->nTableSize =
p->nObjsAlloc/3 + 1;
201 p->vUsedSpots = Vec_IntAlloc( 1000 );
204 p->nWords = Abc_TruthWordNum(
p->nVarsMax );
205 p->nBits =
p->nWords * 8 *
sizeof(unsigned);
206 p->vTruths = Vec_PtrAllocSimInfo(
p->nObjsAlloc,
p->nWords );
207 p->vTruthsElem = Vec_PtrAllocSimInfo(
p->nVarsMax,
p->nWords );
210 Abc_InfoFill( (
unsigned *)Vec_PtrEntry(
p->vTruths, 0),
p->nWords );
211 for ( k = 0; k <
p->nVarsMax; k++ )
214 pData = (
unsigned *)Vec_PtrEntry(
p->vTruthsElem, k );
215 Abc_InfoClear( pData,
p->nWords );
216 for ( i = 0; i <
p->nBits; i++ )
218 pData[i>>5] |= (1 << (i&31));
222 for ( k =
p->nVarsMax; k < p->nPis; k++ )
224 pData = Odc_ObjTruth(
p, Odc_Var(
p, k) );
225 Abc_InfoRandom( pData,
p->nWords );
248 if ( Vec_IntSize(
p->vUsedSpots) >
p->nTableSize/3 )
254 p->pTable[iSpot] = 0;
256 Vec_IntClear(
p->vUsedSpots );
258 p->nObjs = 1 +
p->nPis;
262p->timeClean += Abc_Clock() - clk;
280 printf(
"Wins = %5d. Empty = %5d. SimsEmpty = %5d. QuantOver = %5d. WinsFinish = %5d.\n",
281 p->nWins,
p->nWinsEmpty,
p->nSimsEmpty,
p->nQuantsOver,
p->nWinsFinish );
282 printf(
"Ave DCs per window = %6.2f %%. Ave DCs per finished window = %6.2f %%.\n",
283 1.0*
p->nTotalDcs/
p->nWins, 1.0*
p->nTotalDcs/
p->nWinsFinish );
284 printf(
"Runtime stats of the ODC manager:\n" );
285 ABC_PRT(
"Cleaning ",
p->timeClean );
286 ABC_PRT(
"Windowing ",
p->timeWin );
288 ABC_PRT(
"Simulation ",
p->timeSim );
289 ABC_PRT(
"Quantifying ",
p->timeQuant );
290 ABC_PRT(
"Truth table ",
p->timeTruth );
292 ABC_PRT(
"Aborted ",
p->timeAbort );
294 Vec_PtrFree(
p->vRoots );
295 Vec_PtrFree(
p->vBranches );
296 Vec_PtrFree(
p->vTruths );
297 Vec_PtrFree(
p->vTruthsElem );
298 Vec_IntFree(
p->vUsedSpots );
321 if ( Abc_ObjIsCo(pObj) || (
int)pObj->
Level > nLevelLimit || pObj == pNode )
323 if ( Abc_NodeIsTravIdCurrent(pObj) )
325 Abc_NodeSetTravIdCurrent( pObj );
328 if ( Abc_ObjFanoutNum(pObj) > 100 )
350 Abc_NtkIncrementTravId(
p->pNode->pNtk );
370 assert( Abc_ObjIsNode(pObj) );
371 assert( Abc_NodeIsTravIdCurrent(pObj) );
374 if ( !Abc_NodeIsTravIdCurrent(pFanout) )
377 if ( i < Abc_ObjFanoutNum(pObj) )
379 Vec_PtrPushUnique( vRoots, pObj );
401 assert( !Abc_NodeIsTravIdCurrent(
p->pNode) );
403 Abc_NodeSetTravIdCurrent(
p->pNode );
405 Vec_PtrClear(
p->vRoots );
425 if ( Abc_NodeIsTravIdCurrent(pObj) )
428 if ( !Abc_NodeIsTravIdPrevious(pObj) || Abc_ObjIsCi(pObj) )
430 Abc_NodeSetTravIdCurrent( pObj );
431 Vec_PtrPush(
p->vBranches, pObj );
432 return Vec_PtrSize(
p->vBranches) <= 32;
457 Abc_NtkIncrementTravId(
p->pNode->pNtk );
459 Abc_NodeSetTravIdCurrent( pObj );
461 Vec_PtrClear(
p->vBranches );
485 if ( Vec_PtrSize(
p->vRoots) == 1 && Vec_PtrEntry(
p->vRoots, 0) ==
p->pNode )
517 Key ^= Odc_Regular(iFan0) * 7937;
518 Key ^= Odc_Regular(iFan1) * 2971;
519 Key ^= Odc_IsComplement(iFan0) * 911;
520 Key ^= Odc_IsComplement(iFan1) * 353;
521 return Key % TableSize;
542 uHashKey = Odc_HashKey( iFan0, iFan1,
p->nTableSize );
544 if (
p->pTable[uHashKey] == 0 )
545 Vec_IntPush(
p->vUsedSpots, uHashKey );
547 for ( pEntry =
p->pTable + uHashKey; *pEntry; pEntry = &pObj->
iNext )
549 pObj = Odc_Lit2Obj(
p, *pEntry );
550 if ( pObj->
iFan0 == iFan0 && pObj->
iFan1 == iFan1 )
571 unsigned uMask0, uMask1;
574 if ( iFan0 == iFan1 )
576 if ( iFan0 == Odc_Not(iFan1) )
578 if ( Odc_Regular(iFan0) == Odc_Const1() )
579 return iFan0 == Odc_Const1() ? iFan1 : Odc_Const0();
580 if ( Odc_Regular(iFan1) == Odc_Const1() )
581 return iFan1 == Odc_Const1() ? iFan0 : Odc_Const0();
584 Temp = iFan0, iFan0 = iFan1, iFan1 = Temp;
586 pEntry = Odc_HashLookup(
p, iFan0, iFan1 );
590 pObj = Odc_ObjNew(
p );
596 uMask0 = Odc_Lit2Obj(
p, Odc_Regular(iFan0))->uMask;
597 uMask1 = Odc_Lit2Obj(
p, Odc_Regular(iFan1))->uMask;
598 pObj->
uMask = uMask0 | uMask1;
600 *pEntry = Odc_Obj2Lit(
p, pObj );
617 return Odc_Not( Odc_And(
p, Odc_Not(iFan0), Odc_Not(iFan1)) );
633 return Odc_Or(
p, Odc_And(
p, iFan0, Odc_Not(iFan1)), Odc_And(
p, Odc_Not(iFan0), iFan1) );
653 unsigned uData0, uData1;
655 assert( !Abc_ObjIsComplement(pNode) );
657 if ( Abc_NodeIsTravIdCurrent(pNode) )
659 Abc_NodeSetTravIdCurrent(pNode);
660 assert( Abc_ObjIsNode(pNode) );
662 if ( pNode == pPivot )
663 return pNode->
pCopy = (
Abc_Obj_t *)(ABC_PTRUINT_T)((Odc_Const1() << 16) | Odc_Const0());
668 uLit0 = Odc_NotCond( (
Odc_Lit_t)(uData0 & 0xffff), Abc_ObjFaninC0(pNode) );
669 uLit1 = Odc_NotCond( (
Odc_Lit_t)(uData1 & 0xffff), Abc_ObjFaninC1(pNode) );
670 uRes0 = Odc_And(
p, uLit0, uLit1 );
672 uLit0 = Odc_NotCond( (
Odc_Lit_t)(uData0 >> 16), Abc_ObjFaninC0(pNode) );
673 uLit1 = Odc_NotCond( (
Odc_Lit_t)(uData1 >> 16), Abc_ObjFaninC1(pNode) );
674 uRes1 = Odc_And(
p, uLit0, uLit1 );
676 return pNode->
pCopy = (
Abc_Obj_t *)(ABC_PTRUINT_T)((uRes1 << 16) | uRes0);
697 Abc_NtkIncrementTravId(
p->pNode->pNtk );
701 uLit = Odc_Var(
p, i );
703 Abc_NodeSetTravIdCurrent(pObj);
708 uLit = Odc_Var(
p, i+
p->nVarsMax );
710 Abc_NodeSetTravIdCurrent(pObj);
713 p->iRoot = Odc_Const0();
718 uRes0 = uData & 0xffff;
722 uLit = Odc_Xor(
p, uRes0, uRes1 );
723 p->iRoot = Odc_Or(
p,
p->iRoot, uLit );
743 unsigned uData0, uData1;
745 assert( !Odc_IsComplement(Lit) );
747 pObj = Odc_Lit2Obj(
p, Lit );
748 if ( Odc_ObjIsTravIdCurrent(
p, pObj) )
753 Odc_ObjSetTravIdCurrent(
p, pObj);
755 if ( (pObj->
uMask & uMask) == 0 )
756 return pObj->
uData = ((Lit << 16) | Lit);
758 if ( pObj->
uMask == uMask && Odc_IsTerm(
p, Lit) )
759 return pObj->
uData = ((Odc_Const1() << 16) | Odc_Const0());
764 uLit0 = Odc_NotCond( (
Odc_Lit_t)(uData0 & 0xffff), Odc_ObjFaninC0(pObj) );
765 uLit1 = Odc_NotCond( (
Odc_Lit_t)(uData1 & 0xffff), Odc_ObjFaninC1(pObj) );
766 uRes0 = Odc_And(
p, uLit0, uLit1 );
768 uLit0 = Odc_NotCond( (
Odc_Lit_t)(uData0 >> 16), Odc_ObjFaninC0(pObj) );
769 uLit1 = Odc_NotCond( (
Odc_Lit_t)(uData1 >> 16), Odc_ObjFaninC1(pObj) );
770 uRes1 = Odc_And(
p, uLit0, uLit1 );
773 return pObj->
uData = ((uRes1 << 16) | uRes0);
794 assert( Vec_PtrSize(
p->vBranches) <= 32 );
795 for ( i = 0; i < Vec_PtrSize(
p->vBranches); i++ )
798 Odc_ManIncrementTravId(
p );
802 uRes0 = Odc_NotCond( (
Odc_Lit_t)(uData & 0xffff), Odc_IsComplement(
p->iRoot) );
803 uRes1 = Odc_NotCond( (
Odc_Lit_t)(uData >> 16), Odc_IsComplement(
p->iRoot) );
805 p->iRoot = Odc_Or(
p, uRes0, uRes1 );
810 assert(
p->nObjs <=
p->nObjsAlloc );
831 for ( k = 0; k <
p->nVarsMax; k++ )
833 pData = Odc_ObjTruth(
p, Odc_Var(
p, k) );
834 Abc_InfoClear( pData,
p->nWords );
835 for ( i = 0; i <
p->nBits; i++ )
837 pData[i>>5] |= (1 << (i&31));
854 unsigned * pData, * pData2;
856 for ( k = 0; k <
p->nVarsMax; k++ )
858 pData = Odc_ObjTruth(
p, Odc_Var(
p, k) );
859 pData2 = (
unsigned *)Vec_PtrEntry(
p->vTruthsElem, k );
860 Abc_InfoCopy( pData, pData2,
p->nWords );
879 for ( w = 0; w <
p->nWords; w++ )
882 for ( k = 0; k <
p->nVarsMax; k++ )
884 pData = Odc_ObjTruth(
p, Odc_Var(
p, k) );
885 pData[w] = (Number & (1<<k)) ? ~0 : 0;
904 for ( w = 0; w <
p->nWords; w++ )
924 unsigned * pInfo, * pInfo1, * pInfo2;
925 int k, fComp1, fComp2;
926 assert( !Odc_IsComplement( Lit ) );
927 assert( !Odc_IsTerm(
p, Lit ) );
929 pObj = Odc_Lit2Obj(
p, Lit );
930 pInfo = Odc_ObjTruth(
p, Lit );
931 pInfo1 = Odc_ObjTruth(
p, Odc_ObjFanin0(pObj) );
932 pInfo2 = Odc_ObjTruth(
p, Odc_ObjFanin1(pObj) );
933 fComp1 = Odc_ObjFaninC0( pObj );
934 fComp2 = Odc_ObjFaninC1( pObj );
936 if ( fComp1 && fComp2 )
937 for ( k = 0; k <
p->nWords; k++ )
938 pInfo[k] = ~pInfo1[k] & ~pInfo2[k];
939 else if ( fComp1 && !fComp2 )
940 for ( k = 0; k <
p->nWords; k++ )
941 pInfo[k] = ~pInfo1[k] & pInfo2[k];
942 else if ( !fComp1 && fComp2 )
943 for ( k = 0; k <
p->nWords; k++ )
944 pInfo[k] = pInfo1[k] & ~pInfo2[k];
946 for ( k = 0; k <
p->nWords; k++ )
947 pInfo[k] = pInfo1[k] & pInfo2[k];
964 assert( !Odc_IsComplement(Lit) );
966 if ( Odc_IsTerm(
p, Lit) )
969 pObj = Odc_Lit2Obj(
p, Lit );
970 if ( Odc_ObjIsTravIdCurrent(
p, pObj) )
972 Odc_ObjSetTravIdCurrent(
p, pObj);
993 Odc_ManIncrementTravId(
p );
995 Abc_InfoCopy( puTruth, Odc_ObjTruth(
p, Odc_Regular(
p->iRoot)),
p->nWords );
996 if ( Odc_IsComplement(
p->iRoot) )
997 Abc_InfoNot( puTruth,
p->nWords );
998 return Extra_TruthCountOnes( puTruth,
p->nVarsMax );
1015 int nRounds, Counter, r;
1017 nRounds =
p->nBits /
p->nWords;
1019 for ( r = 0; r < nIters; r++ )
1026 Counter = Counter * nRounds / nIters;
1044 int nMints, RetValue;
1045 abctime clk, clkTotal = Abc_Clock();
1050 assert( !Abc_ObjIsComplement(pNode) );
1051 assert( Abc_ObjIsNode(pNode) );
1052 assert( Vec_PtrSize(vLeaves) <=
p->nVarsMax );
1053 p->vLeaves = vLeaves;
1059p->timeWin += Abc_Clock() - clk;
1062p->timeAbort += Abc_Clock() - clkTotal;
1063 Abc_InfoFill( puTruth,
p->nWords );
1068 if (
p->fVeryVerbose )
1070 printf(
" %5d : ", pNode->
Id );
1071 printf(
"Leaf = %2d ", Vec_PtrSize(
p->vLeaves) );
1072 printf(
"Root = %2d ", Vec_PtrSize(
p->vRoots) );
1073 printf(
"Bran = %2d ", Vec_PtrSize(
p->vBranches) );
1080p->timeMiter += Abc_Clock() - clk;
1085p->timeSim += Abc_Clock() - clk;
1086 if (
p->fVeryVerbose )
1088 printf(
"AIG = %5d ", Odc_NodeNum(
p) );
1089 printf(
"%6.2f %% ", 100.0 * (
p->nBits - nMints) /
p->nBits );
1093 if ( 100.0 * (
p->nBits - nMints) /
p->nBits < 1.0 *
p->nPercCutoff )
1095p->timeAbort += Abc_Clock() - clkTotal;
1096 if (
p->fVeryVerbose )
1097 printf(
"Simulation cutoff.\n" );
1098 Abc_InfoFill( puTruth,
p->nWords );
1106p->timeQuant += Abc_Clock() - clk;
1109p->timeAbort += Abc_Clock() - clkTotal;
1110 if (
p->fVeryVerbose )
1111 printf(
"=== Overflow! ===\n" );
1112 Abc_InfoFill( puTruth,
p->nWords );
1121p->timeTruth += Abc_Clock() - clk;
1122 if (
p->fVeryVerbose )
1124 printf(
"AIG = %5d ", Odc_NodeNum(
p) );
1125 printf(
"%6.2f %% ", 100.0 * (
p->nBits - nMints) /
p->nBits );
1128p->timeTotal += Abc_Clock() - clkTotal;
1130 p->nTotalDcs += (int)(100.0 * (
p->nBits - nMints) /
p->nBits);
void Abc_NtkDontCareSimulateSetElem2(Odc_Man_t *p)
int Abc_NtkDontCareCountMintsWord(Odc_Man_t *p, unsigned *puTruth)
int Abc_NtkDontCareTransfer(Odc_Man_t *p)
int Abc_NtkDontCareQuantify(Odc_Man_t *p)
int Abc_NtkDontCareWindow(Odc_Man_t *p)
void Abc_NtkDontCareWinSweepLeafTfo(Odc_Man_t *p)
void Abc_NtkDontCareFree(Odc_Man_t *p)
#define ABC_DC_MAX_NODES
DECLARATIONS ///.
int Abc_NtkDontCareSimulateBefore(Odc_Man_t *p, unsigned *puTruth)
int Abc_NtkDontCareSimulate(Odc_Man_t *p, unsigned *puTruth)
int Abc_NtkDontCareCompute(Odc_Man_t *p, Abc_Obj_t *pNode, Vec_Ptr_t *vLeaves, unsigned *puTruth)
void Abc_NtkDontCareWinSweepLeafTfo_rec(Abc_Obj_t *pObj, int nLevelLimit, Abc_Obj_t *pNode)
unsigned Abc_NtkDontCareCofactors_rec(Odc_Man_t *p, Odc_Lit_t Lit, unsigned uMask)
void Abc_NtkDontCareSimulateSetRand(Odc_Man_t *p)
void Abc_NtkDontCareTruthOne(Odc_Man_t *p, Odc_Lit_t Lit)
void Abc_NtkDontCareWinCollectRoots(Odc_Man_t *p)
void Abc_NtkDontCareSimulateSetElem(Odc_Man_t *p)
int Abc_NtkDontCareWinAddMissing(Odc_Man_t *p)
struct Odc_Obj_t_ Odc_Obj_t
void Abc_NtkDontCareSimulate_rec(Odc_Man_t *p, Odc_Lit_t Lit)
void * Abc_NtkDontCareTransfer_rec(Odc_Man_t *p, Abc_Obj_t *pNode, Abc_Obj_t *pPivot)
void Abc_NtkDontCareWinCollectRoots_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vRoots)
void Abc_NtkDontCareClear(Odc_Man_t *p)
int Abc_NtkDontCareWinAddMissing_rec(Odc_Man_t *p, Abc_Obj_t *pObj)
Odc_Man_t * Abc_NtkDontCareAlloc(int nVarsMax, int nLevels, int fVerbose, int fVeryVerbose)
FUNCTION DEFINITIONS ///.
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_ObjForEachFanin(pObj, pFanin, i)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
struct Odc_Man_t_ Odc_Man_t
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.