Skip to content

Commit c0be439

Browse files
committed
Performance improvements.
1 parent 1b6b553 commit c0be439

File tree

3 files changed

+71
-46
lines changed

3 files changed

+71
-46
lines changed

src/base/abci/abc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9059,7 +9059,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
90599059
extern Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, char * pGuide );
90609060
extern void Abc_NtkLutCascadeFile( char * pFileName, int nVarNum, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose );
90619061
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
9062-
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, nIters = 1, fGen = 0, fVerbose = 0, fVeryVerbose = 0;
9062+
int c, nVarNum = -1, nLutSize = 6, nStages = 8, nRails = 1, nShared = 2, nIters = 10, fGen = 0, fVerbose = 0, fVeryVerbose = 0;
90639063
Extra_UtilGetoptReset();
90649064
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSINFgvwh" ) ) != EOF )
90659065
{

src/base/abci/abcCas.c

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -621,46 +621,51 @@ Abc_Ntk_t * Abc_NtkLutCascade2( Abc_Ntk_t * pNtk, int nLutSize, int nLuts, int n
621621
{
622622
extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
623623
extern word * Abc_LutCascade2( word * p, int nVars, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose );
624-
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
625-
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
626624
int nWords = Abc_TtWordNum(Abc_NtkCiNum(pNtk));
627625
word * pCopy = ABC_ALLOC( word, nWords );
628-
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
626+
Gia_Man_t * pGia = Abc_NtkStrashToGia( pNtk );
627+
Abc_Ntk_t * pNew = NULL;
628+
Abc_Random(1);
629+
for ( int Iter = 0; Iter < nIters; Iter++ ) {
630+
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
631+
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
629632

630-
int nVars = -1;
631-
Vec_Int_t * vVarIDs = Vec_IntStartNatural( Abc_NtkCiNum(pNtk) );
632-
Abc_TtMinimumBase( pTruth1, Vec_IntArray(vVarIDs), Abc_NtkCiNum(pNtk), &nVars );
633-
Vec_IntShrink( vVarIDs, nVars );
634-
if ( fVerbose ) {
635-
if ( Abc_NtkCiNum(pNtk) != nVars )
636-
printf( "The support of the function is reduced from %d to %d variables.\n", Abc_NtkCiNum(pNtk), nVars );
637-
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs", nVars, nRails, nLutSize );
638-
if ( pGuide )
639-
printf( " using structural info: %s", pGuide );
640-
printf( ".\n" );
641-
}
633+
int nVars = -1;
634+
Vec_Int_t * vVarIDs = Vec_IntStartNatural( Abc_NtkCiNum(pNtk) );
635+
Abc_TtMinimumBase( pTruth1, Vec_IntArray(vVarIDs), Abc_NtkCiNum(pNtk), &nVars );
636+
Vec_IntShrink( vVarIDs, nVars );
637+
if ( fVerbose ) {
638+
if ( Abc_NtkCiNum(pNtk) != nVars )
639+
printf( "The support of the function is reduced from %d to %d variables.\n", Abc_NtkCiNum(pNtk), nVars );
640+
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs", nVars, nRails, nLutSize );
641+
if ( pGuide )
642+
printf( " using structural info: %s", pGuide );
643+
printf( ".\n" );
644+
}
642645

643-
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, fVerbose );
644-
Abc_Ntk_t * pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
645-
Vec_IntFree( vVarIDs );
646-
647-
if ( pLuts ) {
648-
if ( fVerbose )
649-
Abc_LutCascadePrint( pLuts );
650-
word * pTruth2 = Abc_LutCascadeTruth( pLuts, Abc_NtkCiNum(pNtk) );
651-
if ( !Abc_TtEqual(pCopy, pTruth2, nWords) ) {
652-
printf( "Verification FAILED.\n" );
653-
printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, Abc_NtkCiNum(pNtk) ); printf( "\n" );
654-
printf("Function after: "); Abc_TtPrintHexRev( stdout, pTruth2, Abc_NtkCiNum(pNtk) ); printf( "\n" );
646+
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, fVerbose );
647+
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
648+
Vec_IntFree( vVarIDs );
649+
650+
if ( pLuts ) {
651+
if ( fVerbose )
652+
Abc_LutCascadePrint( pLuts );
653+
word * pTruth2 = Abc_LutCascadeTruth( pLuts, Abc_NtkCiNum(pNtk) );
654+
if ( !Abc_TtEqual(pCopy, pTruth2, nWords) ) {
655+
printf( "Verification FAILED.\n" );
656+
printf("Function before: "); Abc_TtPrintHexRev( stdout, pCopy, Abc_NtkCiNum(pNtk) ); printf( "\n" );
657+
printf("Function after: "); Abc_TtPrintHexRev( stdout, pTruth2, Abc_NtkCiNum(pNtk) ); printf( "\n" );
658+
}
659+
else if ( fVerbose )
660+
printf( "Verification passed.\n" );
661+
ABC_FREE( pLuts );
662+
ABC_FREE( pTruth2 );
663+
break;
655664
}
656-
else if ( fVerbose )
657-
printf( "Verification passed.\n" );
658-
ABC_FREE( pLuts );
659-
ABC_FREE( pTruth2 );
665+
//ABC_FREE( pTruth1 );
660666
}
661-
Gia_ManStop( pGia );
662667
ABC_FREE( pCopy );
663-
//ABC_FREE( pTruth1 );
668+
Gia_ManStop( pGia );
664669
return pNew;
665670
}
666671
Abc_Ntk_t * Abc_NtkLutCascadeGen( int nLutSize, int nStages, int nRails, int nShared, int fVerbose )
@@ -1154,7 +1159,7 @@ Vec_Wrd_t * Abc_NtkLutCasReadTruths( char * pFileName, int nVarsOrig )
11541159
void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int nLuts, int nRails, int nIters, int fVerbose, int fVeryVerbose )
11551160
{
11561161
abctime clkStart = Abc_Clock();
1157-
int i, Sum = 0, nWords = Abc_TtWordNum(nVarsOrig);
1162+
int i, Sum = 0, nTotalLuts = 0, nWords = Abc_TtWordNum(nVarsOrig);
11581163
Vec_Wrd_t * vTruths = NULL;
11591164
if ( strstr(pFileName, ".txt") )
11601165
vTruths = Abc_NtkLutCasReadTruths( pFileName, nVarsOrig );
@@ -1172,7 +1177,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
11721177

11731178
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
11741179
word * pCopy = ABC_ALLOC( word, nWords );
1175-
int LutStats[100] = {0};
1180+
int Iter = 0, LutStats[100] = {0};
1181+
Abc_Random(1);
11761182
for ( i = 0; i < nFuncs; i++ )
11771183
{
11781184
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
@@ -1195,15 +1201,22 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
11951201
printf( "The support of the function is reduced from %d to %d variables.\n", nVarsOrig, nVars );
11961202
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize );
11971203
}
1198-
1204+
11991205
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, fVeryVerbose );
12001206
Vec_IntFree( vVarIDs );
12011207
if ( pLuts == NULL ) {
1208+
if ( ++Iter < nIters ) {
1209+
i--;
1210+
continue;
1211+
}
1212+
Iter = 0;
12021213
if ( fVerbose || fVeryVerbose )
12031214
printf( "Not decomposable.\n" );
12041215
continue;
12051216
}
1217+
Iter = 0;
12061218
Sum++;
1219+
nTotalLuts += Abc_LutCascadeCount(pLuts);
12071220
LutStats[Abc_LutCascadeCount(pLuts)]++;
12081221
word * pTruth2 = Abc_LutCascadeTruth( pLuts, nVarsOrig );
12091222
if ( fVeryVerbose )
@@ -1227,7 +1240,8 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
12271240
if ( LutStats[i] )
12281241
printf( " %d LUT6 : Function count = %8d (%6.2f %%)\n", i, LutStats[i], 100.0*LutStats[i]/nFuncs );
12291242
printf( "Non-decomp : Function count = %8d (%6.2f %%)\n", nFuncs-Sum, 100.0*(nFuncs-Sum)/Abc_MaxInt(1, nFuncs) );
1230-
printf( "Finished %d functions (speed = %.2f functions / second). ", nFuncs, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );
1243+
printf( "Finished %d functions (%.2f LUTs / function; %.2f functions / sec). ",
1244+
nFuncs, 1.0*nTotalLuts/Sum, 1.0*nFuncs/(((double)(Abc_Clock() - clkStart))/((double)CLOCKS_PER_SEC)) );
12311245
Abc_PrintTime( 0, "Total time", Abc_Clock() - clkStart );
12321246
}
12331247

src/misc/util/utilBSet.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void Abc_BSEvalOneTest( word * pT, int nVars, int nBVars, int fVerbose )
589589
int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int fShared )
590590
{
591591
int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32];
592-
int nPermVars = nVars-nCVars;
592+
int nPermVars = nVars-nCVars, Count = 0;
593593
assert( p->nVars == nPermVars && p->nBVars == nVars-nFVars );
594594
for ( i = 0; i < nVars; i++ )
595595
Pla2Var[i] = Var2Pla[i] = i;
@@ -605,6 +605,11 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, int nVars, int n
605605
CostBest = CostThis;
606606
if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 );
607607
if ( pPermBest ) memcpy( pPermBest, Pla2Var, sizeof(int)*nVars );
608+
Count = 1;
609+
}
610+
else if ( CostBest == CostThis && (Abc_Random(0) % ++Count) == 0 ) {
611+
if ( pBest ) Abc_TtCopy( pBest, pIn, Abc_Truth6WordNum(nVars), 0 );
612+
if ( pPermBest ) memcpy( pPermBest, Pla2Var, sizeof(int)*nVars );
608613
}
609614
if ( fVerbose )
610615
{
@@ -922,7 +927,7 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR
922927
word * pTruth = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
923928
word * pBest = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
924929
Abc_TtCopy( pTruth, pFunc, Abc_TtWordNum(nVars), 0 );
925-
int i, nVarsCur = nVars, nOutVars = 0;
930+
int i, r, nVarsCur = nVars, nOutVars = 0;
926931
while ( nVarsCur > nLutSize )
927932
{
928933
int pPerm[32] = {0};
@@ -943,8 +948,12 @@ word * Abc_LutCascade2( word * pFunc, int nVars, int nLutSize, int nLuts, int nR
943948
}
944949
int MyuMin = Abc_BSEvalBest( p, pTruth, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, fVerbose, pPerm, 0 );
945950
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
946-
if ( nRailsMin > nRails )
947-
nRailsMin = Abc_SharedEvalBest( p, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, MyuMin, nRails, fVerbose, &Shared, p->pPat );
951+
for ( r = 1; r <= nRails && nRailsMin > r; r++ ) {
952+
int nRailsMinNew = Abc_SharedEvalBest( p, pBest, nVarsCur, nOutVars, nVarsCur-nLutSize, MyuMin, nRails, fVerbose, &Shared, p->pPat );
953+
if ( nRailsMinNew < 100 )
954+
nRailsMin = nRailsMinNew;
955+
}
956+
MyuMin = 1 << nRailsMin;
948957
if ( nRailsMin > nRails ) {
949958
Vec_WrdFreeP( &vRes );
950959
break;
@@ -1007,7 +1016,7 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int
10071016
p->nBVars = nLutSize;
10081017
}
10091018

1010-
int v, nWords = Abc_TtWordNum(nVars);
1019+
int v, r, nWords = Abc_TtWordNum(nVars);
10111020
word * pCopy = ABC_ALLOC( word, nWords );
10121021
Abc_TtCopy( pCopy, pTruth, nWords, 0 );
10131022
//word pPat[MAX_PAT_WORD_SIZE];
@@ -1026,10 +1035,12 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int
10261035
}
10271036

10281037
int Shared = 0, nRailsMin = Abc_Base2Log( MyuMin );
1029-
if ( nRailsMin > nRails ) {
1030-
nRailsMin = Abc_SharedEvalBest( p, pBest, nVars, nRVars, nVars-nLutSize, MyuMin, nRails, 0, &Shared, p->pPat );
1031-
MyuMin = 1 << nRailsMin;
1038+
for ( r = 1; r <= nRails && nRailsMin > r; r++ ) {
1039+
int nRailsMinNew = Abc_SharedEvalBest( p, pBest, nVars, nRVars, nVars-nLutSize, MyuMin, r, 0, &Shared, p->pPat );
1040+
if ( nRailsMinNew < 100 )
1041+
nRailsMin = nRailsMinNew;
10321042
}
1043+
MyuMin = 1 << nRailsMin;
10331044

10341045
ABC_FREE( pCopy );
10351046
ABC_FREE( pBest );

0 commit comments

Comments
 (0)