56static inline int Dam_ObjHand(
Dam_Man_t *
p,
int i ) {
return i < Vec_IntSize(
p->vNod2Set) ? Vec_IntEntry(
p->vNod2Set, i) : 0; }
57static inline int * Dam_ObjSet(
Dam_Man_t *
p,
int i ) {
int h = Dam_ObjHand(
p, i);
if ( h == 0 )
return NULL;
return Vec_IntEntryP(
p->vSetStore, h); }
59static inline int Dam_DivHand(
Dam_Man_t *
p,
int d ) {
return d < Vec_IntSize(
p->vDiv2Nod) ? Vec_IntEntry(
p->vDiv2Nod, d) : 0; }
60static inline int * Dam_DivSet(
Dam_Man_t *
p,
int d ) {
int h = Dam_DivHand(
p, d);
if ( h == 0 )
return NULL;
return Vec_IntEntryP(
p->vNodStore, h); }
80 int i, k = 0, Prev = -1, This, fCompl = 0;
87 else if ( Prev != This )
88 Vec_IntWriteEntry( vSuper, k++, This ), Prev = This;
92 Vec_IntShrink( vSuper, k );
93 if ( Vec_IntSize( vSuper ) == 0 )
94 Vec_IntPush( vSuper, fCompl );
96 Vec_IntWriteEntry( vSuper, 0, Abc_LitNot(Vec_IntEntry(vSuper, 0)) );
100 int i, k = 0, Prev = -1, This;
104 { Vec_IntFill(vSuper, 1, 0);
return; }
107 if ( Prev == -1 || Abc_Lit2Var(Prev) != Abc_Lit2Var(This) )
108 Vec_IntWriteEntry( vSuper, k++, This ), Prev = This;
109 else if ( Prev != This )
110 { Vec_IntFill(vSuper, 1, 0);
return; }
112 Vec_IntShrink( vSuper, k );
113 if ( Vec_IntSize( vSuper ) == 0 )
114 Vec_IntPush( vSuper, 1 );
130 assert( !Gia_IsComplement(pObj) );
131 if ( !Gia_ObjIsXor(pObj) ||
132 (fStrict && Gia_ObjRefNum(
p, pObj) > 1) ||
133 Gia_ObjRefNum(
p, pObj) > 2 ||
134 (Gia_ObjRefNum(
p, pObj) == 2 && (Gia_ObjRefNum(
p, Gia_ObjFanin0(pObj)) == 1 || Gia_ObjRefNum(
p, Gia_ObjFanin1(pObj)) == 1)) ||
135 Vec_IntSize(
p->vSuper) > 50 )
137 Vec_IntPush(
p->vSuper, Gia_ObjToLit(
p, pObj) );
140 assert( !Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) );
146 if ( Gia_IsComplement(pObj) ||
147 !Gia_ObjIsAndReal(
p, pObj) ||
148 (fStrict && Gia_ObjRefNum(
p, pObj) > 1) ||
149 Gia_ObjRefNum(
p, pObj) > 2 ||
150 (Gia_ObjRefNum(
p, pObj) == 2 && (Gia_ObjRefNum(
p, Gia_ObjFanin0(pObj)) == 1 || Gia_ObjRefNum(
p, Gia_ObjFanin1(pObj)) == 1)) ||
151 Vec_IntSize(
p->vSuper) > 50 )
153 Vec_IntPush(
p->vSuper, Gia_ObjToLit(
p, pObj) );
162 if (
p->vSuper == NULL )
163 p->vSuper = Vec_IntAlloc( 1000 );
165 Vec_IntClear(
p->vSuper );
166 if ( Gia_ObjIsXor(pObj) )
168 assert( !Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) );
172 Vec_IntSort(
p->vSuper, 0 );
177 else if ( Gia_ObjIsAndReal(
p, pObj) )
182 Vec_IntSort(
p->vSuper, 0 );
190 assert( Vec_IntSize(
p->vSuper) > 0 );
206 int i, iLit1 = Vec_IntEntryLast(vSuper);
208 int iLit1Level = Gia_ObjLevelId(pNew, Abc_Lit2Var(iLit1));
209 for ( i = Vec_IntSize(vSuper)-1; i >= 0; i-- )
211 int iLit2 = Vec_IntEntry(vSuper, i);
212 if ( iLit1Level != Gia_ObjLevelId(pNew, Abc_Lit2Var(iLit2)) )
217 if ( iLit2 != iLit1 )
219 Vec_IntWriteEntry( vSuper, i, iLit1 );
220 Vec_IntWriteEntry( vSuper, Vec_IntSize(vSuper)-1, iLit2 );
224 return Vec_IntPop(vSuper);
228 int i, k, Stop, Lit1, Lit2, Level1, Level2, * pArray;
229 int nSize = Vec_IntSize(vSuper);
233 Level1 = Gia_ObjLevelId( pNew, Abc_Lit2Var(Vec_IntEntry(vSuper, nSize-2)) );
235 for ( Stop = nSize-3; Stop >= 0; Stop-- )
237 Level2 = Gia_ObjLevelId( pNew, Abc_Lit2Var(Vec_IntEntry(vSuper, Stop)) );
238 if ( Level1 != Level2 )
241 if ( Stop == nSize-3 )
244 Stop = Abc_MaxInt( Stop, nSize - 9 );
245 for ( i = nSize - 1; i > Stop; i-- )
246 for ( k = i - 1; k > Stop; k-- )
248 Lit1 = Vec_IntEntry(vSuper, i);
249 Lit2 = Vec_IntEntry(vSuper, k);
253 pArray = Vec_IntArray( vSuper );
255 ABC_SWAP(
int, pArray[i], pArray[nSize-1] );
257 ABC_SWAP(
int, pArray[k], pArray[nSize-2] );
262 int iLit0 = Vec_IntPop(vSuper);
263 int iLit1 = Vec_IntPop(vSuper);
266 if ( !Gia_ObjIsXor(pObj) )
272 Vec_IntPush( vSuper, iLit );
273 Gia_ObjSetGateLevel( pNew, Gia_ManObj(pNew, Abc_Lit2Var(iLit)) );
275 for ( i = Vec_IntSize(vSuper)-1; i > 0; i-- )
277 int iLit1 = Vec_IntEntry(vSuper, i);
278 int iLit2 = Vec_IntEntry(vSuper, i-1);
279 if ( Gia_ObjLevelId(pNew, Abc_Lit2Var(iLit1)) <= Gia_ObjLevelId(pNew, Abc_Lit2Var(iLit2)) )
281 Vec_IntWriteEntry( vSuper, i, iLit2 );
282 Vec_IntWriteEntry( vSuper, i-1, iLit1 );
287 assert( !Gia_ObjIsBuf(pObj) );
288 Vec_IntClear( vSuper );
290 Vec_IntPush( vSuper, pLits[0] );
291 else if ( nLits == 2 )
293 Vec_IntPush( vSuper, pLits[0] );
294 Vec_IntPush( vSuper, pLits[1] );
297 else if ( nLits > 2 )
300 int i, * pArray, * pPerm;
301 for ( i = 0; i < nLits; i++ )
302 Vec_IntPush( vSuper, Gia_ObjLevelId(pNew, Abc_Lit2Var(pLits[i])) );
304 Vec_IntGrow( vSuper, 4 * nLits );
305 pArray = Vec_IntArray( vSuper );
306 pPerm = pArray + nLits;
309 for ( i = 0; i < nLits; i++ )
310 Vec_IntWriteEntry( vSuper, i, pLits[pPerm[i]] );
311 Vec_IntShrink( vSuper, nLits );
318 while ( Vec_IntSize(vSuper) > 1 )
320 if ( !Gia_ObjIsXor(pObj) )
326 assert( Vec_IntSize(vSuper) == 1 );
327 return Vec_IntEntry(vSuper, 0);
343 int i, iLit, iBeg, iEnd;
346 assert( Gia_ObjIsAnd(pObj) );
347 assert( !Gia_ObjIsBuf(pObj) );
349 if ( Gia_ObjIsMux(
p, pObj) )
354 pObj->
Value =
Gia_ManHashMuxReal( pNew, Gia_ObjFanin2Copy(
p, pObj), Gia_ObjFanin1Copy(pObj), Gia_ObjFanin0Copy(pObj) );
355 Gia_ObjSetGateLevel( pNew, Gia_ManObj(pNew, Abc_Lit2Var(pObj->
Value)) );
361 if (
p->vStore == NULL )
362 p->vStore = Vec_IntAlloc( 1000 );
363 iBeg = Vec_IntSize(
p->vStore );
364 Vec_IntAppend(
p->vStore,
p->vSuper );
365 iEnd = Vec_IntSize(
p->vStore );
369 Gia_Obj_t * pTemp = Gia_ManObj(
p, Abc_Lit2Var(iLit) );
371 Vec_IntWriteEntry(
p->vStore, i, Abc_LitNotCond(pTemp->
Value, Abc_LitIsCompl(iLit)) );
373 assert( Vec_IntSize(
p->vStore) == iEnd );
376 Vec_IntShrink(
p->vStore, iBeg );
387 pNew->
pName = Abc_UtilStrsav(
p->pName );
388 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
392 Gia_ManConst0(
p)->Value = 0;
394 pObj->
Value = Gia_ManAppendCi( pNew );
398 int Id, And2Delay =
p->And2Delay ?
p->And2Delay : 1;
400 Vec_IntWriteEntry( pNew->
vLevels, Id, Vec_IntEntry(
p->vCiArrs, i)/And2Delay );
402 else if (
p->vInArrs )
404 int Id, And2Delay =
p->And2Delay ?
p->And2Delay : 1;
406 Vec_IntWriteEntry( pNew->
vLevels, Id, (
int)(Vec_FltEntry(
p->vInArrs, i)/And2Delay) );
413 pObj->
Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
414 Gia_ObjSetGateLevel( pNew, Gia_ManObj(pNew, Abc_Lit2Var(pObj->
Value)) );
419 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
421 assert( !fStrict || Gia_ManObjNum(pNew) <= Gia_ManObjNum(
p) );
478 p->clkStart = Abc_Clock();
479 p->vVisit = Vec_IntAlloc( 1000 );
485 Vec_IntFreeP( &
p->vVisit );
486 Vec_IntFreeP( &
p->vDivLevR );
487 Vec_IntFreeP( &
p->vNodLevR );
488 Vec_IntFreeP( &
p->vNod2Set );
489 Vec_IntFreeP( &
p->vDiv2Nod );
490 Vec_IntFreeP( &
p->vSetStore );
491 Vec_IntFreeP( &
p->vNodStore );
492 Vec_FltFreeP( &
p->vCounts );
493 Vec_QueFreeP( &
p->vQue );
494 Hash_IntManStop(
p->vHash );
512 int i, iBeg, iEnd, iLit;
513 if ( Dam_ObjHand(
p, Id) || Id == 0 )
515 pObj = Gia_ManObj(
p->pGia, Id);
516 if ( Gia_ObjIsCi(pObj) )
518 if ( Gia_ObjIsBuf(pObj) )
523 if ( Gia_ObjIsMux(
p->pGia, pObj) )
528 Vec_IntPush(
p->vVisit, Id );
536 Vec_IntWriteEntry(
p->vNod2Set, Id, Vec_IntSize(
p->vSetStore) );
537 Vec_IntPush(
p->vSetStore, Vec_IntSize(
p->pGia->vSuper) );
538 p->nAnds += (1 + 2 * Gia_ObjIsXor(pObj)) * (Vec_IntSize(
p->pGia->vSuper) - 1);
540 iBeg = Vec_IntSize(
p->vSetStore );
541 Vec_IntAppend(
p->vSetStore,
p->pGia->vSuper );
542 iEnd = Vec_IntSize(
p->vSetStore );
552 p->vNod2Set = Vec_IntStart( Gia_ManObjNum(
p->pGia) );
553 p->vSetStore = Vec_IntAlloc( Gia_ManObjNum(
p->pGia) );
554 Vec_IntPush(
p->vSetStore, -1 );
555 Vec_IntClear(
p->vVisit );
576 int Lev0 = Gia_ObjLevel(
p->pGia, Gia_ManObj(
p->pGia, Abc_Lit2Var(iLit0)));
577 int Lev1 = Gia_ObjLevel(
p->pGia, Gia_ManObj(
p->pGia, Abc_Lit2Var(iLit1)));
578 int Slack =
p->nLevelMax - LevR - Abc_MaxInt(Lev0, Lev1) - 1 - (int)(iLit0 > iLit1);
579 return Abc_MinInt( Slack, 100 );
586 vRefsAnd = Vec_IntStart( 2 * Gia_ManObjNum(
p->pGia) );
587 vRefsXor = Vec_IntStart( Gia_ManObjNum(
p->pGia) );
590 if ( !Dam_ObjHand(
p, i) )
592 pSet = Dam_ObjSet(
p, i);
593 if ( Gia_ObjIsXor(pObj) )
594 for ( k = 1; k <= pSet[0]; k++ )
596 assert( !Abc_LitIsCompl(pSet[k]) );
597 Vec_IntAddToEntry( vRefsXor, Abc_Lit2Var(pSet[k]), 1 );
599 else if ( Gia_ObjIsAndReal(
p->pGia, pObj) )
600 for ( k = 1; k <= pSet[0]; k++ )
601 Vec_IntAddToEntry( vRefsAnd, pSet[k], 1 );
604 *pvRefsAnd = vRefsAnd;
605 *pvRefsXor = vRefsXor;
611 Vec_Int_t * vRefsAnd, * vRefsXor, * vSuper, * vDivs, * vRemap, * vLevRMax;
612 int i, j, k, Num, FanK, FanJ, nRefs, iNode, iDiv, * pSet;
613 int nPairsAll = 0, nPairsTried = 0, nPairsUsed = 0, nPairsXor = 0;
614 int nDivsAll = 0, nDivsUsed = 0, nDivsXor = 0;
616 vSuper =
p->pGia->vSuper;
617 vDivs = Vec_IntAlloc( Gia_ManObjNum(
p->pGia) );
618 vHash = Hash_IntManStart( Gia_ManObjNum(
p->pGia)/2 );
619 vLevRMax = Vec_IntStart( 1000 );
623 if ( !Dam_ObjHand(
p, i) )
625 pSet = Dam_ObjSet(
p, i);
626 nPairsAll += pSet[0] * (pSet[0] - 1) / 2;
627 Vec_IntClear(vSuper);
628 if ( Gia_ObjIsXor(pObj) )
630 for ( k = 1; k <= pSet[0]; k++ )
631 if ( Vec_IntEntry(vRefsXor, Abc_Lit2Var(pSet[k])) > 1 )
632 Vec_IntPush( vSuper, pSet[k] );
634 else if ( Gia_ObjIsAndReal(
p->pGia, pObj) )
636 for ( k = 1; k <= pSet[0]; k++ )
637 if ( Vec_IntEntry(vRefsAnd, pSet[k]) > 1 )
638 Vec_IntPush( vSuper, pSet[k] );
641 if ( Vec_IntSize(vSuper) < 2 )
644 nPairsTried += Vec_IntSize(vSuper) * (Vec_IntSize(vSuper) - 1) / 2;
645 Vec_IntPush( vDivs, -i );
649 if ( (FanK > FanJ) ^ Gia_ObjIsXor(pObj) )
650 Num = Hash_Int2ManInsert( vHash, FanJ, FanK, 0 );
652 Num = Hash_Int2ManInsert( vHash, FanK, FanJ, 0 );
653 if ( Hash_Int2ObjInc( vHash, Num ) == 1 )
656 nDivsXor += Gia_ObjIsXor(pObj);
658 Vec_IntPush( vDivs, Num );
660 if ( Num >= Vec_IntSize(vLevRMax) )
661 Vec_IntFillExtra( vLevRMax, 3 * Vec_IntSize(vLevRMax) / 2, 0 );
662 Vec_IntUpdateEntry( vLevRMax, Num, Vec_IntEntry(
p->vNodLevR, i) );
665 Vec_IntFree( vRefsAnd );
666 Vec_IntFree( vRefsXor );
669 p->vHash = Hash_IntManStart( 3 * nDivsUsed /2 );
670 p->vCounts = Vec_FltAlloc( 2 * nDivsUsed ); Vec_FltPush(
p->vCounts,
ABC_INFINITY );
671 p->vQue = Vec_QueAlloc( Vec_FltCap(
p->vCounts) );
672 Vec_QueSetPriority(
p->vQue, Vec_FltArrayP(
p->vCounts) );
674 p->vDiv2Nod = Vec_IntAlloc( 2 * nDivsUsed ); Vec_IntPush(
p->vDiv2Nod,
ABC_INFINITY );
675 p->vNodStore = Vec_IntAlloc( Gia_ManObjNum(
p->pGia) ); Vec_IntPush(
p->vNodStore, -1 );
676 nDivsAll = Hash_IntManEntryNum(vHash);
677 vRemap = Vec_IntStartFull( nDivsAll+1 );
678 for ( i = 1; i <= nDivsAll; i++ )
680 nRefs = Hash_IntObjData2(vHash, i);
684 if ( Hash_IntObjData0(vHash, i) > Hash_IntObjData1(vHash, i) )
686 Num = Hash_Int2ManInsert(
p->vHash, Hash_IntObjData0(vHash, i), Hash_IntObjData1(vHash, i), 0 );
687 assert( Num == Hash_IntManEntryNum(
p->vHash) );
688 assert( Num == Vec_FltSize(
p->vCounts) );
689 Vec_FltPush(
p->vCounts, nRefs + 0.005*
Dam_ManDivSlack(
p, Hash_IntObjData0(vHash, i), Hash_IntObjData1(vHash, i), Vec_IntEntry(vLevRMax, i)) );
690 Vec_QuePush(
p->vQue, Num );
692 assert( Num == Vec_IntSize(
p->vDiv2Nod) );
693 Vec_IntPush(
p->vDiv2Nod, Vec_IntSize(
p->vNodStore) );
694 Vec_IntPush(
p->vNodStore, 0 );
695 Vec_IntFillExtra(
p->vNodStore, Vec_IntSize(
p->vNodStore) + nRefs, -1 );
697 Vec_IntWriteEntry( vRemap, i, Num );
699 assert( Vec_FltSize(
p->vCounts) == Hash_IntManEntryNum(
p->vHash)+1 );
700 assert( Vec_IntSize(
p->vDiv2Nod) == nDivsUsed+1 );
701 Hash_IntManStop( vHash );
702 Vec_IntFree( vLevRMax );
712 Num = Vec_IntEntry( vRemap, iDiv );
715 pSet = Dam_DivSet(
p, Num );
716 pSet[++pSet[0]] = iNode;
718 Vec_IntFree( vRemap );
719 Vec_IntFree( vDivs );
721 p->vDivLevR = Vec_IntStart( 2 * nDivsUsed );
729 printf(
" Total =%9d (%6.2f %%)", nPairsAll, 100.0 * nPairsAll / Abc_MaxInt(nPairsAll, 1) );
730 printf(
" Tried =%9d (%6.2f %%)", nPairsTried, 100.0 * nPairsTried / Abc_MaxInt(nPairsAll, 1) );
731 printf(
" Used =%9d (%6.2f %%)", nPairsUsed, 100.0 * nPairsUsed / Abc_MaxInt(nPairsAll, 1) );
732 printf(
" Xor =%9d (%6.2f %%)", nPairsXor, 100.0 * nPairsXor / Abc_MaxInt(nPairsAll, 1) );
735 printf(
" Total =%9d (%6.2f %%)", nDivsAll, 100.0 * nDivsAll / Abc_MaxInt(nDivsAll, 1) );
736 printf(
" Tried =%9d (%6.2f %%)", nDivsAll, 100.0 * nDivsAll / Abc_MaxInt(nDivsAll, 1) );
737 printf(
" Used =%9d (%6.2f %%)", nDivsUsed, 100.0 * nDivsUsed / Abc_MaxInt(nDivsAll, 1) );
738 printf(
" Xor =%9d (%6.2f %%)", nDivsXor, 100.0 * nDivsXor / Abc_MaxInt(nDivsAll, 1) );
758 assert( Gia_ObjIsAnd(pObj) );
759 pSet = Dam_ObjSet(pMan, Gia_ObjId(
p, pObj));
764 if ( Gia_ObjIsMux(
p, pObj) )
767 pObj->
Value =
Gia_ManHashMuxReal( pNew, Gia_ObjFanin2Copy(
p, pObj), Gia_ObjFanin1Copy(pObj), Gia_ObjFanin0Copy(pObj) );
769 else if ( Gia_ObjIsXor(pObj) )
773 Gia_ObjSetGateLevel( pNew, Gia_ManObj(pNew, Abc_Lit2Var(pObj->
Value)) );
776 assert( Gia_ObjIsXor(pObj) || Gia_ObjIsAndReal(
p, pObj) );
778 for ( i = 1; i <= pSet[0]; i++ )
780 Gia_Obj_t * pTemp = Gia_ManObj(
p, Abc_Lit2Var(pSet[i]) );
782 pSet[i] = Abc_LitNotCond( pTemp->
Value, Abc_LitIsCompl(pSet[i]) );
795 pNew->
pName = Abc_UtilStrsav(
p->pName );
796 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
801 Gia_ManConst0(
p)->Value = 0;
804 pObj->
Value = Gia_ManAppendCi( pNew );
805 Vec_IntWriteEntry( pNew->
vLevels, Abc_Lit2Var(pObj->
Value), Gia_ObjLevel(
p, pObj) );
812 pObj->
Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
813 Gia_ObjSetGateLevel( pNew, Gia_ManObj(pNew, Abc_Lit2Var(pObj->
Value)) );
818 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
843 printf(
"Final statistics after extracting %6d divisors: ",
p->nDivs );
847 int iData0 = Hash_IntObjData0(
p->vHash, iDiv);
848 int iData1 = Hash_IntObjData1(
p->vHash, iDiv);
849 printf(
"Div%5d : ",
p->nDivs+1 );
850 printf(
"D%-8d = ", iDiv );
851 sprintf( Buffer,
"%c%d", Abc_LitIsCompl(iData0)?
'!':
' ', Abc_Lit2Var(iData0) );
852 printf(
"%8s ", Buffer );
853 printf(
"%c ", (iData0 < iData1) ?
'*' :
'+' );
854 sprintf( Buffer,
"%c%d", Abc_LitIsCompl(iData1)?
'!':
' ', Abc_Lit2Var(iData1) );
855 printf(
"%8s ", Buffer );
856 printf(
"Weight %9.2f ", Vec_FltEntry(
p->vCounts, iDiv) );
858 printf(
"Divs =%8d ", Hash_IntManEntryNum(
p->vHash) );
859 printf(
"Ands =%8d ",
p->nAnds -
p->nGain );
860 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
865 printf(
"Divisor queue: \n" );
866 for ( i = 1; i <= Hash_IntManEntryNum(
p->vHash); i++ )
868 int iLit0 = Hash_IntObjData0(
p->vHash, i);
869 int iLit1 = Hash_IntObjData1(
p->vHash, i);
870 printf(
"Div %7d : ", i );
871 printf(
"Weight %9.2f ", Vec_FltEntry(
p->vCounts, i) );
872 printf(
"F = %c%c ", Abc_LitIsCompl(iLit0) ?
'!':
' ',
'a' + Abc_Lit2Var(iLit0)-1 );
873 printf(
"%c ", (Hash_IntObjData0(
p->vHash, i) < Hash_IntObjData1(
p->vHash, i)) ?
'*':
'+' );
874 printf(
"%c%c ", Abc_LitIsCompl(iLit1) ?
'!':
' ',
'a' + Abc_Lit2Var(iLit1)-1 );
880 int * pSet = Dam_ObjSet(
p, iObj );
881 int i, k, c, Num, iLit, iLit2, fPres;
883 for ( i = 1; i <= pSet[0]; i++ )
884 if ( pSet[i] == iLit0 )
889 for ( i = 1; i <= pSet[0]; i++ )
890 if ( pSet[i] == iLit1 )
895 Vec_IntPush( vDivs, -iObj );
896 for ( k = i = 1; i <= pSet[0]; i++ )
898 if ( iLit0 == pSet[i] || iLit1 == pSet[i] )
900 pSet[k++] = iLit = pSet[i];
903 for ( c = 0; c < 2; c++ )
905 iLit2 = c ? iLit1 : iLit0;
906 if ( (iLit > iLit2) ^ (iLit0 > iLit1) )
907 Num = *Hash_Int2ManLookup(
p->vHash, iLit2, iLit );
909 Num = *Hash_Int2ManLookup(
p->vHash, iLit, iLit2 );
912 Vec_FltAddToEntry(
p->vCounts, Num, -1 );
913 if ( Vec_QueIsMember(
p->vQue, Num) )
915 Vec_QueUpdate(
p->vQue, Num );
922 if ( (iLit > iLitNew) ^ (iLit0 > iLit1) )
923 Num = Hash_Int2ManInsert(
p->vHash, iLitNew, iLit, 0 );
925 Num = Hash_Int2ManInsert(
p->vHash, iLit, iLitNew, 0 );
926 Hash_Int2ObjInc(
p->vHash, Num );
927 Vec_IntPush( vDivs, Num );
929 if ( Num >= Vec_IntSize(
p->vDivLevR) )
930 Vec_IntFillExtra(
p->vDivLevR, 3 * Vec_IntSize(
p->vDivLevR) / 2, 0 );
931 Vec_IntUpdateEntry(
p->vDivLevR, Num, Vec_IntEntry(
p->vNodLevR, iObj) );
940 int iLit0 = Hash_IntObjData0(
p->vHash, iDiv);
941 int iLit1 = Hash_IntObjData1(
p->vHash, iDiv);
942 int i, iLitNew, * pSet, * pNods = Dam_DivSet(
p, iDiv );
943 int nPresent = 0, nPairsStart, nPairsStop, pPairsNew, nRefs;
944 int fThisIsXor = (iLit0 > iLit1), iDivTemp, iNode;
947 iLitNew = Gia_ManAppendXorReal(
p->pGia, iLit0, iLit1 );
949 iLitNew = Gia_ManAppendAnd(
p->pGia, iLit0, iLit1 );
950 Gia_ObjSetGateLevel(
p->pGia, Gia_ManObj(
p->pGia, Abc_Lit2Var(iLitNew)) );
954 nPairsStart = Hash_IntManEntryNum(
p->vHash) + 1;
955 Vec_IntClear( vDivs );
956 for ( i = 1; i <= pNods[0]; i++ )
958 nPairsStop = Hash_IntManEntryNum(
p->vHash) + 1;
961 Vec_FltFillExtra(
p->vCounts, nPairsStop, 0 );
962 Vec_IntFillExtra(
p->vDiv2Nod, nPairsStop, -1 );
963 for ( i = nPairsStart; i < nPairsStop; i++ )
965 nRefs = Hash_IntObjData2(
p->vHash, i);
968 Vec_FltWriteEntry(
p->vCounts, i, nRefs + 0.001*
Dam_ManDivSlack(
p, Hash_IntObjData0(
p->vHash, i), Hash_IntObjData1(
p->vHash, i), Vec_IntEntry(
p->vDivLevR, i)) );
969 Vec_QuePush(
p->vQue, i );
971 Vec_IntWriteEntry(
p->vDiv2Nod, i, Vec_IntSize(
p->vNodStore) );
972 Vec_IntPush(
p->vNodStore, 0 );
973 Vec_IntFillExtra(
p->vNodStore, Vec_IntSize(
p->vNodStore) + nRefs, -1 );
986 if ( Vec_IntEntry(
p->vDiv2Nod, iDivTemp) == -1 )
988 pSet = Dam_DivSet(
p, iDivTemp );
989 pSet[++pSet[0]] = iNode;
992 for ( i = nPairsStart; i < nPairsStop; i++ )
993 if ( Vec_IntEntry(
p->vDiv2Nod, i) > 0 )
994 assert( Dam_DivSet(
p, i)[0] == Hash_IntObjData2(
p->vHash, i) );
996 Vec_FltWriteEntry(
p->vCounts, iDiv, 0 );
997 p->nGain += (1 + 2 * fThisIsXor) * (nPresent - 1);
998 p->nGainX += 3 * fThisIsXor * (nPresent - 1);
1021 Vec_IntFillExtra(
p->pGia->vLevels, 3*Gia_ManObjNum(
p->pGia)/2, 0 );
1023 for ( i = 0; i < nNewNodesMax && Vec_QueTopPriority(
p->vQue) >= 2; i++ )
1025 iDiv = Vec_QuePop(
p->vQue);
1035 int nDivsAll = Hash_IntManEntryNum(
p->vHash);
1036 int nDivsUsed =
p->nDivs;
1038 printf(
" Total =%9d (%6.2f %%) ", nDivsAll, 100.0 * nDivsAll / Abc_MaxInt(nDivsAll, 1) );
1039 printf(
" Used =%9d (%6.2f %%)", nDivsUsed, 100.0 * nDivsUsed / Abc_MaxInt(nDivsAll, 1) );
1040 printf(
" Gain =%6d (%6.2f %%)",
p->nGain, 100.0 *
p->nGain / Abc_MaxInt(
p->nAnds, 1) );
1041 printf(
" GainX = %d ",
p->nGainX );
1042 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
1049 Gia_Man_t * pNew0, * pNew, * pNew1, * pNew2;
1054 int i, Id, And2Delay =
p->And2Delay ?
p->And2Delay : 1;
1055 Vec_IntFreeP( &
p->vLevels );
1056 p->vLevels = Vec_IntStart( Gia_ManObjNum(
p) );
1058 Vec_IntWriteEntry(
p->vLevels, Id, Vec_IntEntry(
p->vCiArrs, i)/And2Delay );
1060 else if (
p->vInArrs )
1062 int i, Id, And2Delay =
p->And2Delay ?
p->And2Delay : 1;
1064 Vec_IntWriteEntry(
p->vLevels, Id, (
int)(Vec_FltEntry(
p->vInArrs, i)/And2Delay) );
1067 if (
p->pManTime &&
p->vLevels == NULL )
1084 Vec_IntFreeP( &vCiLevels );
#define ABC_SWAP(Type, a, b)
void Abc_QuickSortCostData(int *pCosts, int nSize, int fDecrease, word *pData, int *pResult)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void * Dsm_ManDeriveGia(void *p, int fUseMuxes)
void Dam_PrintDiv(Dam_Man_t *p, int iDiv)
void Dam_ManCreateMultiRefs(Dam_Man_t *p, Vec_Int_t **pvRefsAnd, Vec_Int_t **pvRefsXor)
typedefABC_NAMESPACE_IMPL_START struct Dam_Man_t_ Dam_Man_t
DECLARATIONS ///.
void Dam_ManFree(Dam_Man_t *p)
void Dam_ManUpdate(Dam_Man_t *p, int iDiv)
void Gia_ManSuperCollectAnd_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int fStrict)
void Gia_ManSimplifyAnd(Vec_Int_t *vSuper)
int Dam_ManDivSlack(Dam_Man_t *p, int iLit0, int iLit1, int LevR)
void Dam_ManCollectSets_rec(Dam_Man_t *p, int Id)
Gia_Man_t * Gia_ManAreaBalance(Gia_Man_t *p, int fSimpleAnd, int nNewNodesMax, int fVerbose, int fVeryVerbose)
void Gia_ManCreateGate(Gia_Man_t *pNew, Gia_Obj_t *pObj, Vec_Int_t *vSuper)
void Dam_PrintQue(Dam_Man_t *p)
void Gia_ManPrepareLastTwo(Gia_Man_t *pNew, Vec_Int_t *vSuper)
Gia_Man_t * Gia_ManBalanceInt(Gia_Man_t *p, int fStrict)
void Gia_ManBalance_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj, int fStrict)
int Dam_ManUpdateNode(Dam_Man_t *p, int iObj, int iLit0, int iLit1, int iLitNew, Vec_Int_t *vDivs)
void Gia_ManSuperCollectXor_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int fStrict)
void Gia_ManSuperCollect(Gia_Man_t *p, Gia_Obj_t *pObj, int fStrict)
void Dam_ManMultiAig_rec(Dam_Man_t *pMan, Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
Gia_Man_t * Dam_ManMultiAig(Dam_Man_t *pMan)
void Gia_ManSimplifyXor(Vec_Int_t *vSuper)
FUNCTION DEFINITIONS ///.
int Gia_ManFindSharedNode(Gia_Man_t *pNew, Vec_Int_t *vSuper, int iLit0)
void Dam_ManCollectSets(Dam_Man_t *p)
int Gia_ManBalanceGate(Gia_Man_t *pNew, Gia_Obj_t *pObj, Vec_Int_t *vSuper, int *pLits, int nLits)
Gia_Man_t * Gia_ManBalance(Gia_Man_t *p, int fSimpleAnd, int fStrict, int fVerbose)
Gia_Man_t * Dam_ManAreaBalanceInt(Gia_Man_t *pGia, Vec_Int_t *vCiLevels, int nNewNodesMax, int fVerbose, int fVeryVerbose)
Dam_Man_t * Dam_ManAlloc(Gia_Man_t *pGia)
void Dam_ManCreatePairs(Dam_Man_t *p, int fVerbose)
void Gia_ManStop(Gia_Man_t *p)
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
void Gia_ManHashStart(Gia_Man_t *p)
#define Gia_ManForEachBuf(p, pObj, i)
int Gia_ManIsNormalized(Gia_Man_t *p)
#define Gia_ManForEachAnd(p, pObj, i)
int Gia_ManHashMuxReal(Gia_Man_t *p, int iLitC, int iLit1, int iLit0)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Vec_Int_t * Gia_ManGetCiLevels(Gia_Man_t *p)
int Gia_ManLevelWithBoxes(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
Gia_Man_t * Gia_ManDupNoMuxes(Gia_Man_t *p, int fSkipBufs)
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
void Gia_ManTransferTiming(Gia_Man_t *p, Gia_Man_t *pGia)
int Gia_ManSetLevels(Gia_Man_t *p, Vec_Int_t *vCiLevels)
void Gia_ManCreateRefs(Gia_Man_t *p)
Gia_Man_t * Gia_ManDupNormalize(Gia_Man_t *p, int fHashMapping)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Vec_Int_t * Gia_ManReverseLevel(Gia_Man_t *p)
int Gia_ManHashXorReal(Gia_Man_t *p, int iLit0, int iLit1)
int Gia_ManHashLookupInt(Gia_Man_t *p, int iLit0, int iLit1)
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
void Gia_ManHashStop(Gia_Man_t *p)
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
#define Gia_ManForEachCiId(p, Id, i)
unsigned __int64 word
DECLARATIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
struct Hash_IntMan_t_ Hash_IntMan_t
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStartStop(vVec, Entry, i, Start, Stop)
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Que_t_ Vec_Que_t
INCLUDES ///.