abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkUtil.c File Reference
#include <math.h>
#include "nwk.h"
#include "bool/kit/kit.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Nwk_ManIncrementTravId (Nwk_Man_t *pNtk)
 DECLARATIONS ///. More...
 
int Nwk_ManGetFaninMax (Nwk_Man_t *pNtk)
 
int Nwk_ManGetTotalFanins (Nwk_Man_t *pNtk)
 
int Nwk_ManPiNum (Nwk_Man_t *pNtk)
 
int Nwk_ManPoNum (Nwk_Man_t *pNtk)
 
int Nwk_ManGetAigNodeNum (Nwk_Man_t *pNtk)
 
int Nwk_NodeCompareLevelsIncrease (Nwk_Obj_t **pp1, Nwk_Obj_t **pp2)
 
int Nwk_NodeCompareLevelsDecrease (Nwk_Obj_t **pp1, Nwk_Obj_t **pp2)
 
void Nwk_ObjPrint (Nwk_Obj_t *pObj)
 
void Nwk_ManDumpBlif (Nwk_Man_t *pNtk, char *pFileName, Vec_Ptr_t *vPiNames, Vec_Ptr_t *vPoNames)
 
void Nwk_ManPrintFanioNew (Nwk_Man_t *pNtk)
 
void Nwk_ManCleanMarks (Nwk_Man_t *pMan)
 
int Nwk_ManMinimumBaseNode (Nwk_Obj_t *pObj, Vec_Int_t *vTruth, int fVerbose)
 
int Nwk_ManMinimumBaseInt (Nwk_Man_t *pNtk, int fVerbose)
 
void Nwk_ManMinimumBaseRec (Nwk_Man_t *pNtk, int fVerbose)
 
void Nwk_ManMinimumBase (Nwk_Man_t *pNtk, int fVerbose)
 
void Nwk_ManRemoveDupFaninsNode (Nwk_Obj_t *pObj, int iFan0, int iFan1, Vec_Int_t *vTruth)
 
void Nwk_ManRemoveDupFanins (Nwk_Man_t *pNtk, int fVerbose)
 

Function Documentation

void Nwk_ManCleanMarks ( Nwk_Man_t pMan)

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

Synopsis [Cleans the temporary marks of the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 464 of file nwkUtil.c.

465 {
466  Nwk_Obj_t * pObj;
467  int i;
468  Nwk_ManForEachObj( pMan, pObj, i )
469  pObj->MarkA = pObj->MarkB = 0;
470 }
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
void Nwk_ManDumpBlif ( Nwk_Man_t pNtk,
char *  pFileName,
Vec_Ptr_t vPiNames,
Vec_Ptr_t vPoNames 
)

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

Synopsis [Dumps the BLIF file for the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 257 of file nwkUtil.c.

258 {
259  FILE * pFile;
260  Vec_Ptr_t * vNodes;
261  Vec_Int_t * vTruth;
262  Vec_Int_t * vCover;
263  Nwk_Obj_t * pObj, * pFanin;
264  Aig_MmFlex_t * pMem;
265  char * pSop = NULL;
266  unsigned * pTruth;
267  int i, k, nDigits;
268  if ( Nwk_ManPoNum(pNtk) == 0 )
269  {
270  printf( "Nwk_ManDumpBlif(): Network does not have POs.\n" );
271  return;
272  }
273  // collect nodes in the DFS order
274  nDigits = Abc_Base10Log( Nwk_ManObjNumMax(pNtk) );
275  // write the file
276  pFile = fopen( pFileName, "w" );
277  fprintf( pFile, "# BLIF file written by procedure Nwk_ManDumpBlif()\n" );
278 // fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" );
279  fprintf( pFile, ".model %s\n", pNtk->pName );
280  // write PIs
281  fprintf( pFile, ".inputs" );
282  Nwk_ManForEachCi( pNtk, pObj, i )
283  if ( vPiNames )
284  fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, i) );
285  else
286  fprintf( pFile, " n%0*d", nDigits, pObj->Id );
287  fprintf( pFile, "\n" );
288  // write POs
289  fprintf( pFile, ".outputs" );
290  Nwk_ManForEachCo( pNtk, pObj, i )
291  if ( vPoNames )
292  fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPoNames, i) );
293  else
294  fprintf( pFile, " n%0*d", nDigits, pObj->Id );
295  fprintf( pFile, "\n" );
296  // write nodes
297  pMem = Aig_MmFlexStart();
298  vTruth = Vec_IntAlloc( 1 << 16 );
299  vCover = Vec_IntAlloc( 1 << 16 );
300  vNodes = Nwk_ManDfs( pNtk );
301  Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pObj, i )
302  {
303  if ( !Nwk_ObjIsNode(pObj) )
304  continue;
305  // derive SOP for the AIG
306  pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 );
307  if ( Hop_IsComplement(pObj->pFunc) )
308  Kit_TruthNot( pTruth, pTruth, Nwk_ObjFaninNum(pObj) );
309  pSop = Kit_PlaFromTruth( pMem, pTruth, Nwk_ObjFaninNum(pObj), vCover );
310  // write the node
311  fprintf( pFile, ".names" );
312  if ( !Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) && !Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) )
313  {
314  Nwk_ObjForEachFanin( pObj, pFanin, k )
315  if ( vPiNames && Nwk_ObjIsPi(pFanin) )
316  fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, Nwk_ObjPioNum(pFanin)) );
317  else
318  fprintf( pFile, " n%0*d", nDigits, pFanin->Id );
319  }
320  fprintf( pFile, " n%0*d\n", nDigits, pObj->Id );
321  // write the function
322  fprintf( pFile, "%s", pSop );
323  }
324  Vec_IntFree( vCover );
325  Vec_IntFree( vTruth );
326  Vec_PtrFree( vNodes );
327  Aig_MmFlexStop( pMem, 0 );
328  // write POs
329  Nwk_ManForEachCo( pNtk, pObj, i )
330  {
331  fprintf( pFile, ".names" );
332  if ( vPiNames && Nwk_ObjIsPi(Nwk_ObjFanin0(pObj)) )
333  fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, Nwk_ObjPioNum(Nwk_ObjFanin0(pObj))) );
334  else
335  fprintf( pFile, " n%0*d", nDigits, Nwk_ObjFanin0(pObj)->Id );
336  if ( vPoNames )
337  fprintf( pFile, " %s\n", (char*)Vec_PtrEntry(vPoNames, Nwk_ObjPioNum(pObj)) );
338  else
339  fprintf( pFile, " n%0*d\n", nDigits, pObj->Id );
340  fprintf( pFile, "%d 1\n", !pObj->fInvert );
341  }
342  fprintf( pFile, ".end\n\n" );
343  fclose( pFile );
344 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
#define Nwk_ManForEachCo(p, pObj, i)
Definition: nwk.h:181
int Nwk_ManPoNum(Nwk_Man_t *pNtk)
Definition: nwkUtil.c:135
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
char * Kit_PlaFromTruth(void *p, unsigned *pTruth, int nVars, Vec_Int_t *vCover)
Definition: kitPla.c:337
#define Nwk_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: nwk.h:179
static int Nwk_ObjIsPi(Nwk_Obj_t *p)
Definition: nwk.h:150
static int Kit_TruthIsConst0(unsigned *pIn, int nVars)
Definition: kit.h:315
char * pName
Definition: nwk.h:64
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
static int Kit_TruthIsConst1(unsigned *pIn, int nVars)
Definition: kit.h:323
ABC_DLL Vec_Ptr_t * Nwk_ManDfs(Nwk_Man_t *pNtk)
Definition: nwkDfs.c:321
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
static int Hop_IsComplement(Hop_Obj_t *p)
Definition: hop.h:129
static void Kit_TruthNot(unsigned *pOut, unsigned *pIn, int nVars)
Definition: kit.h:373
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Nwk_ObjPioNum(Nwk_Obj_t *p)
Definition: nwk.h:136
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
static int Nwk_ManObjNumMax(Nwk_Man_t *p)
Definition: nwk.h:129
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static Nwk_Obj_t * Nwk_ObjFanin0(Nwk_Obj_t *p)
Definition: nwk.h:140
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition: hopTruth.c:143
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Nwk_ManGetAigNodeNum ( Nwk_Man_t pNtk)

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

Synopsis [Reads the number of AIG nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 155 of file nwkUtil.c.

156 {
157  Nwk_Obj_t * pNode;
158  int i, nNodes = 0;
159  Nwk_ManForEachNode( pNtk, pNode, i )
160  {
161  if ( pNode->pFunc == NULL )
162  {
163  printf( "Nwk_ManGetAigNodeNum(): Local AIG of node %d is not assigned.\n", pNode->Id );
164  continue;
165  }
166  if ( Nwk_ObjFaninNum(pNode) < 2 )
167  continue;
168  nNodes += Hop_DagSize( pNode->pFunc );
169  }
170  return nNodes;
171 }
int Hop_DagSize(Hop_Obj_t *pObj)
Definition: hopDfs.c:279
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
int Nwk_ManGetFaninMax ( Nwk_Man_t pNtk)

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

Synopsis [Reads the maximum number of fanins of a node.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file nwkUtil.c.

72 {
73  Nwk_Obj_t * pNode;
74  int i, nFaninsMax = 0;
75  Nwk_ManForEachNode( pNtk, pNode, i )
76  {
77  if ( nFaninsMax < Nwk_ObjFaninNum(pNode) )
78  nFaninsMax = Nwk_ObjFaninNum(pNode);
79  }
80  return nFaninsMax;
81 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
int Nwk_ManGetTotalFanins ( Nwk_Man_t pNtk)

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

Synopsis [Reads the total number of all fanins.]

Description []

SideEffects []

SeeAlso []

Definition at line 94 of file nwkUtil.c.

95 {
96  Nwk_Obj_t * pNode;
97  int i, nFanins = 0;
98  Nwk_ManForEachNode( pNtk, pNode, i )
99  nFanins += Nwk_ObjFaninNum(pNode);
100  return nFanins;
101 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
ABC_NAMESPACE_IMPL_START void Nwk_ManIncrementTravId ( Nwk_Man_t pNtk)

DECLARATIONS ///.

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

FileName [nwkUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Logic network representation.]

Synopsis [Various utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id:
nwkUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

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

Synopsis [Increments the current traversal ID of the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file nwkUtil.c.

48 {
49  Nwk_Obj_t * pObj;
50  int i;
51  if ( pNtk->nTravIds >= (1<<26)-1 )
52  {
53  pNtk->nTravIds = 0;
54  Nwk_ManForEachObj( pNtk, pObj, i )
55  pObj->TravId = 0;
56  }
57  pNtk->nTravIds++;
58 }
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
int nTravIds
Definition: nwk.h:78
void Nwk_ManMinimumBase ( Nwk_Man_t pNtk,
int  fVerbose 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 563 of file nwkUtil.c.

564 {
565  Vec_Int_t * vTruth;
566  Nwk_Obj_t * pObj;
567  int i, Counter = 0;
568  vTruth = Vec_IntAlloc( 1 << 16 );
569  Nwk_ManForEachNode( pNtk, pObj, i )
570  Counter += Nwk_ManMinimumBaseNode( pObj, vTruth, fVerbose );
571  if ( fVerbose && Counter )
572  printf( "Support minimization reduced support of %d nodes.\n", Counter );
573  Vec_IntFree( vTruth );
574 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int Nwk_ManMinimumBaseNode(Nwk_Obj_t *pObj, Vec_Int_t *vTruth, int fVerbose)
Definition: nwkUtil.c:483
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
if(last==0)
Definition: sparse_int.h:34
static int Counter
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
int Nwk_ManMinimumBaseInt ( Nwk_Man_t pNtk,
int  fVerbose 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 519 of file nwkUtil.c.

520 {
521  Vec_Int_t * vTruth;
522  Nwk_Obj_t * pObj;
523  int i, Counter = 0;
524  vTruth = Vec_IntAlloc( 1 << 16 );
525  Nwk_ManForEachNode( pNtk, pObj, i )
526  Counter += Nwk_ManMinimumBaseNode( pObj, vTruth, fVerbose );
527  if ( fVerbose && Counter )
528  printf( "Support minimization reduced support of %d nodes.\n", Counter );
529  Vec_IntFree( vTruth );
530  return Counter;
531 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
int Nwk_ManMinimumBaseNode(Nwk_Obj_t *pObj, Vec_Int_t *vTruth, int fVerbose)
Definition: nwkUtil.c:483
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
if(last==0)
Definition: sparse_int.h:34
static int Counter
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
int Nwk_ManMinimumBaseNode ( Nwk_Obj_t pObj,
Vec_Int_t vTruth,
int  fVerbose 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 483 of file nwkUtil.c.

484 {
485  unsigned * pTruth;
486  Nwk_Obj_t * pFanin, * pObjNew;
487  Nwk_Man_t * pNtk = pObj->pMan;
488  int uSupp, nSuppSize, k, Counter = 0;
489  pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 );
490  nSuppSize = Kit_TruthSupportSize(pTruth, Nwk_ObjFaninNum(pObj));
491  if ( nSuppSize == Nwk_ObjFaninNum(pObj) )
492  return 0;
493  Counter++;
494  uSupp = Kit_TruthSupport( pTruth, Nwk_ObjFaninNum(pObj) );
495  // create new node with the given support
496  pObjNew = Nwk_ManCreateNode( pNtk, nSuppSize, Nwk_ObjFanoutNum(pObj) );
497  Nwk_ObjForEachFanin( pObj, pFanin, k )
498  if ( uSupp & (1 << k) )
499  Nwk_ObjAddFanin( pObjNew, pFanin );
500  pObjNew->pFunc = Hop_Remap( pNtk->pManHop, pObj->pFunc, uSupp, Nwk_ObjFaninNum(pObj) );
501  if ( fVerbose )
502  printf( "Reducing node %d fanins from %d to %d.\n",
503  pObj->Id, Nwk_ObjFaninNum(pObj), Nwk_ObjFaninNum(pObjNew) );
504  Nwk_ObjReplace( pObj, pObjNew );
505  return 1;
506 }
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
ABC_DLL void Nwk_ObjReplace(Nwk_Obj_t *pNodeOld, Nwk_Obj_t *pNodeNew)
Definition: nwkFanio.c:302
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
Hop_Obj_t * Hop_Remap(Hop_Man_t *p, Hop_Obj_t *pRoot, unsigned uSupp, int nVars)
Definition: hopDfs.c:518
Hop_Man_t * pManHop
Definition: nwk.h:73
Definition: nwk.h:61
if(last==0)
Definition: sparse_int.h:34
static int Counter
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
unsigned Kit_TruthSupport(unsigned *pTruth, int nVars)
Definition: kitTruth.c:346
unsigned * Hop_ManConvertAigToTruth(Hop_Man_t *p, Hop_Obj_t *pRoot, int nVars, Vec_Int_t *vTruth, int fMsbFirst)
Definition: hopTruth.c:143
ABC_DLL void Nwk_ObjAddFanin(Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
Definition: nwkFanio.c:165
static Hop_Obj_t * Hop_Regular(Hop_Obj_t *p)
Definition: hop.h:126
int Kit_TruthSupportSize(unsigned *pTruth, int nVars)
Definition: kitTruth.c:327
ABC_DLL Nwk_Obj_t * Nwk_ManCreateNode(Nwk_Man_t *pMan, int nFanins, int nFanouts)
Definition: nwkObj.c:134
void Nwk_ManMinimumBaseRec ( Nwk_Man_t pNtk,
int  fVerbose 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 544 of file nwkUtil.c.

545 {
546  int i;
547  abctime clk = Abc_Clock();
548  for ( i = 0; Nwk_ManMinimumBaseInt( pNtk, fVerbose ); i++ );
549  ABC_PRT( "Minbase", Abc_Clock() - clk );
550 }
int Nwk_ManMinimumBaseInt(Nwk_Man_t *pNtk, int fVerbose)
Definition: nwkUtil.c:519
static abctime Abc_Clock()
Definition: abc_global.h:279
#define ABC_PRT(a, t)
Definition: abc_global.h:220
ABC_INT64_T abctime
Definition: abc_global.h:278
int Nwk_ManPiNum ( Nwk_Man_t pNtk)

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

Synopsis [Returns the number of true PIs.]

Description []

SideEffects []

SeeAlso []

Definition at line 115 of file nwkUtil.c.

116 {
117  Nwk_Obj_t * pNode;
118  int i, Counter = 0;
119  Nwk_ManForEachCi( pNtk, pNode, i )
120  Counter += Nwk_ObjIsPi( pNode );
121  return Counter;
122 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
#define Nwk_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition: nwk.h:179
static int Nwk_ObjIsPi(Nwk_Obj_t *p)
Definition: nwk.h:150
static int Counter
int Nwk_ManPoNum ( Nwk_Man_t pNtk)

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

Synopsis [Returns the number of true POs.]

Description []

SideEffects []

SeeAlso []

Definition at line 135 of file nwkUtil.c.

136 {
137  Nwk_Obj_t * pNode;
138  int i, Counter = 0;
139  Nwk_ManForEachCo( pNtk, pNode, i )
140  Counter += Nwk_ObjIsPo( pNode );
141  return Counter;
142 }
#define Nwk_ManForEachCo(p, pObj, i)
Definition: nwk.h:181
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Nwk_ObjIsPo(Nwk_Obj_t *p)
Definition: nwk.h:151
static int Counter
void Nwk_ManPrintFanioNew ( Nwk_Man_t pNtk)

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

Synopsis [Prints the distribution of fanins/fanouts in the network.]

Description []

SideEffects []

SeeAlso []

Definition at line 357 of file nwkUtil.c.

358 {
359  char Buffer[100];
360  Nwk_Obj_t * pNode;
361  Vec_Int_t * vFanins, * vFanouts;
362  int nFanins, nFanouts, nFaninsMax, nFanoutsMax, nFaninsAll, nFanoutsAll;
363  int i, k, nSizeMax;
364 
365  // determine the largest fanin and fanout
366  nFaninsMax = nFanoutsMax = 0;
367  nFaninsAll = nFanoutsAll = 0;
368  Nwk_ManForEachNode( pNtk, pNode, i )
369  {
370  nFanins = Nwk_ObjFaninNum(pNode);
371  nFanouts = Nwk_ObjFanoutNum(pNode);
372  nFaninsAll += nFanins;
373  nFanoutsAll += nFanouts;
374  nFaninsMax = Abc_MaxInt( nFaninsMax, nFanins );
375  nFanoutsMax = Abc_MaxInt( nFanoutsMax, nFanouts );
376  }
377 
378  // allocate storage for fanin/fanout numbers
379  nSizeMax = Abc_MaxInt( 10 * (Abc_Base10Log(nFaninsMax) + 1), 10 * (Abc_Base10Log(nFanoutsMax) + 1) );
380  vFanins = Vec_IntStart( nSizeMax );
381  vFanouts = Vec_IntStart( nSizeMax );
382 
383  // count the number of fanins and fanouts
384  Nwk_ManForEachNode( pNtk, pNode, i )
385  {
386  nFanins = Nwk_ObjFaninNum(pNode);
387  nFanouts = Nwk_ObjFanoutNum(pNode);
388 // nFanouts = Nwk_NodeMffcSize(pNode);
389 
390  if ( nFanins < 10 )
391  Vec_IntAddToEntry( vFanins, nFanins, 1 );
392  else if ( nFanins < 100 )
393  Vec_IntAddToEntry( vFanins, 10 + nFanins/10, 1 );
394  else if ( nFanins < 1000 )
395  Vec_IntAddToEntry( vFanins, 20 + nFanins/100, 1 );
396  else if ( nFanins < 10000 )
397  Vec_IntAddToEntry( vFanins, 30 + nFanins/1000, 1 );
398  else if ( nFanins < 100000 )
399  Vec_IntAddToEntry( vFanins, 40 + nFanins/10000, 1 );
400  else if ( nFanins < 1000000 )
401  Vec_IntAddToEntry( vFanins, 50 + nFanins/100000, 1 );
402  else if ( nFanins < 10000000 )
403  Vec_IntAddToEntry( vFanins, 60 + nFanins/1000000, 1 );
404 
405  if ( nFanouts < 10 )
406  Vec_IntAddToEntry( vFanouts, nFanouts, 1 );
407  else if ( nFanouts < 100 )
408  Vec_IntAddToEntry( vFanouts, 10 + nFanouts/10, 1 );
409  else if ( nFanouts < 1000 )
410  Vec_IntAddToEntry( vFanouts, 20 + nFanouts/100, 1 );
411  else if ( nFanouts < 10000 )
412  Vec_IntAddToEntry( vFanouts, 30 + nFanouts/1000, 1 );
413  else if ( nFanouts < 100000 )
414  Vec_IntAddToEntry( vFanouts, 40 + nFanouts/10000, 1 );
415  else if ( nFanouts < 1000000 )
416  Vec_IntAddToEntry( vFanouts, 50 + nFanouts/100000, 1 );
417  else if ( nFanouts < 10000000 )
418  Vec_IntAddToEntry( vFanouts, 60 + nFanouts/1000000, 1 );
419  }
420 
421  printf( "The distribution of fanins and fanouts in the network:\n" );
422  printf( " Number Nodes with fanin Nodes with fanout\n" );
423  for ( k = 0; k < nSizeMax; k++ )
424  {
425  if ( vFanins->pArray[k] == 0 && vFanouts->pArray[k] == 0 )
426  continue;
427  if ( k < 10 )
428  printf( "%15d : ", k );
429  else
430  {
431  sprintf( Buffer, "%d - %d", (int)pow((double)10, k/10) * (k%10), (int)pow((double)10, k/10) * (k%10+1) - 1 );
432  printf( "%15s : ", Buffer );
433  }
434  if ( vFanins->pArray[k] == 0 )
435  printf( " " );
436  else
437  printf( "%12d ", vFanins->pArray[k] );
438  printf( " " );
439  if ( vFanouts->pArray[k] == 0 )
440  printf( " " );
441  else
442  printf( "%12d ", vFanouts->pArray[k] );
443  printf( "\n" );
444  }
445  Vec_IntFree( vFanins );
446  Vec_IntFree( vFanouts );
447 
448  printf( "Fanins: Max = %d. Ave = %.2f. Fanouts: Max = %d. Ave = %.2f.\n",
449  nFaninsMax, 1.0*nFaninsAll/Nwk_ManNodeNum(pNtk),
450  nFanoutsMax, 1.0*nFanoutsAll/Nwk_ManNodeNum(pNtk) );
451 }
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
Definition: bblif.c:302
static int Abc_Base10Log(unsigned n)
Definition: abc_global.h:252
char * sprintf()
static int Nwk_ManNodeNum(Nwk_Man_t *p)
Definition: nwk.h:127
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
void Nwk_ManRemoveDupFanins ( Nwk_Man_t pNtk,
int  fVerbose 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 608 of file nwkUtil.c.

609 {
610  Vec_Int_t * vTruth;
611  Nwk_Obj_t * pObj;
612  int i, k, m, fFound;
613  // check if the nodes have duplicated fanins
614  vTruth = Vec_IntAlloc( 1 << 16 );
615  Nwk_ManForEachNode( pNtk, pObj, i )
616  {
617  fFound = 0;
618  for ( k = 0; k < pObj->nFanins; k++ )
619  {
620  for ( m = k + 1; m < pObj->nFanins; m++ )
621  if ( pObj->pFanio[k] == pObj->pFanio[m] )
622  {
623  if ( fVerbose )
624  printf( "Removing duplicated fanins of node %d (fanins %d and %d).\n",
625  pObj->Id, pObj->pFanio[k]->Id, pObj->pFanio[m]->Id );
626  Nwk_ManRemoveDupFaninsNode( pObj, k, m, vTruth );
627  fFound = 1;
628  break;
629  }
630  if ( fFound )
631  break;
632  }
633  }
634  Vec_IntFree( vTruth );
635 // Nwk_ManMinimumBase( pNtk, fVerbose );
636 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void Nwk_ManRemoveDupFaninsNode(Nwk_Obj_t *pObj, int iFan0, int iFan1, Vec_Int_t *vTruth)
Definition: nwkUtil.c:587
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
void Nwk_ManRemoveDupFaninsNode ( Nwk_Obj_t pObj,
int  iFan0,
int  iFan1,
Vec_Int_t vTruth 
)

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

Synopsis [Minimizes the support of all nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 587 of file nwkUtil.c.

588 {
589  Hop_Man_t * pManHop = pObj->pMan->pManHop;
590 // Nwk_Obj_t * pFanin0 = pObj->pFanio[iFan0];
591 // Nwk_Obj_t * pFanin1 = pObj->pFanio[iFan1];
592  assert( pObj->pFanio[iFan0] == pObj->pFanio[iFan1] );
593  pObj->pFunc = Hop_Compose( pManHop, pObj->pFunc, Hop_IthVar(pManHop,iFan0), iFan1 );
594  Nwk_ManMinimumBaseNode( pObj, vTruth, 0 );
595 }
Hop_Obj_t * Hop_Compose(Hop_Man_t *p, Hop_Obj_t *pRoot, Hop_Obj_t *pFunc, int iVar)
Definition: hopDfs.c:415
int Nwk_ManMinimumBaseNode(Nwk_Obj_t *pObj, Vec_Int_t *vTruth, int fVerbose)
Definition: nwkUtil.c:483
#define assert(ex)
Definition: util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
int Nwk_NodeCompareLevelsDecrease ( Nwk_Obj_t **  pp1,
Nwk_Obj_t **  pp2 
)

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

Synopsis [Procedure used for sorting the nodes in decreasing order of levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file nwkUtil.c.

206 {
207  int Diff = (*pp1)->Level - (*pp2)->Level;
208  if ( Diff > 0 )
209  return -1;
210  if ( Diff < 0 )
211  return 1;
212  return 0;
213 }
int Nwk_NodeCompareLevelsIncrease ( Nwk_Obj_t **  pp1,
Nwk_Obj_t **  pp2 
)

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

Synopsis [Procedure used for sorting the nodes in increasing order of levels.]

Description []

SideEffects []

SeeAlso []

Definition at line 184 of file nwkUtil.c.

185 {
186  int Diff = (*pp1)->Level - (*pp2)->Level;
187  if ( Diff < 0 )
188  return -1;
189  if ( Diff > 0 )
190  return 1;
191  return 0;
192 }
void Nwk_ObjPrint ( Nwk_Obj_t pObj)

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

Synopsis [Prints the objects.]

Description []

SideEffects []

SeeAlso []

Definition at line 226 of file nwkUtil.c.

227 {
228  Nwk_Obj_t * pNext;
229  int i;
230  printf( "ObjId = %5d. ", pObj->Id );
231  if ( Nwk_ObjIsPi(pObj) )
232  printf( "PI" );
233  if ( Nwk_ObjIsPo(pObj) )
234  printf( "PO" );
235  if ( Nwk_ObjIsNode(pObj) )
236  printf( "Node" );
237  printf( " Fanins = " );
238  Nwk_ObjForEachFanin( pObj, pNext, i )
239  printf( "%d ", pNext->Id );
240  printf( " Fanouts = " );
241  Nwk_ObjForEachFanout( pObj, pNext, i )
242  printf( "%d ", pNext->Id );
243  printf( "\n" );
244 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Nwk_ObjIsPi(Nwk_Obj_t *p)
Definition: nwk.h:150
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
static int Nwk_ObjIsPo(Nwk_Obj_t *p)
Definition: nwk.h:151
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199