From d2453053930d495e0c020842a5f900c7f7cf0759 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 13 May 2025 19:21:56 -0700 Subject: [PATCH] Improvements to "lutcasdec". --- src/base/abci/abc.c | 32 ++++++++++++++++++++++++-------- src/base/abci/abcCas.c | 40 +++++++++++++++++++++------------------- src/misc/util/utilBSet.c | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 4eec2d4b2..be619df7a 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -9167,12 +9167,12 @@ usage: int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) { extern Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose ); - extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, char * pGuide ); - extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, int fVeryVerbose ); + extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int Seed, int fVerbose, char * pGuide ); + extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu ); Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL; - int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, fGen = 0, fVerbose = 0, fVeryVerbose = 0; + int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, nJRatio = 0, fGen = 0, fPrintMyu = 0, fVerbose = 0, fVeryVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCINFgvwh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIJNFgmvwh" ) ) != EOF ) { switch ( c ) { @@ -9242,6 +9242,17 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) if ( nIters < 0 ) goto usage; break; + case 'J': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-J\" should be followed by an integer.\n" ); + goto usage; + } + nJRatio = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( nJRatio < 0 ) + goto usage; + break; case 'N': if ( globalUtilOptind >= argc ) { @@ -9265,6 +9276,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'g': fGen ^= 1; break; + case 'm': + fPrintMyu ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -9284,7 +9298,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "The number of variables should be given on the command line using switch \"-N \".\n" ); return 1; } - Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, Seed, fVerbose, fVeryVerbose ); + Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, nJRatio, Seed, fVerbose, fVeryVerbose, fPrintMyu ); return 1; } if ( fGen ) @@ -9321,7 +9335,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) } if ( argc == globalUtilOptind + 1 ) pGuide = argv[globalUtilOptind]; - pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nStages, nRails, nIters, Seed, fVerbose, pGuide ); + pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nStages, nRails, nIters, nJRatio, Seed, fVerbose, pGuide ); if ( pNtkRes == NULL ) { Abc_Print( -1, "LUT cascade mapping failed.\n" ); @@ -9331,7 +9345,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - Abc_Print( -2, "usage: lutcasdec [-KMRCSIN ] [-F ] [-vwh]\n" ); + Abc_Print( -2, "usage: lutcasdec [-KMRCSIJN ] [-F ] [-gmvwh]\n" ); Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" ); Abc_Print( -2, "\t-K : the number of LUT inputs [default = %d]\n", nLutSize ); Abc_Print( -2, "\t-M : the maximum delay (the number of stages) [default = %d]\n", nStages ); @@ -9339,11 +9353,13 @@ usage: Abc_Print( -2, "\t-C : the number of shared variables in each stage [default = %d]\n", nShared ); Abc_Print( -2, "\t-S : the random seed for randomized bound-set selection [default = %d]\n", Seed ); Abc_Print( -2, "\t-I : the number of iterations when looking for a solution [default = %d]\n", nIters ); + Abc_Print( -2, "\t-J : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio ); Abc_Print( -2, "\t-N : the number of support variables (for truth table files only) [default = unused]\n" ); Abc_Print( -2, "\t-F : a text file with truth tables in hexadecimal listed one per line\n"); Abc_Print( -2, "\t-g : toggle generating random cascade with these parameters [default = %s]\n", fGen? "yes": "no" ); + Abc_Print( -2, "\t-m : toggle printing column multiplicity statistics [default = %s]\n", fPrintMyu? "yes": "no" ); Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" ); - Abc_Print( -2, "\t-w : toggle additional verbose printout [default = %s]\n", fVerbose? "yes": "no" ); + Abc_Print( -2, "\t-w : toggle additional verbose printout [default = %s]\n", fVeryVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1; } diff --git a/src/base/abci/abcCas.c b/src/base/abci/abcCas.c index fcfde345f..f4136f4ce 100644 --- a/src/base/abci/abcCas.c +++ b/src/base/abci/abcCas.c @@ -656,12 +656,12 @@ void Abc_LutCascadeDerive( word * p, int nVars, int nBVars, int Myu, word * pRem } // performs decomposition of one stage -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 fVerbose, Vec_Wrd_t * vCas, int * pMyu ) +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 fVerbose, Vec_Wrd_t * vCas, int * pMyu ) { - extern word Abc_TtFindBVarsSVars( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu ); + extern word Abc_TtFindBVarsSVars( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio ); assert( Vec_IntSize(vVarIDs) > nLutSize ); assert( Vec_IntSize(vVarIDs) <= 24 ); - word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu ); + word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nJRatio ); if ( !pGuide && !Guide ) { if ( fVerbose ) printf( "The function is not decomposable with %d rails.\n", nRails ); @@ -716,7 +716,7 @@ static inline int Abc_LutCascadeDecStage( char * pGuide, int Iter, Vec_Wrd_t * v Vec_IntShrink( vVarIDs, nFVars+nSVars+nEVars ); return nEVars; } -word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t * vVarIDs, int nRails, int nLutSize, int nStages, int fVerbose, int * pnStages, int * pMyu ) +word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t * vVarIDs, int nRails, int nLutSize, int nStages, int nJRatio, int fVerbose, int * pnStages, int * pMyu ) { word * pRes = NULL; int i, nRVars = 0, nVars = Vec_IntSize(vVarIDs); Vec_Wrd_t * vFuncs[3] = { Vec_WrdStart(Abc_TtWordNum(nVars)), Vec_WrdAlloc(0), Vec_WrdAlloc(0) }; @@ -724,7 +724,7 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t Vec_Wrd_t * vCas = Vec_WrdAlloc( 100 ); Vec_WrdPush( vCas, nVarsOrig ); if ( pnStages ) *pnStages = 0; for ( i = 0; Vec_IntSize(vVarIDs) > nLutSize; i++ ) { - nRVars = Abc_LutCascadeDecStage( pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, fVerbose, vCas, i ? NULL : pMyu ); + nRVars = Abc_LutCascadeDecStage( pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, nJRatio, fVerbose, vCas, i ? NULL : pMyu ); if ( i+2 > nStages ) { printf( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n", i+2, nStages ); nRVars = -1; @@ -835,7 +835,7 @@ Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int Gia_ManStop( pGia ); return pNew; } -Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int nRails, int nIters, int Seed, int fVerbose, char * pGuide ) +Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int nRails, int nIters, int nJRatio, int Seed, int fVerbose, char * pGuide ) { extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk ); int i, nWords = Abc_TtWordNum(Abc_NtkCiNum(pNtk)); @@ -845,7 +845,7 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int Abc_Random(1); for ( i = 0; i < Seed; i++ ) Abc_Random(0); - for ( int Iter = 0; Iter < nIters; Iter++ ) { + for ( int Iter = 0; Iter < nIters+nJRatio; Iter++ ) { word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) ); Abc_TtCopy( pCopy, pTruth1, nWords, 0 ); @@ -863,7 +863,7 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int printf( ".\n" ); } - word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, fVerbose, NULL, NULL ); + word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, Iter >= nIters ? 1 : 0, fVerbose, NULL, NULL ); pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL; Vec_IntFree( vVarIDs ); @@ -1376,7 +1376,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig ) SeeAlso [] ***********************************************************************/ -void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, int nRails, int nIters, int Seed, int fVerbose, int fVeryVerbose ) +void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, int nRails, int nIters, int nJRatio, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu ) { abctime clkStart = Abc_Clock(); int i, Sum = 0, nStageCount = 0, MyuMin = 0, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig); @@ -1395,12 +1395,12 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n return; } - printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName ); - word * pCopy = ABC_ALLOC( word, nWords ); - int Iter = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0}; Abc_Random(1); for ( i = 0; i < Seed; i++ ) Abc_Random(0); + printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName ); + word * pCopy = ABC_ALLOC( word, nWords ); + int Iter = 0, IterReal = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0}; for ( i = 0; i < nFuncs; i++ ) { word * pTruth = Vec_WrdEntryP( vTruths, i*nWords ); @@ -1424,11 +1424,11 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize ); } - word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, fVeryVerbose, &nStageCount, &MyuMin ); + word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter >= nIters), fVeryVerbose, &nStageCount, &MyuMin ); Vec_IntFree( vVarIDs ); - if ( MyuMin < 50 ) MyuStats[MyuMin]++; + if ( MyuMin < 50 ) MyuStats[MyuMin]++, IterReal++; if ( pLuts == NULL ) { - if ( ++Iter < nIters ) { + if ( ++Iter < nIters+nJRatio ) { i--; continue; } @@ -1460,10 +1460,12 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n } ABC_FREE( pCopy ); Vec_WrdFree( vTruths ); - printf( "Column multiplicity statistics for %d-rail LUT cascade:\n", nRails ); - for ( i = 0; i < 50; i++ ) - if ( MyuStats[i] ) - printf( " %2d Myu : Function count = %8d (%6.2f %%)\n", i, MyuStats[i], 100.0*MyuStats[i]/nFuncs/nIters ); + if ( fPrintMyu ) { + printf( "Column multiplicity statistics for %d-rail LUT cascade:\n", nRails ); + for ( i = 0; i < 50; i++ ) + if ( MyuStats[i] ) + printf( " %2d Myu : Function count = %8d (%6.2f %%)\n", i, MyuStats[i], 100.0*MyuStats[i]/nFuncs/IterReal ); + } printf( "Level count statistics for %d-rail LUT cascade:\n", nRails ); for ( i = 0; i < 50; i++ ) if ( StageStats[i] ) diff --git a/src/misc/util/utilBSet.c b/src/misc/util/utilBSet.c index 77257b673..705892579 100644 --- a/src/misc/util/utilBSet.c +++ b/src/misc/util/utilBSet.c @@ -586,7 +586,7 @@ void Abc_BSEvalOneTest( word * pT, int nVars, int nBVars, int fVerbose ) printf( "The column multiplicity of the %d-var function with bound-sets of size %d is %d.\n", nVars, nBVars, Best ); Abc_BSEvalFree(p); } -int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int fShared ) +int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, word * pBest2, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int * pPermBest2, int fShared, int nJRatio ) { int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32]; int nPermVars = nVars-nCVars, Count = 0; @@ -597,10 +597,18 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int n for ( i = 0; i < nVars; i++ ) pPermBest[i] = i; int CostBest = 1 << nVars; + int CostBest2 = 1 << nVars; + int iSave = nJRatio ? (Abc_Random(0) % Vec_IntSize(p->vPairs)/2) : -1; + //printf( "The number of pairs = %d.\n", Vec_IntSize(p->vPairs)/2 ); //int Count = 0; Vec_IntForEachEntryDouble( p->vPairs, Var0, Var1, i ) { //Abc_GenChasePrint( Count++, Pla2Var, nVars, nFVars, Var0, Var1 ); int CostThis = Abc_TtGetCM( pIn, nVars, nFVars, p->vCounts, p->vTable, p->vStore, p->vUsed, fShared ); + if ( iSave == i/2 ) { + CostBest2 = CostThis; + if ( pBest2 ) Abc_TtCopy( pBest2, pIn, Abc_Truth6WordNum(nVars), 0 ); + if ( pPermBest2 ) memcpy( pPermBest2, Pla2Var, sizeof(int)*nVars ); + } if ( CostBest > CostThis ) { CostBest = CostThis; if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 ); @@ -661,12 +669,17 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int n Pla2Var[iPlace1] ^= Pla2Var[iPlace0]; Pla2Var[iPlace0] ^= Pla2Var[iPlace1]; } + if ( nJRatio && Abc_Random(0) % nJRatio == 0 ) { + CostBest = CostBest2; + if ( pBest2 ) Abc_TtCopy( pBest, pBest2, Abc_Truth6WordNum(nVars), 0 ); + if ( pPermBest2 ) memcpy( pPermBest, pPermBest2, sizeof(int)*nVars ); + } return CostBest; } void Abc_BSEvalBestTest( word * pIn, int nVars, int nBVars, int fShared, int fVerbose ) { assert( nVars > nBVars ); - Abc_BSEval_t * p = Abc_BSEvalAlloc(); int i, pPerm[32] = {0}; + Abc_BSEval_t * p = Abc_BSEvalAlloc(); int i, pPerm[32] = {0}, pPerm2[32] = {0}; if ( p->nVars != nVars || p->nBVars != nBVars ) { Vec_IntFreeP( &p->vPairs ); p->vPairs = Abc_GenChasePairs( nVars, nBVars ); @@ -674,7 +687,8 @@ void Abc_BSEvalBestTest( word * pIn, int nVars, int nBVars, int fShared, int fVe p->nBVars = nBVars; } word * pFun = ABC_ALLOC( word, Abc_TtWordNum(nVars) ); - int Best = Abc_BSEvalBest( p, pIn, pFun, nVars, 0, nVars-nBVars, fVerbose, pPerm, fShared ); + word * pFun2 = ABC_ALLOC( word, Abc_TtWordNum(nVars) ); + int Best = Abc_BSEvalBest( p, pIn, pFun, pFun2, nVars, 0, nVars-nBVars, fVerbose, pPerm, pPerm2, fShared, 0 ); printf( "The minimum %s of the %d-var function with bound-sets of size %d is %d.\n", fShared ? "number of rails" : "column multiplicity", nVars, nBVars, Best ); printf( "Original: " ); Extra_PrintHex( stdout, (unsigned *)pIn, nVars ); printf( "\n" ); @@ -684,6 +698,7 @@ void Abc_BSEvalBestTest( word * pIn, int nVars, int nBVars, int fShared, int fVe printf( "%d ", pPerm[i] ); printf( "\n" ); ABC_FREE( pFun ); + ABC_FREE( pFun2 ); Abc_BSEvalFree(p); } @@ -706,6 +721,7 @@ void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryA Vec_Int_t * vCounts[2] = { Vec_IntStart(1 << nVars), Vec_IntStart(1 << nVars) }; int i, k, Count, nWords = Abc_TtWordNum(nVars); word * pFun = ABC_ALLOC( word, nWords ); + word * pFun2 = ABC_ALLOC( word, nWords ); if ( p->nVars != nVars || p->nBVars != nBVars ) { Vec_IntFreeP( &p->vPairs ); p->vPairs = Abc_GenChasePairs( nVars, nBVars ); @@ -741,7 +757,7 @@ void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryA } if ( fTryAll ) - Count = Abc_BSEvalBest( p, pFun, NULL, nVars, 0, nVars-nBVars, fVerbose, NULL, fShared ); + Count = Abc_BSEvalBest( p, pFun, pFun2, NULL, nVars, 0, nVars-nBVars, fVerbose, NULL, NULL, fShared, 0 ); else Count = Abc_TtGetCM( pFun, nVars, nVars-nBVars, p->vCounts, p->vTable, p->vStore, p->vUsed, fShared ); if ( fVerbose ) @@ -750,6 +766,7 @@ void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryA Vec_IntAddToEntry( vCounts[1], Abc_Base2Log(Count), 1 ); } ABC_FREE( pFun ); + ABC_FREE( pFun2 ); Abc_BSEvalFree(p); if ( nMints ) printf( "Generated %d random %d-var functions with %d positive minterms.\n", nFuncs, nVars, nMints ); @@ -926,11 +943,13 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR Vec_Wrd_t * vRes = Vec_WrdStart( 1 ); word * pRes = NULL; word * pTruth = ABC_ALLOC( word, Abc_TtWordNum(nVars) ); word * pBest = ABC_ALLOC( word, Abc_TtWordNum(nVars) ); + word * pBest2 = ABC_ALLOC( word, Abc_TtWordNum(nVars) ); Abc_TtCopy( pTruth, pFunc, Abc_TtWordNum(nVars), 0 ); int i, r, nVarsCur = nVars, nOutVars = 0; while ( nVarsCur > nLutSize ) { int pPerm[32] = {0}; + int pPerm2[32] = {0}; if ( p->nVars != nVarsCur || p->nBVars != nLutSize ) { Vec_IntFreeP( &p->vPairs ); if ( p->nBVars != nLutSize ) { @@ -946,7 +965,7 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR p->nVars = nVarsCur; p->nBVars = nLutSize; } - int MyuMin = Abc_BSEvalBest( p, pTruth, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, fVerbose, pPerm, 0 ); + int MyuMin = Abc_BSEvalBest( p, pTruth, pBest, pBest2, nVarsCur, nOutVars, nVarsCur-nLutSize, fVerbose, pPerm, pPerm2, 0, 0 ); int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin ); for ( r = 1; r <= nRails && nRailsMin > r; r++ ) { int nRailsMinNew = Abc_SharedEvalBest( p, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, MyuMin, nRails, fVerbose, &Shared, p->pPat ); @@ -982,6 +1001,7 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR Abc_BSEvalFree(p); ABC_FREE( pTruth ); ABC_FREE( pBest ); + ABC_FREE( pBest2 ); return pRes; } @@ -996,7 +1016,7 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR SeeAlso [] ***********************************************************************/ -word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu ) +word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio ) { Abc_BSEval_t * p = Abc_BSEvalAlloc(); int nPermVars = nVars-nRVars; @@ -1022,9 +1042,11 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int //word pPat[MAX_PAT_WORD_SIZE]; int pPermBest[32] = {0}; + int pPermBest2[32] = {0}; word * pBest = ABC_ALLOC( word, nWords ); + word * pBest2 = ABC_ALLOC( word, nWords ); //printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, nVars ); printf( "\n" ); - int MyuMin = Abc_BSEvalBest( p, pCopy, pBest, nVars, nRVars, nVars-nLutSize, 0, pPermBest, 0 ); + int MyuMin = Abc_BSEvalBest( p, pCopy, pBest, pBest2, nVars, nRVars, nVars-nLutSize, 0, pPermBest, pPermBest2, 0, nJRatio ); //printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, nVars ); printf( "\n" ); if ( pMyu ) *pMyu = MyuMin; @@ -1045,6 +1067,7 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int ABC_FREE( pCopy ); ABC_FREE( pBest ); + ABC_FREE( pBest2 ); Abc_BSEvalFree(p); if ( fVerbose )