00001
00021 #include "hop.h"
00022
00026
00027
00028 static unsigned long Hop_Hash( Hop_Obj_t * pObj, int TableSize )
00029 {
00030 unsigned long Key = Hop_ObjIsExor(pObj) * 1699;
00031 Key ^= Hop_ObjFanin0(pObj)->Id * 7937;
00032 Key ^= Hop_ObjFanin1(pObj)->Id * 2971;
00033 Key ^= Hop_ObjFaninC0(pObj) * 911;
00034 Key ^= Hop_ObjFaninC1(pObj) * 353;
00035 return Key % TableSize;
00036 }
00037
00038
00039 static Hop_Obj_t ** Hop_TableFind( Hop_Man_t * p, Hop_Obj_t * pObj )
00040 {
00041 Hop_Obj_t ** ppEntry;
00042 assert( Hop_ObjChild0(pObj) && Hop_ObjChild1(pObj) );
00043 assert( Hop_ObjFanin0(pObj)->Id < Hop_ObjFanin1(pObj)->Id );
00044 for ( ppEntry = p->pTable + Hop_Hash(pObj, p->nTableSize); *ppEntry; ppEntry = &(*ppEntry)->pNext )
00045 if ( *ppEntry == pObj )
00046 return ppEntry;
00047 assert( *ppEntry == NULL );
00048 return ppEntry;
00049 }
00050
00051 static void Hop_TableResize( Hop_Man_t * p );
00052 static unsigned int Cudd_PrimeAig( unsigned int p );
00053
00057
00069 Hop_Obj_t * Hop_TableLookup( Hop_Man_t * p, Hop_Obj_t * pGhost )
00070 {
00071 Hop_Obj_t * pEntry;
00072 assert( !Hop_IsComplement(pGhost) );
00073 assert( Hop_ObjChild0(pGhost) && Hop_ObjChild1(pGhost) );
00074 assert( Hop_ObjFanin0(pGhost)->Id < Hop_ObjFanin1(pGhost)->Id );
00075 if ( p->fRefCount && (!Hop_ObjRefs(Hop_ObjFanin0(pGhost)) || !Hop_ObjRefs(Hop_ObjFanin1(pGhost))) )
00076 return NULL;
00077 for ( pEntry = p->pTable[Hop_Hash(pGhost, p->nTableSize)]; pEntry; pEntry = pEntry->pNext )
00078 {
00079 if ( Hop_ObjChild0(pEntry) == Hop_ObjChild0(pGhost) &&
00080 Hop_ObjChild1(pEntry) == Hop_ObjChild1(pGhost) &&
00081 Hop_ObjType(pEntry) == Hop_ObjType(pGhost) )
00082 return pEntry;
00083 }
00084 return NULL;
00085 }
00086
00098 void Hop_TableInsert( Hop_Man_t * p, Hop_Obj_t * pObj )
00099 {
00100 Hop_Obj_t ** ppPlace;
00101 assert( !Hop_IsComplement(pObj) );
00102 assert( Hop_TableLookup(p, pObj) == NULL );
00103 if ( (pObj->Id & 0xFF) == 0 && 2 * p->nTableSize < Hop_ManNodeNum(p) )
00104 Hop_TableResize( p );
00105 ppPlace = Hop_TableFind( p, pObj );
00106 assert( *ppPlace == NULL );
00107 *ppPlace = pObj;
00108 }
00109
00121 void Hop_TableDelete( Hop_Man_t * p, Hop_Obj_t * pObj )
00122 {
00123 Hop_Obj_t ** ppPlace;
00124 assert( !Hop_IsComplement(pObj) );
00125 ppPlace = Hop_TableFind( p, pObj );
00126 assert( *ppPlace == pObj );
00127
00128 *ppPlace = pObj->pNext;
00129 pObj->pNext = NULL;
00130 }
00131
00143 int Hop_TableCountEntries( Hop_Man_t * p )
00144 {
00145 Hop_Obj_t * pEntry;
00146 int i, Counter = 0;
00147 for ( i = 0; i < p->nTableSize; i++ )
00148 for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
00149 Counter++;
00150 return Counter;
00151 }
00152
00164 void Hop_TableResize( Hop_Man_t * p )
00165 {
00166 Hop_Obj_t * pEntry, * pNext;
00167 Hop_Obj_t ** pTableOld, ** ppPlace;
00168 int nTableSizeOld, Counter, nEntries, i, clk;
00169 clk = clock();
00170
00171 pTableOld = p->pTable;
00172 nTableSizeOld = p->nTableSize;
00173
00174 p->nTableSize = Cudd_PrimeAig( 2 * Hop_ManNodeNum(p) );
00175 p->pTable = ALLOC( Hop_Obj_t *, p->nTableSize );
00176 memset( p->pTable, 0, sizeof(Hop_Obj_t *) * p->nTableSize );
00177
00178 Counter = 0;
00179 for ( i = 0; i < nTableSizeOld; i++ )
00180 for ( pEntry = pTableOld[i], pNext = pEntry? pEntry->pNext : NULL; pEntry; pEntry = pNext, pNext = pEntry? pEntry->pNext : NULL )
00181 {
00182
00183 ppPlace = Hop_TableFind( p, pEntry );
00184 assert( *ppPlace == NULL );
00185
00186 *ppPlace = pEntry;
00187 pEntry->pNext = NULL;
00188 Counter++;
00189 }
00190 nEntries = Hop_ManNodeNum(p);
00191 assert( Counter == nEntries );
00192
00193
00194
00195 free( pTableOld );
00196 }
00197
00209 void Hop_TableProfile( Hop_Man_t * p )
00210 {
00211 Hop_Obj_t * pEntry;
00212 int i, Counter;
00213 for ( i = 0; i < p->nTableSize; i++ )
00214 {
00215 Counter = 0;
00216 for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext )
00217 Counter++;
00218 if ( Counter )
00219 printf( "%d ", Counter );
00220 }
00221 }
00222
00234 unsigned int Cudd_PrimeAig( unsigned int p)
00235 {
00236 int i,pn;
00237 p--;
00238 do {
00239 p++;
00240 if (p&1) {
00241 pn = 1;
00242 i = 3;
00243 while ((unsigned) (i * i) <= p) {
00244 if (p % i == 0) {
00245 pn = 0;
00246 break;
00247 }
00248 i += 2;
00249 }
00250 } else {
00251 pn = 0;
00252 }
00253 } while (!pn);
00254 return(p);
00255
00256 }
00257
00261
00262