345 Vec_Ptr_t * vRoots2, * vNodes, * vLeaves, * vFanouts;
351 vRoots2 = Vec_PtrAlloc( 100 );
352 vNodes = Vec_PtrAlloc( 100 );
353 vLeaves = Vec_PtrAlloc( 100 );
354 vFanouts = Vec_PtrAlloc( 100 );
358 ppObjs[1] = (
Abc_Obj_t *)Vec_PtrEntry( vRoots1, i );
359 if ( ppObjs[1] == NULL )
361 Vec_PtrPush( vRoots2, NULL );
365 Vec_PtrPush( vRoots2, pRoot2 );
367 Vec_PtrFree( vNodes );
368 Vec_PtrFree( vLeaves );
369 Vec_PtrFree( vFanouts );
371 assert( Vec_PtrSize(vRoots) == Vec_PtrSize(vRoots2) );
470 char pFileName[1000];
471 Vec_Ptr_t * vRoots, * vRoots1, * vRoots2, * vNodes, * vLeaves;
473 int i, nNodes = 0, nNodes2 = 0;
477 vNodes = Vec_PtrAlloc( 100 );
478 vLeaves = Vec_PtrAlloc( 100 );
481 printf(
"%6d : ", i );
485 nNodes += Vec_PtrSize(vNodes);
486 printf(
"%6d ", Abc_ObjId(pObj) );
487 printf(
"Vol =%3d ", Vec_PtrSize(vNodes) );
488 printf(
"Cut =%3d ", Vec_PtrSize(vLeaves) );
489 if ( Vec_PtrSize(vLeaves) < 2 )
496 pNodes[1] = (
Abc_Obj_t *)Vec_PtrEntry( vRoots1, i );
497 pNodes[2] = (
Abc_Obj_t *)Vec_PtrEntry( vRoots2, i );
498 if ( pNodes[1] == NULL || pNodes[2] == NULL )
505 nNodes2 += Vec_PtrSize(vNodes);
506 printf(
"%6d ", Abc_ObjId(pNodes[1]) );
507 printf(
"%6d ", Abc_ObjId(pNodes[2]) );
508 printf(
"Vol =%3d ", Vec_PtrSize(vNodes) );
509 printf(
"Cut =%3d ", Vec_PtrSize(vLeaves) );
511 printf(
"%4.2f ", 1.0 * Vec_PtrSize(vNodes)/Vec_PtrSize(vLeaves) );
515 if ( Vec_PtrSize(vNodes) < 10 )
517 sprintf( pFileName,
"%s_mffc%04d_%02d.blif", Abc_NtkName(pNtk), Abc_ObjId(pObj), Vec_PtrSize(vNodes) );
520 printf(
"Total nodes = %d. Root nodes = %d. Mffc nodes = %d. Mffc nodes2 = %d.\n",
521 Abc_NtkNodeNum(pNtk), Vec_PtrSize(vRoots), nNodes, nNodes2 );
522 Vec_PtrFree( vNodes );
523 Vec_PtrFree( vLeaves );
524 Vec_PtrFree( vRoots );
525 Vec_PtrFree( vRoots1 );
526 Vec_PtrFree( vRoots2 );
544 Vec_Ptr_t * vRoots, * vFanins, * vFanouts, * vNodes, * vLeaves;
546 Vec_Int_t * vCounts, * vNumbers, * vSizes, * vMarks;
548 int i, k, Entry, nSizes;
551 vFanins = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
552 vFanouts = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
553 vCounts = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
554 vNode1 = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
555 vNode2 = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
556 vSizes = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
557 vMarks = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
562 Vec_PtrWriteEntry( vFanins, Abc_ObjId(pObj), Vec_IntAlloc(8) );
563 Vec_PtrWriteEntry( vFanouts, Abc_ObjId(pObj), Vec_IntAlloc(8) );
566 vNodes = Vec_PtrAlloc( 100 );
567 vLeaves = Vec_PtrAlloc( 100 );
574 if ( !Abc_ObjIsNode(pFanin) )
576 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntry(vFanins, Abc_ObjId(pObj)), Abc_ObjId(pFanin) );
577 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntry(vFanouts, Abc_ObjId(pFanin)), Abc_ObjId(pObj) );
579 Vec_IntAddToEntry( vCounts, Abc_ObjId(pFanin), 1 );
581 Vec_IntWriteEntry( vSizes, Abc_ObjId(pObj), Vec_PtrSize(vNodes) );
590 if ( !Abc_ObjIsNode(pFanin) )
592 if ( Vec_IntEntry(vCounts, Abc_ObjId(pFanin)) != 2 )
594 if ( Vec_IntEntry(vNode1, Abc_ObjId(pFanin)) == 0 )
595 Vec_IntWriteEntry( vNode1, Abc_ObjId(pFanin), Abc_ObjId(pObj) );
597 Vec_IntWriteEntry( vNode2, Abc_ObjId(pFanin), Abc_ObjId(pObj) );
599 Vec_IntWriteEntry( vMarks, Abc_ObjId(pFanin), 1 );
600 Vec_IntWriteEntry( vMarks, Abc_ObjId(pObj), 1 );
608 if ( Vec_IntEntry( vMarks, Abc_ObjId(pObj) ) )
609 nSizes += Vec_IntEntry( vSizes, Abc_ObjId(pObj) );
611 printf(
"Included = %6d. Total = %6d. (%6.2f %%)\n",
612 nSizes, Abc_NtkNodeNum(pNtk), 100.0 * nSizes / Abc_NtkNodeNum(pNtk) );
617 if ( Vec_IntEntry(vCounts, Abc_ObjId(pObj)) != 2 )
619 printf(
"%d ", Vec_IntEntry( vSizes, Abc_ObjId(pObj) ) +
620 Vec_IntEntry( vSizes, Vec_IntEntry(vNode1, Abc_ObjId(pObj)) ) +
621 Vec_IntEntry( vSizes, Vec_IntEntry(vNode2, Abc_ObjId(pObj)) ) );
626 vNumbers = Vec_IntStart( 32 );
641 Vec_IntAddToEntry( vNumbers, Entry, 1 );
642 else if ( Entry <= 100 )
643 Vec_IntAddToEntry( vNumbers, 10 + Entry/10, 1 );
644 else if ( Entry < 1000 )
645 Vec_IntAddToEntry( vNumbers, 20 + Entry/100, 1 );
647 Vec_IntAddToEntry( vNumbers, 30, 1 );
649 for ( i = 1; i <= 10; i++ )
650 if ( Vec_IntEntry(vNumbers,i) )
651 printf(
" n = %4d %6d\n", i, Vec_IntEntry(vNumbers,i) );
652 for ( i = 11; i <= 20; i++ )
653 if ( Vec_IntEntry(vNumbers,i) )
654 printf(
"%4d < n <= %4d %6d\n", 10*(i-10), 10*(i-9), Vec_IntEntry(vNumbers,i) );
655 for ( i = 21; i < 30; i++ )
656 if ( Vec_IntEntry(vNumbers,i) )
657 printf(
"%4d < n <= %4d %6d\n", 100*(i-20), 100*(i-19), Vec_IntEntry(vNumbers,i) );
658 if ( Vec_IntEntry(vNumbers,31) )
659 printf(
" n > 1000 %6d\n", Vec_IntEntry(vNumbers,30) );
660 printf(
"Total MFFCs = %d. ", Vec_PtrSize(vRoots) );
661 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
662 Vec_IntFree( vNumbers );
663 Vec_PtrFree( vNodes );
664 Vec_PtrFree( vLeaves );
669 Vec_IntFree( (
Vec_Int_t *)Vec_PtrEntry(vFanins, Abc_ObjId(pObj)) );
670 Vec_IntFree( (
Vec_Int_t *)Vec_PtrEntry(vFanouts, Abc_ObjId(pObj)) );
673 Vec_IntFree( vCounts );
674 Vec_PtrFree( vFanouts );
675 Vec_PtrFree( vFanins );
676 Vec_PtrFree( vRoots );
787 Vec_Ptr_t * vNodes, * vLeaves, * vRoots, * vVolume;
788 Vec_Ptr_t * vLeaves2, * vRoots2, * vVolume2;
790 double Cost, CostBest = 0.0;
792 vNodes = Vec_PtrAlloc( 100 );
793 vLeaves = Vec_PtrAlloc( 100 );
794 vRoots = Vec_PtrAlloc( 100 );
795 vVolume = Vec_PtrAlloc( 100 );
796 vLeaves2 = Vec_PtrAlloc( 100 );
797 vRoots2 = Vec_PtrAlloc( 100 );
798 vVolume2 = Vec_PtrAlloc( 100 );
800 for ( i = 1; i <= 16; i++ )
802 Vec_PtrPush( vNodes, pNodeBest );
806 printf(
"%2d : Node =%6d (%2d%3d) Cost =%6.2f ", i, Abc_ObjId(pNodeBest),
807 Abc_ObjFaninNum(pNodeBest), Abc_ObjFanoutNum(pNodeBest), CostBest );
808 printf(
"Leaf =%2d Root =%2d Vol =%2d\n", Vec_PtrSize(vLeaves), Vec_PtrSize(vRoots), Vec_PtrSize(vVolume) );
814 if ( !Abc_ObjIsNode(pNode) )
816 Vec_PtrPush( vNodes, pNode );
819 Cost = 1.0 * Vec_PtrSize(vVolume2) / (Vec_PtrSize(vLeaves2) + 3 * Vec_PtrSize(vRoots2));
820 if ( pNodeBest == NULL || CostBest < Cost )
825 Vec_PtrPop( vNodes );
829 if ( Vec_PtrFind(vNodes, pNode) >= 0 )
831 if ( !Abc_ObjIsNode(pNode) )
833 Vec_PtrPush( vNodes, pNode );
836 Cost = 1.0 * Vec_PtrSize(vVolume2) / (Vec_PtrSize(vLeaves2) + 3 * Vec_PtrSize(vRoots2));
837 if ( pNodeBest == NULL || CostBest < Cost )
842 Vec_PtrPop( vNodes );
844 if ( pNodeBest == NULL )
848 Vec_PtrFree( vNodes );
849 Vec_PtrFree( vLeaves );
850 Vec_PtrFree( vRoots );
851 Vec_PtrFree( vVolume );
852 Vec_PtrFree( vLeaves2 );
853 Vec_PtrFree( vRoots2 );
854 Vec_PtrFree( vVolume2 );
894 Vec_Ptr_t * vRoots, * vFanins, * vFanouts, * vVolumes, * vNodes, * vLeaves;
901 vFanins = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
902 vFanouts = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
903 vVolumes = Vec_PtrStart( Abc_NtkObjNumMax(pNtk) );
906 Vec_PtrWriteEntry( vFanins, Abc_ObjId(pObj), Vec_IntAlloc(8) );
907 Vec_PtrWriteEntry( vFanouts, Abc_ObjId(pObj), Vec_IntAlloc(8) );
908 Vec_PtrWriteEntry( vVolumes, Abc_ObjId(pObj), Vec_IntAlloc(8) );
911 vNodes = Vec_PtrAlloc( 100 );
912 vLeaves = Vec_PtrAlloc( 100 );
915 if ( Abc_ObjIsCi(pObj) )
921 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntry(vFanins, Abc_ObjId(pObj)), Abc_ObjId(pFanin) );
922 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntry(vFanouts, Abc_ObjId(pFanin)), Abc_ObjId(pObj) );
925 Vec_IntPush( (
Vec_Int_t *)Vec_PtrEntry(vVolumes, Abc_ObjId(pObj)), Abc_ObjId(pFanin) );
928 Vec_PtrFree( vNodes );
929 Vec_PtrFree( vLeaves );
933 Vec_IntSort( (
Vec_Int_t *)Vec_PtrEntry(vFanins, Abc_ObjId(pObj)), 0 );
934 Vec_IntSort( (
Vec_Int_t *)Vec_PtrEntry(vFanouts, Abc_ObjId(pObj)), 0 );
938 *pvFanouts = vFanouts;
939 *pvVolumes = vVolumes;
1030 Vec_Int_t * vIns2, * vOuts, * vOuts2, * vTemp;
1031 Abc_Obj_t * pPivot2, * pObj, * pObjBest = NULL;
1035 vOuts = Vec_IntAlloc( 100 );
1038 vOuts2 = (
Vec_Int_t *)Vec_PtrEntry( vFanouts, Abc_ObjId(pObj) );
1039 if ( Vec_IntSize(vOuts2) > 16 )
1041 vOuts = Vec_IntTwoMerge( vTemp = vOuts, vOuts2 );
1042 Vec_IntFree( vTemp );
1047 if ( Vec_IntEntry(vMarks, Abc_ObjId(pPivot2)) == 0 )
1049 vIns2 = (
Vec_Int_t *)Vec_PtrEntry( vFanins, Abc_ObjId(pPivot2) );
1050 Volume = Vec_IntSize((
Vec_Int_t *)Vec_PtrEntry(vVolumes, Abc_ObjId(pPivot2)));
1055 if ( pObjBest == NULL || CostBest < Cost )
1062 Vec_IntFree( vOuts );
1133 Vec_Ptr_t * vPivots, * vFanins, * vFanouts, * vVolumes;
1137 assert( nOutMax >= 1 && nOutMax <= 32 );
1138 vResult = Vec_PtrAlloc( 100 );
1143 pObj->
iTemp = Vec_IntSize((
Vec_Int_t *)Vec_PtrEntry(vVolumes, Abc_ObjId(pObj)));
1146 vMarks = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
1148 if ( Abc_ObjIsNode(pObj) && Vec_IntSize((
Vec_Int_t *)Vec_PtrEntry(vVolumes, Abc_ObjId(pObj))) > 1 )
1149 Vec_IntWriteEntry( vMarks, Abc_ObjId(pObj), 1 );
1151 vThis = Vec_PtrAlloc( 10 );
1156 if ( Vec_IntEntry(vMarks, Abc_ObjId(pObj)) == 0 )
1159 Vec_PtrClear( vThis );
1160 Vec_PtrPush( vThis, pObj );
1161 Vec_IntWriteEntry( vMarks, Abc_ObjId(pObj), 0 );
1163 vLeaves = (
Vec_Int_t *)Vec_PtrEntry( vFanins, Abc_ObjId(pObj) );
1164 if ( Vec_IntSize(vLeaves) > nInMax )
1170 for ( k = 1; k < nOutMax; k++ )
1174 assert( Vec_IntSize(vLeaves) <= nInMax );
1175 pObj2 =
Abc_NktMffcFindBest( pNtk, vMarks, vLeaves, vFanins, vFanouts, vVolumes, nInMax );
1176 Vec_IntFree( vLeaves );
1178 if ( pObj2 == NULL )
1180 Vec_PtrPush( vThis, pObj2 );
1181 Vec_IntWriteEntry( vMarks, Abc_ObjId(pObj2), 0 );
1186 Vec_PtrFree( vThis );
1187 Vec_IntFree( vMarks );
1206 char pFileName[1000];
1209 double Cost, CostAll = 0.0;
1210 int i, k, Entry, nNodes = 0;
1213 vLeaves = Vec_IntAlloc( 100 );
1214 vRoots = Vec_IntAlloc( 100 );
1217 nNodes += Vec_IntSize(vGlob);
1219 if ( Vec_IntSize(vGlob) <= Vec_IntSize(vRoots) )
1221 Cost = 1.0 * Vec_IntSize(vGlob)/(Vec_IntSize(vLeaves) + Vec_IntSize(vRoots));
1226 printf(
"%6d : Root =%3d. Leaf =%3d. Node =%4d. ",
1227 i, Vec_IntSize(vRoots), Vec_IntSize(vLeaves), Vec_IntSize(vGlob) );
1228 printf(
"Cost =%6.2f ", Cost );
1230 printf(
"%d ", Entry );
1233 sprintf( pFileName,
"%sc%04di%02dn%02d.blif", Abc_NtkName(pNtk), i, Vec_IntSize(vLeaves), Vec_IntSize(vGlob) );
1236 Vec_IntFree( vLeaves );
1237 Vec_IntFree( vRoots );
1239 Vec_IntFree( vGlob );
1240 Vec_PtrFree( vGlobs );
1241 printf(
"Total = %6d. Nodes = %6d. ", Abc_NtkNodeNum(pNtk), nNodes );
1242 printf(
"Cost = %6.2f ", CostAll );
1243 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );