Skip to content

Commit 3bd7bac

Browse files
committed
Improvements to "lutcasdec".
1 parent c5edc56 commit 3bd7bac

File tree

3 files changed

+97
-99
lines changed

3 files changed

+97
-99
lines changed

src/base/abci/abc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9174,9 +9174,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
91749174
extern Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int nZParam, int fXRail, int Seed, int fVerbose, int fVeryVerbose, char * pGuide );
91759175
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int nJRatio, int nZParam, int Seed, int fVerbose, int fVeryVerbose, int fPrintMyu, int fPrintLev, int fXRail );
91769176
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
9177-
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 1, nJRatio = 0, nZParam = 0, fGen = 0, fPrintMyu = 0, fPrintLev = 0, fXRail = 0, fVerbose = 0, fVeryVerbose = 0;
9177+
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, Seed = 0, nIters = 10, nJRatio = -1, nZParam = 5, fGen = 0, fPrintMyu = 0, fPrintLev = 0, fXRail = 0, fVerbose = 0, fVeryVerbose = 0;
91789178
Extra_UtilGetoptReset();
9179-
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIJZNFgmlxvwh" ) ) != EOF )
9179+
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIZNFgmlxvwh" ) ) != EOF )
91809180
{
91819181
switch ( c )
91829182
{
@@ -9364,15 +9364,15 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
93649364
return 0;
93659365

93669366
usage:
9367-
Abc_Print( -2, "usage: lutcasdec [-KMRCSIJZN <num>] [-F <file>] [-gmlxvwh]\n" );
9367+
Abc_Print( -2, "usage: lutcasdec [-KMRCSIZN <num>] [-F <file>] [-gmlxvwh]\n" );
93689368
Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" );
93699369
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
93709370
Abc_Print( -2, "\t-M <num> : the maximum delay (the number of stages) [default = %d]\n", nStages );
93719371
Abc_Print( -2, "\t-R <num> : the number of direct connections (rails) [default = %d]\n", nRails );
93729372
Abc_Print( -2, "\t-C <num> : the number of shared variables in each stage [default = %d]\n", nShared );
93739373
Abc_Print( -2, "\t-S <num> : the random seed for randomized bound-set selection [default = %d]\n", Seed );
93749374
Abc_Print( -2, "\t-I <num> : the number of iterations when looking for a solution [default = %d]\n", nIters );
9375-
Abc_Print( -2, "\t-J <num> : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio );
9375+
//Abc_Print( -2, "\t-J <num> : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio );
93769376
Abc_Print( -2, "\t-Z <num> : the number determining how many decompositions are tried [default = %d]\n", nZParam );
93779377
Abc_Print( -2, "\t-N <num> : the number of support variables (for truth table files only) [default = unused]\n" );
93789378
Abc_Print( -2, "\t-F <file>: a text file with truth tables in hexadecimal listed one per line\n");

src/base/abci/abcCas.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ 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( 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 )
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 nZParam, int fVerbose, Vec_Wrd_t * vCas, int * pMyu )
660660
{
661661
assert( Vec_IntSize(vVarIDs) > nLutSize );
662662
assert( Vec_IntSize(vVarIDs) <= 24 );
@@ -709,20 +709,25 @@ static inline int Abc_LutCascadeDecStage( word Guide0, char * pGuide, int Iter,
709709
Vec_IntShrink( vVarIDs, nFVars+nSVars+nEVars );
710710
return nEVars;
711711
}
712-
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 )
712+
713+
typedef struct Abc_BSEval_t_ Abc_BSEval_t;
714+
extern Abc_BSEval_t * Abc_BSEvalAlloc();
715+
extern void Abc_BSEvalFree( Abc_BSEval_t * p );
716+
717+
word * Abc_LutCascadeDec( Abc_BSEval_t * p, char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t * vVarIDs, int nRails, int nLutSize, int nStages, int fUseRand, int nZParam, int fXRail, int fVerbose, int * pnStages, int * pMyu )
713718
{
714-
extern Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nMyuIncrease );
719+
extern Vec_Wrd_t * Abc_TtFindBVarsSVars2( Abc_BSEval_t * p, word * pTruth, int nVars, int nCVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nMyuIncrease );
715720
word * pRes = NULL; int i, nRVars = 0, nVars = Vec_IntSize(vVarIDs);
716721
Vec_Wrd_t * vFuncs[3] = { Vec_WrdStart(Abc_TtWordNum(nVars)), Vec_WrdAlloc(0), Vec_WrdAlloc(0) };
717722
Abc_TtCopy( Vec_WrdArray(vFuncs[0]), pTruth, Abc_TtWordNum(nVars), 0 );
718723
Vec_Wrd_t * vCas = Vec_WrdAlloc( 100 ); Vec_WrdPush( vCas, nVarsOrig );
719724
if ( pnStages ) *pnStages = 0;
720725
for ( i = 0; Vec_IntSize(vVarIDs) > nLutSize; i++ ) {
721726
int nRVarsOld = nRVars;
722-
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
727+
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( p, Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
723728
if ( vGuides ) {
724-
int iEntry = nJRatio ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
725-
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails, nLutSize, nJRatio, nZParam, fVerbose, vCas, i ? NULL : pMyu );
729+
int iEntry = fUseRand ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
730+
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails, nLutSize, nZParam, fVerbose, vCas, i ? NULL : pMyu );
726731
Vec_WrdFree( vGuides );
727732
}
728733
else
@@ -733,10 +738,10 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
733738
nRVars = -1;
734739
}
735740
if ( fXRail && nRVars == -1 && Vec_IntSize(vVarIDs) > nLutSize-1 ) {
736-
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVarsOld, nRails+1, nLutSize-1, fVerbose, pMyu, nZParam );
741+
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( p, Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVarsOld, nRails+1, nLutSize-1, fVerbose, pMyu, nZParam );
737742
if ( vGuides ) {
738-
int iEntry = nJRatio ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
739-
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails+1, nLutSize-1, nJRatio, nZParam, fVerbose, vCas, NULL );
743+
int iEntry = fUseRand ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
744+
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails+1, nLutSize-1, nZParam, fVerbose, vCas, NULL );
740745
Vec_WrdFree( vGuides );
741746
}
742747
else
@@ -867,7 +872,8 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
867872
Abc_Random(1);
868873
for ( i = 0; i < Seed; i++ )
869874
Abc_Random(0);
870-
for ( int Iter = 0; Iter < nIters+nJRatio; Iter++ ) {
875+
Abc_BSEval_t * p = Abc_BSEvalAlloc();
876+
for ( int Iter = 0; Iter < nIters; Iter++ ) {
871877
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
872878
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
873879

@@ -885,7 +891,7 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
885891
printf( ".\n" );
886892
}
887893

888-
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, Iter >= nIters ? 1 : 0, nZParam, fXRail, fVeryVerbose, NULL, NULL );
894+
word * pLuts = Abc_LutCascadeDec( p, pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, (int)(Iter > 0), nZParam, fXRail, fVeryVerbose, NULL, NULL );
889895
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
890896
Vec_IntFree( vVarIDs );
891897

@@ -906,6 +912,7 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
906912
}
907913
//ABC_FREE( pTruth1 );
908914
}
915+
Abc_BSEvalFree( p );
909916
ABC_FREE( pCopy );
910917
Gia_ManStop( pGia );
911918
return pNew;
@@ -1423,6 +1430,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14231430
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
14241431
word * pCopy = ABC_ALLOC( word, nWords );
14251432
int Iter = 0, IterReal = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0};
1433+
Abc_BSEval_t * p = Abc_BSEvalAlloc();
14261434
for ( i = 0; i < nFuncs; i++ )
14271435
{
14281436
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
@@ -1446,11 +1454,11 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14461454
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize );
14471455
}
14481456

1449-
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter >= nIters), nZParam, fXRail, fVeryVerbose, &nStageCount, &MyuMin );
1457+
word * pLuts = Abc_LutCascadeDec( p, NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter > 0), nZParam, fXRail, fVeryVerbose, &nStageCount, &MyuMin );
14501458
Vec_IntFree( vVarIDs );
14511459
if ( MyuMin < 50 ) MyuStats[MyuMin]++, IterReal++;
14521460
if ( pLuts == NULL ) {
1453-
if ( ++Iter < nIters+nJRatio ) {
1461+
if ( ++Iter < nIters ) {
14541462
i--;
14551463
continue;
14561464
}
@@ -1480,6 +1488,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
14801488
ABC_FREE( pTruth2 );
14811489
ABC_FREE( pLuts );
14821490
}
1491+
Abc_BSEvalFree( p );
14831492
ABC_FREE( pCopy );
14841493
Vec_WrdFree( vTruths );
14851494
if ( fPrintMyu ) {

0 commit comments

Comments
 (0)