00001
00019 #include "mapperInt.h"
00020
00024
00025
00026 #define MAP_TABLE_HASH(u1,u2,nSize) (((u1) + 2003 * (u2)) % nSize)
00027
00028 static void Map_SuperTableResize( Map_HashTable_t * pLib );
00029
00033
00045 Map_HashTable_t * Map_SuperTableCreate( Map_SuperLib_t * pLib )
00046 {
00047 Map_HashTable_t * p;
00048
00049 p = ALLOC( Map_HashTable_t, 1 );
00050 memset( p, 0, sizeof(Map_HashTable_t) );
00051 p->mmMan = pLib->mmEntries;
00052
00053 p->nBins = Cudd_Prime(20000);
00054 p->pBins = ALLOC( Map_HashEntry_t *, p->nBins );
00055 memset( p->pBins, 0, sizeof(Map_HashEntry_t *) * p->nBins );
00056 return p;
00057 }
00058
00059
00071 void Map_SuperTableFree( Map_HashTable_t * p )
00072 {
00073 FREE( p->pBins );
00074 FREE( p );
00075 }
00076
00089 int Map_SuperTableInsertC( Map_HashTable_t * p, unsigned uTruthC[], Map_Super_t * pGate )
00090 {
00091 Map_HashEntry_t * pEnt;
00092 unsigned Key;
00093
00094 if ( p->nEntries >= 2 * p->nBins )
00095 Map_SuperTableResize( p );
00096
00097 Key = MAP_TABLE_HASH( uTruthC[0], uTruthC[1], p->nBins );
00098 for ( pEnt = p->pBins[Key]; pEnt; pEnt = pEnt->pNext )
00099 if ( pEnt->uTruth[0] == uTruthC[0] && pEnt->uTruth[1] == uTruthC[1] )
00100 break;
00101
00102 if ( pEnt == NULL )
00103 {
00104
00105 pEnt = (Map_HashEntry_t *)Extra_MmFixedEntryFetch( p->mmMan );
00106 memset( pEnt, 0, sizeof(Map_HashEntry_t) );
00107 pEnt->uTruth[0] = uTruthC[0];
00108 pEnt->uTruth[1] = uTruthC[1];
00109
00110 pEnt->pNext = p->pBins[Key];
00111 p->pBins[Key] = pEnt;
00112 p->nEntries++;
00113 }
00114
00115 pGate->pNext = pEnt->pGates;
00116 pEnt->pGates = pGate;
00117 return 0;
00118 }
00119
00120
00121
00134 int Map_SuperTableInsert( Map_HashTable_t * p, unsigned uTruth[], Map_Super_t * pGate, unsigned uPhase )
00135 {
00136 Map_HashEntry_t * pEnt;
00137 unsigned Key;
00138
00139 if ( p->nEntries >= 2 * p->nBins )
00140 Map_SuperTableResize( p );
00141
00142 Key = MAP_TABLE_HASH( uTruth[0], uTruth[1], p->nBins );
00143 for ( pEnt = p->pBins[Key]; pEnt; pEnt = pEnt->pNext )
00144 if ( pEnt->uTruth[0] == uTruth[0] && pEnt->uTruth[1] == uTruth[1] )
00145 return 1;
00146
00147 pEnt = (Map_HashEntry_t *)Extra_MmFixedEntryFetch( p->mmMan );
00148 memset( pEnt, 0, sizeof(Map_HashEntry_t) );
00149 pEnt->uTruth[0] = uTruth[0];
00150 pEnt->uTruth[1] = uTruth[1];
00151 pEnt->pGates = pGate;
00152 pEnt->uPhase = uPhase;
00153
00154 pEnt->pNext = p->pBins[Key];
00155 p->pBins[Key] = pEnt;
00156 p->nEntries++;
00157
00158
00159
00160
00161
00162
00163 return 0;
00164 }
00165
00180 Map_Super_t * Map_SuperTableLookupC( Map_SuperLib_t * p, unsigned uTruth[] )
00181 {
00182 Map_HashEntry_t * pEnt;
00183 unsigned Key;
00184 Key = MAP_TABLE_HASH( uTruth[0], uTruth[1], p->tTableC->nBins );
00185 for ( pEnt = p->tTableC->pBins[Key]; pEnt; pEnt = pEnt->pNext )
00186 if ( pEnt->uTruth[0] == uTruth[0] && pEnt->uTruth[1] == uTruth[1] )
00187 return pEnt->pGates;
00188 return NULL;
00189 }
00190
00205 Map_Super_t * Map_SuperTableLookup( Map_HashTable_t * p, unsigned uTruth[], unsigned * puPhase )
00206 {
00207 Map_HashEntry_t * pEnt;
00208 unsigned Key;
00209 Key = MAP_TABLE_HASH( uTruth[0], uTruth[1], p->nBins );
00210 for ( pEnt = p->pBins[Key]; pEnt; pEnt = pEnt->pNext )
00211 if ( pEnt->uTruth[0] == uTruth[0] && pEnt->uTruth[1] == uTruth[1] )
00212 {
00213 *puPhase = pEnt->uPhase;
00214 return pEnt->pGates;
00215 }
00216 return NULL;
00217 }
00218
00230 void Map_SuperTableResize( Map_HashTable_t * p )
00231 {
00232 Map_HashEntry_t ** pBinsNew;
00233 Map_HashEntry_t * pEnt, * pEnt2;
00234 int nBinsNew, Counter, i, clk = clock();
00235 unsigned Key;
00236
00237 nBinsNew = Cudd_Prime(2 * p->nBins);
00238
00239 pBinsNew = ALLOC( Map_HashEntry_t *, nBinsNew );
00240 memset( pBinsNew, 0, sizeof(Map_HashEntry_t *) * nBinsNew );
00241
00242 Counter = 0;
00243 for ( i = 0; i < p->nBins; i++ )
00244 for ( pEnt = p->pBins[i], pEnt2 = pEnt? pEnt->pNext: NULL; pEnt;
00245 pEnt = pEnt2, pEnt2 = pEnt? pEnt->pNext: NULL )
00246 {
00247 Key = MAP_TABLE_HASH( pEnt->uTruth[0], pEnt->uTruth[1], nBinsNew );
00248 pEnt->pNext = pBinsNew[Key];
00249 pBinsNew[Key] = pEnt;
00250 Counter++;
00251 }
00252 assert( Counter == p->nEntries );
00253
00254 free( p->pBins );
00255 p->pBins = pBinsNew;
00256 p->nBins = nBinsNew;
00257 }
00258
00270 int Map_SuperTableCompareSupergates( Map_Super_t ** ppS1, Map_Super_t ** ppS2 )
00271 {
00272 if ( (*ppS1)->nUsed > (*ppS2)->nUsed )
00273 return -1;
00274 if ( (*ppS1)->nUsed < (*ppS2)->nUsed )
00275 return 1;
00276 return 0;
00277 }
00278
00290 int Map_SuperTableCompareGatesInList( Map_Super_t ** ppS1, Map_Super_t ** ppS2 )
00291 {
00292
00293 if ( (*ppS1)->Area > (*ppS2)->Area )
00294 return -1;
00295
00296 if ( (*ppS1)->Area < (*ppS2)->Area )
00297 return 1;
00298 return 0;
00299 }
00300
00312 void Map_SuperTableSortSupergates( Map_HashTable_t * p, int nSupersMax )
00313 {
00314 Map_HashEntry_t * pEnt;
00315 Map_Super_t ** ppSupers;
00316 Map_Super_t * pSuper;
00317 int nSupers, i;
00318
00319
00320 ppSupers = ALLOC( Map_Super_t *, nSupersMax );
00321 nSupers = 0;
00322 for ( i = 0; i < p->nBins; i++ )
00323 for ( pEnt = p->pBins[i]; pEnt; pEnt = pEnt->pNext )
00324 for ( pSuper = pEnt->pGates; pSuper; pSuper = pSuper->pNext )
00325 ppSupers[nSupers++] = pSuper;
00326
00327
00328 qsort( (void *)ppSupers, nSupers, sizeof(Map_Super_t *),
00329 (int (*)(const void *, const void *)) Map_SuperTableCompareSupergates );
00330 assert( Map_SuperTableCompareSupergates( ppSupers, ppSupers + nSupers - 1 ) <= 0 );
00331
00332
00333
00334 for ( i = 0; i < 10; i++ )
00335 {
00336 if ( ppSupers[i]->nUsed == 0 )
00337 break;
00338 printf( "%5d : ", ppSupers[i]->nUsed );
00339 printf( "%5d ", ppSupers[i]->Num );
00340 printf( "A = %5.2f ", ppSupers[i]->Area );
00341 printf( "D = %5.2f ", ppSupers[i]->tDelayMax.Rise );
00342 printf( "%s", ppSupers[i]->pFormula );
00343 printf( "\n" );
00344 }
00345 free( ppSupers );
00346 }
00347
00359 void Map_SuperTableSortSupergatesByDelay( Map_HashTable_t * p, int nSupersMax )
00360 {
00361 Map_HashEntry_t * pEnt;
00362 Map_Super_t ** ppSupers;
00363 Map_Super_t * pSuper;
00364 int nSupers, i, k;
00365
00366 ppSupers = ALLOC( Map_Super_t *, nSupersMax );
00367 for ( i = 0; i < p->nBins; i++ )
00368 for ( pEnt = p->pBins[i]; pEnt; pEnt = pEnt->pNext )
00369 {
00370
00371 nSupers = 0;
00372 for ( pSuper = pEnt->pGates; pSuper; pSuper = pSuper->pNext )
00373 {
00374
00375
00376
00377 ppSupers[nSupers++] = pSuper;
00378 }
00379 pEnt->pGates = NULL;
00380 if ( nSupers == 0 )
00381 continue;
00382
00383 qsort( (void *)ppSupers, nSupers, sizeof(Map_Super_t *),
00384 (int (*)(const void *, const void *)) Map_SuperTableCompareGatesInList );
00385 assert( Map_SuperTableCompareGatesInList( ppSupers, ppSupers + nSupers - 1 ) <= 0 );
00386
00387 for ( k = 0; k < nSupers; k++ )
00388 {
00389 ppSupers[k]->pNext = pEnt->pGates;
00390 pEnt->pGates = ppSupers[k];
00391 }
00392
00393 pEnt->pGates->nSupers = nSupers;
00394 }
00395 FREE( ppSupers );
00396 }
00397
00401
00402