Skip to content

Commit d245305

Browse files
committed
Improvements to "lutcasdec".
1 parent c85f007 commit d245305

File tree

3 files changed

+75
-34
lines changed

3 files changed

+75
-34
lines changed

src/base/abci/abc.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9167,12 +9167,12 @@ int Abc_CommandCascade( Abc_Frame_t * pAbc, int argc, char ** argv )
91679167
int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
91689168
{
91699169
extern Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose );
9170-
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, char * pGuide );
9171-
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int Seed, int fVerbose, int fVeryVerbose );
9170+
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 );
9171+
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 );
91729172
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
9173-
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, fGen = 0, fVerbose = 0, fVeryVerbose = 0;
9173+
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;
91749174
Extra_UtilGetoptReset();
9175-
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCINFgvwh" ) ) != EOF )
9175+
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIJNFgmvwh" ) ) != EOF )
91769176
{
91779177
switch ( c )
91789178
{
@@ -9242,6 +9242,17 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
92429242
if ( nIters < 0 )
92439243
goto usage;
92449244
break;
9245+
case 'J':
9246+
if ( globalUtilOptind >= argc )
9247+
{
9248+
Abc_Print( -1, "Command line switch \"-J\" should be followed by an integer.\n" );
9249+
goto usage;
9250+
}
9251+
nJRatio = atoi(argv[globalUtilOptind]);
9252+
globalUtilOptind++;
9253+
if ( nJRatio < 0 )
9254+
goto usage;
9255+
break;
92459256
case 'N':
92469257
if ( globalUtilOptind >= argc )
92479258
{
@@ -9265,6 +9276,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
92659276
case 'g':
92669277
fGen ^= 1;
92679278
break;
9279+
case 'm':
9280+
fPrintMyu ^= 1;
9281+
break;
92689282
case 'v':
92699283
fVerbose ^= 1;
92709284
break;
@@ -9284,7 +9298,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
92849298
Abc_Print( -1, "The number of variables should be given on the command line using switch \"-N <num>\".\n" );
92859299
return 1;
92869300
}
9287-
Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, Seed, fVerbose, fVeryVerbose );
9301+
Abc_NtkLutCascadeFile( pFileName, nVarNum, nLutSize, nStages, nRails, nIters, nJRatio, Seed, fVerbose, fVeryVerbose, fPrintMyu );
92889302
return 1;
92899303
}
92909304
if ( fGen )
@@ -9321,7 +9335,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
93219335
}
93229336
if ( argc == globalUtilOptind + 1 )
93239337
pGuide = argv[globalUtilOptind];
9324-
pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nStages, nRails, nIters, Seed, fVerbose, pGuide );
9338+
pNtkRes = Abc_NtkLutCascade2( pNtk, nLutSize, nStages, nRails, nIters, nJRatio, Seed, fVerbose, pGuide );
93259339
if ( pNtkRes == NULL )
93269340
{
93279341
Abc_Print( -1, "LUT cascade mapping failed.\n" );
@@ -9331,19 +9345,21 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
93319345
return 0;
93329346

93339347
usage:
9334-
Abc_Print( -2, "usage: lutcasdec [-KMRCSIN <num>] [-F <file>] [-vwh]\n" );
9348+
Abc_Print( -2, "usage: lutcasdec [-KMRCSIJN <num>] [-F <file>] [-gmvwh]\n" );
93359349
Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" );
93369350
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
93379351
Abc_Print( -2, "\t-M <num> : the maximum delay (the number of stages) [default = %d]\n", nStages );
93389352
Abc_Print( -2, "\t-R <num> : the number of direct connections (rails) [default = %d]\n", nRails );
93399353
Abc_Print( -2, "\t-C <num> : the number of shared variables in each stage [default = %d]\n", nShared );
93409354
Abc_Print( -2, "\t-S <num> : the random seed for randomized bound-set selection [default = %d]\n", Seed );
93419355
Abc_Print( -2, "\t-I <num> : the number of iterations when looking for a solution [default = %d]\n", nIters );
9356+
Abc_Print( -2, "\t-J <num> : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio );
93429357
Abc_Print( -2, "\t-N <num> : the number of support variables (for truth table files only) [default = unused]\n" );
93439358
Abc_Print( -2, "\t-F <file>: a text file with truth tables in hexadecimal listed one per line\n");
93449359
Abc_Print( -2, "\t-g : toggle generating random cascade with these parameters [default = %s]\n", fGen? "yes": "no" );
9360+
Abc_Print( -2, "\t-m : toggle printing column multiplicity statistics [default = %s]\n", fPrintMyu? "yes": "no" );
93459361
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
9346-
Abc_Print( -2, "\t-w : toggle additional verbose printout [default = %s]\n", fVerbose? "yes": "no" );
9362+
Abc_Print( -2, "\t-w : toggle additional verbose printout [default = %s]\n", fVeryVerbose? "yes": "no" );
93479363
Abc_Print( -2, "\t-h : print the command usage\n");
93489364
return 1;
93499365
}

src/base/abci/abcCas.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,12 @@ 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 fVerbose, Vec_Wrd_t * vCas, int * pMyu )
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 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 );
661+
extern word Abc_TtFindBVarsSVars( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio );
662662
assert( Vec_IntSize(vVarIDs) > nLutSize );
663663
assert( Vec_IntSize(vVarIDs) <= 24 );
664-
word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu );
664+
word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nJRatio );
665665
if ( !pGuide && !Guide ) {
666666
if ( fVerbose )
667667
printf( "The function is not decomposable with %d rails.\n", nRails );
@@ -716,15 +716,15 @@ 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 nStages, int fVerbose, int * pnStages, int * pMyu )
719+
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 )
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 );
725725
if ( pnStages ) *pnStages = 0;
726726
for ( i = 0; Vec_IntSize(vVarIDs) > nLutSize; i++ ) {
727-
nRVars = Abc_LutCascadeDecStage( pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, fVerbose, vCas, i ? NULL : pMyu );
727+
nRVars = Abc_LutCascadeDecStage( pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, nJRatio, fVerbose, vCas, i ? NULL : pMyu );
728728
if ( i+2 > nStages ) {
729729
printf( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n", i+2, nStages );
730730
nRVars = -1;
@@ -835,7 +835,7 @@ Abc_Ntk_t * Abc_NtkLutCascade( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int
835835
Gia_ManStop( pGia );
836836
return pNew;
837837
}
838-
Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, 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 nJRatio, int Seed, int fVerbose, char * pGuide )
839839
{
840840
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
841841
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
845845
Abc_Random(1);
846846
for ( i = 0; i < Seed; i++ )
847847
Abc_Random(0);
848-
for ( int Iter = 0; Iter < nIters; Iter++ ) {
848+
for ( int Iter = 0; Iter < nIters+nJRatio; Iter++ ) {
849849
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
850850
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
851851

@@ -863,7 +863,7 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nStages, int
863863
printf( ".\n" );
864864
}
865865

866-
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, fVerbose, NULL, NULL );
866+
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, Iter >= nIters ? 1 : 0, fVerbose, NULL, NULL );
867867
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
868868
Vec_IntFree( vVarIDs );
869869

@@ -1376,7 +1376,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
13761376
SeeAlso []
13771377
13781378
***********************************************************************/
1379-
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nStages, 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 nJRatio, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu )
13801380
{
13811381
abctime clkStart = Abc_Clock();
13821382
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
13951395
return;
13961396
}
13971397

1398-
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
1399-
word * pCopy = ABC_ALLOC( word, nWords );
1400-
int Iter = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0};
14011398
Abc_Random(1);
14021399
for ( i = 0; i < Seed; i++ )
14031400
Abc_Random(0);
1401+
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
1402+
word * pCopy = ABC_ALLOC( word, nWords );
1403+
int Iter = 0, IterReal = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0};
14041404
for ( i = 0; i < nFuncs; i++ )
14051405
{
14061406
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
@@ -1424,11 +1424,11 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14241424
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize );
14251425
}
14261426

1427-
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, fVeryVerbose, &nStageCount, &MyuMin );
1427+
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter >= nIters), fVeryVerbose, &nStageCount, &MyuMin );
14281428
Vec_IntFree( vVarIDs );
1429-
if ( MyuMin < 50 ) MyuStats[MyuMin]++;
1429+
if ( MyuMin < 50 ) MyuStats[MyuMin]++, IterReal++;
14301430
if ( pLuts == NULL ) {
1431-
if ( ++Iter < nIters ) {
1431+
if ( ++Iter < nIters+nJRatio ) {
14321432
i--;
14331433
continue;
14341434
}
@@ -1460,10 +1460,12 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14601460
}
14611461
ABC_FREE( pCopy );
14621462
Vec_WrdFree( vTruths );
1463-
printf( "Column multiplicity statistics for %d-rail LUT cascade:\n", nRails );
1464-
for ( i = 0; i < 50; i++ )
1465-
if ( MyuStats[i] )
1466-
printf( " %2d Myu : Function count = %8d (%6.2f %%)\n", i, MyuStats[i], 100.0*MyuStats[i]/nFuncs/nIters );
1463+
if ( fPrintMyu ) {
1464+
printf( "Column multiplicity statistics for %d-rail LUT cascade:\n", nRails );
1465+
for ( i = 0; i < 50; i++ )
1466+
if ( MyuStats[i] )
1467+
printf( " %2d Myu : Function count = %8d (%6.2f %%)\n", i, MyuStats[i], 100.0*MyuStats[i]/nFuncs/IterReal );
1468+
}
14671469
printf( "Level count statistics for %d-rail LUT cascade:\n", nRails );
14681470
for ( i = 0; i < 50; i++ )
14691471
if ( StageStats[i] )

0 commit comments

Comments
 (0)