@@ -656,22 +656,18 @@ void Abc_LutCascadeDerive( word * p, int nVars, int nBVars, int Myu, word * pRem
656656}
657657
658658// performs decomposition of one stage
659- static inline int Abc_LutCascadeDecStage ( char * pGuide , int Iter , Vec_Wrd_t * vFuncs [3 ], Vec_Int_t * vVarIDs , int nRVars , int nRails , int nLutSize , int nJRatio , int nZParam , int fVerbose , Vec_Wrd_t * vCas , int * pMyu )
659+ static inline int Abc_LutCascadeDecStage ( word Guide0 , char * pGuide , int Iter , Vec_Wrd_t * vFuncs [3 ], Vec_Int_t * vVarIDs , int nRVars , int nRails , int nLutSize , int nJRatio , int nZParam , int fVerbose , Vec_Wrd_t * vCas , int * pMyu )
660660{
661- extern word Abc_TtFindBVarsSVars ( word * p , int nVars , int nRVars , int nRails , int nLutSize , int fVerbose , int * pMyu , int nJRatio );
662- extern word Abc_TtFindBVarsSVars2 ( word * p , int nVars , int nRVars , int nRails , int nLutSize , int fVerbose , int * pMyu , int nJRatio );
661+ // extern word Abc_TtFindBVarsSVars( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio );
662+ // extern word Abc_TtFindBVarsSVars2( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio );
663663 assert ( Vec_IntSize (vVarIDs ) > nLutSize );
664664 assert ( Vec_IntSize (vVarIDs ) <= 24 );
665- //word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nJRatio );
666- word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars2 ( Vec_WrdArray (vFuncs [0 ]), Vec_IntSize (vVarIDs ), nRVars , nRails , nLutSize , fVerbose , pMyu , nZParam );
667- // if ( nZParam )
668- // Guide = pGuide ? 0 : Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
669- // else
670- // Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nJRatio );
665+ //word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
666+ word Guide = pGuide ? 0 : Guide0 ;
671667 if ( !pGuide && !Guide ) {
672668 if ( fVerbose )
673669 printf ( "The function is not decomposable with %d rails.\n" , nRails );
674- Vec_IntClear ( vVarIDs );
670+ // Vec_IntClear( vVarIDs );
675671 return -1 ;
676672 }
677673 int m , Myu = pGuide ? 1 << nRails : (Guide >> 48 ) & 0xFF ;
@@ -722,22 +718,48 @@ static inline int Abc_LutCascadeDecStage( char * pGuide, int Iter, Vec_Wrd_t * v
722718 Vec_IntShrink ( vVarIDs , nFVars + nSVars + nEVars );
723719 return nEVars ;
724720}
725- word * Abc_LutCascadeDec ( char * pGuide , word * pTruth , int nVarsOrig , Vec_Int_t * vVarIDs , int nRails , int nLutSize , int nStages , int nJRatio , int nZParam , int fVerbose , int * pnStages , int * pMyu )
721+ word * Abc_LutCascadeDec ( char * pGuide , word * pTruth , int nVarsOrig , Vec_Int_t * vVarIDs , int nRails , int nLutSize , int nStages , int nJRatio , int nZParam , int fXRail , int fVerbose , int * pnStages , int * pMyu )
726722{
723+ extern Vec_Wrd_t * Abc_TtFindBVarsSVars2 ( word * pTruth , int nVars , int nCVars , int nRails , int nLutSize , int fVerbose , int * pMyu , int nMyuIncrease );
727724 word * pRes = NULL ; int i , nRVars = 0 , nVars = Vec_IntSize (vVarIDs );
728725 Vec_Wrd_t * vFuncs [3 ] = { Vec_WrdStart (Abc_TtWordNum (nVars )), Vec_WrdAlloc (0 ), Vec_WrdAlloc (0 ) };
729726 Abc_TtCopy ( Vec_WrdArray (vFuncs [0 ]), pTruth , Abc_TtWordNum (nVars ), 0 );
730727 Vec_Wrd_t * vCas = Vec_WrdAlloc ( 100 ); Vec_WrdPush ( vCas , nVarsOrig );
731728 if ( pnStages ) * pnStages = 0 ;
732729 for ( i = 0 ; Vec_IntSize (vVarIDs ) > nLutSize ; i ++ ) {
733- nRVars = Abc_LutCascadeDecStage ( pGuide , i , vFuncs , vVarIDs , nRVars , nRails , nLutSize , nJRatio , nZParam , fVerbose , vCas , i ? NULL : pMyu );
730+ int nRVarsOld = nRVars ;
731+ Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2 ( Vec_WrdArray (vFuncs [0 ]), Vec_IntSize (vVarIDs ), nRVars , nRails , nLutSize , fVerbose , pMyu , nZParam );
732+ if ( vGuides ) {
733+ word Guide0 = Vec_WrdEntry (vGuides , 0 );
734+ Vec_WrdFree ( vGuides );
735+ nRVars = Abc_LutCascadeDecStage ( Guide0 , pGuide , i , vFuncs , vVarIDs , nRVars , nRails , nLutSize , nJRatio , nZParam , fVerbose , vCas , i ? NULL : pMyu );
736+ }
737+ else
738+ nRVars = -1 ;
734739 if ( i + 2 > nStages ) {
735740 if ( fVerbose )
736741 printf ( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n" , i + 2 , nStages );
737742 nRVars = -1 ;
738743 }
739- if ( nRVars == -1 )
744+ if ( nRVars == -1 && Vec_IntSize (vVarIDs ) > nLutSize - 1 && fXRail ) {
745+ Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2 ( Vec_WrdArray (vFuncs [0 ]), Vec_IntSize (vVarIDs ), nRVarsOld , nRails + 1 , nLutSize - 1 , fVerbose , pMyu , nZParam );
746+ if ( vGuides ) {
747+ word Guide0 = Vec_WrdEntry (vGuides , 0 );
748+ Vec_WrdFree ( vGuides );
749+ nRVars = Abc_LutCascadeDecStage ( Guide0 , pGuide , i , vFuncs , vVarIDs , nRVarsOld , nRails + 1 , nLutSize - 1 , nJRatio , nZParam , fVerbose , vCas , NULL );
750+ }
751+ else
752+ nRVars = -1 ;
753+ if ( i + 2 > nStages ) {
754+ if ( fVerbose )
755+ printf ( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n" , i + 2 , nStages );
756+ nRVars = -1 ;
757+ }
758+ }
759+ if ( nRVars == -1 ) {
760+ Vec_IntClear ( vVarIDs );
740761 break ;
762+ }
741763 }
742764 if ( nRVars != -1 && Vec_IntSize (vVarIDs ) > 0 ) {
743765 Abc_LutCascadeGenOne ( vCas , Vec_IntSize (vVarIDs ), Vec_IntArray (vVarIDs ), Vec_WrdEntry (vCas , 0 ), Vec_WrdArray (vFuncs [0 ]) );
@@ -842,7 +864,7 @@ Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int
842864 Gia_ManStop ( pGia );
843865 return pNew ;
844866}
845- Abc_Ntk_t * Abc_NtkLutCascade2 ( Abc_Ntk_t * pNtk , int nLutSize , int nStages , int nRails , int nIters , int nJRatio , int nZParam , int Seed , int fVerbose , int fVeryVerbose , char * pGuide )
867+ Abc_Ntk_t * Abc_NtkLutCascadeOne ( Abc_Ntk_t * pNtk , int nLutSize , int nStages , int nRails , int nIters , int nJRatio , int nZParam , int fXRail , int Seed , int fVerbose , int fVeryVerbose , char * pGuide )
846868{
847869 extern Gia_Man_t * Abc_NtkStrashToGia ( Abc_Ntk_t * pNtk );
848870 int i , nWords = Abc_TtWordNum (Abc_NtkCiNum (pNtk ));
@@ -870,7 +892,7 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int
870892 printf ( ".\n" );
871893 }
872894
873- word * pLuts = Abc_LutCascadeDec ( pGuide , pTruth1 , Abc_NtkCiNum (pNtk ), vVarIDs , nRails , nLutSize , nStages , Iter >= nIters ? 1 : 0 , nZParam , fVeryVerbose , NULL , NULL );
895+ word * pLuts = Abc_LutCascadeDec ( pGuide , pTruth1 , Abc_NtkCiNum (pNtk ), vVarIDs , nRails , nLutSize , nStages , Iter >= nIters ? 1 : 0 , nZParam , fXRail , fVeryVerbose , NULL , NULL );
874896 pNew = pLuts ? Abc_NtkLutCascadeFromLuts ( pLuts , Abc_NtkCiNum (pNtk ), pNtk , nLutSize , fVerbose ) : NULL ;
875897 Vec_IntFree ( vVarIDs );
876898
@@ -1383,7 +1405,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
13831405 SeeAlso []
13841406
13851407***********************************************************************/
1386- void Abc_NtkLutCascadeFile ( char * pFileName , int nVarsOrig , int nLutSize , int nStages , int nRails , int nIters , int nJRatio , int nZParam , int Seed , int fVerbose , int fVeryVerbose , int fPrintMyu )
1408+ void Abc_NtkLutCascadeFile ( char * pFileName , int nVarsOrig , int nLutSize , int nStages , int nRails , int nIters , int nJRatio , int nZParam , int Seed , int fVerbose , int fVeryVerbose , int fPrintMyu , int fPrintLev , int fXRail )
13871409{
13881410 abctime clkStart = Abc_Clock ();
13891411 int i , Sum = 0 , nStageCount = 0 , MyuMin = 0 , nTotalLuts = 0 , nWords = Abc_TtWordNum (nVarsOrig );
@@ -1431,7 +1453,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14311453 printf ( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n" , nVars , nRails , nLutSize );
14321454 }
14331455
1434- word * pLuts = Abc_LutCascadeDec ( NULL , pTruth , nVarsOrig , vVarIDs , nRails , nLutSize , nStages , (int )(Iter >= nIters ), nZParam , fVeryVerbose , & nStageCount , & MyuMin );
1456+ word * pLuts = Abc_LutCascadeDec ( NULL , pTruth , nVarsOrig , vVarIDs , nRails , nLutSize , nStages , (int )(Iter >= nIters ), nZParam , fXRail , fVeryVerbose , & nStageCount , & MyuMin );
14351457 Vec_IntFree ( vVarIDs );
14361458 if ( MyuMin < 50 ) MyuStats [MyuMin ]++ , IterReal ++ ;
14371459 if ( pLuts == NULL ) {
@@ -1473,7 +1495,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14731495 if ( MyuStats [i ] )
14741496 printf ( " %2d Myu : Function count = %8d (%6.2f %%)\n" , i , MyuStats [i ], 100.0 * MyuStats [i ]/nFuncs /IterReal );
14751497 }
1476- if ( nRails > 1 ) {
1498+ if ( fPrintLev ) {
14771499 printf ( "Level count statistics for %d-rail LUT cascade:\n" , nRails );
14781500 for ( i = 0 ; i < 50 ; i ++ )
14791501 if ( StageStats [i ] )
0 commit comments