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

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START
unsigned 
Ivy_Hash (Ivy_Obj_t *pObj, int TableSize)
 DECLARATIONS ///. More...
 
static int * Ivy_TableFind (Ivy_Man_t *p, Ivy_Obj_t *pObj)
 
static void Ivy_TableResize (Ivy_Man_t *p)
 
static unsigned int Cudd_PrimeAig (unsigned int p)
 
Ivy_Obj_tIvy_TableLookup (Ivy_Man_t *p, Ivy_Obj_t *pObj)
 FUNCTION DEFINITIONS ///. More...
 
void Ivy_TableInsert (Ivy_Man_t *p, Ivy_Obj_t *pObj)
 
void Ivy_TableDelete (Ivy_Man_t *p, Ivy_Obj_t *pObj)
 
void Ivy_TableUpdate (Ivy_Man_t *p, Ivy_Obj_t *pObj, int ObjIdNew)
 
int Ivy_TableCountEntries (Ivy_Man_t *p)
 
void Ivy_TableProfile (Ivy_Man_t *p)
 

Function Documentation

static unsigned int Cudd_PrimeAig ( unsigned int  p)
static
static ABC_NAMESPACE_IMPL_START unsigned Ivy_Hash ( Ivy_Obj_t pObj,
int  TableSize 
)
static

DECLARATIONS ///.

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

FileName [ivyTable.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [And-Inverter Graph package.]

Synopsis [Structural hashing table.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - May 11, 2006. ]

Revision [

Id:
ivyTable.c,v 1.00 2006/05/11 00:00:00 alanmi Exp

]

Definition at line 31 of file ivyTable.c.

32 {
33  unsigned Key = Ivy_ObjIsExor(pObj) * 1699;
34  Key ^= Ivy_ObjFaninId0(pObj) * 7937;
35  Key ^= Ivy_ObjFaninId1(pObj) * 2971;
36  Key ^= Ivy_ObjFaninC0(pObj) * 911;
37  Key ^= Ivy_ObjFaninC1(pObj) * 353;
38  Key ^= Ivy_ObjInit(pObj) * 911;
39  return Key % TableSize;
40 }
static int Ivy_ObjFaninId1(Ivy_Obj_t *pObj)
Definition: ivy.h:268
static int Ivy_ObjFaninId0(Ivy_Obj_t *pObj)
Definition: ivy.h:267
static int Ivy_ObjFaninC1(Ivy_Obj_t *pObj)
Definition: ivy.h:270
static int Ivy_ObjIsExor(Ivy_Obj_t *pObj)
Definition: ivy.h:243
static int Ivy_ObjFaninC0(Ivy_Obj_t *pObj)
Definition: ivy.h:269
static Ivy_Init_t Ivy_ObjInit(Ivy_Obj_t *pObj)
Definition: ivy.h:232
int Ivy_TableCountEntries ( Ivy_Man_t p)

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

Synopsis [Count the number of nodes in the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 187 of file ivyTable.c.

188 {
189  int i, Counter = 0;
190  for ( i = 0; i < p->nTableSize; i++ )
191  Counter += (p->pTable[i] != 0);
192  return Counter;
193 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Counter
void Ivy_TableDelete ( Ivy_Man_t p,
Ivy_Obj_t pObj 
)

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

Synopsis [Deletes the node from the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 132 of file ivyTable.c.

133 {
134  Ivy_Obj_t * pEntry;
135  int i, * pPlace;
136  assert( !Ivy_IsComplement(pObj) );
137  if ( !Ivy_ObjIsHash(pObj) )
138  return;
139  pPlace = Ivy_TableFind( p, pObj );
140  assert( *pPlace == pObj->Id ); // node should be in the table
141  *pPlace = 0;
142  // rehash the adjacent entries
143  i = pPlace - p->pTable;
144  for ( i = (i+1) % p->nTableSize; p->pTable[i]; i = (i+1) % p->nTableSize )
145  {
146  pEntry = Ivy_ManObj( p, p->pTable[i] );
147  p->pTable[i] = 0;
148  Ivy_TableInsert( p, pEntry );
149  }
150 }
static int Ivy_ObjIsHash(Ivy_Obj_t *pObj)
Definition: ivy.h:247
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Id
Definition: ivy.h:75
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
Definition: ivy.h:203
Definition: ivy.h:73
static int * Ivy_TableFind(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyTable.c:43
#define assert(ex)
Definition: util_old.h:213
void Ivy_TableInsert(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyTable.c:105
static int* Ivy_TableFind ( Ivy_Man_t p,
Ivy_Obj_t pObj 
)
static

Definition at line 43 of file ivyTable.c.

44 {
45  int i;
46  assert( Ivy_ObjIsHash(pObj) );
47  for ( i = Ivy_Hash(pObj, p->nTableSize); p->pTable[i]; i = (i+1) % p->nTableSize )
48  if ( p->pTable[i] == pObj->Id )
49  break;
50  return p->pTable + i;
51 }
static int Ivy_ObjIsHash(Ivy_Obj_t *pObj)
Definition: ivy.h:247
static ABC_NAMESPACE_IMPL_START unsigned Ivy_Hash(Ivy_Obj_t *pObj, int TableSize)
DECLARATIONS ///.
Definition: ivyTable.c:31
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Id
Definition: ivy.h:75
#define assert(ex)
Definition: util_old.h:213
void Ivy_TableInsert ( Ivy_Man_t p,
Ivy_Obj_t pObj 
)

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

Synopsis [Adds the node to the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 105 of file ivyTable.c.

106 {
107  int * pPlace;
108  assert( !Ivy_IsComplement(pObj) );
109  if ( !Ivy_ObjIsHash(pObj) )
110  return;
111  if ( (pObj->Id & 63) == 0 )
112  {
113  if ( p->nTableSize < 2 * Ivy_ManHashObjNum(p) )
114  Ivy_TableResize( p );
115  }
116  pPlace = Ivy_TableFind( p, pObj );
117  assert( *pPlace == 0 );
118  *pPlace = pObj->Id;
119 }
static int Ivy_ObjIsHash(Ivy_Obj_t *pObj)
Definition: ivy.h:247
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Id
Definition: ivy.h:75
static int Ivy_ManHashObjNum(Ivy_Man_t *p)
Definition: ivy.h:228
static void Ivy_TableResize(Ivy_Man_t *p)
Definition: ivyTable.c:206
static int * Ivy_TableFind(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyTable.c:43
#define assert(ex)
Definition: util_old.h:213
Ivy_Obj_t* Ivy_TableLookup ( Ivy_Man_t p,
Ivy_Obj_t pObj 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Checks if node with the given attributes is in the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 71 of file ivyTable.c.

72 {
73  Ivy_Obj_t * pEntry;
74  int i;
75  assert( !Ivy_IsComplement(pObj) );
76  if ( !Ivy_ObjIsHash(pObj) )
77  return NULL;
78  assert( Ivy_ObjIsLatch(pObj) || Ivy_ObjFaninId0(pObj) > 0 );
79  assert( Ivy_ObjFaninId1(pObj) == 0 || Ivy_ObjFaninId0(pObj) < Ivy_ObjFaninId1(pObj) );
80  if ( Ivy_ObjFanin0(pObj)->nRefs == 0 || (Ivy_ObjChild1(pObj) && Ivy_ObjFanin1(pObj)->nRefs == 0) )
81  return NULL;
82  for ( i = Ivy_Hash(pObj, p->nTableSize); p->pTable[i]; i = (i+1) % p->nTableSize )
83  {
84  pEntry = Ivy_ManObj( p, p->pTable[i] );
85  if ( Ivy_ObjChild0(pEntry) == Ivy_ObjChild0(pObj) &&
86  Ivy_ObjChild1(pEntry) == Ivy_ObjChild1(pObj) &&
87  Ivy_ObjInit(pEntry) == Ivy_ObjInit(pObj) &&
88  Ivy_ObjType(pEntry) == Ivy_ObjType(pObj) )
89  return pEntry;
90  }
91  return NULL;
92 }
static int Ivy_ObjIsHash(Ivy_Obj_t *pObj)
Definition: ivy.h:247
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static ABC_NAMESPACE_IMPL_START unsigned Ivy_Hash(Ivy_Obj_t *pObj, int TableSize)
DECLARATIONS ///.
Definition: ivyTable.c:31
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Ivy_ObjFaninId1(Ivy_Obj_t *pObj)
Definition: ivy.h:268
static int Ivy_ObjIsLatch(Ivy_Obj_t *pObj)
Definition: ivy.h:241
static Ivy_Obj_t * Ivy_ObjFanin1(Ivy_Obj_t *pObj)
Definition: ivy.h:272
static Ivy_Obj_t * Ivy_ObjFanin0(Ivy_Obj_t *pObj)
Definition: ivy.h:271
static int Ivy_ObjFaninId0(Ivy_Obj_t *pObj)
Definition: ivy.h:267
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
Definition: ivy.h:203
Definition: ivy.h:73
static Ivy_Type_t Ivy_ObjType(Ivy_Obj_t *pObj)
Definition: ivy.h:231
static Ivy_Obj_t * Ivy_ObjChild0(Ivy_Obj_t *pObj)
Definition: ivy.h:273
static Ivy_Obj_t * Ivy_ObjChild1(Ivy_Obj_t *pObj)
Definition: ivy.h:274
#define assert(ex)
Definition: util_old.h:213
static Ivy_Init_t Ivy_ObjInit(Ivy_Obj_t *pObj)
Definition: ivy.h:232
void Ivy_TableProfile ( Ivy_Man_t p)

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

Synopsis [Profiles the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 250 of file ivyTable.c.

251 {
252  int i, Counter = 0;
253  for ( i = 0; i < p->nTableSize; i++ )
254  {
255  if ( p->pTable[i] )
256  Counter++;
257  else if ( Counter )
258  {
259  printf( "%d ", Counter );
260  Counter = 0;
261  }
262  }
263 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Counter
void Ivy_TableResize ( Ivy_Man_t p)
static

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

Synopsis [Resizes the table.]

Description [Typically this procedure should not be called.]

SideEffects []

SeeAlso []

Definition at line 206 of file ivyTable.c.

207 {
208  int * pTableOld, * pPlace;
209  int nTableSizeOld, Counter, nEntries, e;
210  abctime clk;
211 clk = Abc_Clock();
212  // save the old table
213  pTableOld = p->pTable;
214  nTableSizeOld = p->nTableSize;
215  // get the new table
216  p->nTableSize = Abc_PrimeCudd( 5 * Ivy_ManHashObjNum(p) );
217  p->pTable = ABC_ALLOC( int, p->nTableSize );
218  memset( p->pTable, 0, sizeof(int) * p->nTableSize );
219  // rehash the entries from the old table
220  Counter = 0;
221  for ( e = 0; e < nTableSizeOld; e++ )
222  {
223  if ( pTableOld[e] == 0 )
224  continue;
225  Counter++;
226  // get the place where this entry goes in the table table
227  pPlace = Ivy_TableFind( p, Ivy_ManObj(p, pTableOld[e]) );
228  assert( *pPlace == 0 ); // should not be in the table
229  *pPlace = pTableOld[e];
230  }
231  nEntries = Ivy_ManHashObjNum(p);
232 // assert( Counter == nEntries );
233 // printf( "Increasing the structural table size from %6d to %6d. ", nTableSizeOld, p->nTableSize );
234 // ABC_PRT( "Time", Abc_Clock() - clk );
235  // replace the table and the parameters
236  ABC_FREE( pTableOld );
237 }
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static abctime Abc_Clock()
Definition: abc_global.h:279
static Ivy_Obj_t * Ivy_ManObj(Ivy_Man_t *p, int i)
Definition: ivy.h:203
static int Counter
#define ABC_FREE(obj)
Definition: abc_global.h:232
static int Ivy_ManHashObjNum(Ivy_Man_t *p)
Definition: ivy.h:228
static int * Ivy_TableFind(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyTable.c:43
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
void Ivy_TableUpdate ( Ivy_Man_t p,
Ivy_Obj_t pObj,
int  ObjIdNew 
)

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

Synopsis [Updates the table to point to the new node.]

Description [If the old node (pObj) is in the table, updates the table to point to an object with different ID (ObjIdNew). The table should not contain an object with ObjIdNew (this is currently not checked).]

SideEffects []

SeeAlso []

Definition at line 165 of file ivyTable.c.

166 {
167  int * pPlace;
168  assert( !Ivy_IsComplement(pObj) );
169  if ( !Ivy_ObjIsHash(pObj) )
170  return;
171  pPlace = Ivy_TableFind( p, pObj );
172  assert( *pPlace == pObj->Id ); // node should be in the table
173  *pPlace = ObjIdNew;
174 }
static int Ivy_ObjIsHash(Ivy_Obj_t *pObj)
Definition: ivy.h:247
static int Ivy_IsComplement(Ivy_Obj_t *p)
Definition: ivy.h:196
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Id
Definition: ivy.h:75
static int * Ivy_TableFind(Ivy_Man_t *p, Ivy_Obj_t *pObj)
Definition: ivyTable.c:43
#define assert(ex)
Definition: util_old.h:213