Commit e8cf8415 by Alan Mishchenko

Version abc70909

parent 9be1b076
...@@ -2786,6 +2786,14 @@ SOURCE=.\src\aig\csw\cswTable.c ...@@ -2786,6 +2786,14 @@ SOURCE=.\src\aig\csw\cswTable.c
# PROP Default_Filter "" # PROP Default_Filter ""
# Begin Source File # Begin Source File
SOURCE=.\src\aig\kit\cloud.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\kit\cloud.h
# End Source File
# Begin Source File
SOURCE=.\src\aig\kit\kit.h SOURCE=.\src\aig\kit\kit.h
# End Source File # End Source File
# Begin Source File # Begin Source File
...@@ -2794,6 +2802,10 @@ SOURCE=.\src\aig\kit\kitBdd.c ...@@ -2794,6 +2802,10 @@ SOURCE=.\src\aig\kit\kitBdd.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=.\src\aig\kit\kitCloud.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\kit\kitDsd.c SOURCE=.\src\aig\kit\kitDsd.c
# End Source File # End Source File
# Begin Source File # Begin Source File
......
...@@ -36,6 +36,7 @@ extern "C" { ...@@ -36,6 +36,7 @@ extern "C" {
#include <time.h> #include <time.h>
#include "vec.h" #include "vec.h"
#include "extra.h" #include "extra.h"
#include "cloud.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// PARAMETERS /// /// PARAMETERS ///
...@@ -133,6 +134,10 @@ struct Kit_DsdMan_t_ ...@@ -133,6 +134,10 @@ struct Kit_DsdMan_t_
int nWords; // the number of words in TTs int nWords; // the number of words in TTs
Vec_Ptr_t * vTtElems; // elementary truth tables Vec_Ptr_t * vTtElems; // elementary truth tables
Vec_Ptr_t * vTtNodes; // the node truth tables Vec_Ptr_t * vTtNodes; // the node truth tables
// BDD representation
CloudManager * dd; // BDD package
Vec_Ptr_t * vTtBdds; // the node truth tables
Vec_Int_t * vNodes; // temporary array for BDD nodes
}; };
static inline int Kit_DsdVar2Lit( int Var, int fCompl ) { return Var + Var + fCompl; } static inline int Kit_DsdVar2Lit( int Var, int fCompl ) { return Var + Var + fCompl; }
...@@ -431,6 +436,16 @@ static inline void Kit_TruthMux( unsigned * pOut, unsigned * pIn0, unsigned * pI ...@@ -431,6 +436,16 @@ static inline void Kit_TruthMux( unsigned * pOut, unsigned * pIn0, unsigned * pI
for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- )
pOut[w] = (pIn0[w] & ~pCtrl[w]) | (pIn1[w] & pCtrl[w]); pOut[w] = (pIn0[w] & ~pCtrl[w]) | (pIn1[w] & pCtrl[w]);
} }
static inline void Kit_TruthMuxPhase( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, unsigned * pCtrl, int nVars, int fComp0 )
{
int w;
if ( fComp0 )
for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- )
pOut[w] = (~pIn0[w] & ~pCtrl[w]) | (pIn1[w] & pCtrl[w]);
else
for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- )
pOut[w] = (pIn0[w] & ~pCtrl[w]) | (pIn1[w] & pCtrl[w]);
}
static inline void Kit_TruthIthVar( unsigned * pTruth, int nVars, int iVar ) static inline void Kit_TruthIthVar( unsigned * pTruth, int nVars, int iVar )
{ {
unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 }; unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
...@@ -473,11 +488,18 @@ static inline void Kit_TruthIthVar( unsigned * pTruth, int nVars, int iVar ) ...@@ -473,11 +488,18 @@ static inline void Kit_TruthIthVar( unsigned * pTruth, int nVars, int iVar )
extern DdNode * Kit_SopToBdd( DdManager * dd, Kit_Sop_t * cSop, int nVars ); extern DdNode * Kit_SopToBdd( DdManager * dd, Kit_Sop_t * cSop, int nVars );
extern DdNode * Kit_GraphToBdd( DdManager * dd, Kit_Graph_t * pGraph ); extern DdNode * Kit_GraphToBdd( DdManager * dd, Kit_Graph_t * pGraph );
extern DdNode * Kit_TruthToBdd( DdManager * dd, unsigned * pTruth, int nVars, int fMSBonTop ); extern DdNode * Kit_TruthToBdd( DdManager * dd, unsigned * pTruth, int nVars, int fMSBonTop );
/*=== kitCloud.c ==========================================================*/
extern CloudNode * Kit_TruthToCloud( CloudManager * dd, unsigned * pTruth, int nVars );
extern unsigned * Kit_CloudToTruth( Vec_Int_t * vNodes, int nVars, Vec_Ptr_t * vStore, int fInv );
extern int Kit_CreateCloud( CloudManager * dd, CloudNode * pFunc, Vec_Int_t * vNodes );
extern int Kit_CreateCloudFromTruth( CloudManager * dd, unsigned * pTruth, int nVars, Vec_Int_t * vNodes );
extern unsigned * Kit_TruthCompose( CloudManager * dd, unsigned * pTruth, int nVars, unsigned ** pInputs, int nVarsAll, Vec_Ptr_t * vStore, Vec_Int_t * vNodes );
extern void Kit_TruthCofSupports( Vec_Int_t * vBddDir, Vec_Int_t * vBddInv, int nVars, Vec_Int_t * vMemory, unsigned * puSupps );
/*=== kitDsd.c ==========================================================*/ /*=== kitDsd.c ==========================================================*/
extern Kit_DsdMan_t * Kit_DsdManAlloc( int nVars, int nNodes ); extern Kit_DsdMan_t * Kit_DsdManAlloc( int nVars, int nNodes );
extern void Kit_DsdManFree( Kit_DsdMan_t * p ); extern void Kit_DsdManFree( Kit_DsdMan_t * p );
extern Kit_DsdNtk_t * Kit_DsdDeriveNtk( unsigned * pTruth, int nVars, int nLutSize ); extern Kit_DsdNtk_t * Kit_DsdDeriveNtk( unsigned * pTruth, int nVars, int nLutSize );
extern unsigned * Kit_DsdTruthCompute( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned uSupp ); extern unsigned * Kit_DsdTruthCompute( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk );
extern void Kit_DsdTruth( Kit_DsdNtk_t * pNtk, unsigned * pTruthRes ); extern void Kit_DsdTruth( Kit_DsdNtk_t * pNtk, unsigned * pTruthRes );
extern void Kit_DsdTruthPartial( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned * pTruthRes, unsigned uSupp ); extern void Kit_DsdTruthPartial( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned * pTruthRes, unsigned uSupp );
extern void Kit_DsdTruthPartialTwo( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned uSupp, int iVar, unsigned * pTruthCo, unsigned * pTruthDec ); extern void Kit_DsdTruthPartialTwo( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned uSupp, int iVar, unsigned * pTruthCo, unsigned * pTruthDec );
...@@ -485,10 +507,12 @@ extern void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk ); ...@@ -485,10 +507,12 @@ extern void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk );
extern void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk ); extern void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk );
extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars ); extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars );
extern Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars ); extern Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars );
extern Kit_DsdNtk_t * Kit_DsdDecomposeExpand( unsigned * pTruth, int nVars );
extern Kit_DsdNtk_t * Kit_DsdDecomposeMux( unsigned * pTruth, int nVars, int nDecMux ); extern Kit_DsdNtk_t * Kit_DsdDecomposeMux( unsigned * pTruth, int nVars, int nDecMux );
extern void Kit_DsdVerify( Kit_DsdNtk_t * pNtk, unsigned * pTruth, int nVars ); extern void Kit_DsdVerify( Kit_DsdNtk_t * pNtk, unsigned * pTruth, int nVars );
extern void Kit_DsdNtkFree( Kit_DsdNtk_t * pNtk ); extern void Kit_DsdNtkFree( Kit_DsdNtk_t * pNtk );
extern int Kit_DsdNonDsdSizeMax( Kit_DsdNtk_t * pNtk ); extern int Kit_DsdNonDsdSizeMax( Kit_DsdNtk_t * pNtk );
extern unsigned Kit_DsdNonDsdSupports( Kit_DsdNtk_t * pNtk );
extern unsigned Kit_DsdGetSupports( Kit_DsdNtk_t * p ); extern unsigned Kit_DsdGetSupports( Kit_DsdNtk_t * p );
extern Kit_DsdNtk_t * Kit_DsdExpand( Kit_DsdNtk_t * p ); extern Kit_DsdNtk_t * Kit_DsdExpand( Kit_DsdNtk_t * p );
extern Kit_DsdNtk_t * Kit_DsdShrink( Kit_DsdNtk_t * p, int pPrios[] ); extern Kit_DsdNtk_t * Kit_DsdShrink( Kit_DsdNtk_t * p, int pPrios[] );
...@@ -548,6 +572,7 @@ extern void Kit_TruthForallNew( unsigned * pRes, unsigned * pTruth, i ...@@ -548,6 +572,7 @@ extern void Kit_TruthForallNew( unsigned * pRes, unsigned * pTruth, i
extern void Kit_TruthForallSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask ); extern void Kit_TruthForallSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask );
extern void Kit_TruthUniqueNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ); extern void Kit_TruthUniqueNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar );
extern void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar ); extern void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar );
extern void Kit_TruthMuxVarPhase( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar, int fCompl0 );
extern void Kit_TruthChangePhase( unsigned * pTruth, int nVars, int iVar ); extern void Kit_TruthChangePhase( unsigned * pTruth, int nVars, int iVar );
extern int Kit_TruthMinCofSuppOverlap( unsigned * pTruth, int nVars, int * pVarMin ); extern int Kit_TruthMinCofSuppOverlap( unsigned * pTruth, int nVars, int * pVarMin );
extern int Kit_TruthBestCofVar( unsigned * pTruth, int nVars, unsigned * pCof0, unsigned * pCof1 ); extern int Kit_TruthBestCofVar( unsigned * pTruth, int nVars, unsigned * pCof0, unsigned * pCof1 );
......
...@@ -901,6 +901,68 @@ void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int n ...@@ -901,6 +901,68 @@ void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int n
/**Function************************************************************* /**Function*************************************************************
Synopsis [Multiplexes two functions with the given variable.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Kit_TruthMuxVarPhase( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar, int fCompl0 )
{
int nWords = Kit_TruthWordNum( nVars );
int i, k, Step;
if ( fCompl0 == 0 )
{
Kit_TruthMuxVar( pOut, pCof0, pCof1, nVars, iVar );
return;
}
assert( iVar < nVars );
switch ( iVar )
{
case 0:
for ( i = 0; i < nWords; i++ )
pOut[i] = (~pCof0[i] & 0x55555555) | (pCof1[i] & 0xAAAAAAAA);
return;
case 1:
for ( i = 0; i < nWords; i++ )
pOut[i] = (~pCof0[i] & 0x33333333) | (pCof1[i] & 0xCCCCCCCC);
return;
case 2:
for ( i = 0; i < nWords; i++ )
pOut[i] = (~pCof0[i] & 0x0F0F0F0F) | (pCof1[i] & 0xF0F0F0F0);
return;
case 3:
for ( i = 0; i < nWords; i++ )
pOut[i] = (~pCof0[i] & 0x00FF00FF) | (pCof1[i] & 0xFF00FF00);
return;
case 4:
for ( i = 0; i < nWords; i++ )
pOut[i] = (~pCof0[i] & 0x0000FFFF) | (pCof1[i] & 0xFFFF0000);
return;
default:
Step = (1 << (iVar - 5));
for ( k = 0; k < nWords; k += 2*Step )
{
for ( i = 0; i < Step; i++ )
{
pOut[i] = ~pCof0[i];
pOut[Step+i] = pCof1[Step+i];
}
pOut += 2*Step;
pCof0 += 2*Step;
pCof1 += 2*Step;
}
return;
}
}
/**Function*************************************************************
Synopsis [Checks symmetry of two variables.] Synopsis [Checks symmetry of two variables.]
Description [] Description []
...@@ -1623,7 +1685,7 @@ char * Kit_TruthDumpToFile( unsigned * pTruth, int nVars, int nFile ) ...@@ -1623,7 +1685,7 @@ char * Kit_TruthDumpToFile( unsigned * pTruth, int nVars, int nFile )
{ {
static char pFileName[100]; static char pFileName[100];
FILE * pFile; FILE * pFile;
sprintf( pFileName, "s%03d", nFile ); sprintf( pFileName, "tt\\s%04d", nFile );
pFile = fopen( pFileName, "w" ); pFile = fopen( pFileName, "w" );
fprintf( pFile, "rt " ); fprintf( pFile, "rt " );
Extra_PrintHexadecimal( pFile, pTruth, nVars ); Extra_PrintHexadecimal( pFile, pTruth, nVars );
......
SRC += src/aig/kit/kitBdd.c \ SRC += src/aig/kit/kitBdd.c \
src/aig/kit/kitCloud.c src/aig/kit/cloud.c \
src/aig/kit/kitDsd.c \ src/aig/kit/kitDsd.c \
src/aig/kit/kitFactor.c \ src/aig/kit/kitFactor.c \
src/aig/kit/kitGraph.c \ src/aig/kit/kitGraph.c \
......
...@@ -45,8 +45,8 @@ static int Abc_NodeRefDerefStop( Abc_Obj_t * pNode, bool fReference ); ...@@ -45,8 +45,8 @@ static int Abc_NodeRefDerefStop( Abc_Obj_t * pNode, bool fReference );
int Abc_NodeMffcSize( Abc_Obj_t * pNode ) int Abc_NodeMffcSize( Abc_Obj_t * pNode )
{ {
int nConeSize1, nConeSize2; int nConeSize1, nConeSize2;
assert( Abc_NtkIsStrash(pNode->pNtk) ); // assert( Abc_NtkIsStrash(pNode->pNtk) );
assert( !Abc_ObjIsComplement( pNode ) ); // assert( !Abc_ObjIsComplement( pNode ) );
assert( Abc_ObjIsNode( pNode ) ); assert( Abc_ObjIsNode( pNode ) );
if ( Abc_ObjFaninNum(pNode) == 0 ) if ( Abc_ObjFaninNum(pNode) == 0 )
return 0; return 0;
......
...@@ -2979,22 +2979,20 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -2979,22 +2979,20 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv )
pOut = Abc_FrameReadOut(pAbc); pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc); pErr = Abc_FrameReadErr(pAbc);
// printf("This command will be available soon\n");
// return 0;
// set defaults // set defaults
memset( pPars, 0, sizeof(Lpk_Par_t) ); memset( pPars, 0, sizeof(Lpk_Par_t) );
pPars->nLutsMax = 4; // (N) the maximum number of LUTs in the structure pPars->nLutsMax = 4; // (N) the maximum number of LUTs in the structure
pPars->nLutsOver = 3; // (Q) the maximum number of LUTs not in the MFFC pPars->nLutsOver = 3; // (Q) the maximum number of LUTs not in the MFFC
pPars->nVarsShared = 0; // (S) the maximum number of shared variables (crossbars) pPars->nVarsShared = 0; // (S) the maximum number of shared variables (crossbars)
pPars->nGrowthLevel = 1; // (L) the maximum number of increased levels pPars->nGrowthLevel = 0; // (L) the maximum number of increased levels
pPars->fSatur = 1; pPars->fSatur = 1;
pPars->fZeroCost = 0; pPars->fZeroCost = 0;
pPars->fFirst = 0; pPars->fFirst = 0;
pPars->fOldAlgo = 0;
pPars->fVerbose = 0; pPars->fVerbose = 0;
pPars->fVeryVerbose = 0; pPars->fVeryVerbose = 0;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "NQSLszfvwh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "NQSLszfovwh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
...@@ -3051,6 +3049,9 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -3051,6 +3049,9 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'f': case 'f':
pPars->fFirst ^= 1; pPars->fFirst ^= 1;
break; break;
case 'o':
pPars->fOldAlgo ^= 1;
break;
case 'v': case 'v':
pPars->fVerbose ^= 1; pPars->fVerbose ^= 1;
break; break;
...@@ -3074,6 +3075,11 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -3074,6 +3075,11 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv )
fprintf( pErr, "This command can only be applied to a logic network.\n" ); fprintf( pErr, "This command can only be applied to a logic network.\n" );
return 1; return 1;
} }
if ( pPars->nVarsShared < 0 || pPars->nVarsShared > 3 )
{
fprintf( pErr, "The number of shared variables (%d) is not in the range 0 <= S <= 3.\n", pPars->nVarsShared );
return 1;
}
// modify the current network // modify the current network
if ( !Lpk_Resynthesize( pNtk, pPars ) ) if ( !Lpk_Resynthesize( pNtk, pPars ) )
...@@ -3084,17 +3090,18 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -3084,17 +3090,18 @@ int Abc_CommandLutpack( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0; return 0;
usage: usage:
fprintf( pErr, "usage: lutpack [-N <num>] [-Q <num>] [-S <num>] [-L <num>] [-szfvwh]\n" ); fprintf( pErr, "usage: lutpack [-N <num>] [-Q <num>] [-S <num>] [-L <num>] [-szfovwh]\n" );
fprintf( pErr, "\t performs \"rewriting\" for LUT networks\n" ); fprintf( pErr, "\t performs \"rewriting\" for LUT networks\n" );
fprintf( pErr, "\t-N <num> : the max number of LUTs in the structure (2 <= num) [default = %d]\n", pPars->nLutsMax ); fprintf( pErr, "\t-N <num> : the max number of LUTs in the structure (2 <= num) [default = %d]\n", pPars->nLutsMax );
fprintf( pErr, "\t-Q <num> : the max number of LUTs not in MFFC (0 <= num) [default = %d]\n", pPars->nLutsOver ); fprintf( pErr, "\t-Q <num> : the max number of LUTs not in MFFC (0 <= num) [default = %d]\n", pPars->nLutsOver );
fprintf( pErr, "\t-S <num> : the max number of LUT inputs shared (0 <= num) [default = %d]\n", pPars->nVarsShared ); fprintf( pErr, "\t-S <num> : the max number of LUT inputs shared (0 <= num <= 3) [default = %d]\n", pPars->nVarsShared );
fprintf( pErr, "\t-L <num> : the largest increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel ); fprintf( pErr, "\t-L <num> : the largest increase in node level after resynthesis (0 <= num) [default = %d]\n", pPars->nGrowthLevel );
fprintf( pErr, "\t-s : toggle iteration till saturation [default = %s]\n", pPars->fSatur? "yes": "no" ); fprintf( pErr, "\t-s : toggle iteration till saturation [default = %s]\n", pPars->fSatur? "yes": "no" );
fprintf( pErr, "\t-z : toggle zero-cost replacements [default = %s]\n", pPars->fZeroCost? "yes": "no" ); fprintf( pErr, "\t-z : toggle zero-cost replacements [default = %s]\n", pPars->fZeroCost? "yes": "no" );
fprintf( pErr, "\t-f : toggle using only first node and first cut [default = %s]\n", pPars->fFirst? "yes": "no" ); fprintf( pErr, "\t-f : toggle using only first node and first cut [default = %s]\n", pPars->fFirst? "yes": "no" );
fprintf( pErr, "\t-o : toggle using old implementation [default = %s]\n", pPars->fOldAlgo? "yes": "no" );
fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" ); fprintf( pErr, "\t-v : toggle verbose printout [default = %s]\n", pPars->fVerbose? "yes": "no" );
fprintf( pErr, "\t-w : toggle printout subgraph statistics [default = %s]\n", pPars->fVeryVerbose? "yes": "no" ); fprintf( pErr, "\t-w : toggle detailed printout of decomposed functions [default = %s]\n", pPars->fVeryVerbose? "yes": "no" );
fprintf( pErr, "\t-h : print the command usage\n"); fprintf( pErr, "\t-h : print the command usage\n");
return 1; return 1;
} }
......
...@@ -412,7 +412,7 @@ static inline void Vec_StrPush( Vec_Str_t * p, char Entry ) ...@@ -412,7 +412,7 @@ static inline void Vec_StrPush( Vec_Str_t * p, char Entry )
SeeAlso [] SeeAlso []
******************************************************************************/ ******************************************************************************/
static inline Vec_StrBase10Log( unsigned Num ) static inline int Vec_StrBase10Log( unsigned Num )
{ {
int Res; int Res;
assert( Num >= 0 ); assert( Num >= 0 );
......
...@@ -48,6 +48,7 @@ struct Lpk_Par_t_ ...@@ -48,6 +48,7 @@ struct Lpk_Par_t_
int fSatur; // iterate till saturation int fSatur; // iterate till saturation
int fZeroCost; // accept zero-cost replacements int fZeroCost; // accept zero-cost replacements
int fFirst; // use root node and first cut only int fFirst; // use root node and first cut only
int fOldAlgo; // use old algorithm
int fVerbose; // the verbosiness flag int fVerbose; // the verbosiness flag
int fVeryVerbose; // additional verbose info printout int fVeryVerbose; // additional verbose info printout
// internal parameters // internal parameters
......
...@@ -39,17 +39,21 @@ ...@@ -39,17 +39,21 @@
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Abc_Obj_t * Lpk_ImplementFun( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * p ) Abc_Obj_t * Lpk_ImplementFun( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * p )
{ {
extern Hop_Obj_t * Kit_TruthToHop( Hop_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory ); extern Hop_Obj_t * Kit_TruthToHop( Hop_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory );
unsigned * pTruth; unsigned * pTruth;
Abc_Obj_t * pObjNew; Abc_Obj_t * pObjNew;
int i; int i;
if ( p->fMark )
pMan->nMuxes++;
else
pMan->nDsds++;
// create the new node // create the new node
pObjNew = Abc_NtkCreateNode( pNtk ); pObjNew = Abc_NtkCreateNode( pNtk );
for ( i = 0; i < (int)p->nVars; i++ ) for ( i = 0; i < (int)p->nVars; i++ )
Abc_ObjAddFanin( pObjNew, Vec_PtrEntry(vLeaves, p->pFanins[i]) ); Abc_ObjAddFanin( pObjNew, Abc_ObjRegular(Vec_PtrEntry(vLeaves, p->pFanins[i])) );
Abc_ObjLevelNew( pObjNew ); Abc_ObjSetLevel( pObjNew, Abc_ObjLevelNew(pObjNew) );
// assign the node's function // assign the node's function
pTruth = Lpk_FunTruth(p, 0); pTruth = Lpk_FunTruth(p, 0);
if ( p->nVars == 0 ) if ( p->nVars == 0 )
...@@ -78,18 +82,48 @@ Abc_Obj_t * Lpk_ImplementFun( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * ...@@ -78,18 +82,48 @@ Abc_Obj_t * Lpk_ImplementFun( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t *
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Abc_Obj_t * Lpk_Implement( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld ) Abc_Obj_t * Lpk_Implement_rec( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * pFun )
{ {
Lpk_Fun_t * pFun; Abc_Obj_t * pFanin, * pRes;
Abc_Obj_t * pRes;
int i; int i;
for ( i = Vec_PtrSize(vLeaves) - 1; i >= nLeavesOld; i-- ) // prepare the leaves of the function
for ( i = 0; i < (int)pFun->nVars; i++ )
{ {
pFun = Vec_PtrEntry( vLeaves, i ); pFanin = Vec_PtrEntry( vLeaves, pFun->pFanins[i] );
pRes = Lpk_ImplementFun( pNtk, vLeaves, pFun ); if ( !Abc_ObjIsComplement(pFanin) )
Vec_PtrWriteEntry( vLeaves, i, pRes ); Lpk_Implement_rec( pMan, pNtk, vLeaves, (Lpk_Fun_t *)pFanin );
Lpk_FunFree( pFun ); pFanin = Vec_PtrEntry( vLeaves, pFun->pFanins[i] );
assert( Abc_ObjIsComplement(pFanin) );
} }
// construct the function
pRes = Lpk_ImplementFun( pMan, pNtk, vLeaves, pFun );
// replace the function
Vec_PtrWriteEntry( vLeaves, pFun->Id, Abc_ObjNot(pRes) );
Lpk_FunFree( pFun );
return pRes;
}
/**Function*************************************************************
Synopsis [Implements the function.]
Description [Returns the node implementing this function.]
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Obj_t * Lpk_Implement( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld )
{
Abc_Obj_t * pFanin, * pRes;
int i;
assert( nLeavesOld < Vec_PtrSize(vLeaves) );
// mark implemented nodes
Vec_PtrForEachEntryStop( vLeaves, pFanin, i, nLeavesOld )
Vec_PtrWriteEntry( vLeaves, i, Abc_ObjNot(pFanin) );
// recursively construct starting from the first entry
pRes = Lpk_Implement_rec( pMan, pNtk, vLeaves, Vec_PtrEntry( vLeaves, nLeavesOld ) );
Vec_PtrShrink( vLeaves, nLeavesOld ); Vec_PtrShrink( vLeaves, nLeavesOld );
return pRes; return pRes;
} }
...@@ -107,10 +141,13 @@ Abc_Obj_t * Lpk_Implement( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld ...@@ -107,10 +141,13 @@ Abc_Obj_t * Lpk_Implement( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Lpk_Decompose_rec( Lpk_Fun_t * p ) int Lpk_Decompose_rec( Lpk_Man_t * pMan, Lpk_Fun_t * p )
{ {
static Lpk_Res_t Res0, * pRes0 = &Res0;
Lpk_Res_t * pResMux, * pResDsd; Lpk_Res_t * pResMux, * pResDsd;
Lpk_Fun_t * p2; Lpk_Fun_t * p2;
int clk;
// is only called for non-trivial blocks // is only called for non-trivial blocks
assert( p->nLutK >= 3 && p->nLutK <= 6 ); assert( p->nLutK >= 3 && p->nLutK <= 6 );
assert( p->nVars > p->nLutK ); assert( p->nVars > p->nLutK );
...@@ -120,18 +157,37 @@ int Lpk_Decompose_rec( Lpk_Fun_t * p ) ...@@ -120,18 +157,37 @@ int Lpk_Decompose_rec( Lpk_Fun_t * p )
// skip if delay bound is exceeded // skip if delay bound is exceeded
if ( Lpk_SuppDelay(p->uSupp, p->pDelays) > (int)p->nDelayLim ) if ( Lpk_SuppDelay(p->uSupp, p->pDelays) > (int)p->nDelayLim )
return 0; return 0;
// compute supports if needed
if ( !p->fSupports )
Lpk_FunComputeCofSupps( p );
// check DSD decomposition
clk = clock();
pResDsd = Lpk_DsdAnalize( pMan, p, pMan->pPars->nVarsShared );
pMan->timeEvalDsdAn += clock() - clk;
if ( pResDsd && (pResDsd->nBSVars == (int)p->nLutK || pResDsd->nBSVars == (int)p->nLutK - 1) &&
pResDsd->AreaEst <= (int)p->nAreaLim && pResDsd->DelayEst <= (int)p->nDelayLim )
{
clk = clock();
p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
pMan->timeEvalDsdSp += clock() - clk;
assert( p2->nVars <= (int)p->nLutK );
if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
return 0;
return 1;
}
// check MUX decomposition // check MUX decomposition
pResMux = Lpk_MuxAnalize( p ); clk = clock();
pResMux = Lpk_MuxAnalize( pMan, p );
pMan->timeEvalMuxAn += clock() - clk;
// pResMux = NULL;
assert( !pResMux || (pResMux->DelayEst <= (int)p->nDelayLim && pResMux->AreaEst <= (int)p->nAreaLim) ); assert( !pResMux || (pResMux->DelayEst <= (int)p->nDelayLim && pResMux->AreaEst <= (int)p->nAreaLim) );
// accept MUX decomposition if it is "good" // accept MUX decomposition if it is "good"
if ( pResMux && pResMux->nSuppSizeS <= (int)p->nLutK && pResMux->nSuppSizeL <= (int)p->nLutK ) if ( pResMux && pResMux->nSuppSizeS <= (int)p->nLutK && pResMux->nSuppSizeL <= (int)p->nLutK )
pResDsd = NULL; pResDsd = NULL;
else else if ( pResMux && pResDsd )
{
pResDsd = Lpk_DsdAnalize( p );
assert( !pResDsd || (pResDsd->DelayEst <= (int)p->nDelayLim && pResDsd->AreaEst <= (int)p->nAreaLim) );
}
if ( pResMux && pResDsd )
{ {
// compare two decompositions // compare two decompositions
if ( pResMux->AreaEst < pResDsd->AreaEst || if ( pResMux->AreaEst < pResDsd->AreaEst ||
...@@ -144,18 +200,22 @@ int Lpk_Decompose_rec( Lpk_Fun_t * p ) ...@@ -144,18 +200,22 @@ int Lpk_Decompose_rec( Lpk_Fun_t * p )
assert( pResMux == NULL || pResDsd == NULL ); assert( pResMux == NULL || pResDsd == NULL );
if ( pResMux ) if ( pResMux )
{ {
p2 = Lpk_MuxSplit( p, pResMux->pCofVars[0], pResMux->Polarity ); clk = clock();
if ( p2->nVars > p->nLutK && !Lpk_Decompose_rec( p2 ) ) p2 = Lpk_MuxSplit( pMan, p, pResMux->Variable, pResMux->Polarity );
pMan->timeEvalMuxSp += clock() - clk;
if ( p2->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p2 ) )
return 0; return 0;
if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( p ) ) if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
return 0; return 0;
return 1; return 1;
} }
if ( pResDsd ) if ( pResDsd )
{ {
p2 = Lpk_DsdSplit( p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars ); clk = clock();
p2 = Lpk_DsdSplit( pMan, p, pResDsd->pCofVars, pResDsd->nCofVars, pResDsd->BSVars );
pMan->timeEvalDsdSp += clock() - clk;
assert( p2->nVars <= (int)p->nLutK ); assert( p2->nVars <= (int)p->nLutK );
if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( p ) ) if ( p->nVars > p->nLutK && !Lpk_Decompose_rec( pMan, p ) )
return 0; return 0;
return 1; return 1;
} }
...@@ -193,17 +253,31 @@ void Lpk_DecomposeClean( Vec_Ptr_t * vLeaves, int nLeavesOld ) ...@@ -193,17 +253,31 @@ void Lpk_DecomposeClean( Vec_Ptr_t * vLeaves, int nLeavesOld )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
Abc_Obj_t * Lpk_Decompose( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim ) Abc_Obj_t * Lpk_Decompose( Lpk_Man_t * p, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, unsigned * puSupps, int nLutK, int AreaLim, int DelayLim )
{ {
Lpk_Fun_t * pFun; Lpk_Fun_t * pFun;
Abc_Obj_t * pObjNew = NULL; Abc_Obj_t * pObjNew = NULL;
int nLeaves = Vec_PtrSize( vLeaves ); int nLeaves = Vec_PtrSize( vLeaves );
pFun = Lpk_FunCreate( pNtk, vLeaves, pTruth, nLutK, AreaLim, DelayLim ); pFun = Lpk_FunCreate( pNtk, vLeaves, pTruth, nLutK, AreaLim, DelayLim );
if ( puSupps[0] || puSupps[1] )
{
/*
int i;
Lpk_FunComputeCofSupps( pFun );
for ( i = 0; i < nLeaves; i++ )
{
assert( pFun->puSupps[2*i+0] == puSupps[2*i+0] );
assert( pFun->puSupps[2*i+1] == puSupps[2*i+1] );
}
*/
memcpy( pFun->puSupps, puSupps, sizeof(unsigned) * 2 * nLeaves );
pFun->fSupports = 1;
}
Lpk_FunSuppMinimize( pFun ); Lpk_FunSuppMinimize( pFun );
if ( pFun->nVars <= pFun->nLutK ) if ( pFun->nVars <= pFun->nLutK )
pObjNew = Lpk_ImplementFun( pNtk, vLeaves, pFun ); pObjNew = Lpk_ImplementFun( p, pNtk, vLeaves, pFun );
else if ( Lpk_Decompose_rec(pFun) ) else if ( Lpk_Decompose_rec(p, pFun) )
pObjNew = Lpk_Implement( pNtk, vLeaves, nLeaves ); pObjNew = Lpk_Implement( p, pNtk, vLeaves, nLeaves );
Lpk_DecomposeClean( vLeaves, nLeaves ); Lpk_DecomposeClean( vLeaves, nLeaves );
return pObjNew; return pObjNew;
} }
......
...@@ -123,7 +123,7 @@ Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth ) ...@@ -123,7 +123,7 @@ Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth )
memcpy( pNew->pFanins, p->pFanins, 16 ); memcpy( pNew->pFanins, p->pFanins, 16 );
memcpy( pNew->pDelays, p->pDelays, 16 ); memcpy( pNew->pDelays, p->pDelays, 16 );
Vec_PtrPush( p->vNodes, pNew ); Vec_PtrPush( p->vNodes, pNew );
return p; return pNew;
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -137,12 +137,15 @@ Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth ) ...@@ -137,12 +137,15 @@ Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Lpk_FunSuppMinimize( Lpk_Fun_t * p ) int Lpk_FunSuppMinimize( Lpk_Fun_t * p )
{ {
int i, k, nVarsNew; int i, k, nVarsNew;
// compress the truth table // compress the truth table
if ( p->uSupp == Kit_BitMask(p->nVars) ) if ( p->uSupp == Kit_BitMask(p->nVars) )
return; return 0;
// invalidate support info
p->fSupports = 0;
//Extra_PrintBinary( stdout, &p->uSupp, p->nVars ); printf( "\n" );
// minimize support // minimize support
nVarsNew = Kit_WordCountOnes(p->uSupp); nVarsNew = Kit_WordCountOnes(p->uSupp);
Kit_TruthShrink( Lpk_FunTruth(p, 1), Lpk_FunTruth(p, 0), nVarsNew, p->nVars, p->uSupp, 1 ); Kit_TruthShrink( Lpk_FunTruth(p, 1), Lpk_FunTruth(p, 0), nVarsNew, p->nVars, p->uSupp, 1 );
...@@ -151,11 +154,48 @@ void Lpk_FunSuppMinimize( Lpk_Fun_t * p ) ...@@ -151,11 +154,48 @@ void Lpk_FunSuppMinimize( Lpk_Fun_t * p )
{ {
p->pFanins[k] = p->pFanins[i]; p->pFanins[k] = p->pFanins[i];
p->pDelays[k] = p->pDelays[i]; p->pDelays[k] = p->pDelays[i];
/*
if ( p->fSupports )
{
p->puSupps[2*k+0] = p->puSupps[2*i+0];
p->puSupps[2*k+1] = p->puSupps[2*i+1];
}
*/
k++; k++;
} }
assert( k == nVarsNew ); assert( k == nVarsNew );
p->nVars = k; p->nVars = k;
p->uSupp = Kit_BitMask(p->nVars); p->uSupp = Kit_BitMask(p->nVars);
return 1;
}
/**Function*************************************************************
Synopsis [Computes cofactors w.r.t. each variable.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Lpk_FunComputeCofSupps( Lpk_Fun_t * p )
{
unsigned * pTruth = Lpk_FunTruth( p, 0 );
unsigned * pTruth0 = Lpk_FunTruth( p, 1 );
unsigned * pTruth1 = Lpk_FunTruth( p, 2 );
int Var;
assert( p->fSupports == 0 );
// Lpk_SuppForEachVar( p->uSupp, Var )
for ( Var = 0; Var < (int)p->nVars; Var++ )
{
Kit_TruthCofactor0New( pTruth0, pTruth, p->nVars, Var );
Kit_TruthCofactor1New( pTruth1, pTruth, p->nVars, Var );
p->puSupps[2*Var+0] = Kit_TruthSupport( pTruth0, p->nVars );
p->puSupps[2*Var+1] = Kit_TruthSupport( pTruth1, p->nVars );
}
p->fSupports = 1;
} }
/**Function************************************************************* /**Function*************************************************************
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
***********************************************************************/ ***********************************************************************/
#include "lpkInt.h" #include "lpkInt.h"
#include "cloud.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// DECLARATIONS /// /// DECLARATIONS ///
...@@ -39,7 +40,99 @@ ...@@ -39,7 +40,99 @@
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_Ptr_t * vTtNodes, int * iCount ) CloudNode * Lpk_CutTruthBdd_rec( CloudManager * dd, Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars )
{
CloudNode * pTruth, * pTruth0, * pTruth1;
assert( !Hop_IsComplement(pObj) );
if ( pObj->pData )
{
assert( ((unsigned)pObj->pData) & 0xffff0000 );
return pObj->pData;
}
// get the plan for a new truth table
if ( Hop_ObjIsConst1(pObj) )
pTruth = dd->one;
else
{
assert( Hop_ObjIsAnd(pObj) );
// compute the truth tables of the fanins
pTruth0 = Lpk_CutTruthBdd_rec( dd, pMan, Hop_ObjFanin0(pObj), nVars );
pTruth1 = Lpk_CutTruthBdd_rec( dd, pMan, Hop_ObjFanin1(pObj), nVars );
pTruth0 = Cloud_NotCond( pTruth0, Hop_ObjFaninC0(pObj) );
pTruth1 = Cloud_NotCond( pTruth1, Hop_ObjFaninC1(pObj) );
// creat the truth table of the node
pTruth = Cloud_bddAnd( dd, pTruth0, pTruth1 );
}
pObj->pData = pTruth;
return pTruth;
}
/**Function*************************************************************
Synopsis [Verifies that the factoring is correct.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
CloudNode * Lpk_CutTruthBdd( Lpk_Man_t * p, Lpk_Cut_t * pCut )
{
CloudManager * dd = p->pDsdMan->dd;
Hop_Man_t * pManHop = p->pNtk->pManFunc;
Hop_Obj_t * pObjHop;
Abc_Obj_t * pObj, * pFanin;
CloudNode * pTruth;
int i, k, iCount = 0;
// return NULL;
// Lpk_NodePrintCut( p, pCut );
// initialize the leaves
Lpk_CutForEachLeaf( p->pNtk, pCut, pObj, i )
pObj->pCopy = (Abc_Obj_t *)dd->vars[pCut->nLeaves-1-i];
// construct truth table in the topological order
Lpk_CutForEachNodeReverse( p->pNtk, pCut, pObj, i )
{
// get the local AIG
pObjHop = Hop_Regular(pObj->pData);
// clean the data field of the nodes in the AIG subgraph
Hop_ObjCleanData_rec( pObjHop );
// set the initial truth tables at the fanins
Abc_ObjForEachFanin( pObj, pFanin, k )
{
assert( ((unsigned)pFanin->pCopy) & 0xffff0000 );
Hop_ManPi( pManHop, k )->pData = pFanin->pCopy;
}
// compute the truth table of internal nodes
pTruth = Lpk_CutTruthBdd_rec( dd, pManHop, pObjHop, pCut->nLeaves );
if ( Hop_IsComplement(pObj->pData) )
pTruth = Cloud_Not(pTruth);
// set the truth table at the node
pObj->pCopy = (Abc_Obj_t *)pTruth;
}
// Cloud_bddPrint( dd, pTruth );
// printf( "Bdd size = %d. Total nodes = %d.\n", Cloud_DagSize( dd, pTruth ), dd->nNodesCur-dd->nVars-1 );
return pTruth;
}
/**Function*************************************************************
Synopsis [Computes the truth table of one cut.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_Ptr_t * vTtNodes, int * piCount )
{ {
unsigned * pTruth, * pTruth0, * pTruth1; unsigned * pTruth, * pTruth0, * pTruth1;
assert( !Hop_IsComplement(pObj) ); assert( !Hop_IsComplement(pObj) );
...@@ -49,17 +142,17 @@ unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_ ...@@ -49,17 +142,17 @@ unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_
return pObj->pData; return pObj->pData;
} }
// get the plan for a new truth table // get the plan for a new truth table
pTruth = Vec_PtrEntry( vTtNodes, (*iCount)++ ); pTruth = Vec_PtrEntry( vTtNodes, (*piCount)++ );
if ( Hop_ObjIsConst1(pObj) ) if ( Hop_ObjIsConst1(pObj) )
Extra_TruthFill( pTruth, nVars ); Kit_TruthFill( pTruth, nVars );
else else
{ {
assert( Hop_ObjIsAnd(pObj) ); assert( Hop_ObjIsAnd(pObj) );
// compute the truth tables of the fanins // compute the truth tables of the fanins
pTruth0 = Lpk_CutTruth_rec( pMan, Hop_ObjFanin0(pObj), nVars, vTtNodes, iCount ); pTruth0 = Lpk_CutTruth_rec( pMan, Hop_ObjFanin0(pObj), nVars, vTtNodes, piCount );
pTruth1 = Lpk_CutTruth_rec( pMan, Hop_ObjFanin1(pObj), nVars, vTtNodes, iCount ); pTruth1 = Lpk_CutTruth_rec( pMan, Hop_ObjFanin1(pObj), nVars, vTtNodes, piCount );
// creat the truth table of the node // creat the truth table of the node
Extra_TruthAndPhase( pTruth, pTruth0, pTruth1, nVars, Hop_ObjFaninC0(pObj), Hop_ObjFaninC1(pObj) ); Kit_TruthAndPhase( pTruth, pTruth0, pTruth1, nVars, Hop_ObjFaninC0(pObj), Hop_ObjFaninC1(pObj) );
} }
pObj->pData = pTruth; pObj->pData = pTruth;
return pTruth; return pTruth;
...@@ -76,7 +169,7 @@ unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_ ...@@ -76,7 +169,7 @@ unsigned * Lpk_CutTruth_rec( Hop_Man_t * pMan, Hop_Obj_t * pObj, int nVars, Vec_
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut ) unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut, int fInv )
{ {
Hop_Man_t * pManHop = p->pNtk->pManFunc; Hop_Man_t * pManHop = p->pNtk->pManFunc;
Hop_Obj_t * pObjHop; Hop_Obj_t * pObjHop;
...@@ -84,10 +177,11 @@ unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut ) ...@@ -84,10 +177,11 @@ unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut )
unsigned * pTruth; unsigned * pTruth;
int i, k, iCount = 0; int i, k, iCount = 0;
// Lpk_NodePrintCut( p, pCut ); // Lpk_NodePrintCut( p, pCut );
assert( pCut->nNodes > 0 );
// initialize the leaves // initialize the leaves
Lpk_CutForEachLeaf( p->pNtk, pCut, pObj, i ) Lpk_CutForEachLeaf( p->pNtk, pCut, pObj, i )
pObj->pCopy = Vec_PtrEntry( p->vTtElems, i ); pObj->pCopy = Vec_PtrEntry( p->vTtElems, fInv? pCut->nLeaves-1-i : i );
// construct truth table in the topological order // construct truth table in the topological order
Lpk_CutForEachNodeReverse( p->pNtk, pCut, pObj, i ) Lpk_CutForEachNodeReverse( p->pNtk, pCut, pObj, i )
...@@ -105,14 +199,22 @@ unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut ) ...@@ -105,14 +199,22 @@ unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut )
// compute the truth table of internal nodes // compute the truth table of internal nodes
pTruth = Lpk_CutTruth_rec( pManHop, pObjHop, pCut->nLeaves, p->vTtNodes, &iCount ); pTruth = Lpk_CutTruth_rec( pManHop, pObjHop, pCut->nLeaves, p->vTtNodes, &iCount );
if ( Hop_IsComplement(pObj->pData) ) if ( Hop_IsComplement(pObj->pData) )
Extra_TruthNot( pTruth, pTruth, pCut->nLeaves ); Kit_TruthNot( pTruth, pTruth, pCut->nLeaves );
// set the truth table at the node // set the truth table at the node
pObj->pCopy = (Abc_Obj_t *)pTruth; pObj->pCopy = (Abc_Obj_t *)pTruth;
} }
// make sure direct truth table is stored elsewhere (assuming the first call for direct truth!!!)
if ( fInv == 0 )
{
pTruth = Vec_PtrEntry( p->vTtNodes, iCount++ );
Kit_TruthCopy( pTruth, (unsigned *)pObj->pCopy, pCut->nLeaves );
}
assert( iCount <= Vec_PtrSize(p->vTtNodes) );
return pTruth; return pTruth;
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Returns 1 if at least one entry has changed.] Synopsis [Returns 1 if at least one entry has changed.]
...@@ -535,8 +637,10 @@ int Lpk_NodeCuts( Lpk_Man_t * p ) ...@@ -535,8 +637,10 @@ int Lpk_NodeCuts( Lpk_Man_t * p )
// compute the minimum number of LUTs needed to implement this cut // compute the minimum number of LUTs needed to implement this cut
// V = N * (K-1) + 1 ~~~~~ N = Ceiling[(V-1)/(K-1)] = (V-1)/(K-1) + [(V-1)%(K-1) > 0] // V = N * (K-1) + 1 ~~~~~ N = Ceiling[(V-1)/(K-1)] = (V-1)/(K-1) + [(V-1)%(K-1) > 0]
pCut->nLuts = Lpk_LutNumLuts( pCut->nLeaves, p->pPars->nLutSize ); pCut->nLuts = Lpk_LutNumLuts( pCut->nLeaves, p->pPars->nLutSize );
// pCut->Weight = (float)1.0 * (pCut->nNodes - pCut->nNodesDup - 1) / pCut->nLuts; //p->pPars->nLutsMax;
pCut->Weight = (float)1.0 * (pCut->nNodes - pCut->nNodesDup) / pCut->nLuts; //p->pPars->nLutsMax; pCut->Weight = (float)1.0 * (pCut->nNodes - pCut->nNodesDup) / pCut->nLuts; //p->pPars->nLutsMax;
if ( pCut->Weight <= 1.001 ) if ( pCut->Weight <= 1.001 )
// if ( pCut->Weight <= 0.999 )
continue; continue;
pCut->fHasDsd = Lpk_NodeCutsCheckDsd( p, pCut ); pCut->fHasDsd = Lpk_NodeCutsCheckDsd( p, pCut );
if ( pCut->fHasDsd ) if ( pCut->fHasDsd )
......
...@@ -90,12 +90,18 @@ struct Lpk_Man_t_ ...@@ -90,12 +90,18 @@ struct Lpk_Man_t_
int nCalledSRed; // the number of called to SRed int nCalledSRed; // the number of called to SRed
int pRefs[LPK_SIZE_MAX]; // fanin reference counters int pRefs[LPK_SIZE_MAX]; // fanin reference counters
int pCands[LPK_SIZE_MAX]; // internal nodes pointing only to the leaves int pCands[LPK_SIZE_MAX]; // internal nodes pointing only to the leaves
Vec_Ptr_t * vLeaves;
// truth table representation // truth table representation
Vec_Ptr_t * vTtElems; // elementary truth tables Vec_Ptr_t * vTtElems; // elementary truth tables
Vec_Ptr_t * vTtNodes; // storage for temporary truth tables of the nodes Vec_Ptr_t * vTtNodes; // storage for temporary truth tables of the nodes
Vec_Int_t * vMemory;
Vec_Int_t * vBddDir;
Vec_Int_t * vBddInv;
unsigned puSupps[32]; // the supports of the cofactors
unsigned * ppTruths[5][16];
// variable sets // variable sets
Vec_Int_t * vSets[8]; Vec_Int_t * vSets[8];
Kit_DsdMan_t * pDsdMan; Kit_DsdMan_t* pDsdMan;
// statistics // statistics
int nNodesTotal; // total number of nodes int nNodesTotal; // total number of nodes
int nNodesOver; // nodes with cuts over the limit int nNodesOver; // nodes with cuts over the limit
...@@ -104,17 +110,30 @@ struct Lpk_Man_t_ ...@@ -104,17 +110,30 @@ struct Lpk_Man_t_
int nGainTotal; // the gain in LUTs int nGainTotal; // the gain in LUTs
int nChanges; // the number of changed nodes int nChanges; // the number of changed nodes
int nBenefited; // the number of gainful that benefited from decomposition int nBenefited; // the number of gainful that benefited from decomposition
int nMuxes;
int nDsds;
int nTotalNets; int nTotalNets;
int nTotalNets2; int nTotalNets2;
int nTotalNodes;
int nTotalNodes2;
// counter of non-DSD blocks // counter of non-DSD blocks
int nBlocks[17]; int nBlocks[17];
// rutime // runtime
int timeCuts; int timeCuts;
int timeTruth; int timeTruth;
int timeSupps;
int timeTruth2;
int timeTruth3;
int timeEval; int timeEval;
int timeMap; int timeMap;
int timeOther; int timeOther;
int timeTotal; int timeTotal;
// runtime of eval
int timeEvalMuxAn;
int timeEvalMuxSp;
int timeEvalDsdAn;
int timeEvalDsdSp;
}; };
...@@ -122,32 +141,35 @@ struct Lpk_Man_t_ ...@@ -122,32 +141,35 @@ struct Lpk_Man_t_
typedef struct Lpk_Fun_t_ Lpk_Fun_t; typedef struct Lpk_Fun_t_ Lpk_Fun_t;
struct Lpk_Fun_t_ struct Lpk_Fun_t_
{ {
Vec_Ptr_t * vNodes; // the array of leaves and decomposition nodes Vec_Ptr_t * vNodes; // the array of leaves and decomposition nodes
unsigned int Id : 8; // the ID of this node unsigned Id : 7; // the ID of this node
unsigned int nVars : 5; // the number of variables unsigned nVars : 5; // the number of variables
unsigned int nLutK : 4; // the number of LUT inputs unsigned nLutK : 4; // the number of LUT inputs
unsigned int nAreaLim : 5; // the area limit (the largest allowed) unsigned nAreaLim : 5; // the area limit (the largest allowed)
unsigned int nDelayLim : 10; // the delay limit (the largest allowed) unsigned nDelayLim : 9; // the delay limit (the largest allowed)
char pDelays[16]; // the delays of the inputs unsigned fSupports : 1; // supports of cofactors were precomputed
char pFanins[16]; // the fanins of this function unsigned fMark : 1; // marks the MUX-based dec
unsigned uSupp; // the support of this component unsigned uSupp; // the support of this component
unsigned pTruth[0]; // the truth table (contains room for three truth tables) unsigned puSupps[32]; // the supports of the cofactors
char pDelays[16]; // the delays of the inputs
char pFanins[16]; // the fanins of this function
unsigned pTruth[0]; // the truth table (contains room for three truth tables)
}; };
// preliminary decomposition result // preliminary decomposition result
typedef struct Lpk_Res_t_ Lpk_Res_t; typedef struct Lpk_Res_t_ Lpk_Res_t;
struct Lpk_Res_t_ struct Lpk_Res_t_
{ {
int nBSVars; // the number of bound set variables int nBSVars; // the number of bound set variables
unsigned BSVars; // the bound set unsigned BSVars; // the bound set
int nCofVars; // the number of cofactoring variables int nCofVars; // the number of cofactoring variables
char pCofVars[4]; // the cofactoring variables char pCofVars[4]; // the cofactoring variables
int nSuppSizeS; // support size of the smaller (decomposed) function int nSuppSizeS; // support size of the smaller (decomposed) function
int nSuppSizeL; // support size of the larger (composition) function int nSuppSizeL; // support size of the larger (composition) function
int DelayEst; // estimated delay of the decomposition int DelayEst; // estimated delay of the decomposition
int AreaEst; // estimated area of the decomposition int AreaEst; // estimated area of the decomposition
int Variable; // variable in MUX decomposition int Variable; // variable in MUX decomposition
int Polarity; // polarity in MUX decomposition int Polarity; // polarity in MUX decomposition
}; };
static inline int Lpk_LutNumVars( int nLutsLim, int nLutK ) { return nLutsLim * (nLutK - 1) + 1; } static inline int Lpk_LutNumVars( int nLutsLim, int nLutK ) { return nLutsLim * (nLutK - 1) + 1; }
...@@ -177,25 +199,26 @@ static inline unsigned * Lpk_FunTruth( Lpk_Fun_t * p, int Num ) { assert( Num ...@@ -177,25 +199,26 @@ static inline unsigned * Lpk_FunTruth( Lpk_Fun_t * p, int Num ) { assert( Num
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/*=== lpkAbcDec.c ============================================================*/ /*=== lpkAbcDec.c ============================================================*/
extern Abc_Obj_t * Lpk_Decompose( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim ); extern Abc_Obj_t * Lpk_Decompose( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, unsigned * puSupps, int nLutK, int AreaLim, int DelayLim );
/*=== lpkAbcDsd.c ============================================================*/ /*=== lpkAbcDsd.c ============================================================*/
extern Lpk_Res_t * Lpk_DsdAnalize( Lpk_Fun_t * p ); extern Lpk_Res_t * Lpk_DsdAnalize( Lpk_Man_t * pMan, Lpk_Fun_t * p, int nShared );
extern Lpk_Fun_t * Lpk_DsdSplit( Lpk_Fun_t * p, char * pCofVars, int nCofVars, unsigned uBoundSet ); extern Lpk_Fun_t * Lpk_DsdSplit( Lpk_Man_t * pMan, Lpk_Fun_t * p, char * pCofVars, int nCofVars, unsigned uBoundSet );
/*=== lpkAbcMux.c ============================================================*/ /*=== lpkAbcMux.c ============================================================*/
extern Lpk_Res_t * Lpk_MuxAnalize( Lpk_Fun_t * p ); extern Lpk_Res_t * Lpk_MuxAnalize( Lpk_Man_t * pMan, Lpk_Fun_t * p );
extern Lpk_Fun_t * Lpk_MuxSplit( Lpk_Fun_t * p, int Var, int Pol ); extern Lpk_Fun_t * Lpk_MuxSplit( Lpk_Man_t * pMan, Lpk_Fun_t * p, int Var, int Pol );
/*=== lpkAbcUtil.c ============================================================*/ /*=== lpkAbcUtil.c ============================================================*/
extern Lpk_Fun_t * Lpk_FunAlloc( int nVars ); extern Lpk_Fun_t * Lpk_FunAlloc( int nVars );
extern void Lpk_FunFree( Lpk_Fun_t * p ); extern void Lpk_FunFree( Lpk_Fun_t * p );
extern Lpk_Fun_t * Lpk_FunCreate( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim ); extern Lpk_Fun_t * Lpk_FunCreate( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim );
extern Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth ); extern Lpk_Fun_t * Lpk_FunDup( Lpk_Fun_t * p, unsigned * pTruth );
extern void Lpk_FunSuppMinimize( Lpk_Fun_t * p ); extern int Lpk_FunSuppMinimize( Lpk_Fun_t * p );
extern void Lpk_FunComputeCofSupps( Lpk_Fun_t * p );
extern int Lpk_SuppDelay( unsigned uSupp, char * pDelays ); extern int Lpk_SuppDelay( unsigned uSupp, char * pDelays );
extern int Lpk_SuppToVars( unsigned uBoundSet, char * pVars ); extern int Lpk_SuppToVars( unsigned uBoundSet, char * pVars );
/*=== lpkCut.c =========================================================*/ /*=== lpkCut.c =========================================================*/
extern unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut ); extern unsigned * Lpk_CutTruth( Lpk_Man_t * p, Lpk_Cut_t * pCut, int fInv );
extern int Lpk_NodeCuts( Lpk_Man_t * p ); extern int Lpk_NodeCuts( Lpk_Man_t * p );
/*=== lpkMap.c =========================================================*/ /*=== lpkMap.c =========================================================*/
extern Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars ); extern Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars );
......
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars ) Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars )
{ {
Lpk_Man_t * p; Lpk_Man_t * p;
int i; int i, nWords;
assert( pPars->nLutsMax <= 16 ); assert( pPars->nLutsMax <= 16 );
assert( pPars->nVarsMax > 0 ); assert( pPars->nVarsMax > 0 && pPars->nVarsMax <= 16 );
p = ALLOC( Lpk_Man_t, 1 ); p = ALLOC( Lpk_Man_t, 1 );
memset( p, 0, sizeof(Lpk_Man_t) ); memset( p, 0, sizeof(Lpk_Man_t) );
p->pPars = pPars; p->pPars = pPars;
...@@ -52,9 +52,28 @@ Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars ) ...@@ -52,9 +52,28 @@ Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars )
p->vTtElems = Vec_PtrAllocTruthTables( pPars->nVarsMax ); p->vTtElems = Vec_PtrAllocTruthTables( pPars->nVarsMax );
p->vTtNodes = Vec_PtrAllocSimInfo( 1024, Abc_TruthWordNum(pPars->nVarsMax) ); p->vTtNodes = Vec_PtrAllocSimInfo( 1024, Abc_TruthWordNum(pPars->nVarsMax) );
p->vCover = Vec_IntAlloc( 1 << 12 ); p->vCover = Vec_IntAlloc( 1 << 12 );
p->vLeaves = Vec_PtrAlloc( 32 );
for ( i = 0; i < 8; i++ ) for ( i = 0; i < 8; i++ )
p->vSets[i] = Vec_IntAlloc(100); p->vSets[i] = Vec_IntAlloc(100);
p->pDsdMan = Kit_DsdManAlloc( pPars->nVarsMax, 64 ); p->pDsdMan = Kit_DsdManAlloc( pPars->nVarsMax, 64 );
p->vMemory = Vec_IntAlloc( 1024 * 32 );
p->vBddDir = Vec_IntAlloc( 256 );
p->vBddInv = Vec_IntAlloc( 256 );
// allocate temporary storage for truth tables
nWords = Kit_TruthWordNum(pPars->nVarsMax);
p->ppTruths[0][0] = ALLOC( unsigned, 32 * nWords );
p->ppTruths[1][0] = p->ppTruths[0][0] + 1 * nWords;
for ( i = 1; i < 2; i++ )
p->ppTruths[1][i] = p->ppTruths[1][0] + i * nWords;
p->ppTruths[2][0] = p->ppTruths[1][0] + 2 * nWords;
for ( i = 1; i < 4; i++ )
p->ppTruths[2][i] = p->ppTruths[2][0] + i * nWords;
p->ppTruths[3][0] = p->ppTruths[2][0] + 4 * nWords;
for ( i = 1; i < 8; i++ )
p->ppTruths[3][i] = p->ppTruths[3][0] + i * nWords;
p->ppTruths[4][0] = p->ppTruths[3][0] + 8 * nWords;
for ( i = 1; i < 16; i++ )
p->ppTruths[4][i] = p->ppTruths[4][0] + i * nWords;
return p; return p;
} }
...@@ -72,6 +91,10 @@ Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars ) ...@@ -72,6 +91,10 @@ Lpk_Man_t * Lpk_ManStart( Lpk_Par_t * pPars )
void Lpk_ManStop( Lpk_Man_t * p ) void Lpk_ManStop( Lpk_Man_t * p )
{ {
int i; int i;
free( p->ppTruths[0][0] );
Vec_IntFree( p->vBddDir );
Vec_IntFree( p->vBddInv );
Vec_IntFree( p->vMemory );
Kit_DsdManFree( p->pDsdMan ); Kit_DsdManFree( p->pDsdMan );
for ( i = 0; i < 8; i++ ) for ( i = 0; i < 8; i++ )
Vec_IntFree(p->vSets[i]); Vec_IntFree(p->vSets[i]);
...@@ -85,6 +108,7 @@ void Lpk_ManStop( Lpk_Man_t * p ) ...@@ -85,6 +108,7 @@ void Lpk_ManStop( Lpk_Man_t * p )
Vec_VecFree( p->vLevels ); Vec_VecFree( p->vLevels );
if ( p->vVisited ) if ( p->vVisited )
Vec_VecFree( p->vVisited ); Vec_VecFree( p->vVisited );
Vec_PtrFree( p->vLeaves );
Vec_IntFree( p->vCover ); Vec_IntFree( p->vCover );
Vec_PtrFree( p->vTtElems ); Vec_PtrFree( p->vTtElems );
Vec_PtrFree( p->vTtNodes ); Vec_PtrFree( p->vTtNodes );
......
...@@ -140,7 +140,7 @@ unsigned Lpk_ComputeSets( Kit_DsdNtk_t * p, Vec_Int_t * vSets ) ...@@ -140,7 +140,7 @@ unsigned Lpk_ComputeSets( Kit_DsdNtk_t * p, Vec_Int_t * vSets )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Lpk_PrintSetOne( int uSupport ) static void Lpk_PrintSetOne( int uSupport )
{ {
unsigned k; unsigned k;
for ( k = 0; k < 16; k++ ) for ( k = 0; k < 16; k++ )
...@@ -159,7 +159,7 @@ void Lpk_PrintSetOne( int uSupport ) ...@@ -159,7 +159,7 @@ void Lpk_PrintSetOne( int uSupport )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Lpk_PrintSets( Vec_Int_t * vSets ) static void Lpk_PrintSets( Vec_Int_t * vSets )
{ {
unsigned uSupport; unsigned uSupport;
int Number, i; int Number, i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment