@@ -621,46 +621,51 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int n
621621{
622622 extern Gia_Man_t * Abc_NtkStrashToGia ( Abc_Ntk_t * pNtk );
623623 extern word * Abc_LutCascade2 ( word * p , int nVars , int nLutSize , int nLuts , int nRails , int nIters , int fVerbose );
624- Gia_Man_t * pGia = Abc_NtkStrashToGia ( pNtk );
625- word * pTruth1 = Gia_ObjComputeTruthTable ( pGia , Gia_ManCo (pGia , 0 ) );
626624 int nWords = Abc_TtWordNum (Abc_NtkCiNum (pNtk ));
627625 word * pCopy = ABC_ALLOC ( word , nWords );
628- Abc_TtCopy ( pCopy , pTruth1 , nWords , 0 );
626+ Gia_Man_t * pGia = Abc_NtkStrashToGia ( pNtk );
627+ Abc_Ntk_t * pNew = NULL ;
628+ Abc_Random (1 );
629+ for ( int Iter = 0 ; Iter < nIters ; Iter ++ ) {
630+ word * pTruth1 = Gia_ObjComputeTruthTable ( pGia , Gia_ManCo (pGia , 0 ) );
631+ Abc_TtCopy ( pCopy , pTruth1 , nWords , 0 );
629632
630- int nVars = -1 ;
631- Vec_Int_t * vVarIDs = Vec_IntStartNatural ( Abc_NtkCiNum (pNtk ) );
632- Abc_TtMinimumBase ( pTruth1 , Vec_IntArray (vVarIDs ), Abc_NtkCiNum (pNtk ), & nVars );
633- Vec_IntShrink ( vVarIDs , nVars );
634- if ( fVerbose ) {
635- if ( Abc_NtkCiNum (pNtk ) != nVars )
636- printf ( "The support of the function is reduced from %d to %d variables.\n" , Abc_NtkCiNum (pNtk ), nVars );
637- printf ( "Decomposing %d-var function into %d-rail cascade of %d-LUTs" , nVars , nRails , nLutSize );
638- if ( pGuide )
639- printf ( " using structural info: %s" , pGuide );
640- printf ( ".\n" );
641- }
633+ int nVars = -1 ;
634+ Vec_Int_t * vVarIDs = Vec_IntStartNatural ( Abc_NtkCiNum (pNtk ) );
635+ Abc_TtMinimumBase ( pTruth1 , Vec_IntArray (vVarIDs ), Abc_NtkCiNum (pNtk ), & nVars );
636+ Vec_IntShrink ( vVarIDs , nVars );
637+ if ( fVerbose ) {
638+ if ( Abc_NtkCiNum (pNtk ) != nVars )
639+ printf ( "The support of the function is reduced from %d to %d variables.\n" , Abc_NtkCiNum (pNtk ), nVars );
640+ printf ( "Decomposing %d-var function into %d-rail cascade of %d-LUTs" , nVars , nRails , nLutSize );
641+ if ( pGuide )
642+ printf ( " using structural info: %s" , pGuide );
643+ printf ( ".\n" );
644+ }
642645
643- word * pLuts = Abc_LutCascadeDec ( pGuide , pTruth1 , Abc_NtkCiNum (pNtk ), vVarIDs , nRails , nLutSize , fVerbose );
644- Abc_Ntk_t * pNew = pLuts ? Abc_NtkLutCascadeFromLuts ( pLuts , Abc_NtkCiNum (pNtk ), pNtk , nLutSize , fVerbose ) : NULL ;
645- Vec_IntFree ( vVarIDs );
646-
647- if ( pLuts ) {
648- if ( fVerbose )
649- Abc_LutCascadePrint ( pLuts );
650- word * pTruth2 = Abc_LutCascadeTruth ( pLuts , Abc_NtkCiNum (pNtk ) );
651- if ( !Abc_TtEqual (pCopy , pTruth2 , nWords ) ) {
652- printf ( "Verification FAILED.\n" );
653- printf ("Function before: " ); Abc_TtPrintHexRev ( stdout , pCopy , Abc_NtkCiNum (pNtk ) ); printf ( "\n" );
654- printf ("Function after: " ); Abc_TtPrintHexRev ( stdout , pTruth2 , Abc_NtkCiNum (pNtk ) ); printf ( "\n" );
646+ word * pLuts = Abc_LutCascadeDec ( pGuide , pTruth1 , Abc_NtkCiNum (pNtk ), vVarIDs , nRails , nLutSize , fVerbose );
647+ pNew = pLuts ? Abc_NtkLutCascadeFromLuts ( pLuts , Abc_NtkCiNum (pNtk ), pNtk , nLutSize , fVerbose ) : NULL ;
648+ Vec_IntFree ( vVarIDs );
649+
650+ if ( pLuts ) {
651+ if ( fVerbose )
652+ Abc_LutCascadePrint ( pLuts );
653+ word * pTruth2 = Abc_LutCascadeTruth ( pLuts , Abc_NtkCiNum (pNtk ) );
654+ if ( !Abc_TtEqual (pCopy , pTruth2 , nWords ) ) {
655+ printf ( "Verification FAILED.\n" );
656+ printf ("Function before: " ); Abc_TtPrintHexRev ( stdout , pCopy , Abc_NtkCiNum (pNtk ) ); printf ( "\n" );
657+ printf ("Function after: " ); Abc_TtPrintHexRev ( stdout , pTruth2 , Abc_NtkCiNum (pNtk ) ); printf ( "\n" );
658+ }
659+ else if ( fVerbose )
660+ printf ( "Verification passed.\n" );
661+ ABC_FREE ( pLuts );
662+ ABC_FREE ( pTruth2 );
663+ break ;
655664 }
656- else if ( fVerbose )
657- printf ( "Verification passed.\n" );
658- ABC_FREE ( pLuts );
659- ABC_FREE ( pTruth2 );
665+ //ABC_FREE( pTruth1 );
660666 }
661- Gia_ManStop ( pGia );
662667 ABC_FREE ( pCopy );
663- //ABC_FREE( pTruth1 );
668+ Gia_ManStop ( pGia );
664669 return pNew ;
665670}
666671Abc_Ntk_t * Abc_NtkLutCascadeGen ( int nLutSize , int nStages , int nRails , int nShared , int fVerbose )
@@ -1154,7 +1159,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
11541159void Abc_NtkLutCascadeFile ( char * pFileName , int nVarsOrig , int nLutSize , int nLuts , int nRails , int nIters , int fVerbose , int fVeryVerbose )
11551160{
11561161 abctime clkStart = Abc_Clock ();
1157- int i , Sum = 0 , nWords = Abc_TtWordNum (nVarsOrig );
1162+ int i , Sum = 0 , nTotalLuts = 0 , nWords = Abc_TtWordNum (nVarsOrig );
11581163 Vec_Wrd_t * vTruths = NULL ;
11591164 if ( strstr (pFileName , ".txt" ) )
11601165 vTruths = Abc_NtkLutCasReadTruths ( pFileName , nVarsOrig );
@@ -1172,7 +1177,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
11721177
11731178 printf ( "Considering %d functions having %d variables from file \"%s\".\n" , nFuncs , nVarsOrig , pFileName );
11741179 word * pCopy = ABC_ALLOC ( word , nWords );
1175- int LutStats [100 ] = {0 };
1180+ int Iter = 0 , LutStats [100 ] = {0 };
1181+ Abc_Random (1 );
11761182 for ( i = 0 ; i < nFuncs ; i ++ )
11771183 {
11781184 word * pTruth = Vec_WrdEntryP ( vTruths , i * nWords );
@@ -1195,15 +1201,22 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
11951201 printf ( "The support of the function is reduced from %d to %d variables.\n" , nVarsOrig , nVars );
11961202 printf ( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n" , nVars , nRails , nLutSize );
11971203 }
1198-
1204+
11991205 word * pLuts = Abc_LutCascadeDec ( NULL , pTruth , nVarsOrig , vVarIDs , nRails , nLutSize , fVeryVerbose );
12001206 Vec_IntFree ( vVarIDs );
12011207 if ( pLuts == NULL ) {
1208+ if ( ++ Iter < nIters ) {
1209+ i -- ;
1210+ continue ;
1211+ }
1212+ Iter = 0 ;
12021213 if ( fVerbose || fVeryVerbose )
12031214 printf ( "Not decomposable.\n" );
12041215 continue ;
12051216 }
1217+ Iter = 0 ;
12061218 Sum ++ ;
1219+ nTotalLuts += Abc_LutCascadeCount (pLuts );
12071220 LutStats [Abc_LutCascadeCount (pLuts )]++ ;
12081221 word * pTruth2 = Abc_LutCascadeTruth ( pLuts , nVarsOrig );
12091222 if ( fVeryVerbose )
@@ -1227,7 +1240,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
12271240 if ( LutStats [i ] )
12281241 printf ( " %d LUT6 : Function count = %8d (%6.2f %%)\n" , i , LutStats [i ], 100.0 * LutStats [i ]/nFuncs );
12291242 printf ( "Non-decomp : Function count = %8d (%6.2f %%)\n" , nFuncs - Sum , 100.0 * (nFuncs - Sum )/Abc_MaxInt (1 , nFuncs ) );
1230- printf ( "Finished %d functions (speed = %.2f functions / second). " , nFuncs , 1.0 * nFuncs /(((double )(Abc_Clock () - clkStart ))/((double )CLOCKS_PER_SEC )) );
1243+ printf ( "Finished %d functions (%.2f LUTs / function; %.2f functions / sec). " ,
1244+ nFuncs , 1.0 * nTotalLuts /Sum , 1.0 * nFuncs /(((double )(Abc_Clock () - clkStart ))/((double )CLOCKS_PER_SEC )) );
12311245 Abc_PrintTime ( 0 , "Total time" , Abc_Clock () - clkStart );
12321246}
12331247
0 commit comments