ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
nwkMan.c
Go to the documentation of this file.
1
20
21#include "nwk.h"
22
24
25
29
33
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;
55 p->pMemObjs = Aig_MmFlexStart();
56 p->pManHop = Hop_ManStart();
57 return p;
58}
59
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}
85
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}
107
121int Nwk_ManCompareAndSaveBest( Nwk_Man_t * pNtk, void * pNtl )
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}
166
178char * Nwk_FileNameGeneric( char * FileName )
179{
180 char * pDot, * pRes;
181 pRes = Abc_UtilStrsav( FileName );
182 if ( (pDot = strrchr( pRes, '.' )) )
183 *pDot = 0;
184 return pRes;
185}
186
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}
222
234void Nwk_ManPrintStats( Nwk_Man_t * pNtk, If_LibLut_t * pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t * pNtl )
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}
271
275
276
278
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition aigMem.c:337
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
Aig_MmFlex_t * Aig_MmFlexStart()
Definition aigMem.c:305
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Vec_Int_t * Saig_ManComputeSwitchProbs(Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
Definition giaSwitch.c:711
void Hop_ManStop(Hop_Man_t *p)
Definition hopMan.c:84
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition hopMan.c:45
struct If_LibLut_t_ If_LibLut_t
Definition if.h:82
struct Nwk_Man_t_ Nwk_Man_t
Definition ntlnwk.h:41
ABC_DLL Aig_Man_t * Nwk_ManStrash(Nwk_Man_t *p)
Definition nwkStrash.c:99
ABC_DLL void Nwk_ManDumpBlif(Nwk_Man_t *p, char *pFileName, Vec_Ptr_t *vCiNames, Vec_Ptr_t *vCoNames)
Definition nwkUtil.c:257
typedefABC_NAMESPACE_HEADER_START struct Ntl_Man_t_ Ntl_Man_t
INCLUDES ///.
Definition ntlnwk.h:40
int Nwk_ManCompareAndSaveBest(Nwk_Man_t *pNtk, void *pNtl)
Definition nwkMan.c:121
ABC_NAMESPACE_IMPL_START Nwk_Man_t * Nwk_ManAlloc()
DECLARATIONS ///.
Definition nwkMan.c:45
void Nwk_ManPrintStats(Nwk_Man_t *pNtk, If_LibLut_t *pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t *pNtl)
Definition nwkMan.c:234
void Nwk_ManPrintLutSizes(Nwk_Man_t *p, If_LibLut_t *pLutLib)
Definition nwkMan.c:97
float Nwl_ManComputeTotalSwitching(Nwk_Man_t *pNtk)
Definition nwkMan.c:198
char * Nwk_FileNameGeneric(char *FileName)
Definition nwkMan.c:178
void Nwk_ManFree(Nwk_Man_t *p)
Definition nwkMan.c:71
#define Nwk_ManForEachNode(p, pObj, i)
Definition nwk.h:192
ABC_DLL float Nwk_ManDelayTraceLut(Nwk_Man_t *pNtk)
Definition nwkTiming.c:326
ABC_DLL int Nwk_ManPiNum(Nwk_Man_t *pNtk)
Definition nwkUtil.c:115
ABC_DLL int Nwk_ManGetAigNodeNum(Nwk_Man_t *pNtk)
Definition nwkUtil.c:155
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition nwk.h:49
#define Nwk_ManForEachObj(p, pObj, i)
Definition nwk.h:189
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
ABC_DLL int Nwk_ManGetTotalFanins(Nwk_Man_t *pNtk)
Definition nwkUtil.c:94
int Id
Definition aig.h:85
int LutMax
Definition if.h:190
char * pName
Definition nwk.h:64
If_LibLut_t * pLutLib
Definition nwk.h:75
char * pSpec
Definition nwk.h:65
void Tim_ManStop(Tim_Man_t *p)
Definition timMan.c:378
char * strrchr()
char * memset()
int strcmp()
char * sprintf()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42