abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkMan.c File Reference
#include "nwk.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Nwk_Man_t
Nwk_ManAlloc ()
 DECLARATIONS ///. More...
 
void Nwk_ManFree (Nwk_Man_t *p)
 
void Nwk_ManPrintLutSizes (Nwk_Man_t *p, If_LibLut_t *pLutLib)
 
int Nwk_ManCompareAndSaveBest (Nwk_Man_t *pNtk, void *pNtl)
 
char * Nwk_FileNameGeneric (char *FileName)
 
float Nwl_ManComputeTotalSwitching (Nwk_Man_t *pNtk)
 
void Nwk_ManPrintStats (Nwk_Man_t *pNtk, If_LibLut_t *pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t *pNtl)
 

Function Documentation

char* Nwk_FileNameGeneric ( char *  FileName)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 178 of file nwkMan.c.

179 {
180  char * pDot, * pRes;
181  pRes = Abc_UtilStrsav( FileName );
182  if ( (pDot = strrchr( pRes, '.' )) )
183  *pDot = 0;
184  return pRes;
185 }
char * strrchr()
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47

DECLARATIONS ///.

CFile****************************************************************

FileName [nwkMan.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Logic network representation.]

Synopsis [Network manager.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
nwkMan.c,v 1.1 2008/10/10 14:09:30 mjarvin Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Allocates the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file nwkMan.c.

46 {
47  Nwk_Man_t * p;
48  p = ABC_ALLOC( Nwk_Man_t, 1 );
49  memset( p, 0, sizeof(Nwk_Man_t) );
50  p->vCis = Vec_PtrAlloc( 1000 );
51  p->vCos = Vec_PtrAlloc( 1000 );
52  p->vObjs = Vec_PtrAlloc( 1000 );
53  p->vTemp = Vec_PtrAlloc( 1000 );
54  p->nFanioPlus = 2;
56  p->pManHop = Hop_ManStart();
57  return p;
58 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
Aig_MmFlex_t * pMemObjs
Definition: nwk.h:76
Vec_Ptr_t * vCos
Definition: nwk.h:68
Vec_Ptr_t * vCis
Definition: nwk.h:67
Hop_Man_t * pManHop
Definition: nwk.h:73
Definition: nwk.h:61
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition: hopMan.c:45
Vec_Ptr_t * vObjs
Definition: nwk.h:69
Vec_Ptr_t * vTemp
Definition: nwk.h:77
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
int nFanioPlus
Definition: nwk.h:71
int Nwk_ManCompareAndSaveBest ( Nwk_Man_t pNtk,
void *  pNtl 
)

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 []

Definition at line 121 of file nwkMan.c.

122 {
123 // extern void Ntl_WriteBlifLogic( Nwk_Man_t * pNtk, void * pNtl, char * pFileName );
124  extern void Nwk_ManDumpBlif( Nwk_Man_t * pNtk, char * pFileName, Vec_Ptr_t * vPiNames, Vec_Ptr_t * vPoNames );
125  static struct ParStruct {
126  char * pName; // name of the best saved network
127  int Depth; // depth of the best saved network
128  int Flops; // flops in the best saved network
129  int Nodes; // nodes in the best saved network
130  int nPis; // the number of primary inputs
131  int nPos; // the number of primary outputs
132  } ParsNew, ParsBest = { 0 };
133  // free storage for the name
134  if ( pNtk == NULL )
135  {
136  ABC_FREE( ParsBest.pName );
137  return 0;
138  }
139  // get the parameters
140  ParsNew.Depth = Nwk_ManLevel( pNtk );
141  ParsNew.Flops = Nwk_ManLatchNum( pNtk );
142  ParsNew.Nodes = Nwk_ManNodeNum( pNtk );
143  ParsNew.nPis = Nwk_ManPiNum( pNtk );
144  ParsNew.nPos = Nwk_ManPoNum( pNtk );
145  // reset the parameters if the network has the same name
146  if ( ParsBest.pName == NULL ||
147  strcmp(ParsBest.pName, pNtk->pName) ||
148  ParsBest.Depth > ParsNew.Depth ||
149  (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops > ParsNew.Flops) ||
150  (ParsBest.Depth == ParsNew.Depth && ParsBest.Flops == ParsNew.Flops && ParsBest.Nodes > ParsNew.Nodes) )
151  {
152  ABC_FREE( ParsBest.pName );
153  ParsBest.pName = Abc_UtilStrsav( pNtk->pName );
154  ParsBest.Depth = ParsNew.Depth;
155  ParsBest.Flops = ParsNew.Flops;
156  ParsBest.Nodes = ParsNew.Nodes;
157  ParsBest.nPis = ParsNew.nPis;
158  ParsBest.nPos = ParsNew.nPos;
159  // write the network
160 // Ntl_WriteBlifLogic( pNtk, pNtl, "best.blif" );
161 // Nwk_ManDumpBlif( pNtk, "best_map.blif", NULL, NULL );
162  return 1;
163  }
164  return 0;
165 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
ABC_DLL int Nwk_ManLevel(Nwk_Man_t *pNtk)
Definition: nwkDfs.c:215
ABC_DLL int Nwk_ManPoNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:135
static int Nwk_ManLatchNum(Nwk_Man_t *p)
Definition: nwk.h:128
char * pName
Definition: nwk.h:64
int strcmp()
Definition: nwk.h:61
ABC_DLL int Nwk_ManPiNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:115
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL void Nwk_ManDumpBlif(Nwk_Man_t *p, char *pFileName, Vec_Ptr_t *vCiNames, Vec_Ptr_t *vCoNames)
Definition: nwkUtil.c:257
static int Nwk_ManNodeNum(Nwk_Man_t *p)
Definition: nwk.h:127
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
static int Depth
Definition: dsdProc.c:56
void Nwk_ManFree ( Nwk_Man_t p)

Function*************************************************************

Synopsis [Deallocates the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file nwkMan.c.

72 {
73 // printf( "The number of realloced nodes = %d.\n", p->nRealloced );
74  if ( p->pName ) ABC_FREE( p->pName );
75  if ( p->pSpec ) ABC_FREE( p->pSpec );
76  if ( p->vCis ) Vec_PtrFree( p->vCis );
77  if ( p->vCos ) Vec_PtrFree( p->vCos );
78  if ( p->vObjs ) Vec_PtrFree( p->vObjs );
79  if ( p->vTemp ) Vec_PtrFree( p->vTemp );
80  if ( p->pManTime ) Tim_ManStop( p->pManTime );
81  if ( p->pMemObjs ) Aig_MmFlexStop( p->pMemObjs, 0 );
82  if ( p->pManHop ) Hop_ManStop( p->pManHop );
83  ABC_FREE( p );
84 }
char * pSpec
Definition: nwk.h:65
Aig_MmFlex_t * pMemObjs
Definition: nwk.h:76
Vec_Ptr_t * vCos
Definition: nwk.h:68
char * pName
Definition: nwk.h:64
void Hop_ManStop(Hop_Man_t *p)
Definition: hopMan.c:84
Vec_Ptr_t * vCis
Definition: nwk.h:67
Hop_Man_t * pManHop
Definition: nwk.h:73
void Tim_ManStop(Tim_Man_t *p)
Definition: timMan.c:375
Tim_Man_t * pManTime
Definition: nwk.h:74
Vec_Ptr_t * vObjs
Definition: nwk.h:69
Vec_Ptr_t * vTemp
Definition: nwk.h:77
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Nwk_ManPrintLutSizes ( Nwk_Man_t p,
If_LibLut_t pLutLib 
)

Function*************************************************************

Synopsis [Prints stats of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 97 of file nwkMan.c.

98 {
99  Nwk_Obj_t * pObj;
100  int i, Counters[256] = {0};
101  Nwk_ManForEachNode( p, pObj, i )
102  Counters[Nwk_ObjFaninNum(pObj)]++;
103  printf( "LUTs by size: " );
104  for ( i = 0; i <= pLutLib->LutMax; i++ )
105  printf( "%d:%d ", i, Counters[i] );
106 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
for(p=first;p->value< newval;p=p->next)
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
static int size
Definition: cuddSign.c:86
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
void Nwk_ManPrintStats ( Nwk_Man_t pNtk,
If_LibLut_t pLutLib,
int  fSaveBest,
int  fDumpResult,
int  fPower,
Ntl_Man_t pNtl 
)

Function*************************************************************

Synopsis [Prints stats of the manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 234 of file nwkMan.c.

235 {
236 // extern int Ntl_ManLatchNum( Ntl_Man_t * p );
237 // extern void Ntl_ManWriteBlifLogic( Nwk_Man_t * pNtk, void * pNtl, char * pFileName );
238  if ( fSaveBest )
239  Nwk_ManCompareAndSaveBest( pNtk, pNtl );
240  if ( fDumpResult )
241  {
242  char Buffer[1000] = {0};
243  const char * pNameGen = pNtk->pSpec? Nwk_FileNameGeneric( pNtk->pSpec ) : "nameless_";
244  sprintf( Buffer, "%s_dump.blif", pNameGen );
245 // Ntl_ManWriteBlifLogic( pNtk, pNtl, Buffer );
246 // sprintf( Buffer, "%s_dump_map.blif", pNameGen );
247 // Nwk_ManDumpBlif( pNtk, Buffer, NULL, NULL );
248  if ( pNtk->pSpec ) ABC_FREE( pNameGen );
249  }
250 
251  pNtk->pLutLib = pLutLib;
252  printf( "%-15s : ", pNtk->pName );
253  printf( "pi = %5d ", Nwk_ManPiNum(pNtk) );
254  printf( "po = %5d ", Nwk_ManPoNum(pNtk) );
255  printf( "ci = %5d ", Nwk_ManCiNum(pNtk) );
256  printf( "co = %5d ", Nwk_ManCoNum(pNtk) );
257 // printf( "lat = %5d ", Ntl_ManLatchNum(pNtl) );
258  printf( "node = %5d ", Nwk_ManNodeNum(pNtk) );
259  printf( "edge = %5d ", Nwk_ManGetTotalFanins(pNtk) );
260  printf( "aig = %6d ", Nwk_ManGetAigNodeNum(pNtk) );
261  printf( "lev = %3d ", Nwk_ManLevel(pNtk) );
262 // printf( "lev2 = %3d ", Nwk_ManLevelBackup(pNtk) );
263  printf( "delay = %5.2f ", Nwk_ManDelayTraceLut(pNtk) );
264  if ( fPower )
265  printf( "power = %7.2f ", Nwl_ManComputeTotalSwitching(pNtk) );
266  Nwk_ManPrintLutSizes( pNtk, pLutLib );
267  printf( "\n" );
268 // Nwk_ManDelayTracePrint( pNtk, pLutLib );
269  fflush( stdout );
270 }
ABC_DLL int Nwk_ManLevel(Nwk_Man_t *pNtk)
Definition: nwkDfs.c:215
ABC_DLL int Nwk_ManPoNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:135
char * pSpec
Definition: nwk.h:65
char * pName
Definition: nwk.h:64
ABC_DLL int Nwk_ManGetAigNodeNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:155
char * Nwk_FileNameGeneric(char *FileName)
Definition: nwkMan.c:178
If_LibLut_t * pLutLib
Definition: nwk.h:75
ABC_DLL int Nwk_ManPiNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:115
char * sprintf()
static int Nwk_ManCiNum(Nwk_Man_t *p)
MACRO DEFINITIONS ///.
Definition: nwk.h:125
#define ABC_FREE(obj)
Definition: abc_global.h:232
int Nwk_ManCompareAndSaveBest(Nwk_Man_t *pNtk, void *pNtl)
Definition: nwkMan.c:121
ABC_DLL float Nwk_ManDelayTraceLut(Nwk_Man_t *pNtk)
Definition: nwkTiming.c:326
float Nwl_ManComputeTotalSwitching(Nwk_Man_t *pNtk)
Definition: nwkMan.c:198
ABC_DLL int Nwk_ManGetTotalFanins(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:94
static int Nwk_ManNodeNum(Nwk_Man_t *p)
Definition: nwk.h:127
void Nwk_ManPrintLutSizes(Nwk_Man_t *p, If_LibLut_t *pLutLib)
Definition: nwkMan.c:97
static int Nwk_ManCoNum(Nwk_Man_t *p)
Definition: nwk.h:126
float Nwl_ManComputeTotalSwitching ( Nwk_Man_t pNtk)

Function*************************************************************

Synopsis [Marks nodes for power-optimization.]

Description []

SideEffects []

SeeAlso []

Definition at line 198 of file nwkMan.c.

199 {
200  extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
201  Vec_Int_t * vSwitching;
202  float * pSwitching;
203  Aig_Man_t * pAig;
204  Aig_Obj_t * pObjAig;
205  Nwk_Obj_t * pObjAbc;
206  float Result = (float)0;
207  int i;
208  // strash the network
209  // map network into an AIG
210  pAig = Nwk_ManStrash( pNtk );
211  vSwitching = Saig_ManComputeSwitchProbs( pAig, 48, 16, 0 );
212  pSwitching = (float *)vSwitching->pArray;
213  Nwk_ManForEachObj( pNtk, pObjAbc, i )
214  {
215  if ( (pObjAig = Aig_Regular((Aig_Obj_t *)pObjAbc->pCopy)) )
216  Result += Nwk_ObjFanoutNum(pObjAbc) * pSwitching[pObjAig->Id];
217  }
218  Vec_IntFree( vSwitching );
219  Aig_ManStop( pAig );
220  return Result;
221 }
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
ABC_DLL Aig_Man_t * Nwk_ManStrash(Nwk_Man_t *p)
Definition: nwkStrash.c:99
Vec_Int_t * Saig_ManComputeSwitchProbs(Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
Definition: giaSwitch.c:684
Definition: aig.h:69
#define Nwk_ManForEachObj(p, pObj, i)
Definition: nwk.h:189
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
int Id
Definition: aig.h:85