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

Go to the source code of this file.

Data Structures

struct  Iso_Dat_t_
 
struct  Iso_Dat2_t_
 
struct  Iso_Sto_t_
 

Macros

#define AIG_ISO_NUM   16
 DECLARATIONS ///. More...
 

Typedefs

typedef struct Iso_Dat_t_ Iso_Dat_t
 
typedef struct Iso_Dat2_t_ Iso_Dat2_t
 
typedef struct Iso_Sto_t_ Iso_Sto_t
 

Functions

Iso_Sto_tIso_StoStart (Aig_Man_t *pAig)
 FUNCTION DEFINITIONS ///. More...
 
void Iso_StoStop (Iso_Sto_t *p)
 
void Iso_StoCollectInfo_rec (Aig_Man_t *p, Aig_Obj_t *pObj, int fCompl, Vec_Int_t *vVisited, Iso_Dat_t *pData, Vec_Ptr_t *vRoots)
 
Vec_Int_tIso_StoCollectInfo (Iso_Sto_t *p, Aig_Obj_t *pPo)
 
int Iso_StoCompareVecInt (Vec_Int_t **p1, Vec_Int_t **p2)
 
Vec_Vec_tSaig_IsoDetectFast (Aig_Man_t *pAig)
 

Macro Definition Documentation

#define AIG_ISO_NUM   16

DECLARATIONS ///.

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

FileName [aigIsoFast.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [AIG package.]

Synopsis [Graph isomorphism package.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
aigIsoFast.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

]

Definition at line 30 of file saigIsoFast.c.

Typedef Documentation

typedef struct Iso_Dat2_t_ Iso_Dat2_t

Definition at line 44 of file saigIsoFast.c.

typedef struct Iso_Dat_t_ Iso_Dat_t

Definition at line 32 of file saigIsoFast.c.

typedef struct Iso_Sto_t_ Iso_Sto_t

Definition at line 50 of file saigIsoFast.c.

Function Documentation

Vec_Int_t* Iso_StoCollectInfo ( Iso_Sto_t p,
Aig_Obj_t pPo 
)

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

Synopsis [Collect statistics about one output.]

Description []

SideEffects []

SeeAlso []

Definition at line 176 of file saigIsoFast.c.

177 {
178  int fVerboseShow = 0;
179  Vec_Int_t * vInfo;
180  Iso_Dat2_t * pData2 = (Iso_Dat2_t *)p->pData;
181  Aig_Man_t * pAig = p->pAig;
182  Aig_Obj_t * pObj;
183  int i, Value, Entry, * pPerm;
184 // abctime clk = Abc_Clock();
185 
186  assert( Aig_ObjIsCo(pPo) );
187 
188  // collect initial POs
189  Vec_IntClear( p->vVisited );
190  Vec_PtrClear( p->vRoots );
191  Vec_PtrPush( p->vRoots, pPo );
192 
193  // mark internal nodes
194  Vec_PtrForEachEntry( Aig_Obj_t *, p->vRoots, pObj, i )
195  if ( !Aig_ObjIsConst1(Aig_ObjFanin0(pObj)) )
196  Iso_StoCollectInfo_rec( pAig, Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj), p->vVisited, p->pData, p->vRoots );
197 // time_Trav += Abc_Clock() - clk;
198 
199  // count how many times each data entry appears
200  Vec_IntClear( p->vPlaces );
201  Vec_IntForEachEntry( p->vVisited, Entry, i )
202  {
203  Value = pData2[Entry].Data;
204 // assert( Value > 0 );
205  if ( p->pCounters[Value]++ == 0 )
206  Vec_IntPush( p->vPlaces, Value );
207 // pData2[Entry].Data = 0;
208  *((int *)(p->pData + Entry)) = 0;
209  }
210 
211  // collect non-trivial counters
212  Vec_IntClear( p->vVisited );
213  Vec_IntForEachEntry( p->vPlaces, Entry, i )
214  {
215  assert( p->pCounters[Entry] );
216  Vec_IntPush( p->vVisited, p->pCounters[Entry] );
217  p->pCounters[Entry] = 0;
218  }
219 // printf( "%d ", Vec_IntSize(p->vVisited) );
220 
221  // sort the costs in the increasing order
224 
225  // create information
226  vInfo = Vec_IntAlloc( Vec_IntSize(p->vVisited) );
227  for ( i = Vec_IntSize(p->vVisited)-1; i >= 0; i-- )
228  {
229  Entry = Vec_IntEntry( p->vVisited, pPerm[i] );
230  Entry = (Entry << AIG_ISO_NUM) | Vec_IntEntry( p->vPlaces, pPerm[i] );
231  Vec_IntPush( vInfo, Entry );
232  }
233  ABC_FREE( pPerm );
234 
235  // show the final result
236  if ( fVerboseShow )
237  Vec_IntForEachEntry( vInfo, Entry, i )
238  {
239  Iso_Dat2_t Data = { Entry & 0xFFFF };
240  Iso_Dat_t * pData = (Iso_Dat_t *)&Data;
241 
242  printf( "%6d : ", i );
243  printf( "Freq =%6d ", Entry >> 16 );
244 
245  printf( "FiNeg =%3d ", pData->nFiNeg );
246  printf( "FoNeg =%3d ", pData->nFoNeg );
247  printf( "FoPos =%3d ", pData->nFoPos );
248  printf( "Fi0L =%3d ", pData->Fi0Lev );
249  printf( "Fi1L =%3d ", pData->Fi1Lev );
250  printf( "Lev =%3d ", pData->Level );
251  printf( "\n" );
252  }
253  return vInfo;
254 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
unsigned nFoPos
Definition: saigIsoFast.c:37
Aig_Man_t * pAig
Definition: saigIsoFast.c:53
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
unsigned nFiNeg
Definition: saigIsoFast.c:35
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned nFoNeg
Definition: saigIsoFast.c:36
unsigned Fi0Lev
Definition: saigIsoFast.c:38
#define AIG_ISO_NUM
DECLARATIONS ///.
Definition: saigIsoFast.c:30
Vec_Int_t * vPlaces
Definition: saigIsoFast.c:58
unsigned Level
Definition: saigIsoFast.c:40
void Iso_StoCollectInfo_rec(Aig_Man_t *p, Aig_Obj_t *pObj, int fCompl, Vec_Int_t *vVisited, Iso_Dat_t *pData, Vec_Ptr_t *vRoots)
Definition: saigIsoFast.c:111
int * Abc_MergeSortCost(int *pCosts, int nSize)
Definition: utilSort.c:238
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Iso_Dat_t * pData
Definition: saigIsoFast.c:55
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
if(last==0)
Definition: sparse_int.h:34
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int pPerm[13719]
Definition: rwrTemp.c:32
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
unsigned Fi1Lev
Definition: saigIsoFast.c:39
int * pCounters
Definition: saigIsoFast.c:59
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
#define ABC_FREE(obj)
Definition: abc_global.h:232
unsigned Data
Definition: saigIsoFast.c:47
Vec_Int_t * vVisited
Definition: saigIsoFast.c:56
#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
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
Vec_Ptr_t * vRoots
Definition: saigIsoFast.c:57
static int Aig_ObjIsCo(Aig_Obj_t *pObj)
Definition: aig.h:276
void Iso_StoCollectInfo_rec ( Aig_Man_t p,
Aig_Obj_t pObj,
int  fCompl,
Vec_Int_t vVisited,
Iso_Dat_t pData,
Vec_Ptr_t vRoots 
)

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

Synopsis [Collect statistics about one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file saigIsoFast.c.

112 {
113  Iso_Dat_t * pThis = pData + Aig_ObjId(pObj);
114  assert( Aig_ObjIsCi(pObj) || Aig_ObjIsNode(pObj) );
115  if ( pThis->fVisit )
116  {
117  if ( fCompl )
118  pThis->nFoNeg++;
119  else
120  pThis->nFoPos++;
121  return;
122  }
123  assert( *((int *)pThis) == 0 );
124  pThis->fVisit = 1;
125  if ( fCompl )
126  pThis->nFoNeg++;
127  else
128  pThis->nFoPos++;
129  pThis->Level = pObj->Level;
130  pThis->nFiNeg = Aig_ObjFaninC0(pObj) + Aig_ObjFaninC1(pObj);
131  if ( Aig_ObjIsNode(pObj) )
132  {
133  if ( Aig_ObjFaninC0(pObj) < Aig_ObjFaninC1(pObj) || (Aig_ObjFaninC0(pObj) == Aig_ObjFaninC1(pObj) && Aig_ObjFanin0(pObj)->Level < Aig_ObjFanin1(pObj)->Level) )
134  {
135  pThis->Fi0Lev = pObj->Level - Aig_ObjFanin0(pObj)->Level;
136  pThis->Fi1Lev = pObj->Level - Aig_ObjFanin1(pObj)->Level;
137  }
138  else
139  {
140  pThis->Fi0Lev = pObj->Level - Aig_ObjFanin1(pObj)->Level;
141  pThis->Fi1Lev = pObj->Level - Aig_ObjFanin0(pObj)->Level;
142  }
143  Iso_StoCollectInfo_rec( p, Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj), vVisited, pData, vRoots );
144  Iso_StoCollectInfo_rec( p, Aig_ObjFanin1(pObj), Aig_ObjFaninC1(pObj), vVisited, pData, vRoots );
145  }
146  else if ( Saig_ObjIsLo(p, pObj) )
147  {
148  pThis->Fi0Lev = 1;
149  pThis->Fi1Lev = 0;
150  Vec_PtrPush( vRoots, Saig_ObjLoToLi(p, pObj) );
151  }
152  else if ( Saig_ObjIsPi(p, pObj) )
153  {
154  pThis->Fi0Lev = 0;
155  pThis->Fi1Lev = 0;
156  }
157  else
158  assert( 0 );
159  assert( pThis->nFoNeg + pThis->nFoPos );
160  Vec_IntPush( vVisited, Aig_ObjId(pObj) );
161 }
unsigned nFoPos
Definition: saigIsoFast.c:37
unsigned Level
Definition: aig.h:82
static int Saig_ObjIsLo(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:84
static Llb_Mgr_t * p
Definition: llb3Image.c:950
unsigned nFiNeg
Definition: saigIsoFast.c:35
unsigned fVisit
Definition: saigIsoFast.c:41
static Aig_Obj_t * Saig_ObjLoToLi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:86
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned nFoNeg
Definition: saigIsoFast.c:36
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
unsigned Fi0Lev
Definition: saigIsoFast.c:38
unsigned Level
Definition: saigIsoFast.c:40
void Iso_StoCollectInfo_rec(Aig_Man_t *p, Aig_Obj_t *pObj, int fCompl, Vec_Int_t *vVisited, Iso_Dat_t *pData, Vec_Ptr_t *vRoots)
Definition: saigIsoFast.c:111
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
unsigned Fi1Lev
Definition: saigIsoFast.c:39
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
#define assert(ex)
Definition: util_old.h:213
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
static int Saig_ObjIsPi(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: saig.h:82
int Iso_StoCompareVecInt ( Vec_Int_t **  p1,
Vec_Int_t **  p2 
)

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

Synopsis [Takes multi-output sequential AIG.]

Description [Returns candidate equivalence classes of POs.]

SideEffects []

SeeAlso []

Definition at line 267 of file saigIsoFast.c.

268 {
269  return Vec_IntCompareVec( *p1, *p2 );
270 }
static int Vec_IntCompareVec(Vec_Int_t *p1, Vec_Int_t *p2)
Definition: vecInt.h:1829
Iso_Sto_t* Iso_StoStart ( Aig_Man_t pAig)

FUNCTION DEFINITIONS ///.

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 77 of file saigIsoFast.c.

78 {
79  Iso_Sto_t * p;
80  p = ABC_CALLOC( Iso_Sto_t, 1 );
81  p->pAig = pAig;
82  p->nObjs = Aig_ManObjNumMax( pAig );
83  p->pData = ABC_CALLOC( Iso_Dat_t, p->nObjs );
84  p->vVisited = Vec_IntStart( 1000 );
85  p->vPlaces = Vec_IntStart( 1000 );
86  p->vRoots = Vec_PtrStart( 1000 );
87  p->pCounters = ABC_CALLOC( int, (1 << AIG_ISO_NUM) );
88  return p;
89 }
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
Aig_Man_t * pAig
Definition: saigIsoFast.c:53
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define AIG_ISO_NUM
DECLARATIONS ///.
Definition: saigIsoFast.c:30
Vec_Int_t * vPlaces
Definition: saigIsoFast.c:58
static Vec_Int_t * Vec_IntStart(int nSize)
Definition: bblif.c:172
Iso_Dat_t * pData
Definition: saigIsoFast.c:55
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
int * pCounters
Definition: saigIsoFast.c:59
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
Vec_Int_t * vVisited
Definition: saigIsoFast.c:56
Vec_Ptr_t * vRoots
Definition: saigIsoFast.c:57
void Iso_StoStop ( Iso_Sto_t p)

Definition at line 90 of file saigIsoFast.c.

91 {
92  Vec_IntFree( p->vPlaces );
93  Vec_IntFree( p->vVisited );
94  Vec_PtrFree( p->vRoots );
95  ABC_FREE( p->pCounters );
96  ABC_FREE( p->pData );
97  ABC_FREE( p );
98 }
Vec_Int_t * vPlaces
Definition: saigIsoFast.c:58
Iso_Dat_t * pData
Definition: saigIsoFast.c:55
int * pCounters
Definition: saigIsoFast.c:59
#define ABC_FREE(obj)
Definition: abc_global.h:232
Vec_Int_t * vVisited
Definition: saigIsoFast.c:56
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Vec_Ptr_t * vRoots
Definition: saigIsoFast.c:57
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
Vec_Vec_t* Saig_IsoDetectFast ( Aig_Man_t pAig)

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

Synopsis [Takes multi-output sequential AIG.]

Description [Returns candidate equivalence classes of POs.]

SideEffects []

SeeAlso []

Definition at line 283 of file saigIsoFast.c.

284 {
285  Iso_Sto_t * pMan;
286  Aig_Obj_t * pObj;
287  Vec_Ptr_t * vClasses, * vInfos;
288  Vec_Int_t * vInfo, * vPrev, * vLevel;
289  int i, Number, nUnique = 0;
290  abctime clk = Abc_Clock();
291 
292  // collect infos and remember their number
293  pMan = Iso_StoStart( pAig );
294  vInfos = Vec_PtrAlloc( Saig_ManPoNum(pAig) );
295  Saig_ManForEachPo( pAig, pObj, i )
296  {
297  vInfo = Iso_StoCollectInfo(pMan, pObj);
298  Vec_IntPush( vInfo, i );
299  Vec_PtrPush( vInfos, vInfo );
300  }
301  Iso_StoStop( pMan );
302  Abc_PrintTime( 1, "Info computation time", Abc_Clock() - clk );
303 
304  // sort the infos
305  clk = Abc_Clock();
306  Vec_PtrSort( vInfos, (int (*)(void))Iso_StoCompareVecInt );
307 
308  // create classes
309  clk = Abc_Clock();
310  vClasses = Vec_PtrAlloc( Saig_ManPoNum(pAig) );
311  // start the first class
312  Vec_PtrPush( vClasses, (vLevel = Vec_IntAlloc(4)) );
313  vPrev = (Vec_Int_t *)Vec_PtrEntry( vInfos, 0 );
314  Vec_IntPush( vLevel, Vec_IntPop(vPrev) );
315  // consider other classes
316  Vec_PtrForEachEntryStart( Vec_Int_t *, vInfos, vInfo, i, 1 )
317  {
318  Number = Vec_IntPop( vInfo );
319  if ( Vec_IntCompareVec(vPrev, vInfo) )
320  Vec_PtrPush( vClasses, Vec_IntAlloc(4) );
321  vLevel = (Vec_Int_t *)Vec_PtrEntryLast( vClasses );
322  Vec_IntPush( vLevel, Number );
323  vPrev = vInfo;
324  }
325  Vec_VecFree( (Vec_Vec_t *)vInfos );
326  Abc_PrintTime( 1, "Sorting time", Abc_Clock() - clk );
327 // Abc_PrintTime( 1, "Traversal time", time_Trav );
328 
329  // report the results
330 // Vec_VecPrintInt( (Vec_Vec_t *)vClasses );
331  printf( "Devided %d outputs into %d cand equiv classes.\n", Saig_ManPoNum(pAig), Vec_PtrSize(vClasses) );
332 
333  Vec_PtrForEachEntry( Vec_Int_t *, vClasses, vLevel, i )
334  if ( Vec_IntSize(vLevel) > 1 )
335  printf( "%d ", Vec_IntSize(vLevel) );
336  else
337  nUnique++;
338  printf( " Unique = %d\n", nUnique );
339 
340 // return (Vec_Vec_t *)vClasses;
341  Vec_VecFree( (Vec_Vec_t *)vClasses );
342  return NULL;
343 }
void Iso_StoStop(Iso_Sto_t *p)
Definition: saigIsoFast.c:90
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition: vecPtr.h:57
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static int Saig_ManPoNum(Aig_Man_t *p)
Definition: saig.h:74
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Iso_Sto_t * Iso_StoStart(Aig_Man_t *pAig)
FUNCTION DEFINITIONS ///.
Definition: saigIsoFast.c:77
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
Vec_Int_t * Iso_StoCollectInfo(Iso_Sto_t *p, Aig_Obj_t *pPo)
Definition: saigIsoFast.c:176
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static void * Vec_PtrEntryLast(Vec_Ptr_t *p)
Definition: vecPtr.h:413
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
static int Vec_IntPop(Vec_Int_t *p)
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Vec_IntCompareVec(Vec_Int_t *p1, Vec_Int_t *p2)
Definition: vecInt.h:1829
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
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
#define Saig_ManForEachPo(p, pObj, i)
Definition: saig.h:93
int Iso_StoCompareVecInt(Vec_Int_t **p1, Vec_Int_t **p2)
Definition: saigIsoFast.c:267
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
ABC_INT64_T abctime
Definition: abc_global.h:278