summaryrefslogtreecommitdiffstats
path: root/src/aig/nwk
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2009-01-18 08:01:00 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2009-01-18 08:01:00 -0800
commitf936cc0680c98ffe51b3a1716c996072d5dbf76c (patch)
tree784a2a809fb6b972ec6a8e2758ab758ca590d01a /src/aig/nwk
parentc9ad5880cc61787dec6d018111b63023407ce0e6 (diff)
downloadabc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.tar.gz
abc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.tar.bz2
abc-f936cc0680c98ffe51b3a1716c996072d5dbf76c.zip
Version abc90118
Diffstat (limited to 'src/aig/nwk')
-rw-r--r--src/aig/nwk/nwk.h13
-rw-r--r--src/aig/nwk/nwkBidec.c53
-rw-r--r--src/aig/nwk/nwkMan.c42
-rw-r--r--src/aig/nwk/nwkMap.c26
-rw-r--r--src/aig/nwk/nwkMerge.c6
-rw-r--r--src/aig/nwk/nwkStrash.c1
6 files changed, 126 insertions, 15 deletions
diff --git a/src/aig/nwk/nwk.h b/src/aig/nwk/nwk.h
index 603c1fb8..0ea8241b 100644
--- a/src/aig/nwk/nwk.h
+++ b/src/aig/nwk/nwk.h
@@ -123,14 +123,14 @@ struct Nwk_Obj_t_
//#pragma warning( disable : 4273 )
#ifdef WIN32
-#define DLLEXPORT __declspec(dllexport)
-#define DLLIMPORT __declspec(dllimport)
+#define ABC_DLLEXPORT __declspec(dllexport)
+#define ABC_DLLIMPORT __declspec(dllimport)
#else /* defined(WIN32) */
-#define DLLIMPORT
+#define ABC_DLLIMPORT
#endif /* defined(WIN32) */
#ifndef ABC_DLL
-#define ABC_DLL DLLIMPORT
+#define ABC_DLL ABC_DLLIMPORT
#endif
static inline int Nwk_ManCiNum( Nwk_Man_t * p ) { return p->nObjs[NWK_OBJ_CI]; }
@@ -234,7 +234,7 @@ static inline int Nwk_ManTimeMore( float f1, float f2, float Eps ) { r
extern ABC_DLL Vec_Ptr_t * Nwk_ManDeriveRetimingCut( Aig_Man_t * p, int fForward, int fVerbose );
/*=== nwkBidec.c ==========================================================*/
extern ABC_DLL void Nwk_ManBidecResyn( Nwk_Man_t * pNtk, int fVerbose );
-extern ABC_DLL Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare );
+extern ABC_DLL Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb );
/*=== nwkCheck.c ==========================================================*/
extern ABC_DLL int Nwk_ManCheck( Nwk_Man_t * p );
/*=== nwkDfs.c ==========================================================*/
@@ -265,7 +265,8 @@ extern ABC_DLL Vec_Ptr_t * Nwk_ManRetimeCutBackward( Nwk_Man_t * pMan, int n
/*=== nwkMan.c ============================================================*/
extern ABC_DLL Nwk_Man_t * Nwk_ManAlloc();
extern ABC_DLL void Nwk_ManFree( Nwk_Man_t * p );
-extern ABC_DLL void Nwk_ManPrintStats( Nwk_Man_t * p, If_Lib_t * pLutLib, int fSaveBest, int fDumpResult, void * pNtl );
+extern ABC_DLL float Nwl_ManComputeTotalSwitching( Nwk_Man_t * pNtk );
+extern ABC_DLL void Nwk_ManPrintStats( Nwk_Man_t * p, If_Lib_t * pLutLib, int fSaveBest, int fDumpResult, int fPower, void * pNtl );
/*=== nwkMap.c ============================================================*/
extern ABC_DLL Nwk_Man_t * Nwk_MappingIf( Aig_Man_t * p, Tim_Man_t * pManTime, If_Par_t * pPars );
/*=== nwkObj.c ============================================================*/
diff --git a/src/aig/nwk/nwkBidec.c b/src/aig/nwk/nwkBidec.c
index e30d2c02..2b60d779 100644
--- a/src/aig/nwk/nwkBidec.c
+++ b/src/aig/nwk/nwkBidec.c
@@ -24,6 +24,26 @@
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
+static inline int Extra_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); }
+static inline void Extra_TruthNot( unsigned * pOut, unsigned * pIn, int nVars )
+{
+ int w;
+ for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
+ pOut[w] = ~pIn[w];
+}
+static inline void Extra_TruthOr( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
+{
+ int w;
+ for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
+ pOut[w] = pIn0[w] | pIn1[w];
+}
+static inline void Extra_TruthSharp( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars )
+{
+ int w;
+ for ( w = Extra_TruthWordNum(nVars)-1; w >= 0; w-- )
+ pOut[w] = pIn0[w] & ~pIn1[w];
+}
+
static inline Hop_Obj_t * Bdc_FunCopyHop( Bdc_Fun_t * pObj ) { return Hop_NotCond( Bdc_FuncCopy(Bdc_Regular(pObj)), Bdc_IsComplement(pObj) ); }
////////////////////////////////////////////////////////////////////////
@@ -41,7 +61,7 @@ static inline Hop_Obj_t * Bdc_FunCopyHop( Bdc_Fun_t * pObj ) { return Hop_NotCo
SeeAlso []
***********************************************************************/
-Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare )
+Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb )
{
unsigned * pTruth;
Bdc_Fun_t * pFunc;
@@ -52,8 +72,33 @@ Hop_Obj_t * Nwk_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pR
if ( Hop_IsComplement(pRoot) )
for ( i = Aig_TruthWordNum(nVars)-1; i >= 0; i-- )
pTruth[i] = ~pTruth[i];
- // decompose truth table
- Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
+ // perform power-aware decomposition
+ if ( dProb >= 0.0 )
+ {
+ float Prob = (float)2.0 * dProb * (1.0 - dProb);
+ assert( Prob >= 0.0 && Prob <= 0.5 );
+ if ( Prob >= 0.4 )
+ {
+ Extra_TruthNot( puCare, puCare, nVars );
+ if ( dProb > 0.5 ) // more 1s than 0s
+ Extra_TruthOr( pTruth, pTruth, puCare, nVars );
+ else
+ Extra_TruthSharp( pTruth, pTruth, puCare, nVars );
+ Extra_TruthNot( puCare, puCare, nVars );
+ // decompose truth table
+ Bdc_ManDecompose( p, pTruth, NULL, nVars, NULL, 1000 );
+ }
+ else
+ {
+ // decompose truth table
+ Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
+ }
+ }
+ else
+ {
+ // decompose truth table
+ Bdc_ManDecompose( p, pTruth, puCare, nVars, NULL, 1000 );
+ }
// convert back into HOP
Bdc_FuncSetCopy( Bdc_ManFunc( p, 0 ), Hop_ManConst1( pHop ) );
for ( i = 0; i < nVars; i++ )
@@ -106,7 +151,7 @@ void Nwk_ManBidecResyn( Nwk_Man_t * pNtk, int fVerbose )
if ( Nwk_ObjFaninNum(pObj) > 15 )
continue;
nNodes1 = Hop_DagSize(pObj->pFunc);
- pObj->pFunc = Nwk_NodeIfNodeResyn( p, pNtk->pManHop, pObj->pFunc, Nwk_ObjFaninNum(pObj), vTruth, NULL );
+ pObj->pFunc = Nwk_NodeIfNodeResyn( p, pNtk->pManHop, pObj->pFunc, Nwk_ObjFaninNum(pObj), vTruth, NULL, -1.0 );
nNodes2 = Hop_DagSize(pObj->pFunc);
nGainTotal += nNodes1 - nNodes2;
}
diff --git a/src/aig/nwk/nwkMan.c b/src/aig/nwk/nwkMan.c
index 55cdf42b..6b67d3c1 100644
--- a/src/aig/nwk/nwkMan.c
+++ b/src/aig/nwk/nwkMan.c
@@ -183,6 +183,42 @@ char * Nwk_FileNameGeneric( char * FileName )
/**Function*************************************************************
+ Synopsis [Marks nodes for power-optimization.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+float Nwl_ManComputeTotalSwitching( Nwk_Man_t * pNtk )
+{
+ extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
+ Vec_Int_t * vSwitching;
+ float * pSwitching;
+ Aig_Man_t * pAig;
+ Aig_Obj_t * pObjAig;
+ Nwk_Obj_t * pObjAbc;
+ float Result = (float)0;
+ int i;
+ // strash the network
+ // map network into an AIG
+ pAig = Nwk_ManStrash( pNtk );
+ vSwitching = Saig_ManComputeSwitchProbs( pAig, 48, 16, 0 );
+ pSwitching = (float *)vSwitching->pArray;
+ Nwk_ManForEachObj( pNtk, pObjAbc, i )
+ {
+ if ( (pObjAig = Aig_Regular(pObjAbc->pCopy)) )
+ Result += Nwk_ObjFanoutNum(pObjAbc) * pSwitching[pObjAig->Id];
+ }
+ Vec_IntFree( vSwitching );
+ Aig_ManStop( pAig );
+ return Result;
+}
+
+/**Function*************************************************************
+
Synopsis [Prints stats of the manager.]
Description []
@@ -192,7 +228,7 @@ char * Nwk_FileNameGeneric( char * FileName )
SeeAlso []
***********************************************************************/
-void Nwk_ManPrintStats( Nwk_Man_t * pNtk, If_Lib_t * pLutLib, int fSaveBest, int fDumpResult, void * pNtl )
+void Nwk_ManPrintStats( Nwk_Man_t * pNtk, If_Lib_t * pLutLib, int fSaveBest, int fDumpResult, int fPower, void * pNtl )
{
extern int Ntl_ManLatchNum( void * p );
extern void Ioa_WriteBlifLogic( Nwk_Man_t * pNtk, void * pNtl, char * pFileName );
@@ -221,7 +257,9 @@ void Nwk_ManPrintStats( Nwk_Man_t * pNtk, If_Lib_t * pLutLib, int fSaveBest, int
printf( "aig = %6d ", Nwk_ManGetAigNodeNum(pNtk) );
printf( "lev = %3d ", Nwk_ManLevel(pNtk) );
// printf( "lev2 = %3d ", Nwk_ManLevelBackup(pNtk) );
- printf( "delay = %5.2f ", Nwk_ManDelayTraceLut(pNtk) );
+ printf( "delay = %5.2f ", Nwk_ManDelayTraceLut(pNtk) );
+ if ( fPower )
+ printf( "power = %7.2f ", Nwl_ManComputeTotalSwitching(pNtk) );
Nwk_ManPrintLutSizes( pNtk, pLutLib );
printf( "\n" );
// Nwk_ManDelayTracePrint( pNtk, pLutLib );
diff --git a/src/aig/nwk/nwkMap.c b/src/aig/nwk/nwkMap.c
index 88e08413..a70bb9b1 100644
--- a/src/aig/nwk/nwkMap.c
+++ b/src/aig/nwk/nwkMap.c
@@ -59,6 +59,7 @@ void Nwk_ManSetIfParsDefault( If_Par_t * pPars )
pPars->fExpRed = 1; ////
pPars->fLatchPaths = 0;
pPars->fEdge = 1;
+ pPars->fPower = 0;
pPars->fCutMin = 0;
pPars->fSeqMap = 0;
pPars->fVerbose = 0;
@@ -98,12 +99,29 @@ void Nwk_ManSetIfParsDefault( If_Par_t * pPars )
***********************************************************************/
If_Man_t * Nwk_ManToIf( Aig_Man_t * p, If_Par_t * pPars, Vec_Ptr_t * vAigToIf )
{
+ extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
+ Vec_Int_t * vSwitching = NULL, * vSwitching2 = NULL;
+ float * pSwitching, * pSwitching2;
If_Man_t * pIfMan;
If_Obj_t * pIfObj;
Aig_Obj_t * pNode, * pFanin, * pPrev;
- int i;
+ int i, clk = clock();
+ // set the number of registers (switch activity will be combinational)
+ Aig_ManSetRegNum( p, 0 );
+ if ( pPars->fPower )
+ {
+ vSwitching = Saig_ManComputeSwitchProbs( p, 48, 16, 0 );
+ if ( pPars->fVerbose )
+ {
+ PRT( "Computing switching activity", clock() - clk );
+ }
+ pSwitching = (float *)vSwitching->pArray;
+ vSwitching2 = Vec_IntStart( Aig_ManObjNumMax(p) );
+ pSwitching2 = (float *)vSwitching2->pArray;
+ }
// start the mapping manager and set its parameters
pIfMan = If_ManStart( pPars );
+ pIfMan->vSwitching = vSwitching2;
// load the AIG into the mapper
Aig_ManForEachObj( p, pNode, i )
{
@@ -116,6 +134,8 @@ If_Man_t * Nwk_ManToIf( Aig_Man_t * p, If_Par_t * pPars, Vec_Ptr_t * vAigToIf )
pIfObj = If_ManCreateCi( pIfMan );
If_ObjSetLevel( pIfObj, Aig_ObjLevel(pNode) );
// printf( "pi=%d ", pIfObj->Level );
+ if ( pIfMan->nLevelMax < (int)pIfObj->Level )
+ pIfMan->nLevelMax = (int)pIfObj->Level;
}
else if ( Aig_ObjIsPo(pNode) )
{
@@ -130,6 +150,8 @@ If_Man_t * Nwk_ManToIf( Aig_Man_t * p, If_Par_t * pPars, Vec_Ptr_t * vAigToIf )
assert( Vec_PtrEntry(vAigToIf, i) == NULL );
Vec_PtrWriteEntry( vAigToIf, i, pIfObj );
pNode->pData = pIfObj;
+ if ( vSwitching2 )
+ pSwitching2[pIfObj->Id] = pSwitching[pNode->Id];
// set up the choice node
if ( Aig_ObjIsChoice( p, pNode ) )
{
@@ -140,6 +162,8 @@ If_Man_t * Nwk_ManToIf( Aig_Man_t * p, If_Par_t * pPars, Vec_Ptr_t * vAigToIf )
}
// assert( If_ObjLevel(pIfObj) == Aig_ObjLevel(pNode) );
}
+ if ( vSwitching )
+ Vec_IntFree( vSwitching );
return pIfMan;
}
diff --git a/src/aig/nwk/nwkMerge.c b/src/aig/nwk/nwkMerge.c
index 531bc1c0..3aec4faa 100644
--- a/src/aig/nwk/nwkMerge.c
+++ b/src/aig/nwk/nwkMerge.c
@@ -913,7 +913,7 @@ int Nwk_ManCountTotalFanins( Nwk_Obj_t * pLut, Nwk_Obj_t * pCand )
SeeAlso []
***********************************************************************/
-void Nwl_ManCollectOverlapCands( Nwk_Obj_t * pLut, Vec_Ptr_t * vCands, Nwk_LMPars_t * pPars )
+void Nwk_ManCollectOverlapCands( Nwk_Obj_t * pLut, Vec_Ptr_t * vCands, Nwk_LMPars_t * pPars )
{
Nwk_Obj_t * pFanin, * pObj;
int i, k;
@@ -985,7 +985,7 @@ Vec_Int_t * Nwk_ManLutMerge( Nwk_Man_t * pNtk, Nwk_LMPars_t * pPars )
{
if ( Nwk_ObjFaninNum(pLut) > pPars->nMaxLutSize )
continue;
- Nwl_ManCollectOverlapCands( pLut, vCands1, pPars );
+ Nwk_ManCollectOverlapCands( pLut, vCands1, pPars );
if ( pPars->fUseDiffSupp )
Nwk_ManCollectNonOverlapCands( pLut, vStart, vNext, vCands2, pPars );
if ( Vec_PtrSize(vCands1) == 0 && Vec_PtrSize(vCands2) == 0 )
@@ -1022,9 +1022,11 @@ Vec_Int_t * Nwk_ManLutMerge( Nwk_Man_t * pNtk, Nwk_LMPars_t * pPars )
Nwk_ManGraphReportMemoryUsage( p );
}
vResult = p->vPairs; p->vPairs = NULL;
+/*
for ( i = 0; i < vResult->nSize; i += 2 )
printf( "(%d,%d) ", vResult->pArray[i], vResult->pArray[i+1] );
printf( "\n" );
+*/
Nwk_ManGraphFree( p );
return vResult;
}
diff --git a/src/aig/nwk/nwkStrash.c b/src/aig/nwk/nwkStrash.c
index a4ce5e39..6c2a3677 100644
--- a/src/aig/nwk/nwkStrash.c
+++ b/src/aig/nwk/nwkStrash.c
@@ -133,6 +133,7 @@ Aig_Man_t * Nwk_ManStrash( Nwk_Man_t * pNtk )
}
Vec_PtrFree( vObjs );
Aig_ManCleanup( pMan );
+ Aig_ManSetRegNum( pMan, 0 );
return pMan;
}