abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigTable.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigTable.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Structural hashing table.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigTable.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 // hashing the node
31 static unsigned long Aig_Hash( Aig_Obj_t * pObj, int TableSize )
32 {
33  unsigned long Key = Aig_ObjIsExor(pObj) * 1699;
34  Key ^= Aig_ObjFanin0(pObj)->Id * 7937;
35  Key ^= Aig_ObjFanin1(pObj)->Id * 2971;
36  Key ^= Aig_ObjFaninC0(pObj) * 911;
37  Key ^= Aig_ObjFaninC1(pObj) * 353;
38  return Key % TableSize;
39 }
40 
41 // returns the place where this node is stored (or should be stored)
43 {
44  Aig_Obj_t ** ppEntry;
45  assert( Aig_ObjChild0(pObj) && Aig_ObjChild1(pObj) );
46  assert( Aig_ObjFanin0(pObj)->Id < Aig_ObjFanin1(pObj)->Id );
47  for ( ppEntry = p->pTable + Aig_Hash(pObj, p->nTableSize); *ppEntry; ppEntry = &(*ppEntry)->pNext )
48  if ( *ppEntry == pObj )
49  return ppEntry;
50  assert( *ppEntry == NULL );
51  return ppEntry;
52 }
53 
54 ////////////////////////////////////////////////////////////////////////
55 /// FUNCTION DEFINITIONS ///
56 ////////////////////////////////////////////////////////////////////////
57 
58 /**Function*************************************************************
59 
60  Synopsis [Resizes the table.]
61 
62  Description [Typically this procedure should not be called.]
63 
64  SideEffects []
65 
66  SeeAlso []
67 
68 ***********************************************************************/
70 {
71  Aig_Obj_t * pEntry, * pNext;
72  Aig_Obj_t ** pTableOld, ** ppPlace;
73  int nTableSizeOld, Counter, i;
74  abctime clk;
75  assert( p->pTable != NULL );
76 clk = Abc_Clock();
77  // save the old table
78  pTableOld = p->pTable;
79  nTableSizeOld = p->nTableSize;
80  // get the new table
81  p->nTableSize = Abc_PrimeCudd( 2 * Aig_ManNodeNum(p) );
82  p->pTable = ABC_ALLOC( Aig_Obj_t *, p->nTableSize );
83  memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize );
84  // rehash the entries from the old table
85  Counter = 0;
86  for ( i = 0; i < nTableSizeOld; i++ )
87  for ( pEntry = pTableOld[i], pNext = pEntry? pEntry->pNext : NULL;
88  pEntry; pEntry = pNext, pNext = pEntry? pEntry->pNext : NULL )
89  {
90  // get the place where this entry goes in the table
91  ppPlace = Aig_TableFind( p, pEntry );
92  assert( *ppPlace == NULL ); // should not be there
93  // add the entry to the list
94  *ppPlace = pEntry;
95  pEntry->pNext = NULL;
96  Counter++;
97  }
98  assert( Counter == Aig_ManNodeNum(p) );
99 // printf( "Increasing the structural table size from %6d to %6d. ", nTableSizeOld, p->nTableSize );
100 // ABC_PRT( "Time", Abc_Clock() - clk );
101  // replace the table and the parameters
102  ABC_FREE( pTableOld );
103 }
104 
105 /**Function*************************************************************
106 
107  Synopsis [Checks if node with the given attributes is in the hash table.]
108 
109  Description []
110 
111  SideEffects []
112 
113  SeeAlso []
114 
115 ***********************************************************************/
117 {
118  Aig_Obj_t * pEntry;
119  assert( !Aig_IsComplement(pGhost) );
120  assert( Aig_ObjIsNode(pGhost) );
121  assert( Aig_ObjChild0(pGhost) && Aig_ObjChild1(pGhost) );
122  assert( Aig_ObjFanin0(pGhost)->Id < Aig_ObjFanin1(pGhost)->Id );
123  if ( p->pTable == NULL || !Aig_ObjRefs(Aig_ObjFanin0(pGhost)) || !Aig_ObjRefs(Aig_ObjFanin1(pGhost)) )
124  return NULL;
125  for ( pEntry = p->pTable[Aig_Hash(pGhost, p->nTableSize)]; pEntry; pEntry = pEntry->pNext )
126  {
127  if ( Aig_ObjChild0(pEntry) == Aig_ObjChild0(pGhost) &&
128  Aig_ObjChild1(pEntry) == Aig_ObjChild1(pGhost) &&
129  Aig_ObjType(pEntry) == Aig_ObjType(pGhost) )
130  return pEntry;
131  }
132  return NULL;
133 }
134 
135 /**Function*************************************************************
136 
137  Synopsis [Checks if node with the given attributes is in the hash table.]
138 
139  Description []
140 
141  SideEffects []
142 
143  SeeAlso []
144 
145 ***********************************************************************/
147 {
148  Aig_Obj_t * pGhost;
149  // consider simple cases
150  if ( pFanin0 == pFanin1 )
151  return pFanin0;
152  if ( pFanin0 == Aig_Not(pFanin1) )
153  return Aig_ManConst0(p);
154  if ( Aig_Regular(pFanin0) == Aig_ManConst1(p) )
155  return pFanin0 == Aig_ManConst1(p) ? pFanin1 : Aig_ManConst0(p);
156  if ( Aig_Regular(pFanin1) == Aig_ManConst1(p) )
157  return pFanin1 == Aig_ManConst1(p) ? pFanin0 : Aig_ManConst0(p);
158  pGhost = Aig_ObjCreateGhost( p, pFanin0, pFanin1, AIG_OBJ_AND );
159  return Aig_TableLookup( p, pGhost );
160 }
161 
162 /**Function*************************************************************
163 
164  Synopsis [Adds the new node to the hash table.]
165 
166  Description []
167 
168  SideEffects []
169 
170  SeeAlso []
171 
172 ***********************************************************************/
174 {
175  Aig_Obj_t ** ppPlace;
176  assert( !Aig_IsComplement(pObj) );
177  assert( Aig_TableLookup(p, pObj) == NULL );
178  if ( (pObj->Id & 0xFF) == 0 && 2 * p->nTableSize < Aig_ManNodeNum(p) )
179  Aig_TableResize( p );
180  ppPlace = Aig_TableFind( p, pObj );
181  assert( *ppPlace == NULL );
182  *ppPlace = pObj;
183 }
184 
185 /**Function*************************************************************
186 
187  Synopsis [Deletes the node from the hash table.]
188 
189  Description []
190 
191  SideEffects []
192 
193  SeeAlso []
194 
195 ***********************************************************************/
197 {
198  Aig_Obj_t ** ppPlace;
199  assert( !Aig_IsComplement(pObj) );
200  ppPlace = Aig_TableFind( p, pObj );
201  assert( *ppPlace == pObj ); // node should be in the table
202  // remove the node
203  *ppPlace = pObj->pNext;
204  pObj->pNext = NULL;
205 }
206 
207 /**Function*************************************************************
208 
209  Synopsis [Count the number of nodes in the table.]
210 
211  Description []
212 
213  SideEffects []
214 
215  SeeAlso []
216 
217 ***********************************************************************/
219 {
220  Aig_Obj_t * pEntry;
221  int i, Counter = 0;
222  for ( i = 0; i < p->nTableSize; i++ )
223  for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
224  Counter++;
225  return Counter;
226 }
227 
228 /**Function********************************************************************
229 
230  Synopsis [Profiles the hash table.]
231 
232  Description []
233 
234  SideEffects []
235 
236  SeeAlso []
237 
238 ******************************************************************************/
240 {
241  Aig_Obj_t * pEntry;
242  int i, Counter;
243  printf( "Table size = %d. Entries = %d.\n", p->nTableSize, Aig_ManNodeNum(p) );
244  for ( i = 0; i < p->nTableSize; i++ )
245  {
246  Counter = 0;
247  for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
248  Counter++;
249  if ( Counter )
250  printf( "%d ", Counter );
251  }
252 }
253 
254 /**Function********************************************************************
255 
256  Synopsis [Profiles the hash table.]
257 
258  Description []
259 
260  SideEffects []
261 
262  SeeAlso []
263 
264 ******************************************************************************/
266 {
267  ABC_FREE( p->pTable );
268  p->nTableSize = 0;
269 }
270 
271 ////////////////////////////////////////////////////////////////////////
272 /// END OF FILE ///
273 ////////////////////////////////////////////////////////////////////////
274 
275 
277 
char * memset()
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
void Aig_TableProfile(Aig_Man_t *p)
Definition: aigTable.c:239
static Aig_Type_t Aig_ObjType(Aig_Obj_t *pObj)
Definition: aig.h:272
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Aig_Obj_t * Aig_ObjChild0(Aig_Obj_t *pObj)
Definition: aig.h:310
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Aig_TableResize(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: aigTable.c:69
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
static Aig_Obj_t * Aig_ManConst0(Aig_Man_t *p)
Definition: aig.h:263
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Aig_TableCountEntries(Aig_Man_t *p)
Definition: aigTable.c:218
static Aig_Obj_t * Aig_Not(Aig_Obj_t *p)
Definition: aig.h:247
static abctime Abc_Clock()
Definition: abc_global.h:279
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
static ABC_NAMESPACE_IMPL_START unsigned long Aig_Hash(Aig_Obj_t *pObj, int TableSize)
DECLARATIONS ///.
Definition: aigTable.c:31
void Aig_TableClear(Aig_Man_t *p)
Definition: aigTable.c:265
Aig_Obj_t * Aig_TableLookupTwo(Aig_Man_t *p, Aig_Obj_t *pFanin0, Aig_Obj_t *pFanin1)
Definition: aigTable.c:146
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static Aig_Obj_t * Aig_ObjChild1(Aig_Obj_t *pObj)
Definition: aig.h:311
Definition: aig.h:69
Aig_Obj_t * pNext
Definition: aig.h:72
static int Counter
static Aig_Obj_t * Aig_ObjCreateGhost(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1, Aig_Type_t Type)
Definition: aig.h:346
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
void Aig_TableInsert(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTable.c:173
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
static int Aig_ObjIsExor(Aig_Obj_t *pObj)
Definition: aig.h:279
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_TableDelete(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTable.c:196
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
Aig_Obj_t * Aig_TableLookup(Aig_Man_t *p, Aig_Obj_t *pGhost)
Definition: aigTable.c:116
#define assert(ex)
Definition: util_old.h:213
static int Aig_ObjRefs(Aig_Obj_t *pObj)
Definition: aig.h:300
ABC_INT64_T abctime
Definition: abc_global.h:278
int Id
Definition: aig.h:85
static Aig_Obj_t ** Aig_TableFind(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aigTable.c:42