00001
00019 #include "fpgaInt.h"
00020 #include "main.h"
00021
00025
00026 static void Fpga_TableCreate( Fpga_Man_t * p );
00027 static void Fpga_TableResize( Fpga_Man_t * p );
00028 static Fpga_Node_t * Fpga_TableLookup( Fpga_Man_t * p, Fpga_Node_t * p1, Fpga_Node_t * p2 );
00029
00030
00031 static inline unsigned Fpga_HashKey2( Fpga_Node_t * p0, Fpga_Node_t * p1, int TableSize ) { return ((unsigned)(p0) + (unsigned)(p1) * 12582917) % TableSize; }
00032
00036
00048 int Fpga_ManReadInputNum( Fpga_Man_t * p ) { return p->nInputs; }
00049 int Fpga_ManReadOutputNum( Fpga_Man_t * p ) { return p->nOutputs; }
00050 Fpga_Node_t ** Fpga_ManReadInputs ( Fpga_Man_t * p ) { return p->pInputs; }
00051 Fpga_Node_t ** Fpga_ManReadOutputs( Fpga_Man_t * p ) { return p->pOutputs; }
00052 Fpga_Node_t * Fpga_ManReadConst1 ( Fpga_Man_t * p ) { return p->pConst1; }
00053 float * Fpga_ManReadInputArrivals( Fpga_Man_t * p ) { return p->pInputArrivals;}
00054 int Fpga_ManReadVerbose( Fpga_Man_t * p ) { return p->fVerbose; }
00055 float * Fpga_ManReadLutAreas( Fpga_Man_t * p ) { return p->pLutLib->pLutAreas; }
00056 void Fpga_ManSetTimeToMap( Fpga_Man_t * p, int Time ) { p->timeToMap = Time; }
00057 void Fpga_ManSetTimeToNet( Fpga_Man_t * p, int Time ) { p->timeToNet = Time; }
00058 void Fpga_ManSetTimeTotal( Fpga_Man_t * p, int Time ) { p->timeTotal = Time; }
00059 void Fpga_ManSetOutputNames( Fpga_Man_t * p, char ** ppNames ) { p->ppOutputNames = ppNames; }
00060 void Fpga_ManSetInputArrivals( Fpga_Man_t * p, float * pArrivals ) { p->pInputArrivals = pArrivals; }
00061 void Fpga_ManSetAreaRecovery( Fpga_Man_t * p, int fAreaRecovery ) { p->fAreaRecovery = fAreaRecovery;}
00062 void Fpga_ManSetDelayLimit( Fpga_Man_t * p, float DelayLimit ) { p->DelayLimit = DelayLimit; }
00063 void Fpga_ManSetAreaLimit( Fpga_Man_t * p, float AreaLimit ) { p->AreaLimit = AreaLimit; }
00064 void Fpga_ManSetTimeLimit( Fpga_Man_t * p, float TimeLimit ) { p->TimeLimit = TimeLimit; }
00065 void Fpga_ManSetChoiceNodeNum( Fpga_Man_t * p, int nChoiceNodes ) { p->nChoiceNodes = nChoiceNodes; }
00066 void Fpga_ManSetChoiceNum( Fpga_Man_t * p, int nChoices ) { p->nChoices = nChoices; }
00067 void Fpga_ManSetVerbose( Fpga_Man_t * p, int fVerbose ) { p->fVerbose = fVerbose; }
00068 void Fpga_ManSetSwitching( Fpga_Man_t * p, int fSwitching ) { p->fSwitching = fSwitching; }
00069 void Fpga_ManSetLatchPaths( Fpga_Man_t * p, int fLatchPaths ) { p->fLatchPaths = fLatchPaths; }
00070 void Fpga_ManSetLatchNum( Fpga_Man_t * p, int nLatches ) { p->nLatches = nLatches; }
00071 void Fpga_ManSetDelayTarget( Fpga_Man_t * p, float DelayTarget ) { p->DelayTarget = DelayTarget; }
00072 void Fpga_ManSetName( Fpga_Man_t * p, char * pFileName ) { p->pFileName = pFileName; }
00073
00085 int Fpga_LibReadLutMax( Fpga_LutLib_t * pLib ) { return pLib->LutMax; }
00086
00098 char * Fpga_NodeReadData0( Fpga_Node_t * p ) { return p->pData0; }
00099 Fpga_Node_t * Fpga_NodeReadData1( Fpga_Node_t * p ) { return p->pLevel; }
00100 int Fpga_NodeReadRefs( Fpga_Node_t * p ) { return p->nRefs; }
00101 int Fpga_NodeReadNum( Fpga_Node_t * p ) { return p->Num; }
00102 int Fpga_NodeReadLevel( Fpga_Node_t * p ) { return Fpga_Regular(p)->Level; }
00103 Fpga_Cut_t * Fpga_NodeReadCuts( Fpga_Node_t * p ) { return p->pCuts; }
00104 Fpga_Cut_t * Fpga_NodeReadCutBest( Fpga_Node_t * p ) { return p->pCutBest; }
00105 Fpga_Node_t * Fpga_NodeReadOne( Fpga_Node_t * p ) { return p->p1; }
00106 Fpga_Node_t * Fpga_NodeReadTwo( Fpga_Node_t * p ) { return p->p2; }
00107 void Fpga_NodeSetData0( Fpga_Node_t * p, char * pData ) { p->pData0 = pData; }
00108 void Fpga_NodeSetData1( Fpga_Node_t * p, Fpga_Node_t * pNode ) { p->pLevel = pNode; }
00109 void Fpga_NodeSetNextE( Fpga_Node_t * p, Fpga_Node_t * pNextE ) { p->pNextE = pNextE; }
00110 void Fpga_NodeSetRepr( Fpga_Node_t * p, Fpga_Node_t * pRepr ) { p->pRepr = pRepr; }
00111 void Fpga_NodeSetSwitching( Fpga_Node_t * p, float Switching ) { p->Switching = Switching; }
00112
00124 int Fpga_NodeIsConst( Fpga_Node_t * p ) { return (Fpga_Regular(p))->Num == -1; }
00125 int Fpga_NodeIsVar( Fpga_Node_t * p ) { return (Fpga_Regular(p))->p1 == NULL && (Fpga_Regular(p))->Num >= 0; }
00126 int Fpga_NodeIsAnd( Fpga_Node_t * p ) { return (Fpga_Regular(p))->p1 != NULL; }
00127 int Fpga_NodeComparePhase( Fpga_Node_t * p1, Fpga_Node_t * p2 ) { assert( !Fpga_IsComplement(p1) ); assert( !Fpga_IsComplement(p2) ); return p1->fInv ^ p2->fInv; }
00128
00140 int Fpga_CutReadLeavesNum( Fpga_Cut_t * p ) { return p->nLeaves; }
00141 Fpga_Node_t ** Fpga_CutReadLeaves( Fpga_Cut_t * p ) { return p->ppLeaves; }
00142
00143
00162 Fpga_Man_t * Fpga_ManCreate( int nInputs, int nOutputs, int fVerbose )
00163 {
00164 Fpga_Man_t * p;
00165 int i;
00166
00167
00168 p = ALLOC( Fpga_Man_t, 1 );
00169 memset( p, 0, sizeof(Fpga_Man_t) );
00170 p->pLutLib = Abc_FrameReadLibLut();
00171 p->nVarsMax = p->pLutLib->LutMax;
00172 p->fVerbose = fVerbose;
00173 p->fAreaRecovery = 1;
00174 p->fEpsilon = (float)0.001;
00175
00176 Fpga_TableCreate( p );
00177
00178
00179 p->mmNodes = Extra_MmFixedStart( FPGA_NUM_BYTES(sizeof(Fpga_Node_t)) );
00180 p->mmCuts = Extra_MmFixedStart( sizeof(Fpga_Cut_t) );
00181
00182 assert( p->nVarsMax > 0 );
00183
00184
00185
00186 p->nNodes = -1;
00187
00188 p->pConst1 = Fpga_NodeCreate( p, NULL, NULL );
00189 p->vNodesAll = Fpga_NodeVecAlloc( 1000 );
00190 p->vMapping = Fpga_NodeVecAlloc( 1000 );
00191
00192
00193 p->nInputs = nInputs;
00194 p->pInputs = ALLOC( Fpga_Node_t *, nInputs );
00195 for ( i = 0; i < nInputs; i++ )
00196 p->pInputs[i] = Fpga_NodeCreate( p, NULL, NULL );
00197
00198
00199 p->nOutputs = nOutputs;
00200 p->pOutputs = ALLOC( Fpga_Node_t *, nOutputs );
00201 memset( p->pOutputs, 0, sizeof(Fpga_Node_t *) * nOutputs );
00202 return p;
00203 }
00204
00216 void Fpga_ManFree( Fpga_Man_t * p )
00217 {
00218
00219
00220
00221
00222
00223 if ( p->vMapping )
00224 Fpga_NodeVecFree( p->vMapping );
00225 if ( p->vAnds )
00226 Fpga_NodeVecFree( p->vAnds );
00227 if ( p->vNodesAll )
00228 Fpga_NodeVecFree( p->vNodesAll );
00229 Extra_MmFixedStop( p->mmNodes );
00230 Extra_MmFixedStop( p->mmCuts );
00231 FREE( p->ppOutputNames );
00232 FREE( p->pInputArrivals );
00233 FREE( p->pInputs );
00234 FREE( p->pOutputs );
00235 FREE( p->pBins );
00236 FREE( p );
00237 }
00238
00239
00251 void Fpga_ManPrintTimeStats( Fpga_Man_t * p )
00252 {
00253 extern char * pNetName;
00254 extern int TotalLuts;
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 PRT( "ToMap", p->timeToMap );
00271 PRT( "Cuts ", p->timeCuts );
00272 PRT( "Match", p->timeMatch );
00273 PRT( "Area ", p->timeRecover );
00274 PRT( "ToNet", p->timeToNet );
00275 PRT( "TOTAL", p->timeTotal );
00276 if ( p->time1 ) { PRT( "time1", p->time1 ); }
00277 if ( p->time2 ) { PRT( "time2", p->time2 ); }
00278 }
00279
00292 Fpga_Node_t * Fpga_NodeCreate( Fpga_Man_t * p, Fpga_Node_t * p1, Fpga_Node_t * p2 )
00293 {
00294 Fpga_Node_t * pNode;
00295
00296 pNode = (Fpga_Node_t *)Extra_MmFixedEntryFetch( p->mmNodes );
00297 memset( pNode, 0, sizeof(Fpga_Node_t) );
00298
00299 pNode->tRequired = FPGA_FLOAT_LARGE;
00300 pNode->aEstFanouts = -1;
00301 pNode->p1 = p1;
00302 pNode->p2 = p2;
00303
00304 pNode->Num = p->nNodes++;
00305
00306
00307
00308 if ( pNode->Num >= 0 )
00309 Fpga_NodeVecPush( p->vNodesAll, pNode );
00310 else
00311 pNode->fInv = 1;
00312
00313 if ( p1 )
00314 {
00315 #ifdef FPGA_ALLOCATE_FANOUT
00316
00317 Fpga_NodeAddFaninFanout( Fpga_Regular(p1), pNode );
00318 Fpga_NodeAddFaninFanout( Fpga_Regular(p2), pNode );
00319 #endif
00320
00321 pNode->Level = 1 + FPGA_MAX(Fpga_Regular(p1)->Level, Fpga_Regular(p2)->Level);
00322 pNode->fInv = Fpga_NodeIsSimComplement(p1) & Fpga_NodeIsSimComplement(p2);
00323 }
00324
00325 if ( p1 ) Fpga_NodeRef(p1);
00326 if ( p2 ) Fpga_NodeRef(p2);
00327 return pNode;
00328 }
00329
00341 void Fpga_TableCreate( Fpga_Man_t * pMan )
00342 {
00343 assert( pMan->pBins == NULL );
00344 pMan->nBins = Cudd_Prime(50000);
00345 pMan->pBins = ALLOC( Fpga_Node_t *, pMan->nBins );
00346 memset( pMan->pBins, 0, sizeof(Fpga_Node_t *) * pMan->nBins );
00347 pMan->nNodes = 0;
00348 }
00349
00364 Fpga_Node_t * Fpga_TableLookup( Fpga_Man_t * pMan, Fpga_Node_t * p1, Fpga_Node_t * p2 )
00365 {
00366 Fpga_Node_t * pEnt;
00367 unsigned Key;
00368
00369 if ( p1 == p2 )
00370 return p1;
00371 if ( p1 == Fpga_Not(p2) )
00372 return Fpga_Not(pMan->pConst1);
00373 if ( Fpga_NodeIsConst(p1) )
00374 {
00375 if ( p1 == pMan->pConst1 )
00376 return p2;
00377 return Fpga_Not(pMan->pConst1);
00378 }
00379 if ( Fpga_NodeIsConst(p2) )
00380 {
00381 if ( p2 == pMan->pConst1 )
00382 return p1;
00383 return Fpga_Not(pMan->pConst1);
00384 }
00385
00386 if ( Fpga_Regular(p1)->Num > Fpga_Regular(p2)->Num )
00387 pEnt = p1, p1 = p2, p2 = pEnt;
00388
00389 Key = Fpga_HashKey2( p1, p2, pMan->nBins );
00390 for ( pEnt = pMan->pBins[Key]; pEnt; pEnt = pEnt->pNext )
00391 if ( pEnt->p1 == p1 && pEnt->p2 == p2 )
00392 return pEnt;
00393
00394 if ( pMan->nNodes >= 2 * pMan->nBins )
00395 {
00396 Fpga_TableResize( pMan );
00397 Key = Fpga_HashKey2( p1, p2, pMan->nBins );
00398 }
00399
00400 pEnt = Fpga_NodeCreate( pMan, p1, p2 );
00401
00402 pEnt->pNext = pMan->pBins[Key];
00403 pMan->pBins[Key] = pEnt;
00404 return pEnt;
00405 }
00406
00407
00419 void Fpga_TableResize( Fpga_Man_t * pMan )
00420 {
00421 Fpga_Node_t ** pBinsNew;
00422 Fpga_Node_t * pEnt, * pEnt2;
00423 int nBinsNew, Counter, i, clk;
00424 unsigned Key;
00425
00426 clk = clock();
00427
00428 nBinsNew = Cudd_Prime(2 * pMan->nBins);
00429
00430 pBinsNew = ALLOC( Fpga_Node_t *, nBinsNew );
00431 memset( pBinsNew, 0, sizeof(Fpga_Node_t *) * nBinsNew );
00432
00433 Counter = 0;
00434 for ( i = 0; i < pMan->nBins; i++ )
00435 for ( pEnt = pMan->pBins[i], pEnt2 = pEnt? pEnt->pNext: NULL; pEnt;
00436 pEnt = pEnt2, pEnt2 = pEnt? pEnt->pNext: NULL )
00437 {
00438 Key = Fpga_HashKey2( pEnt->p1, pEnt->p2, nBinsNew );
00439 pEnt->pNext = pBinsNew[Key];
00440 pBinsNew[Key] = pEnt;
00441 Counter++;
00442 }
00443 assert( Counter == pMan->nNodes - pMan->nInputs );
00444 if ( pMan->fVerbose )
00445 {
00446
00447
00448 }
00449
00450 free( pMan->pBins );
00451 pMan->pBins = pBinsNew;
00452 pMan->nBins = nBinsNew;
00453 }
00454
00455
00456
00468 Fpga_Node_t * Fpga_NodeAnd( Fpga_Man_t * p, Fpga_Node_t * p1, Fpga_Node_t * p2 )
00469 {
00470 Fpga_Node_t * pNode;
00471 pNode = Fpga_TableLookup( p, p1, p2 );
00472 return pNode;
00473 }
00474
00486 Fpga_Node_t * Fpga_NodeOr( Fpga_Man_t * p, Fpga_Node_t * p1, Fpga_Node_t * p2 )
00487 {
00488 Fpga_Node_t * pNode;
00489 pNode = Fpga_Not( Fpga_TableLookup( p, Fpga_Not(p1), Fpga_Not(p2) ) );
00490 return pNode;
00491 }
00492
00504 Fpga_Node_t * Fpga_NodeExor( Fpga_Man_t * p, Fpga_Node_t * p1, Fpga_Node_t * p2 )
00505 {
00506 return Fpga_NodeMux( p, p1, Fpga_Not(p2), p2 );
00507 }
00508
00520 Fpga_Node_t * Fpga_NodeMux( Fpga_Man_t * p, Fpga_Node_t * pC, Fpga_Node_t * pT, Fpga_Node_t * pE )
00521 {
00522 Fpga_Node_t * pAnd1, * pAnd2, * pRes;
00523 pAnd1 = Fpga_TableLookup( p, pC, pT );
00524 pAnd2 = Fpga_TableLookup( p, Fpga_Not(pC), pE );
00525 pRes = Fpga_NodeOr( p, pAnd1, pAnd2 );
00526 return pRes;
00527 }
00528
00529
00542 void Fpga_NodeSetChoice( Fpga_Man_t * pMan, Fpga_Node_t * pNodeOld, Fpga_Node_t * pNodeNew )
00543 {
00544 pNodeNew->pNextE = pNodeOld->pNextE;
00545 pNodeOld->pNextE = pNodeNew;
00546 pNodeNew->pRepr = pNodeOld;
00547 }
00548
00549
00550
00562 void Fpga_ManStats( Fpga_Man_t * p )
00563 {
00564 FILE * pTable;
00565 pTable = fopen( "stats.txt", "a+" );
00566 fprintf( pTable, "%s ", p->pFileName );
00567 fprintf( pTable, "%4d ", p->nInputs - p->nLatches );
00568 fprintf( pTable, "%4d ", p->nOutputs - p->nLatches );
00569 fprintf( pTable, "%4d ", p->nLatches );
00570 fprintf( pTable, "%7d ", p->vAnds->nSize );
00571 fprintf( pTable, "%7d ", Fpga_CutCountAll(p) );
00572 fprintf( pTable, "%2d\n", (int)p->fRequiredGlo );
00573 fclose( pTable );
00574 }
00575
00576
00580