Skip to content

Commit 391a767

Browse files
committed
Updating LUT cascade mapping.
1 parent 6a03162 commit 391a767

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/base/abci/abcCas.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void Abc_LutBddTest( DdManager * dd, DdNode * bFunc, char ** ppNames, int nNames
332332
#else
333333

334334
Abc_Ntk_t * Abc_NtkCascade( Abc_Ntk_t * pNtk, int nLutSize, int fCheck, int fVerbose ) { return NULL; }
335-
word * Abc_LutCascade( Mini_Aig_t * p, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose ) { return NULL; }
335+
word * Abc_LutCascade( Mini_Aig_t * p, int nLutSize, int nStages, int nRails, int nIters, int fVerbose ) { return NULL; }
336336

337337
#endif
338338

@@ -716,21 +716,27 @@ static inline int Abc_LutCascadeDecStage( char * pGuide, int Iter, Vec_Wrd_t * v
716716
Vec_IntShrink( vVarIDs, nFVars+nSVars+nEVars );
717717
return nEVars;
718718
}
719-
word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t * vVarIDs, int nRails, int nLutSize, int fVerbose )
719+
word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t * vVarIDs, int nRails, int nLutSize, int nStages, int fVerbose, int * pnStages )
720720
{
721721
word * pRes = NULL; int i, nRVars = 0, nVars = Vec_IntSize(vVarIDs);
722722
Vec_Wrd_t * vFuncs[3] = { Vec_WrdStart(Abc_TtWordNum(nVars)), Vec_WrdAlloc(0), Vec_WrdAlloc(0) };
723723
Abc_TtCopy( Vec_WrdArray(vFuncs[0]), pTruth, Abc_TtWordNum(nVars), 0 );
724724
Vec_Wrd_t * vCas = Vec_WrdAlloc( 100 ); Vec_WrdPush( vCas, nVarsOrig );
725+
if ( pnStages ) *pnStages = 0;
725726
for ( i = 0; Vec_IntSize(vVarIDs) > nLutSize; i++ ) {
726727
nRVars = Abc_LutCascadeDecStage( pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, fVerbose, vCas );
728+
if ( i+2 > nStages ) {
729+
printf( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n", i+2, nStages );
730+
nRVars = -1;
731+
}
727732
if ( nRVars == -1 )
728733
break;
729734
}
730735
if ( nRVars != -1 && Vec_IntSize(vVarIDs) > 0 ) {
731736
Abc_LutCascadeGenOne( vCas, Vec_IntSize(vVarIDs), Vec_IntArray(vVarIDs), Vec_WrdEntry(vCas, 0), Vec_WrdArray(vFuncs[0]) );
732737
Vec_WrdAddToEntry( vCas, 0, -nVarsOrig );
733738
pRes = Vec_WrdReleaseArray(vCas);
739+
if ( pnStages ) *pnStages = i+1;
734740
}
735741
Vec_WrdFree( vCas );
736742
for ( i = 0; i < 3; i++ )
@@ -814,25 +820,24 @@ Abc_Ntk_t * Abc_NtkLutCascadeFromLuts( word * pLuts, int nVars, Abc_Ntk_t * pNtk
814820
}
815821
return pNtkNew;
816822
}
817-
Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose )
823+
Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int nRails, int nIters, int fVerbose )
818824
{
819825
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
820826
extern Mini_Aig_t * Gia_ManToMiniAig( Gia_Man_t * pGia );
821-
extern word * Abc_LutCascade( Mini_Aig_t * p, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
827+
//extern word * Abc_LutCascade( Mini_Aig_t * p, int nLutSize, int nStages, int nRails, int nIters, int fVerbose );
822828
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
823829
Mini_Aig_t * pM = Gia_ManToMiniAig( pGia );
824-
//word * pLuts = Abc_LutCascade( pM, nLutSize, nLuts, nRails, nIters, fVerbose );
830+
//word * pLuts = Abc_LutCascade( pM, nLutSize, nStages, nRails, nIters, fVerbose );
825831
word * pLuts = Abc_LutCascadeTest( pM, nLutSize, 0 );
826832
Abc_Ntk_t * pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
827833
ABC_FREE( pLuts );
828834
Mini_AigStop( pM );
829835
Gia_ManStop( pGia );
830836
return pNew;
831837
}
832-
Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, char * pGuide )
838+
Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int nRails, int nIters, int Seed, int fVerbose, char * pGuide )
833839
{
834840
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
835-
extern word * Abc_LutCascade2( word * p, int nVars, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
836841
int i, nWords = Abc_TtWordNum(Abc_NtkCiNum(pNtk));
837842
word * pCopy = ABC_ALLOC( word, nWords );
838843
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
@@ -858,7 +863,7 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int n
858863
printf( ".\n" );
859864
}
860865

861-
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, fVerbose );
866+
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, fVerbose, NULL );
862867
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
863868
Vec_IntFree( vVarIDs );
864869

@@ -1371,10 +1376,10 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
13711376
SeeAlso []
13721377
13731378
***********************************************************************/
1374-
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, int fVeryVerbose )
1379+
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, int nRails, int nIters, int Seed, int fVerbose, int fVeryVerbose )
13751380
{
13761381
abctime clkStart = Abc_Clock();
1377-
int i, Sum = 0, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig);
1382+
int i, Sum = 0, nStageCount, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig);
13781383
Vec_Wrd_t * vTruths = NULL;
13791384
if ( strstr(pFileName, ".txt") )
13801385
vTruths = Abc_NtkLutCasReadTruths( pFileName, nVarsOrig );
@@ -1392,7 +1397,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
13921397

13931398
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
13941399
word * pCopy = ABC_ALLOC( word, nWords );
1395-
int Iter = 0, LutStats[100] = {0};
1400+
int Iter = 0, LutStats[100] = {0}, StageStats[100] = {0};
13961401
Abc_Random(1);
13971402
for ( i = 0; i < Seed; i++ )
13981403
Abc_Random(0);
@@ -1419,7 +1424,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14191424
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize );
14201425
}
14211426

1422-
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, fVeryVerbose );
1427+
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, fVeryVerbose, &nStageCount );
14231428
Vec_IntFree( vVarIDs );
14241429
if ( pLuts == NULL ) {
14251430
if ( ++Iter < nIters ) {
@@ -1435,6 +1440,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14351440
Sum++;
14361441
nTotalLuts += Abc_LutCascadeCount(pLuts);
14371442
LutStats[Abc_LutCascadeCount(pLuts)]++;
1443+
StageStats[nStageCount]++;
14381444
word * pTruth2 = Abc_LutCascadeTruth( pLuts, nVarsOrig );
14391445
if ( fVeryVerbose )
14401446
Abc_LutCascadePrint( pLuts );
@@ -1452,10 +1458,14 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14521458
}
14531459
ABC_FREE( pCopy );
14541460
Vec_WrdFree( vTruths );
1455-
printf( "Statistics for %d-rail LUT cascade:\n", nRails );
1461+
printf( "Level count statistics for %d-rail LUT cascade:\n", nRails );
1462+
for ( i = 0; i < 100; i++ )
1463+
if ( StageStats[i] )
1464+
printf( " %2d level : Function count = %8d (%6.2f %%)\n", i, StageStats[i], 100.0*StageStats[i]/nFuncs );
1465+
printf( "LUT count statistics for %d-rail LUT cascade:\n", nRails );
14561466
for ( i = 0; i < 100; i++ )
14571467
if ( LutStats[i] )
1458-
printf( " %2d LUT%d : Function count = %8d (%6.2f %%)\n", i, nLutSize, LutStats[i], 100.0*LutStats[i]/nFuncs );
1468+
printf( " %2d LUT%d : Function count = %8d (%6.2f %%)\n", i, nLutSize, LutStats[i], 100.0*LutStats[i]/nFuncs );
14591469
printf( "Non-decomp : Function count = %8d (%6.2f %%)\n", nFuncs-Sum, 100.0*(nFuncs-Sum)/Abc_MaxInt(1, nFuncs) );
14601470
printf( "Finished %d functions (%.2f LUTs / function; %.2f functions / sec). ",
14611471
nFuncs, 1.0*nTotalLuts/Sum, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );

0 commit comments

Comments
 (0)