mirror of https://github.com/YosysHQ/abc.git
Improvements to "lutcasdec".
This commit is contained in:
parent
c5edc566ff
commit
3bd7bac552
|
|
@ -9174,9 +9174,9 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
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 );
|
||||
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 );
|
||||
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc), * pNtkRes; char * pGuide = NULL, * pFileName = NULL;
|
||||
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;
|
||||
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;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIJZNFgmlxvwh" ) ) != EOF )
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "KMRSCIZNFgmlxvwh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
|
|
@ -9364,7 +9364,7 @@ int Abc_CommandLutCasDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
return 0;
|
||||
|
||||
usage:
|
||||
Abc_Print( -2, "usage: lutcasdec [-KMRCSIJZN <num>] [-F <file>] [-gmlxvwh]\n" );
|
||||
Abc_Print( -2, "usage: lutcasdec [-KMRCSIZN <num>] [-F <file>] [-gmlxvwh]\n" );
|
||||
Abc_Print( -2, "\t decomposes the primary output functions into LUT cascades\n" );
|
||||
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
|
||||
Abc_Print( -2, "\t-M <num> : the maximum delay (the number of stages) [default = %d]\n", nStages );
|
||||
|
|
@ -9372,7 +9372,7 @@ usage:
|
|||
Abc_Print( -2, "\t-C <num> : the number of shared variables in each stage [default = %d]\n", nShared );
|
||||
Abc_Print( -2, "\t-S <num> : the random seed for randomized bound-set selection [default = %d]\n", Seed );
|
||||
Abc_Print( -2, "\t-I <num> : the number of iterations when looking for a solution [default = %d]\n", nIters );
|
||||
Abc_Print( -2, "\t-J <num> : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio );
|
||||
//Abc_Print( -2, "\t-J <num> : toggle using random bound-set every this many iterations [default = %d]\n", nJRatio );
|
||||
Abc_Print( -2, "\t-Z <num> : the number determining how many decompositions are tried [default = %d]\n", nZParam );
|
||||
Abc_Print( -2, "\t-N <num> : the number of support variables (for truth table files only) [default = unused]\n" );
|
||||
Abc_Print( -2, "\t-F <file>: a text file with truth tables in hexadecimal listed one per line\n");
|
||||
|
|
|
|||
|
|
@ -656,7 +656,7 @@ void Abc_LutCascadeDerive( word * p, int nVars, int nBVars, int Myu, word * pRem
|
|||
}
|
||||
|
||||
// performs decomposition of one stage
|
||||
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 )
|
||||
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 )
|
||||
{
|
||||
assert( Vec_IntSize(vVarIDs) > nLutSize );
|
||||
assert( Vec_IntSize(vVarIDs) <= 24 );
|
||||
|
|
@ -709,9 +709,14 @@ static inline int Abc_LutCascadeDecStage( word Guide0, char * pGuide, int Iter,
|
|||
Vec_IntShrink( vVarIDs, nFVars+nSVars+nEVars );
|
||||
return nEVars;
|
||||
}
|
||||
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 )
|
||||
|
||||
typedef struct Abc_BSEval_t_ Abc_BSEval_t;
|
||||
extern Abc_BSEval_t * Abc_BSEvalAlloc();
|
||||
extern void Abc_BSEvalFree( Abc_BSEval_t * p );
|
||||
|
||||
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 )
|
||||
{
|
||||
extern Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nMyuIncrease );
|
||||
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 );
|
||||
word * pRes = NULL; int i, nRVars = 0, nVars = Vec_IntSize(vVarIDs);
|
||||
Vec_Wrd_t * vFuncs[3] = { Vec_WrdStart(Abc_TtWordNum(nVars)), Vec_WrdAlloc(0), Vec_WrdAlloc(0) };
|
||||
Abc_TtCopy( Vec_WrdArray(vFuncs[0]), pTruth, Abc_TtWordNum(nVars), 0 );
|
||||
|
|
@ -719,10 +724,10 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
|
|||
if ( pnStages ) *pnStages = 0;
|
||||
for ( i = 0; Vec_IntSize(vVarIDs) > nLutSize; i++ ) {
|
||||
int nRVarsOld = nRVars;
|
||||
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
|
||||
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( p, Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVars, nRails, nLutSize, fVerbose, pMyu, nZParam );
|
||||
if ( vGuides ) {
|
||||
int iEntry = nJRatio ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
|
||||
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails, nLutSize, nJRatio, nZParam, fVerbose, vCas, i ? NULL : pMyu );
|
||||
int iEntry = fUseRand ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
|
||||
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails, nLutSize, nZParam, fVerbose, vCas, i ? NULL : pMyu );
|
||||
Vec_WrdFree( vGuides );
|
||||
}
|
||||
else
|
||||
|
|
@ -733,10 +738,10 @@ word * Abc_LutCascadeDec( char * pGuide, word * pTruth, int nVarsOrig, Vec_Int_t
|
|||
nRVars = -1;
|
||||
}
|
||||
if ( fXRail && nRVars == -1 && Vec_IntSize(vVarIDs) > nLutSize-1 ) {
|
||||
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVarsOld, nRails+1, nLutSize-1, fVerbose, pMyu, nZParam );
|
||||
Vec_Wrd_t * vGuides = Abc_TtFindBVarsSVars2( p, Vec_WrdArray(vFuncs[0]), Vec_IntSize(vVarIDs), nRVarsOld, nRails+1, nLutSize-1, fVerbose, pMyu, nZParam );
|
||||
if ( vGuides ) {
|
||||
int iEntry = nJRatio ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
|
||||
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails+1, nLutSize-1, nJRatio, nZParam, fVerbose, vCas, NULL );
|
||||
int iEntry = fUseRand ? Abc_Random(0) % Vec_WrdSize(vGuides) : 0;
|
||||
nRVars = Abc_LutCascadeDecStage( Vec_WrdEntry(vGuides, iEntry), pGuide, i, vFuncs, vVarIDs, nRVarsOld, nRails+1, nLutSize-1, nZParam, fVerbose, vCas, NULL );
|
||||
Vec_WrdFree( vGuides );
|
||||
}
|
||||
else
|
||||
|
|
@ -867,7 +872,8 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
|
|||
Abc_Random(1);
|
||||
for ( i = 0; i < Seed; i++ )
|
||||
Abc_Random(0);
|
||||
for ( int Iter = 0; Iter < nIters+nJRatio; Iter++ ) {
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
for ( int Iter = 0; Iter < nIters; Iter++ ) {
|
||||
word * pTruth1 = Gia_ObjComputeTruthTable( pGia, Gia_ManCo(pGia, 0) );
|
||||
Abc_TtCopy( pCopy, pTruth1, nWords, 0 );
|
||||
|
||||
|
|
@ -885,7 +891,7 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
|
|||
printf( ".\n" );
|
||||
}
|
||||
|
||||
word * pLuts = Abc_LutCascadeDec( pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, Iter >= nIters ? 1 : 0, nZParam, fXRail, fVeryVerbose, NULL, NULL );
|
||||
word * pLuts = Abc_LutCascadeDec( p, pGuide, pTruth1, Abc_NtkCiNum(pNtk), vVarIDs, nRails, nLutSize, nStages, (int)(Iter > 0), nZParam, fXRail, fVeryVerbose, NULL, NULL );
|
||||
pNew = pLuts ? Abc_NtkLutCascadeFromLuts( pLuts, Abc_NtkCiNum(pNtk), pNtk, nLutSize, fVerbose ) : NULL;
|
||||
Vec_IntFree( vVarIDs );
|
||||
|
||||
|
|
@ -906,6 +912,7 @@ Abc_Ntk_t * Abc_NtkLutCascadeOne( Abc_Ntk_t * pNtk, int nLutSize, int nStages, i
|
|||
}
|
||||
//ABC_FREE( pTruth1 );
|
||||
}
|
||||
Abc_BSEvalFree( p );
|
||||
ABC_FREE( pCopy );
|
||||
Gia_ManStop( pGia );
|
||||
return pNew;
|
||||
|
|
@ -1423,6 +1430,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
|||
printf( "Considering %d functions having %d variables from file \"%s\".\n", nFuncs, nVarsOrig, pFileName );
|
||||
word * pCopy = ABC_ALLOC( word, nWords );
|
||||
int Iter = 0, IterReal = 0, LutStats[50] = {0}, StageStats[50] = {0}, MyuStats[50] = {0};
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
for ( i = 0; i < nFuncs; i++ )
|
||||
{
|
||||
word * pTruth = Vec_WrdEntryP( vTruths, i*nWords );
|
||||
|
|
@ -1446,11 +1454,11 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
|||
printf( "Decomposing %d-var function into %d-rail cascade of %d-LUTs.\n", nVars, nRails, nLutSize );
|
||||
}
|
||||
|
||||
word * pLuts = Abc_LutCascadeDec( NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter >= nIters), nZParam, fXRail, fVeryVerbose, &nStageCount, &MyuMin );
|
||||
word * pLuts = Abc_LutCascadeDec( p, NULL, pTruth, nVarsOrig, vVarIDs, nRails, nLutSize, nStages, (int)(Iter > 0), nZParam, fXRail, fVeryVerbose, &nStageCount, &MyuMin );
|
||||
Vec_IntFree( vVarIDs );
|
||||
if ( MyuMin < 50 ) MyuStats[MyuMin]++, IterReal++;
|
||||
if ( pLuts == NULL ) {
|
||||
if ( ++Iter < nIters+nJRatio ) {
|
||||
if ( ++Iter < nIters ) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1480,6 +1488,7 @@ void Abc_NtkLutCascadeFile( char * pFileName, int nVarsOrig, int nLutSize, int n
|
|||
ABC_FREE( pTruth2 );
|
||||
ABC_FREE( pLuts );
|
||||
}
|
||||
Abc_BSEvalFree( p );
|
||||
ABC_FREE( pCopy );
|
||||
Vec_WrdFree( vTruths );
|
||||
if ( fPrintMyu ) {
|
||||
|
|
|
|||
|
|
@ -38,19 +38,22 @@ ABC_NAMESPACE_IMPL_START
|
|||
/// DECLARATIONS ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MAX_TT_SIZE 24
|
||||
|
||||
typedef struct Abc_BSEval_t_ Abc_BSEval_t;
|
||||
struct Abc_BSEval_t_
|
||||
{
|
||||
int nVars;
|
||||
int nLVars;
|
||||
int nBVars;
|
||||
Vec_Int_t * vPairs; // perm pairs
|
||||
Vec_Int_t * vCounts; // cofactor counts
|
||||
Vec_Int_t * vTable; // hash table
|
||||
Vec_Int_t * vUsed; // used entries
|
||||
Vec_Wrd_t * vStore; // cofactors
|
||||
Vec_Wec_t * vSets; // sets
|
||||
Vec_Wrd_t * vCofs; // cofactors
|
||||
word * pPat; // patterns
|
||||
Vec_Int_t * vPairs[MAX_TT_SIZE][MAX_TT_SIZE]; // perm pairs
|
||||
Vec_Int_t * vCounts; // cofactor counts
|
||||
Vec_Int_t * vTable; // hash table
|
||||
Vec_Int_t * vUsed; // used entries
|
||||
Vec_Wrd_t * vStore; // cofactors
|
||||
Vec_Wec_t * vSets[MAX_TT_SIZE]; // sets
|
||||
Vec_Wrd_t * vCofs[MAX_TT_SIZE]; // cofactors
|
||||
word * pPat; // patterns
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -561,36 +564,40 @@ Abc_BSEval_t * Abc_BSEvalAlloc()
|
|||
}
|
||||
void Abc_BSEvalFree( Abc_BSEval_t * p )
|
||||
{
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
for ( int i = 0; i < MAX_TT_SIZE; i++ )
|
||||
for ( int k = 0; k < MAX_TT_SIZE; k++ )
|
||||
Vec_IntFreeP( &p->vPairs[i][k] );
|
||||
Vec_IntFree( p->vCounts );
|
||||
Vec_IntFree( p->vTable );
|
||||
Vec_IntFree( p->vUsed );
|
||||
Vec_WrdFree( p->vStore );
|
||||
Vec_WecFreeP( &p->vSets );
|
||||
Vec_WrdFreeP( &p->vCofs );
|
||||
for ( int i = 0; i < MAX_TT_SIZE; i++ )
|
||||
Vec_WecFreeP( &p->vSets[i] );
|
||||
for ( int i = 0; i < MAX_TT_SIZE; i++ )
|
||||
Vec_WrdFreeP( &p->vCofs[i] );
|
||||
ABC_FREE( p->pPat );
|
||||
ABC_FREE( p );
|
||||
}
|
||||
void Abc_BSEvalOneTest( word * pT, int nVars, int nBVars, int fVerbose )
|
||||
void Abc_BSEvalOneTest( word * pT, int nVars, int nLVars, int fVerbose )
|
||||
{
|
||||
assert( nVars > nBVars );
|
||||
assert( nVars > nLVars );
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
if ( p->nVars != nVars || p->nBVars != nBVars ) {
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
p->vPairs = Abc_GenChasePairs( nVars, nBVars );
|
||||
if ( p->nVars != nVars || p->nLVars != nLVars ) {
|
||||
p->nVars = nVars;
|
||||
p->nBVars = nBVars;
|
||||
p->nLVars = nLVars;
|
||||
if ( p->vPairs[p->nVars][p->nLVars] == NULL )
|
||||
p->vPairs[p->nVars][p->nLVars] = Abc_GenChasePairs( nVars, nLVars );
|
||||
}
|
||||
int Best = Abc_TtGetCM( pT, nVars, nVars-nBVars, p->vCounts, p->vTable, p->vStore, p->vUsed, 0 );
|
||||
int Best = Abc_TtGetCM( pT, nVars, nVars-nLVars, p->vCounts, p->vTable, p->vStore, p->vUsed, 0 );
|
||||
printf( "Function: " ); Extra_PrintHex( stdout, (unsigned *)pT, nVars ); printf( "\n" );
|
||||
printf( "The column multiplicity of the %d-var function with bound-sets of size %d is %d.\n", nVars, nBVars, Best );
|
||||
printf( "The column multiplicity of the %d-var function with bound-sets of size %d is %d.\n", nVars, nLVars, Best );
|
||||
Abc_BSEvalFree(p);
|
||||
}
|
||||
int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, word * pBest2, int nVars, int nCVars, int nFVars, int fVerbose, int * pPermBest, int * pPermBest2, int fShared, int nJRatio )
|
||||
{
|
||||
int i, k, Var0, Var1, Pla2Var[32], Var2Pla[32];
|
||||
int nPermVars = nVars-nCVars, Count = 0;
|
||||
assert( p->nVars == nPermVars && p->nBVars == nVars-nFVars );
|
||||
assert( p->nVars == nPermVars && p->nLVars == nVars-nFVars );
|
||||
for ( i = 0; i < nVars; i++ )
|
||||
Pla2Var[i] = Var2Pla[i] = i;
|
||||
if ( pPermBest )
|
||||
|
|
@ -598,10 +605,10 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, word * pBest2, i
|
|||
pPermBest[i] = i;
|
||||
int CostBest = 1 << nVars;
|
||||
int CostBest2 = 1 << nVars;
|
||||
int iSave = nJRatio ? (Abc_Random(0) % Vec_IntSize(p->vPairs)/2) : -1;
|
||||
//printf( "The number of pairs = %d.\n", Vec_IntSize(p->vPairs)/2 );
|
||||
int iSave = nJRatio ? (Abc_Random(0) % Vec_IntSize(p->vPairs[p->nVars][p->nLVars])/2) : -1;
|
||||
//printf( "The number of pairs = %d.\n", Vec_IntSize(p->vPairs[p->nVars][p->nLVars])/2 );
|
||||
//int Count = 0;
|
||||
Vec_IntForEachEntryDouble( p->vPairs, Var0, Var1, i ) {
|
||||
Vec_IntForEachEntryDouble( p->vPairs[p->nVars][p->nLVars], Var0, Var1, i ) {
|
||||
//Abc_GenChasePrint( Count++, Pla2Var, nVars, nFVars, Var0, Var1 );
|
||||
int CostThis = Abc_TtGetCM( pIn, nVars, nFVars, p->vCounts, p->vTable, p->vStore, p->vUsed, fShared );
|
||||
if ( iSave == i/2 ) {
|
||||
|
|
@ -676,21 +683,21 @@ int Abc_BSEvalBest( Abc_BSEval_t * p, word * pIn, word * pBest, word * pBest2, i
|
|||
}
|
||||
return CostBest;
|
||||
}
|
||||
void Abc_BSEvalBestTest( word * pIn, int nVars, int nBVars, int fShared, int fVerbose )
|
||||
void Abc_BSEvalBestTest( word * pIn, int nVars, int nLVars, int fShared, int fVerbose )
|
||||
{
|
||||
assert( nVars > nBVars );
|
||||
assert( nVars > nLVars );
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc(); int i, pPerm[32] = {0}, pPerm2[32] = {0};
|
||||
if ( p->nVars != nVars || p->nBVars != nBVars ) {
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
p->vPairs = Abc_GenChasePairs( nVars, nBVars );
|
||||
if ( p->nVars != nVars || p->nLVars != nLVars ) {
|
||||
p->nVars = nVars;
|
||||
p->nBVars = nBVars;
|
||||
p->nLVars = nLVars;
|
||||
if ( p->vPairs[p->nVars][p->nLVars] == NULL )
|
||||
p->vPairs[p->nVars][p->nLVars] = Abc_GenChasePairs( nVars, nLVars );
|
||||
}
|
||||
word * pFun = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
||||
word * pFun2 = ABC_ALLOC( word, Abc_TtWordNum(nVars) );
|
||||
int Best = Abc_BSEvalBest( p, pIn, pFun, pFun2, nVars, 0, nVars-nBVars, fVerbose, pPerm, pPerm2, fShared, 0 );
|
||||
int Best = Abc_BSEvalBest( p, pIn, pFun, pFun2, nVars, 0, nVars-nLVars, fVerbose, pPerm, pPerm2, fShared, 0 );
|
||||
printf( "The minimum %s of the %d-var function with bound-sets of size %d is %d.\n",
|
||||
fShared ? "number of rails" : "column multiplicity", nVars, nBVars, Best );
|
||||
fShared ? "number of rails" : "column multiplicity", nVars, nLVars, Best );
|
||||
printf( "Original: " ); Extra_PrintHex( stdout, (unsigned *)pIn, nVars ); printf( "\n" );
|
||||
printf( "Permuted: " ); Extra_PrintHex( stdout, (unsigned *)pFun, nVars ); printf( "\n" );
|
||||
printf( "Permutation is " );
|
||||
|
|
@ -713,20 +720,20 @@ void Abc_BSEvalBestTest( word * pIn, int nVars, int nBVars, int fShared, int fVe
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryAll, int fShared, int fVerbose )
|
||||
void Abc_BSEvalBestGen( int nVars, int nLVars, int nFuncs, int nMints, int fTryAll, int fShared, int fVerbose )
|
||||
{
|
||||
assert( nVars > nBVars );
|
||||
assert( nVars > nLVars );
|
||||
abctime clkTotal = Abc_Clock();
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
Vec_Int_t * vCounts[2] = { Vec_IntStart(1 << nVars), Vec_IntStart(1 << nVars) };
|
||||
int i, k, Count, nWords = Abc_TtWordNum(nVars);
|
||||
word * pFun = ABC_ALLOC( word, nWords );
|
||||
word * pFun2 = ABC_ALLOC( word, nWords );
|
||||
if ( p->nVars != nVars || p->nBVars != nBVars ) {
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
p->vPairs = Abc_GenChasePairs( nVars, nBVars );
|
||||
if ( p->nVars != nVars || p->nLVars != nLVars ) {
|
||||
p->nVars = nVars;
|
||||
p->nBVars = nBVars;
|
||||
p->nLVars = nLVars;
|
||||
if ( p->vPairs[p->nVars][p->nLVars] == NULL )
|
||||
p->vPairs[p->nVars][p->nLVars] = Abc_GenChasePairs( nVars, nLVars );
|
||||
}
|
||||
Abc_Random(1);
|
||||
for ( i = 0; i < nFuncs; i++ ) {
|
||||
|
|
@ -757,9 +764,9 @@ void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryA
|
|||
}
|
||||
|
||||
if ( fTryAll )
|
||||
Count = Abc_BSEvalBest( p, pFun, pFun2, NULL, nVars, 0, nVars-nBVars, fVerbose, NULL, NULL, fShared, 0 );
|
||||
Count = Abc_BSEvalBest( p, pFun, pFun2, NULL, nVars, 0, nVars-nLVars, fVerbose, NULL, NULL, fShared, 0 );
|
||||
else
|
||||
Count = Abc_TtGetCM( pFun, nVars, nVars-nBVars, p->vCounts, p->vTable, p->vStore, p->vUsed, fShared );
|
||||
Count = Abc_TtGetCM( pFun, nVars, nVars-nLVars, p->vCounts, p->vTable, p->vStore, p->vUsed, fShared );
|
||||
if ( fVerbose )
|
||||
printf( "Myu = %d\n", Count );
|
||||
Vec_IntAddToEntry( vCounts[0], Count, 1 );
|
||||
|
|
@ -773,19 +780,19 @@ void Abc_BSEvalBestGen( int nVars, int nBVars, int nFuncs, int nMints, int fTryA
|
|||
else
|
||||
printf( "Generated %d random %d-var functions.\n", nFuncs, nVars );
|
||||
if ( fShared ) {
|
||||
printf( "Distribution of the %s number of rails for bound set size %d with one shared variable:\n", fTryAll ? "MINIMUM": "ORIGINAL", nBVars );
|
||||
printf( "Distribution of the %s number of rails for bound set size %d with one shared variable:\n", fTryAll ? "MINIMUM": "ORIGINAL", nLVars );
|
||||
assert( Vec_IntSum(vCounts[0]) == nFuncs );
|
||||
Vec_IntForEachEntry( vCounts[0], Count, i )
|
||||
if ( Count ) printf( "%d=%d (%.2f %%) ", i, Count, 100.0*Count/nFuncs );
|
||||
printf( "\n" );
|
||||
}
|
||||
else {
|
||||
printf( "Distribution of the %s column multiplicity for bound set size %d with no shared variables:\n", fTryAll ? "MINIMUM": "ORIGINAL", nBVars );
|
||||
printf( "Distribution of the %s column multiplicity for bound set size %d with no shared variables:\n", fTryAll ? "MINIMUM": "ORIGINAL", nLVars );
|
||||
assert( Vec_IntSum(vCounts[0]) == nFuncs );
|
||||
Vec_IntForEachEntry( vCounts[0], Count, i )
|
||||
if ( Count ) printf( "%d=%d (%.2f %%) ", i, Count, 100.0*Count/nFuncs );
|
||||
printf( "\n" );
|
||||
printf( "Distribution of the %s number of rails for bound set size %d with no shared variables:\n", fTryAll ? "MINIMUM": "ORIGINAL", nBVars );
|
||||
printf( "Distribution of the %s number of rails for bound set size %d with no shared variables:\n", fTryAll ? "MINIMUM": "ORIGINAL", nLVars );
|
||||
assert( Vec_IntSum(vCounts[1]) == nFuncs );
|
||||
Vec_IntForEachEntry( vCounts[1], Count, i )
|
||||
if ( Count ) printf( "%d=%d (%.2f %%) ", i, Count, 100.0*Count/nFuncs );
|
||||
|
|
@ -860,25 +867,6 @@ static inline int Abc_BSEvalCountUniqueMax( word * pISets, int nISets, int nBSWo
|
|||
}
|
||||
return CountMax;
|
||||
}
|
||||
int Abc_BSEvalFindShared( int nVars, word * pISets, int nISets, int nBSWords, Vec_Wec_t * vSets, Vec_Wrd_t * vCofs, int nSharedMax )
|
||||
{
|
||||
Vec_Int_t * vLevel; int i, k, iSet, iStart, nMinMyu = nISets, nMinRails = Abc_Base2Log(nISets), MinShared = 0, MinSet = -1;
|
||||
Vec_WecForEachLevelStartStop( vSets, vLevel, i, 1, nSharedMax+1 ) {
|
||||
Vec_IntForEachEntryDouble( vLevel, iSet, iStart, k ) {
|
||||
int Count = Abc_BSEvalCountUniqueMax( pISets, nISets, nBSWords, Vec_WrdEntryP(vCofs, iStart), i, 1 << (nMinRails-1) );
|
||||
if ( Count == 0 )
|
||||
continue;
|
||||
int CountRails = Abc_Base2Log(Count);
|
||||
if ( nMinRails > CountRails || (nMinRails == CountRails && nMinMyu > Count && MinShared == i) ) {
|
||||
nMinRails = CountRails;
|
||||
nMinMyu = Count;
|
||||
MinShared = i;
|
||||
MinSet = iSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (MinSet << 16) | nMinMyu;
|
||||
}
|
||||
|
||||
|
||||
/**Function*************************************************************
|
||||
|
|
@ -899,12 +887,12 @@ int Abc_SharedEvalBest( Abc_BSEval_t * p, word * pTruth, int nVars, int nCVars,
|
|||
int nRailsCur = Abc_Base2Log( Myu ); Vec_Int_t * vLevel;
|
||||
assert( Myu == MyuMin && nRailsCur >= nRails );
|
||||
int i, k, iSet, iStart, nSharedMax = nVars - nFVars - nRails, nRailsMin = 100;
|
||||
Vec_WecForEachLevelStartStop( p->vSets, vLevel, i, 1, nSharedMax ) {
|
||||
Vec_WecForEachLevelStartStop( p->vSets[p->nBVars], vLevel, i, 1, nSharedMax ) {
|
||||
Vec_IntForEachEntryDouble( vLevel, iSet, iStart, k ) {
|
||||
if ( iSet & CVarMask )
|
||||
continue;
|
||||
//printf( "\nTrying set " ); Extra_PrintBinary( stdout, &iSet, nVars-nFVars ); printf( "\n" );
|
||||
MyuCur = Abc_BSEvalCountUniqueMax( pPat, Myu, nBSWords, Vec_WrdEntryP(p->vCofs, iStart), i, 1 << nRails );
|
||||
MyuCur = Abc_BSEvalCountUniqueMax( pPat, Myu, nBSWords, Vec_WrdEntryP(p->vCofs[p->nBVars], iStart), i, 1 << nRails );
|
||||
//printf( " Res = %d", MyuCur );
|
||||
if ( MyuCur == 0 || MyuCur > (1 << nRails) )
|
||||
continue;
|
||||
|
|
@ -939,14 +927,14 @@ word Abc_TtFindBVarsSVars( word * pTruth, int nVars, int nRVars, int nRails, int
|
|||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
int nPermVars = nVars-nRVars;
|
||||
if ( p->nVars != nPermVars ) {
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
p->vPairs = Abc_GenChasePairs( nPermVars, nLutSize-nRVars );
|
||||
p->nVars = nPermVars;
|
||||
p->nVars = nPermVars;
|
||||
p->nLVars = nLutSize-nRVars;
|
||||
if ( p->vPairs[p->nVars][p->nLVars] == NULL )
|
||||
p->vPairs[p->nVars][p->nLVars] = Abc_GenChasePairs( p->nVars, p->nLVars );
|
||||
}
|
||||
if ( p->nBVars != nLutSize ) {
|
||||
Vec_WecFreeP( &p->vSets );
|
||||
Vec_WrdFreeP( &p->vCofs );
|
||||
p->vCofs = Abc_BSEvalCreateCofactorSets( nLutSize, &p->vSets );
|
||||
if ( p->vCofs[nLutSize] == NULL )
|
||||
p->vCofs[nLutSize] = Abc_BSEvalCreateCofactorSets( nLutSize, &p->vSets[nLutSize] );
|
||||
if ( p->nBVars < nLutSize ) {
|
||||
ABC_FREE( p->pPat );
|
||||
p->pPat = ABC_ALLOC( word, (1 << nLutSize)*Abc_TtWordNum(nLutSize) );
|
||||
|
|
@ -1018,26 +1006,27 @@ word Abc_BSEvalEncode( int * pPermBest, int nVars, int nLutSize, int Shared, int
|
|||
mSVars |= (word)1 << (nVars-nLutSize+v);
|
||||
return ((word)MyuMin << 48) | (mSVars << 24) | mBVars;
|
||||
}
|
||||
Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRails, int nLutSize, int fVerbose, int * pMyu, int nMyuIncrease )
|
||||
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 )
|
||||
{
|
||||
Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
// Abc_BSEval_t * p = Abc_BSEvalAlloc();
|
||||
int nFVars = nVars-nLutSize;
|
||||
int nPermVars = nVars-nCVars;
|
||||
|
||||
if ( p->nVars != nPermVars ) {
|
||||
Vec_IntFreeP( &p->vPairs );
|
||||
p->vPairs = Abc_GenChasePairs( nPermVars, nLutSize-nCVars );
|
||||
p->nVars = nPermVars;
|
||||
p->nVars = nPermVars;
|
||||
p->nLVars = nLutSize-nCVars;
|
||||
if ( p->vPairs[p->nVars][p->nLVars] == NULL )
|
||||
p->vPairs[p->nVars][p->nLVars] = Abc_GenChasePairs( p->nVars, p->nLVars );
|
||||
}
|
||||
if ( p->nBVars != nLutSize ) {
|
||||
Vec_WecFreeP( &p->vSets );
|
||||
Vec_WrdFreeP( &p->vCofs );
|
||||
p->vCofs = Abc_BSEvalCreateCofactorSets( nLutSize, &p->vSets );
|
||||
if ( p->vCofs[nLutSize] == NULL )
|
||||
p->vCofs[nLutSize] = Abc_BSEvalCreateCofactorSets( nLutSize, &p->vSets[nLutSize] );
|
||||
if ( p->nBVars < nLutSize ) {
|
||||
ABC_FREE( p->pPat );
|
||||
p->pPat = ABC_ALLOC( word, (1 << nLutSize)*Abc_TtWordNum(nLutSize) );
|
||||
}
|
||||
p->nBVars = nLutSize;
|
||||
}
|
||||
}
|
||||
|
||||
int nWords = Abc_TtWordNum(nVars);
|
||||
word * pCopy = ABC_ALLOC( word, nWords );
|
||||
|
|
@ -1052,7 +1041,7 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
|
|||
int nSetSizeBest = nVars;
|
||||
|
||||
if ( pMyu ) *pMyu = 1 << nVars;
|
||||
Vec_IntForEachEntryDouble( p->vPairs, Var0, Var1, i ) {
|
||||
Vec_IntForEachEntryDouble( p->vPairs[p->nVars][p->nLVars], Var0, Var1, i ) {
|
||||
int MyuThis = Abc_TtGetCM( pCopy, nVars, nFVars, p->vCounts, p->vTable, p->vStore, p->vUsed, 0 );
|
||||
MyuOrigBest = Abc_MinInt( MyuOrigBest, MyuThis );
|
||||
if ( pMyu ) *pMyu = Abc_MinInt( *pMyu, MyuThis );
|
||||
|
|
@ -1091,7 +1080,7 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
|
|||
int fSave = (MyuBest == MyuThis && nSetSizeBest == nSetSize);
|
||||
MyuBest = MyuThis;
|
||||
nSetSizeBest = nSetSize;
|
||||
word Result = Abc_BSEvalEncode( Pla2Var, nVars, p->nBVars, Shared, MyuBest, nSetSize );
|
||||
word Result = Abc_BSEvalEncode( Pla2Var, nVars, nLutSize, Shared, MyuBest, nSetSize );
|
||||
if ( fSave )
|
||||
Vec_WrdPush( vRes, Result );
|
||||
else
|
||||
|
|
@ -1128,8 +1117,8 @@ Vec_Wrd_t * Abc_TtFindBVarsSVars2( word * pTruth, int nVars, int nCVars, int nRa
|
|||
}
|
||||
if ( !Abc_TtEqual(pCopy, pTruth, nWords) )
|
||||
printf( "Internal truth table check failed.\n" );
|
||||
|
||||
Abc_BSEvalFree(p);
|
||||
|
||||
// Abc_BSEvalFree(p);
|
||||
if ( MyuBest > (1 << nRails) ) {
|
||||
Vec_WrdFree(vRes);
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Reference in New Issue