ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
aigTable.c
Go to the documentation of this file.
1
20
21#include "aig.h"
22
24
25
29
30// hashing the node
31static 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)
42static Aig_Obj_t ** Aig_TableFind( Aig_Man_t * p, Aig_Obj_t * pObj )
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
57
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 );
76clk = 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
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
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
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) )
180 ppPlace = Aig_TableFind( p, pObj );
181 assert( *ppPlace == NULL );
182 *ppPlace = pObj;
183}
184
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
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
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
266{
267 ABC_FREE( p->pTable );
268 p->nTableSize = 0;
269}
270
274
275
277
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
void Aig_TableClear(Aig_Man_t *p)
Definition aigTable.c:265
void Aig_TableResize(Aig_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition aigTable.c:69
void Aig_TableInsert(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigTable.c:173
Aig_Obj_t * Aig_TableLookup(Aig_Man_t *p, Aig_Obj_t *pGhost)
Definition aigTable.c:116
int Aig_TableCountEntries(Aig_Man_t *p)
Definition aigTable.c:218
Aig_Obj_t * Aig_TableLookupTwo(Aig_Man_t *p, Aig_Obj_t *pFanin0, Aig_Obj_t *pFanin1)
Definition aigTable.c:146
void Aig_TableProfile(Aig_Man_t *p)
Definition aigTable.c:239
void Aig_TableDelete(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition aigTable.c:196
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
@ AIG_OBJ_AND
Definition aig.h:63
Cube * p
Definition exorList.c:222
int Id
Definition aig.h:85
Aig_Obj_t * pNext
Definition aig.h:72
#define assert(ex)
Definition util_old.h:213
char * memset()