32#define Dtc_ForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += pCut[0] + 1 )
33#define Dtc_ForEachFadd( vFadds, i ) for ( i = 0; i < Vec_IntSize(vFadds)/5; i++ )
52 Vec_Int_t * vHadds = Vec_IntAlloc( 1000 );
54 int i, iLit, iFan0, iFan1, fComplDiff, Count, Counts[5] = {0};
60 if ( !Gia_ObjIsXor(pObj) )
63 iFan0 = Gia_ObjFaninId0(pObj, i);
64 iFan1 = Gia_ObjFaninId1(pObj, i);
66 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
68 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
70 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
72 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
85 if ( Gia_ObjRefNumId(
p, Gia_ObjFaninId0(pObj, i)) > 1 )
86 Vec_IntPushTwo( vHadds, i, Gia_ObjFaninId0(pObj, i) ), Count++;
87 if ( Gia_ObjRefNumId(
p, Gia_ObjFaninId1(pObj, i)) > 1 )
88 Vec_IntPushTwo( vHadds, i, Gia_ObjFaninId1(pObj, i) ), Count++;
89 iFan0 = Gia_ObjId(
p, pFan0 );
90 iFan1 = Gia_ObjId(
p, pFan1 );
91 fComplDiff = (Gia_ObjFaninC0(Gia_ObjFanin0(pObj)) ^ Gia_ObjFaninC1(Gia_ObjFanin0(pObj)));
92 assert( fComplDiff == (Gia_ObjFaninC0(Gia_ObjFanin1(pObj)) ^ Gia_ObjFaninC1(Gia_ObjFanin1(pObj))) );
96 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
98 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
103 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
105 Vec_IntPushTwo( vHadds, i, Abc_Lit2Var(iLit) ), Count++;
115 printf(
"Found %d half-adders with XOR gates: ", Vec_IntSize(vHadds)/2 );
116 for ( i = 0; i <= 4; i++ )
117 printf(
"%d=%d ", i, Counts[i] );
122 pObj = Gia_ManObj(
p, iXor );
123 printf(
"%3d : %5d %5d -> %5d %5d\n", i, Gia_ObjFaninId0(pObj, iXor), Gia_ObjFaninId1(pObj, iXor), iXor, iAnd );
144 int i, k, curCi, curCo, nBoxIns, nBoxOuts;
149 for ( i = 0; i < nBoxes; i++ )
153 printf(
"Box %4d [%d x %d] : ", i, nBoxIns, nBoxOuts );
154 printf(
"Input obj IDs = " );
155 for ( k = 0; k < nBoxIns; k++ )
157 pObj = Gia_ManCo(
p, curCo + k );
158 printf(
"%d ", Gia_ObjId(
p, pObj) );
160 printf(
" Output obj IDs = " );
161 for ( k = 0; k < nBoxOuts; k++ )
163 pObj = Gia_ManCi(
p, curCi + k );
164 printf(
"%d ", Gia_ObjId(
p, pObj) );
172 assert( curCi == Gia_ManCiNum(
p) );
173 assert( curCo == Gia_ManCoNum(
p) );
190 for ( k = 0; k <= pCut1[0]; k++ )
192 for ( i = 1; i <= pCut0[0]; i++ )
194 for ( k = 1; k <= pCut1[0]; k++ )
195 if ( pCut0[i] == pCut1[k] )
201 pCut[1+pCut[0]++] = pCut0[i];
203 assert( pCut[0] == 2 || pCut[0] == 3 );
204 if ( pCut[1] > pCut[2] )
206 assert( pCut[1] < pCut[2] );
209 if ( pCut[2] > pCut[3] )
211 if ( pCut[1] > pCut[2] )
213 assert( pCut[1] < pCut[2] );
214 assert( pCut[2] < pCut[3] );
219 int * pList = Vec_IntArray( vCuts );
223 for ( k = 0; k <= pCut[0]; k++ )
224 if ( pCut[k] != pCutNew[k] )
236 assert( Gia_ObjIsAnd(pObj) );
239 if ( Gia_ObjIsXor(pObj) )
240 return (pObj->
Value = (Gia_ObjFaninC0(pObj) ? ~Truth0 : Truth0) ^ (Gia_ObjFaninC1(pObj) ? ~Truth1 : Truth1));
242 return (pObj->
Value = (Gia_ObjFaninC0(pObj) ? ~Truth0 : Truth0) & (Gia_ObjFaninC1(pObj) ? ~Truth1 : Truth1));
249 if ( !Gia_ObjIsAnd(pObj) )
256 unsigned Truth, Truths[3] = { 0xAA, 0xCC, 0xF0 };
int i;
257 for ( i = 1; i <= pCut[0]; i++ )
258 Gia_ManObj(
p, pCut[i])->Value = Truths[i-1];
263 if ( Truth == 0x66 || Truth == 0x99 )
265 if ( Truth == 0x96 || Truth == 0x69 )
267 if ( Truth == 0xE8 || Truth == 0xD4 || Truth == 0xB2 || Truth == 0x71 ||
268 Truth == 0x17 || Truth == 0x2B || Truth == 0x4D || Truth == 0x8E )
276 int i, k, c, Type, * pCut0, * pCut1, pCut[4];
278 printf(
"Object %d = :\n", iObj );
279 Vec_IntFill( vCuts, 2, 1 );
280 Vec_IntPush( vCuts, iObj );
288 Vec_IntAddToEntry( vCuts, 0, 1 );
290 printf(
"%d : ", pCut[0] );
291 for ( c = 0; c <= pCut[0]; c++ )
293 Vec_IntPush( vCuts, pCut[c] );
295 printf(
"%d ", pCut[c] );
302 assert( Value == 3 || Value == 0 );
305 Vec_IntPush( vCutsXor2, pCut[1] );
306 Vec_IntPush( vCutsXor2, pCut[2] );
307 Vec_IntPush( vCutsXor2, iObj );
316 vTemp = Type == 1 ? vCutsXor : vCutsMaj;
317 if ( 0 && Type == 2 )
321 printf(
"%d = %s(", iObj, Type == 1 ?
"XOR" :
"MAJ" );
322 for ( c = 1; c <= pCut[0]; c++ )
325 printf(
" %d", pCut[c] );
326 Vec_IntPush( vTemp, pCut[c] );
332 Vec_IntPush( vTemp, iObj );
338 int * pList0, * pList1, i, nCuts = 0;
339 Vec_Int_t * vTemp = Vec_IntAlloc( 1000 );
340 Vec_Int_t * vCutsXor2 = Vec_IntAlloc( Gia_ManAndNum(
p) );
341 Vec_Int_t * vCutsXor = Vec_IntAlloc( Gia_ManAndNum(
p) );
342 Vec_Int_t * vCutsMaj = Vec_IntAlloc( Gia_ManAndNum(
p) );
343 Vec_Int_t * vCuts = Vec_IntAlloc( 30 * Gia_ManAndNum(
p) );
344 Vec_IntFill( vCuts, Gia_ManObjNum(
p), 0 );
348 Vec_IntWriteEntry( vCuts, Gia_ObjId(
p, pObj), Vec_IntSize(vCuts) );
349 Vec_IntPush( vCuts, 1 );
350 Vec_IntPush( vCuts, 1 );
351 Vec_IntPush( vCuts, Gia_ObjId(
p, pObj) );
355 pList0 = Vec_IntEntryP( vCuts, Vec_IntEntry(vCuts, Gia_ObjFaninId0(pObj, i)) );
356 pList1 = Vec_IntEntryP( vCuts, Vec_IntEntry(vCuts, Gia_ObjFaninId1(pObj, i)) );
357 Dtc_ManCutMerge(
p, i, pList0, pList1, vTemp, vCutsXor2, vCutsXor, vCutsMaj );
358 Vec_IntWriteEntry( vCuts, i, Vec_IntSize(vCuts) );
359 Vec_IntAppend( vCuts, vTemp );
360 nCuts += Vec_IntEntry( vTemp, 0 );
363 printf(
"Nodes = %d. Cuts = %d. Cuts/Node = %.2f. Ints/Node = %.2f.\n",
364 Gia_ManAndNum(
p), nCuts, 1.0*nCuts/Gia_ManAndNum(
p), 1.0*Vec_IntSize(vCuts)/Gia_ManAndNum(
p) );
365 Vec_IntFree( vTemp );
366 Vec_IntFree( vCuts );
368 *pvCutsXor2 = vCutsXor2;
370 Vec_IntFree( vCutsXor2 );
371 *pvCutsXor = vCutsXor;
372 *pvCutsMaj = vCutsMaj;
376 int * pCuts0 = Vec_IntArray(vCutsXor);
377 int * pCuts1 = Vec_IntArray(vCutsMaj);
378 int * pLimit0 = Vec_IntLimit(vCutsXor);
379 int * pLimit1 = Vec_IntLimit(vCutsMaj);
int i;
380 Vec_Int_t * vFadds = Vec_IntAlloc( 1000 );
381 assert( Vec_IntSize(vCutsXor) % 4 == 0 );
382 assert( Vec_IntSize(vCutsMaj) % 4 == 0 );
383 while ( pCuts0 < pLimit0 && pCuts1 < pLimit1 )
385 for ( i = 0; i < 3; i++ )
386 if ( pCuts0[i] != pCuts1[i] )
390 for ( i = 0; i < 4; i++ )
391 Vec_IntPush( vFadds, pCuts0[i] );
392 Vec_IntPush( vFadds, pCuts1[3] );
396 else if ( pCuts0[i] < pCuts1[i] )
398 else if ( pCuts0[i] > pCuts1[i] )
401 assert( Vec_IntSize(vFadds) % 5 == 0 );
409 printf(
"%6d : ", i );
410 printf(
"%6d ", Vec_IntEntry(vFadds, 5*i+0) );
411 printf(
"%6d ", Vec_IntEntry(vFadds, 5*i+1) );
412 printf(
"%6d ", Vec_IntEntry(vFadds, 5*i+2) );
414 printf(
"%6d ", Vec_IntEntry(vFadds, 5*i+3) );
415 printf(
"%6d ", Vec_IntEntry(vFadds, 5*i+4) );
420 printf(
"Skipping other FADDs.\n" );
427 if ( pCut0[0] < pCut1[0] )
return -1;
428 if ( pCut0[0] > pCut1[0] )
return 1;
429 if ( pCut0[1] < pCut1[1] )
return -1;
430 if ( pCut0[1] > pCut1[1] )
return 1;
431 if ( pCut0[2] < pCut1[2] )
return -1;
432 if ( pCut0[2] > pCut1[2] )
return 1;
437 if ( pCut0[4] < pCut1[4] )
return -1;
438 if ( pCut0[4] > pCut1[4] )
return 1;
444 Vec_Int_t * vCutsXor, * vCutsMaj, * vFadds;
446 qsort( Vec_IntArray(vCutsXor), (
size_t)(Vec_IntSize(vCutsXor)/4), 16, (
int (*)(
const void *,
const void *))
Dtc_ManCompare );
447 qsort( Vec_IntArray(vCutsMaj), (
size_t)(Vec_IntSize(vCutsMaj)/4), 16, (
int (*)(
const void *,
const void *))
Dtc_ManCompare );
449 qsort( Vec_IntArray(vFadds), (
size_t)(Vec_IntSize(vFadds)/5), 20, (
int (*)(
const void *,
const void *))
Dtc_ManCompare2 );
451 printf(
"XOR3 cuts = %d. MAJ cuts = %d. Full-adders = %d.\n", Vec_IntSize(vCutsXor)/4, Vec_IntSize(vCutsMaj)/4, Vec_IntSize(vFadds)/5 );
454 Vec_IntFree( vCutsXor );
455 Vec_IntFree( vCutsMaj );
460 Vec_Int_t * vCutsXor2, * vCutsXor, * vCutsMaj;
463 printf(
"XOR3 cuts = %d. MAJ cuts = %d.\n", Vec_IntSize(vCutsXor)/4, Vec_IntSize(vCutsMaj)/4 );
464 Vec_IntFree( vCutsXor2 );
465 Vec_IntFree( vCutsXor );
466 Vec_IntFree( vCutsMaj );
483 Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(
p) );
int i;
485 Vec_IntWriteEntry( vMap, Vec_IntEntry(vFadds, 5*i+4), i );
491 assert( Vec_IntEntry(vMap, iMaj) >= 0 );
492 if ( Vec_IntEntry(vLength, iMaj) >= 0 )
493 return Vec_IntEntry(vLength, iMaj);
494 assert( Gia_ObjIsAnd(Gia_ManObj(
p, iMaj)) );
496 int iFadd = Vec_IntEntry( vMap, iMaj );
497 int iXor0 = Vec_IntEntry( vFadds, 5*iFadd+0 );
498 int iXor1 = Vec_IntEntry( vFadds, 5*iFadd+1 );
499 int iXor2 = Vec_IntEntry( vFadds, 5*iFadd+2 );
500 int iLen0 = Vec_IntEntry( vMap, iXor0 ) == -1 ? 0 :
Gia_ManFindChains_rec(
p, iXor0, vFadds, vMap, vLength );
501 int iLen1 = Vec_IntEntry( vMap, iXor1 ) == -1 ? 0 :
Gia_ManFindChains_rec(
p, iXor1, vFadds, vMap, vLength );
502 int iLen2 = Vec_IntEntry( vMap, iXor2 ) == -1 ? 0 :
Gia_ManFindChains_rec(
p, iXor2, vFadds, vMap, vLength );
503 int iLen = Abc_MaxInt( iLen0, Abc_MaxInt(iLen1, iLen2) );
508 ABC_SWAP(
int, Vec_IntArray(vFadds)[5*iFadd+0], Vec_IntArray(vFadds)[5*iFadd+1] );
510 else if ( iLen == iLen2 )
512 ABC_SWAP(
int, Vec_IntArray(vFadds)[5*iFadd+0], Vec_IntArray(vFadds)[5*iFadd+2] );
515 Vec_IntWriteEntry( vLength, iMaj, iLen + 1 );
524 Vec_Int_t * vLength = Vec_IntStartFull( Gia_ManObjNum(
p) );
527 Vec_IntFree( vLength );
533 Vec_IntClear( vChain );
534 for ( iFadd = iFaddTop; iFadd >= 0 &&
535 !Gia_ObjIsTravIdCurrentId(
p, Vec_IntEntry(vFadds, 5*iFadd+3)) &&
536 !Gia_ObjIsTravIdCurrentId(
p, Vec_IntEntry(vFadds, 5*iFadd+4));
537 iFadd = Vec_IntEntry(vMap, Vec_IntEntry(vFadds, 5*iFadd+0)) )
539 Vec_IntPush( vChain, iFadd );
541 Vec_IntReverseOrder( vChain );
546 if ( Gia_ObjIsTravIdCurrentId(
p, Id) )
548 Gia_ObjSetTravIdCurrentId(
p, Id);
549 pObj = Gia_ManObj(
p, Id );
550 if ( Gia_ObjIsAnd(pObj) )
552 if ( Gia_ObjIsAnd(pObj) )
559 Vec_Int_t * vChain = Vec_IntAlloc( 100 );
560 Vec_Wec_t * vChains = Vec_WecAlloc( Vec_IntSize(vFadds)/5 );
562 Vec_Bit_t * vMarksTop = Vec_BitStart( Vec_IntSize(vFadds)/5 );
564 if ( (iFadd = Vec_IntEntry(vMap, Vec_IntEntry(vFadds, 5*i+0))) >= 0 )
565 Vec_BitWriteEntry( vMarksTop, iFadd, 1 );
570 if ( Vec_BitEntry(vMarksTop, i) )
573 if ( Vec_IntSize(vChain) < nFaddMin )
575 Vec_IntAppend( Vec_WecPushLevel(vChains), vChain );
578 assert( !Gia_ObjIsTravIdCurrentId(
p, Vec_IntEntry(vFadds, 5*iFadd+3)) );
579 assert( !Gia_ObjIsTravIdCurrentId(
p, Vec_IntEntry(vFadds, 5*iFadd+4)) );
585 Vec_BitFree( vMarksTop );
586 Vec_IntFree( vChain );
593 int i, k, iFadd, Count = 0;
596 Count += Vec_IntSize(vChain);
599 printf(
"Chain %4d : %4d ", i, Vec_IntSize(vChain) );
602 printf(
"%d(%d) ", iFadd, Vec_IntEntry(vFadds, 5*iFadd+4) );
603 if ( k != Vec_IntSize(vChain) - 1 )
617 printf(
"Total chains = %d. Total full-adders = %d.\n", Vec_WecSize(vChains), Count );
623 int i, k, iFadd = -1;
624 Vec_Int_t * vMap2Chain = Vec_IntStartFull( Gia_ManObjNum(
p) );
627 assert( Vec_IntSize(vChain) > 0 );
631 assert( Vec_IntEntry(vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+3)) == -1 );
632 Vec_IntWriteEntry( vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+3), i );
635 assert( Vec_IntEntry(vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+4)) == -1 );
636 Vec_IntWriteEntry( vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+4), i );
654 int i, k, Type, Truth, pCut[4] = {3};
655 Vec_Int_t * vTruths = Vec_IntAlloc( 2*Vec_IntSize(vFadds)/5 );
659 for ( k = 0; k < 3; k++ )
660 pCut[k+1] = Vec_IntEntry( vFadds, 5*i+k );
663 Vec_IntPush( vTruths, Truth );
666 Vec_IntPush( vTruths, Truth );
672 int i, Total = nIns * nOuts;
673 float * pDelayTable =
ABC_ALLOC(
float, Total + 3 );
675 pDelayTable[1] = nIns;
676 pDelayTable[2] = nOuts;
677 for ( i = 0; i < Total; i++ )
678 pDelayTable[i+3] = 1;
686 Vec_Ptr_t * vDelayTables = Vec_PtrAlloc( 1 );
688 pMan =
Tim_ManStart( nPis + nOuts * nBoxes, nPos + nIns * nBoxes );
692 for ( i = 0; i < nBoxes; i++ )
707 int i, k, pInLits[16], pOutLits[16];
708 assert( nIns < 16 && nOuts < 16 );
709 for ( i = 0; i < nIns; i++ )
710 pInLits[i] = Gia_ManAppendCi( pNew );
711 pOutLits[0] = Gia_ManAppendXor( pNew, Gia_ManAppendXor(pNew, pInLits[0], pInLits[1]), pInLits[2] );
712 pOutLits[1] = Gia_ManAppendMaj( pNew, pInLits[0], pInLits[1], pInLits[2] );
713 for ( i = 0; i < nBoxes; i++ )
714 for ( k = 0; k < nOuts; k++ )
715 Gia_ManAppendCo( pNew, pOutLits[k] );
721 int i, k, iFadd = -1, iCiLit, pLits[3];
725 for ( k = 0; k < 3; k++ )
727 if ( i && !k )
continue;
728 pObj = Gia_ManObj(
p, Vec_IntEntry(vFadds, 5*iFadd+k) );
735 int iXorTruth = Vec_IntEntry( vTruths, 2*iFadd+0 );
736 int iMajTruth = Vec_IntEntry( vTruths, 2*iFadd+1 );
737 for ( k = 0; k < 3; k++ )
739 pObj = Gia_ManObj(
p, Vec_IntEntry(vFadds, 5*iFadd+k) );
740 pLits[k] = (!k && iCiLit) ? iCiLit : pObj->
Value;
746 if ( iMajTruth == 0x4D )
747 pLits[0] = Abc_LitNot(pLits[0]), iMajTruth = 0x8E, iXorTruth = 0xFF & ~iXorTruth;
748 else if ( iMajTruth == 0xD4 )
749 pLits[0] = Abc_LitNot(pLits[0]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
750 else if ( iMajTruth == 0x2B )
751 pLits[1] = Abc_LitNot(pLits[1]), iMajTruth = 0x8E, iXorTruth = 0xFF & ~iXorTruth;
752 else if ( iMajTruth == 0xB2 )
753 pLits[1] = Abc_LitNot(pLits[1]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
754 if ( iMajTruth == 0x8E )
755 pLits[2] = Abc_LitNot(pLits[2]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
756 else if ( iMajTruth == 0x71 )
757 pLits[2] = Abc_LitNot(pLits[2]), iMajTruth = 0x17, iXorTruth = 0xFF & ~iXorTruth;
758 else assert( iMajTruth == 0xE8 || iMajTruth == 0x17 );
760 if ( Abc_LitIsCompl(pLits[0]) )
762 for ( k = 0; k < 3; k++ )
763 pLits[k] = Abc_LitNot(pLits[k]);
764 iXorTruth = 0xFF & ~iXorTruth;
765 iMajTruth = 0xFF & ~iMajTruth;
768 assert( !Abc_LitIsCompl(pLits[0]) );
769 for ( k = 0; k < 3; k++ )
770 Gia_ManAppendCo( pNew, pLits[k] );
772 assert( iXorTruth == 0x96 || iXorTruth == 0x69 );
773 pObj = Gia_ManObj(
p, Vec_IntEntry(vFadds, 5*iFadd+3) );
774 pObj->
Value = Abc_LitNotCond( Gia_ManAppendCi(pNew), (
int)(iXorTruth == 0x69) );
776 assert( iMajTruth == 0xE8 || iMajTruth == 0x17 );
777 iCiLit = Abc_LitNotCond( Gia_ManAppendCi(pNew), (
int)(iMajTruth == 0x17) );
780 assert( iFadd == Vec_IntEntryLast(vChain) );
781 pObj = Gia_ManObj(
p, Vec_IntEntry(vFadds, 5*iFadd+4) );
782 pObj->
Value = iCiLit;
789 assert( Gia_ObjIsAnd(pObj) );
790 iChain = Vec_IntEntry( vMap2Chain, Gia_ObjId(
p, pObj) );
802 pObj->
Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
808 Vec_Int_t * vFadds, * vMap, * vMap2Chain, * vTruths, * vChain;
814 printf(
"Currently natural carry-chains cannot be detected when boxes are present.\n" );
821 assert( Vec_IntSize(vFadds) % 5 == 0 );
830 if ( Vec_WecSize(vChains) == 0 )
832 Vec_IntFree( vFadds );
834 Vec_WecFree( vChains );
842 Abc_PrintTime( 1,
"Carry-chain detection time", Abc_Clock() - clk );
848 pNew->
pName = Abc_UtilStrsav(
p->pName );
849 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
850 Gia_ManConst0(
p)->Value = 0;
852 pObj->
Value = Gia_ManAppendCi( pNew );
854 Gia_ManDupFadd( pNew,
p, vChain, vFadds, vMap, vChains, vMap2Chain, vTruths );
858 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
860 if ( Gia_ManRegNum(
p) )
863 printf(
"Warning: Sequential design is converted into combinational one by adding white boxes.\n" );
869 Vec_IntFree( vFadds );
871 Vec_WecFree( vChains );
872 Vec_IntFree( vMap2Chain );
873 Vec_IntFree( vTruths );
876 nBoxes = (Gia_ManCiNum(pNew) - Gia_ManCiNum(
p)) / 2;
877 assert( nBoxes == (Gia_ManCoNum(pNew) - Gia_ManCoNum(
p)) / 3 );
892 Abc_PrintTime( 1,
"AIG with boxes construction time", Abc_Clock() - clk );
911 if ( vCarries == NULL || Vec_IntEntry(vCarries, Gia_ObjFaninId0(pObj, Id)) == -1 )
912 return Gia_ObjFanin0Copy(pObj);
913 return Abc_LitNotCond( Vec_IntEntry(vCarries, Gia_ObjFaninId0(pObj, Id)), Gia_ObjFaninC0(pObj) );
917 if ( vCarries == NULL || Vec_IntEntry(vCarries, Gia_ObjFaninId1(pObj, Id)) == -1 )
918 return Gia_ObjFanin1Copy(pObj);
919 return Abc_LitNotCond( Vec_IntEntry(vCarries, Gia_ObjFaninId1(pObj, Id)), Gia_ObjFaninC1(pObj) );
926 int i, nRealPis, nRealPos;
939 assert( Gia_ObjFanin0(pObj)->fPhase == 0 );
940 Gia_ObjFanin0(pObj)->fPhase = 1;
944 assert( Gia_ObjFanin1(pObj)->fPhase == 0 );
945 Gia_ObjFanin1(pObj)->fPhase = 1;
950 vCarries = Vec_IntStartFull( Gia_ManObjNum(
p) );
957 Gia_ObjRefFanin0Dec(
p, pObj );
959 Gia_ObjRefFanin1Dec(
p, pObj );
964 pNew->
pName = Abc_UtilStrsav(
p->pName );
965 pNew->
pSpec = Abc_UtilStrsav(
p->pSpec );
966 Gia_ManConst0(
p)->Value = 0;
969 if ( Gia_ObjIsCi(pObj) )
970 pObj->
Value = Gia_ManAppendCi( pNew );
971 else if ( Gia_ObjIsCo(pObj) )
972 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
974 pObj->
Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
977 int iCiLit, iOtherLit, iLit0, iLit1, iLit2, iXorLit;
980 iOtherLit = pObj->
fMark0 ? Gia_ObjFanin1Copy(pObj) : Gia_ObjFanin0Copy(pObj);
981 assert( iCiLit >= 0 && iOtherLit >= 0 );
982 iLit0 = Abc_LitNotCond( iCiLit, Abc_LitIsCompl(iCiLit) );
983 iLit1 = Abc_LitNotCond( iOtherLit, Abc_LitIsCompl(iCiLit) );
984 iLit2 = Abc_LitNotCond( 0, Abc_LitIsCompl(iCiLit) );
986 assert( !Abc_LitIsCompl(iLit0) );
987 Gia_ManAppendCo( pNew, iLit0 );
988 Gia_ManAppendCo( pNew, iLit1 );
989 Gia_ManAppendCo( pNew, iLit2 );
991 iXorLit = Gia_ManAppendCi(pNew);
993 pObj->
Value = Abc_LitNotCond( Gia_ManAppendCi(pNew), Abc_LitIsCompl(iCiLit) );
994 if ( vCarries && pObj->
fPhase )
996 Vec_IntWriteEntry( vCarries, i, pObj->
Value );
997 if ( Gia_ObjRefNum(
p, pObj) > 0 )
1000 pObj->
Value = Gia_ManAppendAnd( pNew, Abc_LitNotCond(iXorLit, !Abc_LitIsCompl(iCiLit)), iOtherLit );
1002 pObj->
Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1009 Vec_IntFreeP( &vCarries );
1059 int * pDelays = Vec_IntArray(
p->vLevels);
1060 int i, k, iBox, iBoxOutId, Delay, Delay0, Delay1, DelayMax = 0, nBoxes = 0;
1061 Vec_IntFill(
p->vLevels, Gia_ManObjNum(
p), 0 );
1064 if ( Gia_ObjIsCi(pObj) )
1066 if ( fIgnoreBoxDelays )
1069 iBoxOutId = Gia_ObjCioId(pObj) - nRealPis;
1070 if ( iBoxOutId < 0 )
1073 iBox = iBoxOutId / 2;
1077 for ( k = 0; k < 3; k++ )
1079 int Id = Gia_ObjId(
p, Gia_ManCo(
p, iBox*3+k) );
1081 Delay = Abc_MaxInt( Delay, pDelays[Id] );
1084 if ( iBoxOutId & 1 )
1091 if ( Gia_ObjIsCo(pObj) )
1093 pDelays[i] = pDelays[Gia_ObjFaninId0(pObj, i)];
1094 DelayMax = Abc_MaxInt( DelayMax, pDelays[i] );
1098 Delay0 = pDelays[Gia_ObjFaninId0(pObj, i)];
1099 Delay1 = pDelays[Gia_ObjFaninId1(pObj, i)];
1102 Delay = Abc_MaxInt( Delay0 + DelayC, Delay1 + 100 );
1107 Delay = Abc_MaxInt( Delay1 + DelayC, Delay0 + 100 );
1111 Delay = Abc_MaxInt( Delay0 + 100, Delay1 + 100 );
1119static inline int Gia_ObjIsUsed(
Gia_Obj_t * pObj )
1127 int * pDelays = Vec_IntArray(
p->vLevels);
1128 int i, iMax = -1, DelayMax = 0;
1131 if ( Gia_ObjIsUsed(pObj) )
1133 if ( DelayMax > pDelays[i] )
1135 DelayMax = pDelays[i];
1144 int * pDelays = Vec_IntArray(
p->vLevels);
1148 Vec_IntClear( vPath );
1149 pObj = Gia_ManObj(
p, iMax);
1150 assert( Gia_ObjIsAnd(pObj) );
1151 while ( Gia_ObjIsAnd(pObj) )
1153 assert( !Gia_ObjIsUsed(pObj) );
1154 pFanin0 = Gia_ObjFanin0(pObj);
1155 pFanin1 = Gia_ObjFanin1(pObj);
1156 if ( Gia_ObjIsUsed(pFanin0) && Gia_ObjIsUsed(pFanin1) )
1158 if ( Gia_ObjIsUsed(pFanin0) )
1160 Vec_IntPush( vPath, Abc_Var2Lit(Gia_ObjId(
p, pObj), 1) );
1163 else if ( Gia_ObjIsUsed(pFanin1) )
1165 Vec_IntPush( vPath, Abc_Var2Lit(Gia_ObjId(
p, pObj), 0) );
1170 if ( pDelays[Gia_ObjId(
p, pFanin1)] > pDelays[Gia_ObjId(
p, pFanin0)] )
1172 Vec_IntPush( vPath, Abc_Var2Lit(Gia_ObjId(
p, pObj), 1) );
1177 Vec_IntPush( vPath, Abc_Var2Lit(Gia_ObjId(
p, pObj), 0) );
1182 if ( Vec_IntSize(vPath) < nPathMin )
1184 Gia_ManObj(
p, iMax)->fPhase = 1;
1188 if ( Vec_IntSize(vPath) > nPathMax )
1189 Vec_IntShrink( vPath, nPathMax );
1192 pObj = Gia_ManObj(
p, Abc_Lit2Var(iLit) );
1193 if ( Abc_LitIsCompl(iLit) )
1197 assert( Gia_ObjFanin1(pObj)->fPhase == 0 );
1198 Gia_ObjFanin1(pObj)->fPhase = 1;
1204 assert( Gia_ObjFanin0(pObj)->fPhase == 0 );
1205 Gia_ObjFanin0(pObj)->fPhase = 1;
1208 return Vec_IntSize(vPath);
1214 Vec_Int_t * vPath = Vec_IntAlloc( 100 );
1215 int i, RetValue, nBoxes, MaxDelay, nPaths = 0;
1217 p->vLevels = Vec_IntStart( Gia_ManObjNum(
p) );
1223 printf(
"Running path detection: BoxDelay = %d, PathMin = %d, PathMax = %d, PathLimit = %d.\n", DelayC, nPathMin, nPathMax, nPathLimit );
1224 for ( i = 0; i < nPathLimit; i++ )
1228 if ( RetValue == -1 )
1230 nPaths += (RetValue > 0);
1232 printf(
"Iter %5d : Paths = %2d. Boxes = %2d. Total boxes = %6d. Max delay = %5d.\n", i, nPaths, RetValue, nBoxes, MaxDelay );
1234 Vec_IntFree( vPath );
1235 Vec_IntFreeP( &
p->vLevels );
#define ABC_SWAP(Type, a, b)
#define ABC_ALLOC(type, num)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Gia_ManDetectFullAdders2(Gia_Man_t *p, int fVerbose)
void Gia_ManCollectOneChain(Gia_Man_t *p, Vec_Int_t *vFadds, int iFaddTop, Vec_Int_t *vMap, Vec_Int_t *vChain)
void Gia_ManDupWithFaddBoxes_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vFadds, Vec_Int_t *vMap, Vec_Wec_t *vChains, Vec_Int_t *vMap2Chain, Vec_Int_t *vTruths)
void Dtc_ObjCleanTruth_rec(Gia_Obj_t *pObj)
Vec_Int_t * Gia_ManCreateMap(Gia_Man_t *p, Vec_Int_t *vFadds)
void Gia_ManIllustrateBoxes(Gia_Man_t *p)
int Gia_ManFindChains_rec(Gia_Man_t *p, int iMaj, Vec_Int_t *vFadds, Vec_Int_t *vMap, Vec_Int_t *vLength)
int Dtc_ObjComputeTruth(Gia_Man_t *p, int iObj, int *pCut, int *pTruth)
int Gia_ObjFanin0CopyCarry(Vec_Int_t *vCarries, Gia_Obj_t *pObj, int Id)
int Gia_ObjFanin1CopyCarry(Vec_Int_t *vCarries, Gia_Obj_t *pObj, int Id)
Gia_Man_t * Gia_ManGenerateExtraAig(int nBoxes, int nIns, int nOuts)
void Gia_ManPrintChains(Gia_Man_t *p, Vec_Int_t *vFadds, Vec_Int_t *vMap, Vec_Wec_t *vChains)
void Dtc_ManComputeCuts(Gia_Man_t *p, Vec_Int_t **pvCutsXor2, Vec_Int_t **pvCutsXor, Vec_Int_t **pvCutsMaj, int fVerbose)
Vec_Int_t * Gia_ManDetectFullAdders(Gia_Man_t *p, int fVerbose, Vec_Int_t **pvCutsXor2)
int Gia_ManIteratePaths(Gia_Man_t *p, int DelayC, int nPathMin, int nPathMax, int nPathLimit, int fIgnoreBoxDelays, int fVerbose)
void Gia_ManDupFadd(Gia_Man_t *pNew, Gia_Man_t *p, Vec_Int_t *vChain, Vec_Int_t *vFadds, Vec_Int_t *vMap, Vec_Wec_t *vChains, Vec_Int_t *vMap2Chain, Vec_Int_t *vTruths)
int Dtc_ManCompare(int *pCut0, int *pCut1)
int Dtc_ManCutCheckEqual(Vec_Int_t *vCuts, int *pCutNew)
int Dtc_ObjComputeTruth_rec(Gia_Obj_t *pObj)
#define Dtc_ForEachFadd(vFadds, i)
void Gia_ManFindChains(Gia_Man_t *p, Vec_Int_t *vFadds, Vec_Int_t *vMap)
Gia_Man_t * Gia_ManDupWithArtificalFaddBoxes(Gia_Man_t *p, int fUseFanout, int fXorTrick)
int Gia_ManFindChainStart(Gia_Man_t *p)
int Gia_ManFindPath(Gia_Man_t *p, int DelayC, int nPathMin, int nPathMax, Vec_Int_t *vPath)
Vec_Int_t * Gia_ManDetectHalfAdders(Gia_Man_t *p, int fVerbose)
FUNCTION DEFINITIONS ///.
Vec_Int_t * Dtc_ManFindCommonCuts(Gia_Man_t *p, Vec_Int_t *vCutsXor, Vec_Int_t *vCutsMaj)
void Dtc_ManCutMerge(Gia_Man_t *p, int iObj, int *pList0, int *pList1, Vec_Int_t *vCuts, Vec_Int_t *vCutsXor2, Vec_Int_t *vCutsXor, Vec_Int_t *vCutsMaj)
Gia_Man_t * Gia_ManDupWithNaturalBoxes(Gia_Man_t *p, int nFaddMin, int fVerbose)
Vec_Int_t * Gia_ManCollectTruthTables(Gia_Man_t *p, Vec_Int_t *vFadds)
float * Gia_ManGenerateDelayTableFloat(int nIns, int nOuts)
Gia_Man_t * Gia_ManDupWithArtificialBoxes(Gia_Man_t *p, int DelayC, int nPathMin, int nPathMax, int nPathLimit, int fUseFanout, int fXorTrick, int fIgnoreBoxDelays, int fVerbose)
void Gia_ManMarkWithTravId_rec(Gia_Man_t *p, int Id)
Gia_Man_t * Gia_ManDupWithArtificalFaddBoxesTest(Gia_Man_t *p)
void Dtc_ManPrintFadds(Vec_Int_t *vFadds)
Vec_Int_t * Gia_ManFindMapping(Gia_Man_t *p, Vec_Int_t *vFadds, Vec_Int_t *vMap, Vec_Wec_t *vChains)
int Gia_ManFindAnnotatedDelay(Gia_Man_t *p, int DelayC, int *pnBoxes, int fIgnoreBoxDelays)
int Dtc_ManCutMergeOne(int *pCut0, int *pCut1, int *pCut)
#define Dtc_ForEachCut(pList, pCut, i)
DECLARATIONS ///.
Tim_Man_t * Gia_ManGenerateTim(int nPis, int nPos, int nBoxes, int nIns, int nOuts)
int Dtc_ManCompare2(int *pCut0, int *pCut1)
Vec_Wec_t * Gia_ManCollectTopmost(Gia_Man_t *p, Vec_Int_t *vFadds, Vec_Int_t *vMap, int nFaddMin)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
void Gia_ManHashStart(Gia_Man_t *p)
int Gia_ManHasDangling(Gia_Man_t *p)
#define Gia_ManForEachAnd(p, pObj, i)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManBoxNum(Gia_Man_t *p)
DECLARATIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
void Gia_ManFillValue(Gia_Man_t *p)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObj1(p, pObj, i)
void Gia_ManCleanValue(Gia_Man_t *p)
void Gia_ManCleanPhase(Gia_Man_t *p)
int Gia_ObjRecognizeExor(Gia_Obj_t *pObj, Gia_Obj_t **ppFan0, Gia_Obj_t **ppFan1)
void Gia_ManCreateRefs(Gia_Man_t *p)
void Gia_ManIncrementTravId(Gia_Man_t *p)
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_ManCleanMark01(Gia_Man_t *p)
int Tim_ManBoxOutputNum(Tim_Man_t *p, int iBox)
void Tim_ManSetDelayTables(Tim_Man_t *p, Vec_Ptr_t *vDelayTables)
int Tim_ManBoxNum(Tim_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
int Tim_ManCiNum(Tim_Man_t *p)
void Tim_ManCreateBox(Tim_Man_t *p, int firstIn, int nIns, int firstOut, int nOuts, int iDelayTable, int fBlack)
ITERATORS ///.
int Tim_ManPoNum(Tim_Man_t *p)
int Tim_ManBoxInputNum(Tim_Man_t *p, int iBox)
Tim_Man_t * Tim_ManStart(int nCis, int nCos)
DECLARATIONS ///.
int Tim_ManPiNum(Tim_Man_t *p)
int Tim_ManCoNum(Tim_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.