/**CFile****************************************************************
FileName [abcPrint.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Printing statistics.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: abcPrint.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include <math.h>
#include "base/abc/abc.h"
#include "bool/dec/dec.h"
#include "base/main/main.h"
#include "map/mio/mio.h"
#include "aig/aig/aig.h"
#include "map/if/if.h"
#ifdef ABC_USE_CUDD
#include "bdd/extrab/extraBdd.h"
#endif
#ifdef WIN32
#include <windows.h>
#endif
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
//extern int s_TotalNodes = 0;
//extern int s_TotalChanges = 0;
abctime s_MappingTime = 0;
int s_MappingMem = 0;
abctime s_ResubTime = 0;
abctime s_ResynTime = 0;
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [If the network is best, saves it in "best.blif" and returns 1.]
Description [If the networks are incomparable, saves the new network,
returns its parameters in the internal parameter structure, and returns 1.
If the new network is not a logic network, quits without saving and returns 0.]
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_NtkCompareAndSaveBest( Abc_Ntk_t * pNtk )
{
extern void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType );
static struct ParStruct {
char * pName; // name of the best saved network
int Depth; // depth of the best saved network
int Flops; // flops in the best saved network
int Nodes; // nodes in the best saved network
int Edges; // edges in the best saved network
int nPis; // the number of primary inputs
int nPos; // the number of primary outputs
} ParsNew, ParsBest = { 0 };
char * pFileNameOut;
// free storage for the name
if ( pNtk == NULL )
{
ABC_FREE( ParsBest.pName );
return 0;
}
// quit if not a logic network
if ( !Abc_NtkIsLogic(pNtk) )
return 0;
// get the parameters
ParsNew.Depth = Abc_NtkLevel( pNtk );
ParsNew.Flops = Abc_NtkLatchNum( pNtk );
ParsNew.Nodes = Abc_NtkNodeNum( pNtk );
ParsNew.Edges = Abc_NtkGetTotalFanins( pNtk );
ParsNew.nPis = Abc_NtkPiNum( pNtk );
ParsNew.nPos = Abc_NtkPoNum( pNtk );
// reset the parameters if the network has the same name
if ( ParsBest.pName == NULL ||
strcmp(ParsBest.pName, pNtk->pName) ||
ParsBest.Depth > ParsNew.Depth ||
(ParsBest.Depth == ParsNew.Depth && ParsBest.Flops > ParsNew.Flops) ||
(ParsBest.Depth == ParsNew.Depth && ParsBest.Flops == ParsNew.Flops && ParsBest.Edges > ParsNew.Edges) )
{
ABC_FREE( ParsBest.pName );
ParsBest.pName = Extra_UtilStrsav( pNtk->pName );
ParsBest.Depth = ParsNew.Depth;
ParsBest.Flops = ParsNew.Flops;
ParsBest.Nodes = ParsNew.Nodes;
ParsBest.Edges = ParsNew.Edges;
ParsBest.nPis = ParsNew.nPis;
ParsBest.nPos = ParsNew.nPos;
// writ the network
if ( strcmp(pNtk->pSpec + strlen(pNtk->pSpec) - strlen("_best.blif"), "_best.blif") )
pFileNameOut = Extra_FileNameGenericAppend( pNtk->pSpec, "_best.blif" );
else
pFileNameOut = pNtk->pSpec;
Io_Write( pNtk, pFileNameOut, IO_FILE_BLIF );
return 1;
}
return 0;
}
/**Function*************************************************************
Synopsis [Collects memory usage.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
double Abc_NtkMemory( Abc_Ntk_t * p )
{
Abc_Obj_t * pObj; int i;
double Memory = sizeof(Abc_Ntk_t);
Memory += sizeof(Abc_Obj_t) * Abc_NtkObjNum(p);
Memory += Vec_PtrMemory(p->vPis);
Memory += Vec_PtrMemory(p->vPos);
Memory += Vec_PtrMemory(p->vCis);
Memory += Vec_PtrMemory(p->vCos);
Memory += Vec_PtrMemory(p->vObjs);
Memory += Vec_IntMemory(&p->vTravIds);
Memory += Vec_IntMemory(p->vLevelsR);
Abc_NtkForEachObj( p, pObj, i )
Memory += sizeof(int) * (Vec_IntCap(&pObj->vFanins) + Vec_IntCap(&pObj->vFanouts));
return Memory;
}
/**Function*************************************************************
Synopsis [Marks nodes for power-optimization.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Abc_NtkMfsTotalSwitching( Abc_Ntk_t * pNtk )
{
extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
Vec_Int_t * vSwitching;
float * pSwitching;
Abc_Ntk_t * pNtkStr;
Aig_Man_t * pAig;
Aig_Obj_t * pObjAig;
Abc_Obj_t * pObjAbc, * pObjAbc2;
float Result = (float)0;
int i;
// strash the network
pNtkStr = Abc_NtkStrash( pNtk, 0, 1, 0 );
Abc_NtkForEachObj( pNtk, pObjAbc, i )
if ( Abc_ObjRegular((Abc_Obj_t *)pObjAbc->pTemp)->Type == ABC_FUNC_NONE || (!Abc_ObjIsCi(pObjAbc) && !Abc_ObjIsNode(pObjAbc)) )
pObjAbc->pTemp = NULL;
// map network into an AIG
pAig = Abc_NtkToDar( pNtkStr, 0, (int)(Abc_NtkLatchNum(pNtk) > 0) );
vSwitching = Saig_ManComputeSwitchProbs( pAig, 48, 16, 0 );
pSwitching = (float *)vSwitching->pArray;
Abc_NtkForEachObj( pNtk, pObjAbc, i )
{
if ( (pObjAbc2 = Abc_ObjRegular((Abc_Obj_t *)pObjAbc->pTemp)) && (pObjAig = Aig_Regular((Aig_Obj_t *)pObjAbc2->pTemp)) )
{
Result += Abc_ObjFanoutNum(pObjAbc) * pSwitching[pObjAig->Id];
// Abc_ObjPrint( stdout, pObjAbc );
// printf( "%d = %.2f\n", i, Abc_ObjFanoutNum(pObjAbc) * pSwitching[pObjAig->Id] );
}
}
Vec_IntFree( vSwitching );
Aig_ManStop( pAig );
Abc_NtkDelete( pNtkStr );
return Result;
}
/**Function*************************************************************
Synopsis [Compute area using LUT library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
float Abc_NtkGetArea( Abc_Ntk_t * pNtk )
{
If_LibLut_t * pLutLib;
Abc_Obj_t * pObj;
float Counter = 0.0;
int i;
assert( Abc_NtkIsLogic(pNtk) );
// get the library
pLutLib = (If_LibLut_t *)Abc_FrameReadLibLut();
if ( pLutLib && pLutLib->LutMax >= Abc_NtkGetFaninMax(pNtk) )
{
Abc_NtkForEachNode( pNtk, pObj, i )
Counter += pLutLib->pLutAreas[Abc_ObjFaninNum(pObj)];
}
return Counter;
}
/**Function*************************************************************
Synopsis [Print the vital stats of the network.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkPrintStats( Abc_Ntk_t * pNtk, int fFactored, int fSaveBest, int fDumpResult, int fUseLutLib, int fPrintMuxes, int fPower, int fGlitch, int fSkipBuf, int fSkipSmall, int fPrintMem )
{
int nSingles = fSkipBuf ? Abc_NtkGetBufNum(pNtk) : 0;
if ( fPrintMuxes && Abc_NtkIsStrash(pNtk) )
{
extern int Abc_NtkCountMuxes( Abc_Ntk_t * pNtk );
int nXors = Abc_NtkGetExorNum(pNtk);
int nMuxs = Abc_NtkCountMuxes(pNtk) - nXors;
int nAnds = Abc_NtkNodeNum(pNtk) - (nMuxs + nXors) * 3 - nSingles;
Abc_Print( 1, "XMA stats: " );
Abc_Print( 1,"Xor =%7d (%6.2f %%) ", nXors, 300.0 * nXors / Abc_NtkNodeNum(pNtk) );
Abc_Print( 1,"Mux =%7d (%6.2f %%) ", nMuxs, 300.0 * nMuxs / Abc_NtkNodeNum(pNtk) );
Abc_Print( 1,"And =%7d (%6.2f %%)", nAnds, 100.0 * nAnds / Abc_NtkNodeNum(pNtk) );
Abc_Print( 1,"\n" );
return;
}
if ( fSaveBest )
Abc_NtkCompareAndSaveBest( pNtk );
/*
if ( fDumpResult )
{
char Buffer[1000] = {0};
const char * pNameGen = pNtk->pSpec? Extra_FileNameGeneric( pNtk->pSpec ) : "nameless_";
sprintf( Buffer, "%s_dump.blif", pNameGen );
Io_Write( pNtk, Buffer, IO_FILE_BLIF );
if ( pNtk->pSpec ) ABC_FREE( pNameGen );
}
*/
// if ( Abc_NtkIsStrash(pNtk) )
// Abc_AigCountNext( pNtk->pManFunc );
#ifdef WIN32
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 15 ); // bright
Abc_Print( 1,"%-30s:", pNtk->pName );
SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 7 ); // normal
#else
Abc_Print( 1,"%s%-30s:%s", "\033[1;37m", pNtk->pName, "\033[0m" ); // bright