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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Nwk_Grf_t
Nwk_ManGraphAlloc (int nVertsMax)
 DECLARATIONS ///. More...
 
void Nwk_ManGraphFree (Nwk_Grf_t *p)
 
void Nwk_ManGraphReportMemoryUsage (Nwk_Grf_t *p)
 
void Nwk_ManGraphHashEdge (Nwk_Grf_t *p, int iLut1, int iLut2)
 
static void Nwk_ManGraphListAdd (Nwk_Grf_t *p, int *pList, Nwk_Vrt_t *pVertex)
 
static void Nwk_ManGraphListDelete (Nwk_Grf_t *p, int *pList, Nwk_Vrt_t *pVertex)
 
static void Nwk_ManGraphListInsert (Nwk_Grf_t *p, Nwk_Vrt_t *pVertex)
 
static void Nwk_ManGraphListExtract (Nwk_Grf_t *p, Nwk_Vrt_t *pVertex)
 
void Nwk_ManGraphPrepare (Nwk_Grf_t *p)
 
void Nwk_ManGraphSortPairs (Nwk_Grf_t *p)
 
void Nwk_ManGraphCheckLists (Nwk_Grf_t *p)
 
static void Nwk_ManGraphVertexRemoveEdge (Nwk_Vrt_t *pThis, Nwk_Vrt_t *pNext)
 
void Nwk_ManGraphUpdate (Nwk_Grf_t *p, Nwk_Vrt_t *pVertex, Nwk_Vrt_t *pNext)
 
int Nwk_ManGraphListLength (Nwk_Grf_t *p, int List)
 
Nwk_Vrt_tNwk_ManGraphListFindMinEdge (Nwk_Grf_t *p, Nwk_Vrt_t *pVert)
 
Nwk_Vrt_tNwk_ManGraphListFindMin (Nwk_Grf_t *p, int List)
 
void Nwk_ManGraphSolve (Nwk_Grf_t *p)
 
Nwk_Grf_tNwk_ManLutMergeReadGraph (char *pFileName)
 
int Nwk_ManLutMergeGraphTest (char *pFileName)
 
void Nwk_ManMarkFanins_rec (Nwk_Obj_t *pLut, int nLevMin)
 
void Nwk_ManMarkFanouts_rec (Nwk_Obj_t *pLut, int nLevMax, int nFanMax)
 
void Nwk_ManCollectCircle (Vec_Ptr_t *vStart, Vec_Ptr_t *vNext, int nFanMax)
 
void Nwk_ManCollectNonOverlapCands (Nwk_Obj_t *pLut, Vec_Ptr_t *vStart, Vec_Ptr_t *vNext, Vec_Ptr_t *vCands, Nwk_LMPars_t *pPars)
 
int Nwk_ManCountTotalFanins (Nwk_Obj_t *pLut, Nwk_Obj_t *pCand)
 
void Nwk_ManCollectOverlapCands (Nwk_Obj_t *pLut, Vec_Ptr_t *vCands, Nwk_LMPars_t *pPars)
 
Vec_Int_tNwk_ManLutMerge (Nwk_Man_t *pNtk, void *pParsInit)
 

Function Documentation

void Nwk_ManCollectCircle ( Vec_Ptr_t vStart,
Vec_Ptr_t vNext,
int  nFanMax 
)

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

Synopsis [Collects the circle of nodes around the given set.]

Description []

SideEffects []

SeeAlso []

Definition at line 789 of file nwkMerge.c.

790 {
791  Nwk_Obj_t * pObj, * pNext;
792  int i, k;
793  Vec_PtrClear( vNext );
794  Vec_PtrForEachEntry( Nwk_Obj_t *, vStart, pObj, i )
795  {
796  Nwk_ObjForEachFanin( pObj, pNext, k )
797  {
798  if ( !Nwk_ObjIsNode(pNext) )
799  continue;
800  if ( Nwk_ObjIsTravIdCurrent( pNext ) )
801  continue;
802  Nwk_ObjSetTravIdCurrent( pNext );
803  Vec_PtrPush( vNext, pNext );
804  }
805  Nwk_ObjForEachFanout( pObj, pNext, k )
806  {
807  if ( !Nwk_ObjIsNode(pNext) )
808  continue;
809  if ( Nwk_ObjIsTravIdCurrent( pNext ) )
810  continue;
811  Nwk_ObjSetTravIdCurrent( pNext );
812  if ( Nwk_ObjFanoutNum(pNext) > nFanMax )
813  continue;
814  Vec_PtrPush( vNext, pNext );
815  }
816  }
817 }
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
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static void Nwk_ObjSetTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:166
static int Nwk_ObjIsTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:168
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Nwk_ManCollectNonOverlapCands ( Nwk_Obj_t pLut,
Vec_Ptr_t vStart,
Vec_Ptr_t vNext,
Vec_Ptr_t vCands,
Nwk_LMPars_t pPars 
)

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

Synopsis [Collects the circle of nodes removes from the given one.]

Description []

SideEffects []

SeeAlso []

Definition at line 830 of file nwkMerge.c.

831 {
832  Vec_Ptr_t * vTemp;
833  Nwk_Obj_t * pObj;
834  int i, k;
835  Vec_PtrClear( vCands );
836  if ( pPars->nMaxSuppSize - Nwk_ObjFaninNum(pLut) <= 1 )
837  return;
838 
839  // collect nodes removed by this distance
840  assert( pPars->nMaxDistance > 0 );
841  Vec_PtrClear( vStart );
842  Vec_PtrPush( vStart, pLut );
843  Nwk_ManIncrementTravId( pLut->pMan );
844  Nwk_ObjSetTravIdCurrent( pLut );
845  for ( i = 1; i <= pPars->nMaxDistance; i++ )
846  {
847  Nwk_ManCollectCircle( vStart, vNext, pPars->nMaxFanout );
848  vTemp = vStart;
849  vStart = vNext;
850  vNext = vTemp;
851  // collect the nodes in vStart
852  Vec_PtrForEachEntry( Nwk_Obj_t *, vStart, pObj, k )
853  Vec_PtrPush( vCands, pObj );
854  }
855 
856  // mark the TFI/TFO nodes
857  Nwk_ManIncrementTravId( pLut->pMan );
858  if ( pPars->fUseTfiTfo )
859  Nwk_ObjSetTravIdCurrent( pLut );
860  else
861  {
862  Nwk_ObjSetTravIdPrevious( pLut );
863  Nwk_ManMarkFanins_rec( pLut, Nwk_ObjLevel(pLut) - pPars->nMaxDistance );
864  Nwk_ObjSetTravIdPrevious( pLut );
865  Nwk_ManMarkFanouts_rec( pLut, Nwk_ObjLevel(pLut) + pPars->nMaxDistance, pPars->nMaxFanout );
866  }
867 
868  // collect nodes satisfying the following conditions:
869  // - they are close enough in terms of distance
870  // - they are not in the TFI/TFO of the LUT
871  // - they have no more than the given number of fanins
872  // - they have no more than the given diff in delay
873  k = 0;
874  Vec_PtrForEachEntry( Nwk_Obj_t *, vCands, pObj, i )
875  {
876  if ( Nwk_ObjIsTravIdCurrent(pObj) )
877  continue;
878  if ( Nwk_ObjFaninNum(pLut) + Nwk_ObjFaninNum(pObj) > pPars->nMaxSuppSize )
879  continue;
880  if ( Nwk_ObjLevel(pLut) - Nwk_ObjLevel(pObj) > pPars->nMaxLevelDiff ||
881  Nwk_ObjLevel(pObj) - Nwk_ObjLevel(pLut) > pPars->nMaxLevelDiff )
882  continue;
883  Vec_PtrWriteEntry( vCands, k++, pObj );
884  }
885  Vec_PtrShrink( vCands, k );
886 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int nMaxFanout
Definition: nwkMerge.h:52
void Nwk_ManMarkFanins_rec(Nwk_Obj_t *pLut, int nLevMin)
Definition: nwkMerge.c:735
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
int nMaxDistance
Definition: nwkMerge.h:50
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
static void Nwk_ObjSetTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:166
int nMaxSuppSize
Definition: nwkMerge.h:49
static int Nwk_ObjIsTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:168
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
static void Nwk_ObjSetTravIdPrevious(Nwk_Obj_t *pObj)
Definition: nwk.h:167
ABC_DLL void Nwk_ManIncrementTravId(Nwk_Man_t *pNtk)
DECLARATIONS ///.
Definition: nwkUtil.c:47
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
void Nwk_ManMarkFanouts_rec(Nwk_Obj_t *pLut, int nLevMax, int nFanMax)
Definition: nwkMerge.c:761
static int Nwk_ObjLevel(Nwk_Obj_t *pObj)
Definition: nwk.h:162
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
void Nwk_ManCollectCircle(Vec_Ptr_t *vStart, Vec_Ptr_t *vNext, int nFanMax)
Definition: nwkMerge.c:789
static void Vec_PtrShrink(Vec_Ptr_t *p, int nSizeNew)
Definition: vecPtr.h:528
int nMaxLevelDiff
Definition: nwkMerge.h:51
void Nwk_ManCollectOverlapCands ( Nwk_Obj_t pLut,
Vec_Ptr_t vCands,
Nwk_LMPars_t pPars 
)

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

Synopsis [Collects overlapping candidates.]

Description []

SideEffects []

SeeAlso []

Definition at line 920 of file nwkMerge.c.

921 {
922  Nwk_Obj_t * pFanin, * pObj;
923  int i, k;
924  // mark fanins of pLut
925  Nwk_ObjForEachFanin( pLut, pFanin, i )
926  pFanin->MarkC = 1;
927  // collect the matching fanouts of each fanin of the node
928  Vec_PtrClear( vCands );
929  Nwk_ManIncrementTravId( pLut->pMan );
930  Nwk_ObjSetTravIdCurrent( pLut );
931  Nwk_ObjForEachFanin( pLut, pFanin, i )
932  {
933  if ( !Nwk_ObjIsNode(pFanin) )
934  continue;
935  if ( Nwk_ObjFanoutNum(pFanin) > pPars->nMaxFanout )
936  continue;
937  Nwk_ObjForEachFanout( pFanin, pObj, k )
938  {
939  if ( !Nwk_ObjIsNode(pObj) )
940  continue;
941  if ( Nwk_ObjIsTravIdCurrent( pObj ) )
942  continue;
943  Nwk_ObjSetTravIdCurrent( pObj );
944  // check the difference in delay
945  if ( Nwk_ObjLevel(pLut) - Nwk_ObjLevel(pObj) > pPars->nMaxLevelDiff ||
946  Nwk_ObjLevel(pObj) - Nwk_ObjLevel(pLut) > pPars->nMaxLevelDiff )
947  continue;
948  // check the total number of fanins of the node
949  if ( Nwk_ManCountTotalFanins(pLut, pObj) > pPars->nMaxSuppSize )
950  continue;
951  Vec_PtrPush( vCands, pObj );
952  }
953  }
954  // unmark fanins of pLut
955  Nwk_ObjForEachFanin( pLut, pFanin, i )
956  pFanin->MarkC = 0;
957 }
int nMaxFanout
Definition: nwkMerge.h:52
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
int Nwk_ManCountTotalFanins(Nwk_Obj_t *pLut, Nwk_Obj_t *pCand)
Definition: nwkMerge.c:900
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static void Nwk_ObjSetTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:166
int nMaxSuppSize
Definition: nwkMerge.h:49
static int Nwk_ObjIsTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:168
ABC_DLL void Nwk_ManIncrementTravId(Nwk_Man_t *pNtk)
DECLARATIONS ///.
Definition: nwkUtil.c:47
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
static int Nwk_ObjLevel(Nwk_Obj_t *pObj)
Definition: nwk.h:162
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int nMaxLevelDiff
Definition: nwkMerge.h:51
int Nwk_ManCountTotalFanins ( Nwk_Obj_t pLut,
Nwk_Obj_t pCand 
)

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

Synopsis [Count the total number of fanins.]

Description []

SideEffects []

SeeAlso []

Definition at line 900 of file nwkMerge.c.

901 {
902  Nwk_Obj_t * pFanin;
903  int i, nCounter = Nwk_ObjFaninNum(pLut);
904  Nwk_ObjForEachFanin( pCand, pFanin, i )
905  nCounter += !pFanin->MarkC;
906  return nCounter;
907 }
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_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
ABC_NAMESPACE_IMPL_START Nwk_Grf_t* Nwk_ManGraphAlloc ( int  nVertsMax)

DECLARATIONS ///.

INLINED FUNCTIONS ///.

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

FileName [nwkMerge.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Netlist representation.]

Synopsis [LUT merging algorithm.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

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

Synopsis [Allocates the graph.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file nwkMerge.c.

47 {
48  Nwk_Grf_t * p;
49  p = ABC_ALLOC( Nwk_Grf_t, 1 );
50  memset( p, 0, sizeof(Nwk_Grf_t) );
51  p->nVertsMax = nVertsMax;
52  p->nEdgeHash = Abc_PrimeCudd( 3 * nVertsMax );
54  p->pMemEdges = Aig_MmFixedStart( sizeof(Nwk_Edg_t), p->nEdgeHash );
55  p->vPairs = Vec_IntAlloc( 1000 );
56  return p;
57 }
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nEdgeHash
Definition: nwkMerge.h:86
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nVertsMax
Definition: nwkMerge.h:85
Aig_MmFixed_t * Aig_MmFixedStart(int nEntrySize, int nEntriesMax)
FUNCTION DEFINITIONS ///.
Definition: aigMem.c:96
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Nwk_Edg_t ** pEdgeHash
Definition: nwkMerge.h:87
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
Vec_Int_t * vPairs
Definition: nwkMerge.h:98
Aig_MmFixed_t * pMemEdges
Definition: nwkMerge.h:88
void Nwk_ManGraphCheckLists ( Nwk_Grf_t p)

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

Synopsis [Updates the problem after pulling out one edge.]

Description []

SideEffects []

SeeAlso []

Definition at line 402 of file nwkMerge.c.

403 {
404  Nwk_Vrt_t * pVertex, * pNext;
405  int i, j;
406  assert( p->pLists1[0] == 0 );
407  for ( i = 1; i <= NWK_MAX_LIST; i++ )
408  if ( p->pLists1[i] )
409  {
410  pVertex = p->pVerts[ p->pLists1[i] ];
411  assert( pVertex->nEdges == 1 );
412  pNext = p->pVerts[ pVertex->pEdges[0] ];
413  assert( pNext->nEdges == i || pNext->nEdges > NWK_MAX_LIST );
414  }
415  // find the next vertext to extract
416  assert( p->pLists2[0] == 0 );
417  assert( p->pLists2[1] == 0 );
418  for ( j = 2; j <= NWK_MAX_LIST; j++ )
419  if ( p->pLists2[j] )
420  {
421  pVertex = p->pVerts[ p->pLists2[j] ];
422  assert( pVertex->nEdges == j || pVertex->nEdges > NWK_MAX_LIST );
423  }
424 }
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int pLists2[NWK_MAX_LIST+1]
Definition: nwkMerge.h:96
int nEdges
Definition: nwkMerge.h:75
int pLists1[NWK_MAX_LIST+1]
Definition: nwkMerge.h:95
#define NWK_MAX_LIST
INCLUDES ///.
Definition: nwkMerge.h:38
#define assert(ex)
Definition: util_old.h:213
void Nwk_ManGraphFree ( Nwk_Grf_t p)

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

Synopsis [Deallocates the graph.]

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file nwkMerge.c.

71 {
72  if ( p->vPairs ) Vec_IntFree( p->vPairs );
73  if ( p->pMemEdges ) Aig_MmFixedStop( p->pMemEdges, 0 );
74  if ( p->pMemVerts ) Aig_MmFlexStop( p->pMemVerts, 0 );
75  ABC_FREE( p->pVerts );
76  ABC_FREE( p->pEdgeHash );
77  ABC_FREE( p->pMapLut2Id );
78  ABC_FREE( p->pMapId2Lut );
79  ABC_FREE( p );
80 }
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
Aig_MmFlex_t * pMemVerts
Definition: nwkMerge.h:93
Nwk_Edg_t ** pEdgeHash
Definition: nwkMerge.h:87
int * pMapLut2Id
Definition: nwkMerge.h:100
int * pMapId2Lut
Definition: nwkMerge.h:101
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
Vec_Int_t * vPairs
Definition: nwkMerge.h:98
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Aig_MmFixed_t * pMemEdges
Definition: nwkMerge.h:88
void Nwk_ManGraphHashEdge ( Nwk_Grf_t p,
int  iLut1,
int  iLut2 
)

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

Synopsis [Finds or adds the edge to the graph.]

Description []

SideEffects []

SeeAlso []

Definition at line 119 of file nwkMerge.c.

120 {
121  Nwk_Edg_t * pEntry;
122  unsigned Key;
123  if ( iLut1 == iLut2 )
124  return;
125  if ( iLut1 > iLut2 )
126  {
127  Key = iLut1;
128  iLut1 = iLut2;
129  iLut2 = Key;
130  }
131  assert( iLut1 < iLut2 );
132  if ( p->nObjs < iLut2 )
133  p->nObjs = iLut2;
134  Key = (unsigned)(741457 * iLut1 + 4256249 * iLut2) % p->nEdgeHash;
135  for ( pEntry = p->pEdgeHash[Key]; pEntry; pEntry = pEntry->pNext )
136  if ( pEntry->iNode1 == iLut1 && pEntry->iNode2 == iLut2 )
137  return;
138  pEntry = (Nwk_Edg_t *)Aig_MmFixedEntryFetch( p->pMemEdges );
139  pEntry->iNode1 = iLut1;
140  pEntry->iNode2 = iLut2;
141  pEntry->pNext = p->pEdgeHash[Key];
142  p->pEdgeHash[Key] = pEntry;
143  p->nEdges++;
144 }
int iNode1
Definition: nwkMerge.h:63
int nEdgeHash
Definition: nwkMerge.h:86
int nEdges
Definition: nwkMerge.h:90
int nObjs
Definition: nwkMerge.h:84
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
Definition: aigMem.c:161
Nwk_Edg_t ** pEdgeHash
Definition: nwkMerge.h:87
int iNode2
Definition: nwkMerge.h:64
Nwk_Edg_t * pNext
Definition: nwkMerge.h:65
#define assert(ex)
Definition: util_old.h:213
Aig_MmFixed_t * pMemEdges
Definition: nwkMerge.h:88
static void Nwk_ManGraphListAdd ( Nwk_Grf_t p,
int *  pList,
Nwk_Vrt_t pVertex 
)
inlinestatic

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

Synopsis [Adds one entry to the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 157 of file nwkMerge.c.

158 {
159  if ( *pList )
160  {
161  Nwk_Vrt_t * pHead;
162  pHead = p->pVerts[*pList];
163  pVertex->iPrev = 0;
164  pVertex->iNext = pHead->Id;
165  pHead->iPrev = pVertex->Id;
166  }
167  *pList = pVertex->Id;
168 }
int iPrev
Definition: nwkMerge.h:73
int iNext
Definition: nwkMerge.h:74
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int Id
Definition: nwkMerge.h:72
static void Nwk_ManGraphListDelete ( Nwk_Grf_t p,
int *  pList,
Nwk_Vrt_t pVertex 
)
inlinestatic

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

Synopsis [Deletes one entry from the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 181 of file nwkMerge.c.

182 {
183  assert( *pList );
184  if ( pVertex->iPrev )
185  {
186 // assert( p->pVerts[pVertex->iPrev]->iNext == pVertex->Id );
187  p->pVerts[pVertex->iPrev]->iNext = pVertex->iNext;
188  }
189  if ( pVertex->iNext )
190  {
191 // assert( p->pVerts[pVertex->iNext]->iPrev == pVertex->Id );
192  p->pVerts[pVertex->iNext]->iPrev = pVertex->iPrev;
193  }
194  if ( *pList == pVertex->Id )
195  *pList = pVertex->iNext;
196  pVertex->iPrev = pVertex->iNext = 0;
197 }
int iPrev
Definition: nwkMerge.h:73
int iNext
Definition: nwkMerge.h:74
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int Id
Definition: nwkMerge.h:72
#define assert(ex)
Definition: util_old.h:213
static void Nwk_ManGraphListExtract ( Nwk_Grf_t p,
Nwk_Vrt_t pVertex 
)
inlinestatic

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

Synopsis [Extracts the edge from one of the linked lists.]

Description []

SideEffects []

SeeAlso []

Definition at line 243 of file nwkMerge.c.

244 {
245  Nwk_Vrt_t * pNext;
246  assert( pVertex->nEdges > 0 );
247 
248  if ( pVertex->nEdges == 1 )
249  {
250  pNext = p->pVerts[ pVertex->pEdges[0] ];
251  if ( pNext->nEdges >= NWK_MAX_LIST )
252  Nwk_ManGraphListDelete( p, p->pLists1 + NWK_MAX_LIST, pVertex );
253  else
254  Nwk_ManGraphListDelete( p, p->pLists1 + pNext->nEdges, pVertex );
255  }
256  else
257  {
258  if ( pVertex->nEdges >= NWK_MAX_LIST )
259  Nwk_ManGraphListDelete( p, p->pLists2 + NWK_MAX_LIST, pVertex );
260  else
261  Nwk_ManGraphListDelete( p, p->pLists2 + pVertex->nEdges, pVertex );
262  }
263 }
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int pLists2[NWK_MAX_LIST+1]
Definition: nwkMerge.h:96
static void Nwk_ManGraphListDelete(Nwk_Grf_t *p, int *pList, Nwk_Vrt_t *pVertex)
Definition: nwkMerge.c:181
int nEdges
Definition: nwkMerge.h:75
int pLists1[NWK_MAX_LIST+1]
Definition: nwkMerge.h:95
#define NWK_MAX_LIST
INCLUDES ///.
Definition: nwkMerge.h:38
#define assert(ex)
Definition: util_old.h:213
Nwk_Vrt_t* Nwk_ManGraphListFindMin ( Nwk_Grf_t p,
int  List 
)

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

Synopsis [Finds the best vertext in the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 590 of file nwkMerge.c.

591 {
592  Nwk_Vrt_t * pThis, * pMinCost = NULL;
593  int k, Counter = 10000, BestCost = 1000000;
594  Nwk_ListForEachVertex( p, List, pThis )
595  {
596  for ( k = 0; k < pThis->nEdges; k++ )
597  {
598  if ( pMinCost == NULL || BestCost > p->pVerts[pThis->pEdges[k]]->nEdges )
599  {
600  BestCost = p->pVerts[pThis->pEdges[k]]->nEdges;
601  pMinCost = pThis;
602  }
603  }
604  if ( --Counter == 0 )
605  break;
606  }
607  return pMinCost;
608 }
#define Nwk_ListForEachVertex(p, List, pVrt)
Definition: nwkMerge.h:115
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int nEdges
Definition: nwkMerge.h:75
static int Counter
Nwk_Vrt_t* Nwk_ManGraphListFindMinEdge ( Nwk_Grf_t p,
Nwk_Vrt_t pVert 
)

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

Synopsis [Returns the adjacent vertex with the mininum number of edges.]

Description []

SideEffects []

SeeAlso []

Definition at line 567 of file nwkMerge.c.

568 {
569  Nwk_Vrt_t * pThis, * pMinCost = NULL;
570  int k;
571  Nwk_VertexForEachAdjacent( p, pVert, pThis, k )
572  {
573  if ( pMinCost == NULL || pMinCost->nEdges > pThis->nEdges )
574  pMinCost = pThis;
575  }
576  return pMinCost;
577 }
#define Nwk_VertexForEachAdjacent(p, pVrt, pNext, k)
Definition: nwkMerge.h:119
int nEdges
Definition: nwkMerge.h:75
static void Nwk_ManGraphListInsert ( Nwk_Grf_t p,
Nwk_Vrt_t pVertex 
)
inlinestatic

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

Synopsis [Inserts the edge into one of the linked lists.]

Description []

SideEffects []

SeeAlso []

Definition at line 210 of file nwkMerge.c.

211 {
212  Nwk_Vrt_t * pNext;
213  assert( pVertex->nEdges > 0 );
214 
215  if ( pVertex->nEdges == 1 )
216  {
217  pNext = p->pVerts[ pVertex->pEdges[0] ];
218  if ( pNext->nEdges >= NWK_MAX_LIST )
219  Nwk_ManGraphListAdd( p, p->pLists1 + NWK_MAX_LIST, pVertex );
220  else
221  Nwk_ManGraphListAdd( p, p->pLists1 + pNext->nEdges, pVertex );
222  }
223  else
224  {
225  if ( pVertex->nEdges >= NWK_MAX_LIST )
226  Nwk_ManGraphListAdd( p, p->pLists2 + NWK_MAX_LIST, pVertex );
227  else
228  Nwk_ManGraphListAdd( p, p->pLists2 + pVertex->nEdges, pVertex );
229  }
230 }
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int pLists2[NWK_MAX_LIST+1]
Definition: nwkMerge.h:96
static void Nwk_ManGraphListAdd(Nwk_Grf_t *p, int *pList, Nwk_Vrt_t *pVertex)
Definition: nwkMerge.c:157
int nEdges
Definition: nwkMerge.h:75
int pLists1[NWK_MAX_LIST+1]
Definition: nwkMerge.h:95
#define NWK_MAX_LIST
INCLUDES ///.
Definition: nwkMerge.h:38
#define assert(ex)
Definition: util_old.h:213
int Nwk_ManGraphListLength ( Nwk_Grf_t p,
int  List 
)

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

Synopsis [Counts the number of entries in the list.]

Description []

SideEffects []

SeeAlso []

Definition at line 540 of file nwkMerge.c.

541 {
542  Nwk_Vrt_t * pThis;
543  int fVerbose = 0;
544  int Counter = 0;
545  Nwk_ListForEachVertex( p, List, pThis )
546  {
547  if ( fVerbose && Counter < 20 )
548  printf( "%d ", p->pVerts[pThis->pEdges[0]]->nEdges );
549  Counter++;
550  }
551  if ( fVerbose )
552  printf( "\n" );
553  return Counter;
554 }
#define Nwk_ListForEachVertex(p, List, pVrt)
Definition: nwkMerge.h:115
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int nEdges
Definition: nwkMerge.h:75
static int Counter
void Nwk_ManGraphPrepare ( Nwk_Grf_t p)

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

Synopsis [Prepares the graph for solving the problem.]

Description []

SideEffects []

SeeAlso []

Definition at line 276 of file nwkMerge.c.

277 {
278  Nwk_Edg_t * pEntry;
279  Nwk_Vrt_t * pVertex;
280  int * pnEdges, nBytes, i;
281  // allocate memory for the present objects
282  p->pMapLut2Id = ABC_ALLOC( int, p->nObjs+1 );
283  p->pMapId2Lut = ABC_ALLOC( int, p->nVertsMax+1 );
284  memset( p->pMapLut2Id, 0xff, sizeof(int) * (p->nObjs+1) );
285  memset( p->pMapId2Lut, 0xff, sizeof(int) * (p->nVertsMax+1) );
286  // mark present objects
287  Nwk_GraphForEachEdge( p, pEntry, i )
288  {
289  assert( pEntry->iNode1 <= p->nObjs );
290  assert( pEntry->iNode2 <= p->nObjs );
291  p->pMapLut2Id[ pEntry->iNode1 ] = 0;
292  p->pMapLut2Id[ pEntry->iNode2 ] = 0;
293  }
294  // map objects
295  p->nVerts = 0;
296  for ( i = 0; i <= p->nObjs; i++ )
297  {
298  if ( p->pMapLut2Id[i] == 0 )
299  {
300  p->pMapLut2Id[i] = ++p->nVerts;
301  p->pMapId2Lut[p->nVerts] = i;
302  }
303  }
304  // count the edges and mark present objects
305  pnEdges = ABC_CALLOC( int, p->nVerts+1 );
306  Nwk_GraphForEachEdge( p, pEntry, i )
307  {
308  // translate into vertices
309  assert( pEntry->iNode1 <= p->nObjs );
310  assert( pEntry->iNode2 <= p->nObjs );
311  pEntry->iNode1 = p->pMapLut2Id[pEntry->iNode1];
312  pEntry->iNode2 = p->pMapLut2Id[pEntry->iNode2];
313  // count the edges
314  assert( pEntry->iNode1 <= p->nVerts );
315  assert( pEntry->iNode2 <= p->nVerts );
316  pnEdges[pEntry->iNode1]++;
317  pnEdges[pEntry->iNode2]++;
318  }
319  // allocate the real graph
320  p->pMemVerts = Aig_MmFlexStart();
321  p->pVerts = ABC_ALLOC( Nwk_Vrt_t *, p->nVerts + 1 );
322  p->pVerts[0] = NULL;
323  for ( i = 1; i <= p->nVerts; i++ )
324  {
325  assert( pnEdges[i] > 0 );
326  nBytes = sizeof(Nwk_Vrt_t) + sizeof(int) * pnEdges[i];
327  p->pVerts[i] = (Nwk_Vrt_t *)Aig_MmFlexEntryFetch( p->pMemVerts, nBytes );
328  memset( p->pVerts[i], 0, nBytes );
329  p->pVerts[i]->Id = i;
330  }
331  // add edges to the real graph
332  Nwk_GraphForEachEdge( p, pEntry, i )
333  {
334  pVertex = p->pVerts[pEntry->iNode1];
335  pVertex->pEdges[ pVertex->nEdges++ ] = pEntry->iNode2;
336  pVertex = p->pVerts[pEntry->iNode2];
337  pVertex->pEdges[ pVertex->nEdges++ ] = pEntry->iNode1;
338  }
339  // put vertices into the data structure
340  for ( i = 1; i <= p->nVerts; i++ )
341  {
342  assert( p->pVerts[i]->nEdges == pnEdges[i] );
343  Nwk_ManGraphListInsert( p, p->pVerts[i] );
344  }
345  // clean up
346  Aig_MmFixedStop( p->pMemEdges, 0 ); p->pMemEdges = NULL;
347  ABC_FREE( p->pEdgeHash );
348 // p->nEdgeHash = 0;
349  ABC_FREE( pnEdges );
350 }
char * memset()
static void Nwk_ManGraphListInsert(Nwk_Grf_t *p, Nwk_Vrt_t *pVertex)
Definition: nwkMerge.c:210
int iNode1
Definition: nwkMerge.h:63
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int Id
Definition: nwkMerge.h:72
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Definition: aigMem.c:366
#define Nwk_GraphForEachEdge(p, pEdge, k)
MACRO DEFINITIONS ///.
Definition: nwkMerge.h:111
int pEdges[0]
Definition: nwkMerge.h:76
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nVertsMax
Definition: nwkMerge.h:85
Aig_MmFlex_t * pMemVerts
Definition: nwkMerge.h:93
int nVerts
Definition: nwkMerge.h:91
int nEdges
Definition: nwkMerge.h:75
int nObjs
Definition: nwkMerge.h:84
Nwk_Edg_t ** pEdgeHash
Definition: nwkMerge.h:87
int * pMapLut2Id
Definition: nwkMerge.h:100
int iNode2
Definition: nwkMerge.h:64
int * pMapId2Lut
Definition: nwkMerge.h:101
struct Nwk_Vrt_t_ Nwk_Vrt_t
Definition: nwkMerge.h:69
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
Aig_MmFixed_t * pMemEdges
Definition: nwkMerge.h:88
void Nwk_ManGraphReportMemoryUsage ( Nwk_Grf_t p)

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

Synopsis [Prepares the graph for solving the problem.]

Description []

SideEffects []

SeeAlso []

Definition at line 93 of file nwkMerge.c.

94 {
95  p->nMemBytes1 =
96  sizeof(Nwk_Grf_t) +
97  sizeof(void *) * p->nEdgeHash +
98  sizeof(int) * (p->nObjs + p->nVertsMax) +
99  sizeof(Nwk_Edg_t) * p->nEdges;
100  p->nMemBytes2 =
101  sizeof(Nwk_Vrt_t) * p->nVerts +
102  sizeof(int) * 2 * p->nEdges;
103  printf( "Memory usage stats: Preprocessing = %.2f MB. Solving = %.2f MB.\n",
104  1.0 * p->nMemBytes1 / (1<<20), 1.0 * p->nMemBytes2 / (1<<20) );
105 }
int nMemBytes1
Definition: nwkMerge.h:103
int nEdgeHash
Definition: nwkMerge.h:86
int nEdges
Definition: nwkMerge.h:90
int nVertsMax
Definition: nwkMerge.h:85
int nVerts
Definition: nwkMerge.h:91
struct Nwk_Edg_t_ Nwk_Edg_t
Definition: nwkMerge.h:60
int nMemBytes2
Definition: nwkMerge.h:104
int nObjs
Definition: nwkMerge.h:84
struct Nwk_Grf_t_ Nwk_Grf_t
Definition: nwkMerge.h:80
void Nwk_ManGraphSolve ( Nwk_Grf_t p)

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

Synopsis [Solves the problem by extracting one edge at a time.]

Description []

SideEffects []

SeeAlso []

Definition at line 621 of file nwkMerge.c.

622 {
623  Nwk_Vrt_t * pVertex, * pNext;
624  int i, j;
625  Nwk_ManGraphPrepare( p );
626  while ( 1 )
627  {
628  // find the next vertex to extract
629  assert( p->pLists1[0] == 0 );
630  for ( i = 1; i <= NWK_MAX_LIST; i++ )
631  if ( p->pLists1[i] )
632  {
633 // printf( "%d ", i );
634 // printf( "ListA = %2d. Length = %5d.\n", i, Nwk_ManGraphListLength(p,p->pLists1[i]) );
635  pVertex = p->pVerts[ p->pLists1[i] ];
636  assert( pVertex->nEdges == 1 );
637  pNext = p->pVerts[ pVertex->pEdges[0] ];
638  Nwk_ManGraphUpdate( p, pVertex, pNext );
639  break;
640  }
641  if ( i < NWK_MAX_LIST + 1 )
642  continue;
643  // find the next vertex to extract
644  assert( p->pLists2[0] == 0 );
645  assert( p->pLists2[1] == 0 );
646  for ( j = 2; j <= NWK_MAX_LIST; j++ )
647  if ( p->pLists2[j] )
648  {
649 // printf( "***%d ", j );
650 // printf( "ListB = %2d. Length = %5d.\n", j, Nwk_ManGraphListLength(p,p->pLists2[j]) );
651  pVertex = Nwk_ManGraphListFindMin( p, p->pLists2[j] );
652  assert( pVertex->nEdges == j || j == NWK_MAX_LIST );
653  pNext = Nwk_ManGraphListFindMinEdge( p, pVertex );
654  Nwk_ManGraphUpdate( p, pVertex, pNext );
655  break;
656  }
657  if ( j == NWK_MAX_LIST + 1 )
658  break;
659  }
661 }
Nwk_Vrt_t ** pVerts
Definition: nwkMerge.h:92
int pEdges[0]
Definition: nwkMerge.h:76
int pLists2[NWK_MAX_LIST+1]
Definition: nwkMerge.h:96
int nEdges
Definition: nwkMerge.h:75
int pLists1[NWK_MAX_LIST+1]
Definition: nwkMerge.h:95
Nwk_Vrt_t * Nwk_ManGraphListFindMinEdge(Nwk_Grf_t *p, Nwk_Vrt_t *pVert)
Definition: nwkMerge.c:567
void Nwk_ManGraphUpdate(Nwk_Grf_t *p, Nwk_Vrt_t *pVertex, Nwk_Vrt_t *pNext)
Definition: nwkMerge.c:460
void Nwk_ManGraphSortPairs(Nwk_Grf_t *p)
Definition: nwkMerge.c:363
#define NWK_MAX_LIST
INCLUDES ///.
Definition: nwkMerge.h:38
void Nwk_ManGraphPrepare(Nwk_Grf_t *p)
Definition: nwkMerge.c:276
#define assert(ex)
Definition: util_old.h:213
Nwk_Vrt_t * Nwk_ManGraphListFindMin(Nwk_Grf_t *p, int List)
Definition: nwkMerge.c:590
void Nwk_ManGraphSortPairs ( Nwk_Grf_t p)

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

Synopsis [Sort pairs by the first vertex in the topological order.]

Description []

SideEffects []

SeeAlso []

Definition at line 363 of file nwkMerge.c.

364 {
365  int nSize = Vec_IntSize(p->vPairs);
366  int * pIdToPair, i;
367  // allocate storage
368  pIdToPair = ABC_ALLOC( int, p->nObjs+1 );
369  for ( i = 0; i <= p->nObjs; i++ )
370  pIdToPair[i] = -1;
371  // create mapping
372  for ( i = 0; i < p->vPairs->nSize; i += 2 )
373  {
374  assert( pIdToPair[ p->vPairs->pArray[i] ] == -1 );
375  pIdToPair[ p->vPairs->pArray[i] ] = p->vPairs->pArray[i+1];
376  }
377  // recreate pairs
378  Vec_IntClear( p->vPairs );
379  for ( i = 0; i <= p->nObjs; i++ )
380  if ( pIdToPair[i] >= 0 )
381  {
382  assert( i < pIdToPair[i] );
383  Vec_IntPush( p->vPairs, i );
384  Vec_IntPush( p->vPairs, pIdToPair[i] );
385  }
386  assert( nSize == Vec_IntSize(p->vPairs) );
387  ABC_FREE( pIdToPair );
388 }
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int nObjs
Definition: nwkMerge.h:84
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
Vec_Int_t * vPairs
Definition: nwkMerge.h:98
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
void Nwk_ManGraphUpdate ( Nwk_Grf_t p,
Nwk_Vrt_t pVertex,
Nwk_Vrt_t pNext 
)

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

Synopsis [Updates the problem after pulling out one edge.]

Description []

SideEffects []

SeeAlso []

Definition at line 460 of file nwkMerge.c.

461 {
462  Nwk_Vrt_t * pChanged, * pOther;
463  int i, k;
464 // Nwk_ManGraphCheckLists( p );
465  Nwk_ManGraphListExtract( p, pVertex );
466  Nwk_ManGraphListExtract( p, pNext );
467  // update neihbors of pVertex
468  Nwk_VertexForEachAdjacent( p, pVertex, pChanged, i )
469  {
470  if ( pChanged == pNext )
471  continue;
472  Nwk_ManGraphListExtract( p, pChanged );
473  // move those that use this one
474  if ( pChanged->nEdges > 1 )
475  Nwk_VertexForEachAdjacent( p, pChanged, pOther, k )
476  {
477  if ( pOther == pVertex || pOther->nEdges > 1 )
478  continue;
479  assert( pOther->nEdges == 1 );
480  Nwk_ManGraphListExtract( p, pOther );
481  pChanged->nEdges--;
482  Nwk_ManGraphListInsert( p, pOther );
483  pChanged->nEdges++;
484  }
485  // remove the edge
486  Nwk_ManGraphVertexRemoveEdge( pChanged, pVertex );
487  // add the changed vertex back
488  if ( pChanged->nEdges > 0 )
489  Nwk_ManGraphListInsert( p, pChanged );
490  }
491  // update neihbors of pNext
492  Nwk_VertexForEachAdjacent( p, pNext, pChanged, i )
493  {
494  if ( pChanged == pVertex )
495  continue;
496  Nwk_ManGraphListExtract( p, pChanged );
497  // move those that use this one
498  if ( pChanged->nEdges > 1 )
499  Nwk_VertexForEachAdjacent( p, pChanged, pOther, k )
500  {
501  if ( pOther == pNext || pOther->nEdges > 1 )
502  continue;
503  assert( pOther->nEdges == 1 );
504  Nwk_ManGraphListExtract( p, pOther );
505  pChanged->nEdges--;
506  Nwk_ManGraphListInsert( p, pOther );
507  pChanged->nEdges++;
508  }
509  // remove the edge
510  Nwk_ManGraphVertexRemoveEdge( pChanged, pNext );
511  // add the changed vertex back
512  if ( pChanged->nEdges > 0 )
513  Nwk_ManGraphListInsert( p, pChanged );
514  }
515  // add to the result
516  if ( pVertex->Id < pNext->Id )
517  {
518  Vec_IntPush( p->vPairs, p->pMapId2Lut[pVertex->Id] );
519  Vec_IntPush( p->vPairs, p->pMapId2Lut[pNext->Id] );
520  }
521  else
522  {
523  Vec_IntPush( p->vPairs, p->pMapId2Lut[pNext->Id] );
524  Vec_IntPush( p->vPairs, p->pMapId2Lut[pVertex->Id] );
525  }
526 // Nwk_ManGraphCheckLists( p );
527 }
static void Nwk_ManGraphListInsert(Nwk_Grf_t *p, Nwk_Vrt_t *pVertex)
Definition: nwkMerge.c:210
static void Nwk_ManGraphVertexRemoveEdge(Nwk_Vrt_t *pThis, Nwk_Vrt_t *pNext)
Definition: nwkMerge.c:437
int Id
Definition: nwkMerge.h:72
static void Nwk_ManGraphListExtract(Nwk_Grf_t *p, Nwk_Vrt_t *pVertex)
Definition: nwkMerge.c:243
#define Nwk_VertexForEachAdjacent(p, pVrt, pNext, k)
Definition: nwkMerge.h:119
int nEdges
Definition: nwkMerge.h:75
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
int * pMapId2Lut
Definition: nwkMerge.h:101
Vec_Int_t * vPairs
Definition: nwkMerge.h:98
#define assert(ex)
Definition: util_old.h:213
static void Nwk_ManGraphVertexRemoveEdge ( Nwk_Vrt_t pThis,
Nwk_Vrt_t pNext 
)
inlinestatic

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

Synopsis [Extracts the edge from one of the linked lists.]

Description []

SideEffects []

SeeAlso []

Definition at line 437 of file nwkMerge.c.

438 {
439  int k;
440  for ( k = 0; k < pThis->nEdges; k++ )
441  if ( pThis->pEdges[k] == pNext->Id )
442  break;
443  assert( k < pThis->nEdges );
444  pThis->nEdges--;
445  for ( ; k < pThis->nEdges; k++ )
446  pThis->pEdges[k] = pThis->pEdges[k+1];
447 }
int Id
Definition: nwkMerge.h:72
int pEdges[0]
Definition: nwkMerge.h:76
int nEdges
Definition: nwkMerge.h:75
#define assert(ex)
Definition: util_old.h:213
Vec_Int_t* Nwk_ManLutMerge ( Nwk_Man_t pNtk,
void *  pParsInit 
)

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

Synopsis [Performs LUT merging with parameters.]

Description []

SideEffects []

SeeAlso []

Definition at line 970 of file nwkMerge.c.

971 {
972  Nwk_LMPars_t * pPars = (Nwk_LMPars_t *)pParsInit;
973  Nwk_Grf_t * p;
974  Vec_Int_t * vResult;
975  Vec_Ptr_t * vStart, * vNext, * vCands1, * vCands2;
976  Nwk_Obj_t * pLut, * pCand;
977  int i, k, nVertsMax, nCands;
978  abctime clk = Abc_Clock();
979  // count the number of vertices
980  nVertsMax = 0;
981  Nwk_ManForEachNode( pNtk, pLut, i )
982  nVertsMax += (int)(Nwk_ObjFaninNum(pLut) <= pPars->nMaxLutSize);
983  p = Nwk_ManGraphAlloc( nVertsMax );
984  // create graph
985  vStart = Vec_PtrAlloc( 1000 );
986  vNext = Vec_PtrAlloc( 1000 );
987  vCands1 = Vec_PtrAlloc( 1000 );
988  vCands2 = Vec_PtrAlloc( 1000 );
989  nCands = 0;
990  Nwk_ManForEachNode( pNtk, pLut, i )
991  {
992  if ( Nwk_ObjFaninNum(pLut) > pPars->nMaxLutSize )
993  continue;
994  Nwk_ManCollectOverlapCands( pLut, vCands1, pPars );
995  if ( pPars->fUseDiffSupp )
996  Nwk_ManCollectNonOverlapCands( pLut, vStart, vNext, vCands2, pPars );
997  if ( Vec_PtrSize(vCands1) == 0 && Vec_PtrSize(vCands2) == 0 )
998  continue;
999  nCands += Vec_PtrSize(vCands1) + Vec_PtrSize(vCands2);
1000  // save candidates
1001  Vec_PtrForEachEntry( Nwk_Obj_t *, vCands1, pCand, k )
1002  Nwk_ManGraphHashEdge( p, Nwk_ObjId(pLut), Nwk_ObjId(pCand) );
1003  Vec_PtrForEachEntry( Nwk_Obj_t *, vCands2, pCand, k )
1004  Nwk_ManGraphHashEdge( p, Nwk_ObjId(pLut), Nwk_ObjId(pCand) );
1005  // print statistics about this node
1006  if ( pPars->fVeryVerbose )
1007  printf( "Node %6d : Fanins = %d. Fanouts = %3d. Cand1 = %3d. Cand2 = %3d.\n",
1008  Nwk_ObjId(pLut), Nwk_ObjFaninNum(pLut), Nwk_ObjFaninNum(pLut),
1009  Vec_PtrSize(vCands1), Vec_PtrSize(vCands2) );
1010  }
1011  Vec_PtrFree( vStart );
1012  Vec_PtrFree( vNext );
1013  Vec_PtrFree( vCands1 );
1014  Vec_PtrFree( vCands2 );
1015  if ( pPars->fVerbose )
1016  {
1017  printf( "Mergable LUTs = %6d. Total cands = %6d. ", p->nVertsMax, nCands );
1018  ABC_PRT( "Deriving graph", Abc_Clock() - clk );
1019  }
1020  // solve the graph problem
1021  clk = Abc_Clock();
1022  Nwk_ManGraphSolve( p );
1023  if ( pPars->fVerbose )
1024  {
1025  printf( "GRAPH: Nodes = %6d. Edges = %6d. Pairs = %6d. ",
1026  p->nVerts, p->nEdges, Vec_IntSize(p->vPairs)/2 );
1027  ABC_PRT( "Solving", Abc_Clock() - clk );
1029  }
1030  vResult = p->vPairs; p->vPairs = NULL;
1031 /*
1032  for ( i = 0; i < vResult->nSize; i += 2 )
1033  printf( "(%d,%d) ", vResult->pArray[i], vResult->pArray[i+1] );
1034  printf( "\n" );
1035 */
1036  Nwk_ManGraphFree( p );
1037  return vResult;
1038 }
void Nwk_ManGraphReportMemoryUsage(Nwk_Grf_t *p)
Definition: nwkMerge.c:93
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int fUseDiffSupp
Definition: nwkMerge.h:53
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
static int Nwk_ObjId(Nwk_Obj_t *p)
Definition: nwk.h:135
void Nwk_ManGraphFree(Nwk_Grf_t *p)
Definition: nwkMerge.c:70
void Nwk_ManGraphSolve(Nwk_Grf_t *p)
Definition: nwkMerge.c:621
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Nwk_ObjFaninNum(Nwk_Obj_t *p)
Definition: nwk.h:137
void Nwk_ManCollectOverlapCands(Nwk_Obj_t *pLut, Vec_Ptr_t *vCands, Nwk_LMPars_t *pPars)
Definition: nwkMerge.c:920
void Nwk_ManGraphHashEdge(Nwk_Grf_t *p, int iLut1, int iLut2)
Definition: nwkMerge.c:119
ABC_NAMESPACE_IMPL_START Nwk_Grf_t * Nwk_ManGraphAlloc(int nVertsMax)
DECLARATIONS ///.
Definition: nwkMerge.c:46
if(last==0)
Definition: sparse_int.h:34
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
void Nwk_ManCollectNonOverlapCands(Nwk_Obj_t *pLut, Vec_Ptr_t *vStart, Vec_Ptr_t *vNext, Vec_Ptr_t *vCands, Nwk_LMPars_t *pPars)
Definition: nwkMerge.c:830
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nMaxLutSize
Definition: nwkMerge.h:48
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
ABC_INT64_T abctime
Definition: abc_global.h:278
int fVerbose
Definition: nwkMerge.h:56
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
#define Nwk_ManForEachNode(p, pObj, i)
Definition: nwk.h:192
int Nwk_ManLutMergeGraphTest ( char *  pFileName)

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

Synopsis [Solves the graph coming from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 703 of file nwkMerge.c.

704 {
705  int nPairs;
706  Nwk_Grf_t * p;
707  abctime clk = Abc_Clock();
708  p = Nwk_ManLutMergeReadGraph( pFileName );
709  ABC_PRT( "Reading", Abc_Clock() - clk );
710  clk = Abc_Clock();
711  Nwk_ManGraphSolve( p );
712  printf( "GRAPH: Nodes = %6d. Edges = %6d. Pairs = %6d. ",
713  p->nVerts, p->nEdges, Vec_IntSize(p->vPairs)/2 );
714  ABC_PRT( "Solving", Abc_Clock() - clk );
715  nPairs = Vec_IntSize(p->vPairs)/2;
717  Nwk_ManGraphFree( p );
718  return nPairs;
719 }
void Nwk_ManGraphReportMemoryUsage(Nwk_Grf_t *p)
Definition: nwkMerge.c:93
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Nwk_ManGraphFree(Nwk_Grf_t *p)
Definition: nwkMerge.c:70
int nEdges
Definition: nwkMerge.h:90
void Nwk_ManGraphSolve(Nwk_Grf_t *p)
Definition: nwkMerge.c:621
static abctime Abc_Clock()
Definition: abc_global.h:279
int nVerts
Definition: nwkMerge.h:91
Nwk_Grf_t * Nwk_ManLutMergeReadGraph(char *pFileName)
Definition: nwkMerge.c:674
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_PRT(a, t)
Definition: abc_global.h:220
Vec_Int_t * vPairs
Definition: nwkMerge.h:98
ABC_INT64_T abctime
Definition: abc_global.h:278
Nwk_Grf_t* Nwk_ManLutMergeReadGraph ( char *  pFileName)

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

Synopsis [Reads graph from file.]

Description []

SideEffects []

SeeAlso []

Definition at line 674 of file nwkMerge.c.

675 {
676  Nwk_Grf_t * p;
677  FILE * pFile;
678  char Buffer[100];
679  int nNodes, nEdges, iNode1, iNode2;
680  int RetValue;
681  pFile = fopen( pFileName, "r" );
682  RetValue = fscanf( pFile, "%s %d", Buffer, &nNodes );
683  RetValue = fscanf( pFile, "%s %d", Buffer, &nEdges );
684  p = Nwk_ManGraphAlloc( nNodes );
685  while ( fscanf( pFile, "%s %d %d", Buffer, &iNode1, &iNode2 ) == 3 )
686  Nwk_ManGraphHashEdge( p, iNode1, iNode2 );
687  assert( p->nEdges == nEdges );
688  fclose( pFile );
689  return p;
690 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int nEdges
Definition: nwkMerge.h:90
void Nwk_ManGraphHashEdge(Nwk_Grf_t *p, int iLut1, int iLut2)
Definition: nwkMerge.c:119
ABC_NAMESPACE_IMPL_START Nwk_Grf_t * Nwk_ManGraphAlloc(int nVertsMax)
DECLARATIONS ///.
Definition: nwkMerge.c:46
#define assert(ex)
Definition: util_old.h:213
void Nwk_ManMarkFanins_rec ( Nwk_Obj_t pLut,
int  nLevMin 
)

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

Synopsis [Marks the fanins of the node with the current trav ID.]

Description []

SideEffects []

SeeAlso []

Definition at line 735 of file nwkMerge.c.

736 {
737  Nwk_Obj_t * pNext;
738  int i;
739  if ( !Nwk_ObjIsNode(pLut) )
740  return;
741  if ( Nwk_ObjIsTravIdCurrent( pLut ) )
742  return;
743  Nwk_ObjSetTravIdCurrent( pLut );
744  if ( Nwk_ObjLevel(pLut) < nLevMin )
745  return;
746  Nwk_ObjForEachFanin( pLut, pNext, i )
747  Nwk_ManMarkFanins_rec( pNext, nLevMin );
748 }
void Nwk_ManMarkFanins_rec(Nwk_Obj_t *pLut, int nLevMin)
Definition: nwkMerge.c:735
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static void Nwk_ObjSetTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:166
static int Nwk_ObjIsTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:168
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
static int Nwk_ObjLevel(Nwk_Obj_t *pObj)
Definition: nwk.h:162
void Nwk_ManMarkFanouts_rec ( Nwk_Obj_t pLut,
int  nLevMax,
int  nFanMax 
)

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

Synopsis [Marks the fanouts of the node with the current trav ID.]

Description []

SideEffects []

SeeAlso []

Definition at line 761 of file nwkMerge.c.

762 {
763  Nwk_Obj_t * pNext;
764  int i;
765  if ( !Nwk_ObjIsNode(pLut) )
766  return;
767  if ( Nwk_ObjIsTravIdCurrent( pLut ) )
768  return;
769  Nwk_ObjSetTravIdCurrent( pLut );
770  if ( Nwk_ObjLevel(pLut) > nLevMax )
771  return;
772  if ( Nwk_ObjFanoutNum(pLut) > nFanMax )
773  return;
774  Nwk_ObjForEachFanout( pLut, pNext, i )
775  Nwk_ManMarkFanouts_rec( pNext, nLevMax, nFanMax );
776 }
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
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
static void Nwk_ObjSetTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:166
static int Nwk_ObjIsTravIdCurrent(Nwk_Obj_t *pObj)
Definition: nwk.h:168
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
void Nwk_ManMarkFanouts_rec(Nwk_Obj_t *pLut, int nLevMax, int nFanMax)
Definition: nwkMerge.c:761
static int Nwk_ObjLevel(Nwk_Obj_t *pObj)
Definition: nwk.h:162