ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
hopTable.c
Go to the documentation of this file.
1
20
21#include "hop.h"
22
24
25
29
30// hashing the node
31static unsigned long Hop_Hash( Hop_Obj_t * pObj, int TableSize )
32{
33 unsigned long Key = Hop_ObjIsExor(pObj) * 1699;
34 Key ^= Hop_ObjFanin0(pObj)->Id * 7937;
35 Key ^= Hop_ObjFanin1(pObj)->Id * 2971;
36 Key ^= Hop_ObjFaninC0(pObj) * 911;
37 Key ^= Hop_ObjFaninC1(pObj) * 353;
38 return Key % TableSize;
39}
40
41// returns the place where this node is stored (or should be stored)
42static Hop_Obj_t ** Hop_TableFind( Hop_Man_t * p, Hop_Obj_t * pObj )
43{
44 Hop_Obj_t ** ppEntry;
45 assert( Hop_ObjChild0(pObj) && Hop_ObjChild1(pObj) );
46 assert( Hop_ObjFanin0(pObj)->Id < Hop_ObjFanin1(pObj)->Id );
47 for ( ppEntry = p->pTable + Hop_Hash(pObj, p->nTableSize); *ppEntry; ppEntry = &(*ppEntry)->pNext )
48 if ( *ppEntry == pObj )
49 return ppEntry;
50 assert( *ppEntry == NULL );
51 return ppEntry;
52}
53
54static void Hop_TableResize( Hop_Man_t * p );
55
59
72{
73 Hop_Obj_t * pEntry;
74 assert( !Hop_IsComplement(pGhost) );
75 assert( Hop_ObjChild0(pGhost) && Hop_ObjChild1(pGhost) );
76 assert( Hop_ObjFanin0(pGhost)->Id < Hop_ObjFanin1(pGhost)->Id );
77 if ( p->fRefCount && (!Hop_ObjRefs(Hop_ObjFanin0(pGhost)) || !Hop_ObjRefs(Hop_ObjFanin1(pGhost))) )
78 return NULL;
79 for ( pEntry = p->pTable[Hop_Hash(pGhost, p->nTableSize)]; pEntry; pEntry = pEntry->pNext )
80 {
81 if ( Hop_ObjChild0(pEntry) == Hop_ObjChild0(pGhost) &&
82 Hop_ObjChild1(pEntry) == Hop_ObjChild1(pGhost) &&
83 Hop_ObjType(pEntry) == Hop_ObjType(pGhost) )
84 return pEntry;
85 }
86 return NULL;
87}
88
101{
102 Hop_Obj_t ** ppPlace;
103 assert( !Hop_IsComplement(pObj) );
104 assert( Hop_TableLookup(p, pObj) == NULL );
105 if ( (pObj->Id & 0xFF) == 0 && 2 * p->nTableSize < Hop_ManNodeNum(p) )
106 Hop_TableResize( p );
107 ppPlace = Hop_TableFind( p, pObj );
108 assert( *ppPlace == NULL );
109 *ppPlace = pObj;
110}
111
124{
125 Hop_Obj_t ** ppPlace;
126 assert( !Hop_IsComplement(pObj) );
127 ppPlace = Hop_TableFind( p, pObj );
128 assert( *ppPlace == pObj ); // node should be in the table
129 // remove the node
130 *ppPlace = pObj->pNext;
131 pObj->pNext = NULL;
132}
133
146{
147 Hop_Obj_t * pEntry;
148 int i, Counter = 0;
149 for ( i = 0; i < p->nTableSize; i++ )
150 for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
151 Counter++;
152 return Counter;
153}
154
166void Hop_TableResize( Hop_Man_t * p )
167{
168 Hop_Obj_t * pEntry, * pNext;
169 Hop_Obj_t ** pTableOld, ** ppPlace;
170 int nTableSizeOld, Counter, nEntries, i;
171 abctime clk;
172clk = Abc_Clock();
173 // save the old table
174 pTableOld = p->pTable;
175 nTableSizeOld = p->nTableSize;
176 // get the new table
177 p->nTableSize = Abc_PrimeCudd( 2 * Hop_ManNodeNum(p) );
178 p->pTable = ABC_ALLOC( Hop_Obj_t *, p->nTableSize );
179 memset( p->pTable, 0, sizeof(Hop_Obj_t *) * p->nTableSize );
180 // rehash the entries from the old table
181 Counter = 0;
182 for ( i = 0; i < nTableSizeOld; i++ )
183 for ( pEntry = pTableOld[i], pNext = pEntry? pEntry->pNext : NULL; pEntry; pEntry = pNext, pNext = pEntry? pEntry->pNext : NULL )
184 {
185 // get the place where this entry goes in the table
186 ppPlace = Hop_TableFind( p, pEntry );
187 assert( *ppPlace == NULL ); // should not be there
188 // add the entry to the list
189 *ppPlace = pEntry;
190 pEntry->pNext = NULL;
191 Counter++;
192 }
193 nEntries = Hop_ManNodeNum(p);
194 assert( Counter == nEntries );
195// printf( "Increasing the structural table size from %6d to %6d. ", nTableSizeOld, p->nTableSize );
196// ABC_PRT( "Time", Abc_Clock() - clk );
197 // replace the table and the parameters
198 ABC_FREE( pTableOld );
199}
200
213{
214 Hop_Obj_t * pEntry;
215 int i, Counter;
216 for ( i = 0; i < p->nTableSize; i++ )
217 {
218 Counter = 0;
219 for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
220 Counter++;
221 if ( Counter )
222 printf( "%d ", Counter );
223 }
224}
225
229
230
232
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
void Hop_TableDelete(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition hopTable.c:123
int Hop_TableCountEntries(Hop_Man_t *p)
Definition hopTable.c:145
void Hop_TableInsert(Hop_Man_t *p, Hop_Obj_t *pObj)
Definition hopTable.c:100
void Hop_TableProfile(Hop_Man_t *p)
Definition hopTable.c:212
Hop_Obj_t * Hop_TableLookup(Hop_Man_t *p, Hop_Obj_t *pGhost)
FUNCTION DEFINITIONS ///.
Definition hopTable.c:71
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
Hop_Obj_t * pNext
Definition hop.h:71
int Id
Definition hop.h:80
#define assert(ex)
Definition util_old.h:213
char * memset()