Skip to content

Commit c5edc56

Browse files
committed
Improvements to "lutcasdec".
1 parent 29c8d3e commit c5edc56

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/base/abci/abcCas.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -658,18 +658,9 @@ void Abc_LutCascadeDerive( word * p, int nVars, int nBVars, int Myu, word * pRem
658658
// performs decomposition of one stage
659659
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 )
660660
{
661-
//extern word Abc_TtFindBVarsSVars( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio );
662-
//extern word Abc_TtFindBVarsSVars2( word * p, int nVars, int nRVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nJRatio );
663661
assert( Vec_IntSize(vVarIDs) > nLutSize );
664662
assert( Vec_IntSize(vVarIDs) <= 24 );
665-
//word Guide = pGuide ? 0 : Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
666663
word Guide = pGuide ? 0 : Guide0;
667-
if ( !pGuide && !Guide ) {
668-
if ( fVerbose )
669-
printf( "The function is not decomposable with %d rails.\n", nRails );
670-
//Vec_IntClear( vVarIDs );
671-
return -1;
672-
}
673664
int m, Myu = pGuide ? 1 << nRails : (Guide >> 48) & 0xFF;
674665
int nEVars = Abc_Base2Log(Myu);
675666
int nVars = Vec_IntSize(vVarIDs);
@@ -730,9 +721,9 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
730721
int nRVarsOld = nRVars;
731722
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
732723
if ( vGuides ) {
733-
word Guide0 = Vec_WrdEntry(vGuides, 0);
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 );
734726
Vec_WrdFree( vGuides );
735-
nRVars = Abc_LutCascadeDecStage( Guide0, pGuide, i, vFuncs, vVarIDs, nRVars, nRails, nLutSize, nJRatio, nZParam, fVerbose, vCas, i ? NULL : pMyu );
736727
}
737728
else
738729
nRVars = -1;
@@ -741,12 +732,12 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
741732
printf( "The length of the cascade (%d) exceeds the max allowed number of stages (%d).\n", i+2, nStages );
742733
nRVars = -1;
743734
}
744-
if ( nRVars == -1 && Vec_IntSize(vVarIDs) > nLutSize-1 && fXRail ) {
735+
if ( fXRail && nRVars == -1 && Vec_IntSize(vVarIDs) > nLutSize-1 ) {
745736
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVarsOld, nRails+1, nLutSize-1, fVerbose, pMyu, nZParam );
746737
if ( vGuides ) {
747-
word Guide0 = Vec_WrdEntry(vGuides, 0);
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 );
748740
Vec_WrdFree( vGuides );
749-
nRVars = Abc_LutCascadeDecStage( Guide0, pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails+1, nLutSize-1, nJRatio, nZParam, fVerbose, vCas, NULL );
750741
}
751742
else
752743
nRVars = -1;
@@ -758,6 +749,8 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
758749
}
759750
if ( nRVars == -1 ) {
760751
Vec_IntClear( vVarIDs );
752+
if ( fVerbose )
753+
printf( "The function is not decomposable with %d rails.\n", nRails );
761754
break;
762755
}
763756
}

src/misc/util/utilBSet.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,12 +1047,14 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
10471047
int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32];
10481048
for ( i = 0; i < nVars; i++ )
10491049
Pla2Var[i] = Var2Pla[i] = i;
1050-
int MyuBest = 1 << nVars;
1050+
int MyuOrigBest = 1 << nVars;
1051+
int MyuBest = 1 << nVars;
10511052
int nSetSizeBest = nVars;
10521053

10531054
if ( pMyu ) *pMyu = 1 << nVars;
10541055
Vec_IntForEachEntryDouble( p->vPairs, Var0, Var1, i ) {
10551056
int MyuThis = Abc_TtGetCM( pCopy, nVars, nFVars, p->vCounts, p->vTable, p->vStore, p->vUsed, 0 );
1057+
MyuOrigBest = Abc_MinInt( MyuOrigBest, MyuThis );
10561058
if ( pMyu ) *pMyu = Abc_MinInt( *pMyu, MyuThis );
10571059
if ( fVerbose )
10581060
{
@@ -1067,7 +1069,7 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
10671069
printf( " %d", Pla2Var[k] );
10681070
printf( " : Myu = %3d", MyuThis );
10691071
}
1070-
if ( MyuThis <= MyuBest + nMyuIncrease ) {
1072+
if ( MyuThis <= MyuOrigBest + nMyuIncrease ) {
10711073
int Shared = 0, nSetSize = 0;
10721074
if ( MyuThis > 2 ) {
10731075
int SharedThis = 0, nSetSizeThis = 0;
@@ -1086,7 +1088,7 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
10861088
}
10871089
}
10881090
if ( MyuBest > MyuThis || (MyuBest == MyuThis && nSetSizeBest >= nSetSize) ) {
1089-
int fSave = MyuBest == MyuThis && nSetSizeBest == nSetSize;
1091+
int fSave = (MyuBest == MyuThis && nSetSizeBest == nSetSize);
10901092
MyuBest = MyuThis;
10911093
nSetSizeBest = nSetSize;
10921094
word Result = Abc_BSEvalEncode( Pla2Var, nVars, p->nBVars, Shared, MyuBest, nSetSize );
@@ -1097,7 +1099,7 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
10971099
if ( fVerbose )
10981100
printf( " <== best" );
10991101
}
1100-
}
1102+
}
11011103
if ( fVerbose )
11021104
printf( "\n" );
11031105
int iPlace0 = Var2Pla[Var0];
@@ -1126,13 +1128,14 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
11261128
}
11271129
if ( !Abc_TtEqual(pCopy, pTruth, nWords) )
11281130
printf( "Internal truth table check failed.\n" );
1129-
//printf( "%d ", Count );
1130-
1131+
11311132
Abc_BSEvalFree(p);
11321133
if ( MyuBest > (1 << nRails) ) {
11331134
Vec_WrdFree(vRes);
11341135
return NULL;
11351136
}
1137+
if ( fVerbose )
1138+
printf( "COllected %d solutions with MyuMin = %d and SharedSize = %d.\n", Vec_WrdSize(vRes), MyuBest, nSetSizeBest );
11361139
return vRes;
11371140
}
11381141

0 commit comments

Comments
 (0)