00001
00019 #include "fpgaInt.h"
00020
00024
00028
00040 Fpga_Cut_t * Fpga_CutAlloc( Fpga_Man_t * p )
00041 {
00042 Fpga_Cut_t * pCut;
00043 pCut = (Fpga_Cut_t *)Extra_MmFixedEntryFetch( p->mmCuts );
00044 memset( pCut, 0, sizeof(Fpga_Cut_t) );
00045 return pCut;
00046 }
00047
00059 Fpga_Cut_t * Fpga_CutDup( Fpga_Man_t * p, Fpga_Cut_t * pCutOld )
00060 {
00061 Fpga_Cut_t * pCutNew;
00062 int i;
00063 pCutNew = Fpga_CutAlloc( p );
00064 pCutNew->pRoot = pCutOld->pRoot;
00065 pCutNew->nLeaves = pCutOld->nLeaves;
00066 for ( i = 0; i < pCutOld->nLeaves; i++ )
00067 pCutNew->ppLeaves[i] = pCutOld->ppLeaves[i];
00068 return pCutNew;
00069 }
00070
00082 void Fpga_CutFree( Fpga_Man_t * p, Fpga_Cut_t * pCut )
00083 {
00084 if ( pCut )
00085 Extra_MmFixedEntryRecycle( p->mmCuts, (char *)pCut );
00086 }
00087
00099 void Fpga_CutPrint( Fpga_Man_t * p, Fpga_Node_t * pRoot, Fpga_Cut_t * pCut )
00100 {
00101 int i;
00102 printf( "CUT: Delay = %4.2f. Area = %4.2f. Nodes = %d -> {",
00103 pCut->tArrival, pCut->aFlow, pRoot->Num );
00104 for ( i = 0; i < pCut->nLeaves; i++ )
00105 printf( " %d", pCut->ppLeaves[i]->Num );
00106 printf( " } \n" );
00107 }
00108
00120 Fpga_Cut_t * Fpga_CutCreateSimple( Fpga_Man_t * p, Fpga_Node_t * pNode )
00121 {
00122 Fpga_Cut_t * pCut;
00123 pCut = Fpga_CutAlloc( p );
00124 pCut->pRoot = pNode;
00125 pCut->nLeaves = 1;
00126 pCut->ppLeaves[0] = pNode;
00127 pCut->uSign = FPGA_SEQ_SIGN(pCut->ppLeaves[0]);
00128 return pCut;
00129 }
00130
00131
00143 float Fpga_CutGetRootArea( Fpga_Man_t * p, Fpga_Cut_t * pCut )
00144 {
00145 return p->pLutLib->pLutAreas[pCut->nLeaves];
00146 }
00147
00159 Fpga_Cut_t * Fpga_CutListAppend( Fpga_Cut_t * pSetAll, Fpga_Cut_t * pSets )
00160 {
00161 Fpga_Cut_t * pPrev, * pTemp;
00162 if ( pSetAll == NULL )
00163 return pSets;
00164 if ( pSets == NULL )
00165 return pSetAll;
00166
00167 for ( pTemp = pSets; pTemp; pTemp = pTemp->pNext )
00168 pPrev = pTemp;
00169
00170 assert( pPrev->pNext == NULL );
00171 pPrev->pNext = pSetAll;
00172 return pSets;
00173 }
00174
00186 void Fpga_CutListRecycle( Fpga_Man_t * p, Fpga_Cut_t * pSetList, Fpga_Cut_t * pSave )
00187 {
00188 Fpga_Cut_t * pNext, * pTemp;
00189 for ( pTemp = pSetList, pNext = pTemp? pTemp->pNext : NULL;
00190 pTemp;
00191 pTemp = pNext, pNext = pNext? pNext->pNext : NULL )
00192 if ( pTemp != pSave )
00193 Extra_MmFixedEntryRecycle( p->mmCuts, (char *)pTemp );
00194 }
00195
00207 int Fpga_CutListCount( Fpga_Cut_t * pSets )
00208 {
00209 Fpga_Cut_t * pTemp;
00210 int i;
00211 for ( i = 0, pTemp = pSets; pTemp; pTemp = pTemp->pNext, i++ );
00212 return i;
00213 }
00214
00215 #if 0
00216
00228 void Fpga_CutRemoveFanouts( Fpga_Man_t * p, Fpga_Node_t * pNode, Fpga_Cut_t * pCut )
00229 {
00230 Fpga_NodeVec_t * vFanouts;
00231 int i, k;
00232 for ( i = 0; i < pCut->nLeaves; i++ )
00233 {
00234 vFanouts = pCut->ppLeaves[i]->vFanouts;
00235 for ( k = 0; k < vFanouts->nSize; k++ )
00236 if ( vFanouts->pArray[k] == pNode )
00237 break;
00238 assert( k != vFanouts->nSize );
00239 for ( k++; k < vFanouts->nSize; k++ )
00240 vFanouts->pArray[k-1] = vFanouts->pArray[k];
00241 vFanouts->nSize--;
00242 }
00243 }
00244
00256 void Fpga_CutInsertFanouts( Fpga_Man_t * p, Fpga_Node_t * pNode, Fpga_Cut_t * pCut )
00257 {
00258 int i;
00259 for ( i = 0; i < pCut->nLeaves; i++ )
00260 Fpga_NodeVecPush( pCut->ppLeaves[i]->vFanouts, pNode );
00261 }
00262 #endif
00263
00275 void Fpga_CutGetParameters( Fpga_Man_t * pMan, Fpga_Cut_t * pCut )
00276 {
00277 Fpga_Cut_t * pFaninCut;
00278 int i;
00279 pCut->tArrival = -FPGA_FLOAT_LARGE;
00280 pCut->aFlow = pMan->pLutLib->pLutAreas[pCut->nLeaves];
00281 for ( i = 0; i < pCut->nLeaves; i++ )
00282 {
00283 pFaninCut = pCut->ppLeaves[i]->pCutBest;
00284 if ( pCut->tArrival < pFaninCut->tArrival )
00285 pCut->tArrival = pFaninCut->tArrival;
00286
00287 if ( pCut->ppLeaves[i]->nRefs == 0 )
00288 pCut->aFlow += pFaninCut->aFlow;
00289 else
00290
00291 pCut->aFlow += pFaninCut->aFlow / pCut->ppLeaves[i]->aEstFanouts;
00292 }
00293
00294
00295 pCut->tArrival += pMan->pLutLib->pLutDelays[pCut->nLeaves][0];
00296 }
00297
00298
00310 float Fpga_CutGetAreaFlow( Fpga_Man_t * pMan, Fpga_Cut_t * pCut )
00311 {
00312 Fpga_Cut_t * pCutFanin;
00313 int i;
00314 pCut->aFlow = pMan->pLutLib->pLutAreas[pCut->nLeaves];
00315 for ( i = 0; i < pCut->nLeaves; i++ )
00316 {
00317
00318 pCutFanin = pCut->ppLeaves[i]->pCutBest;
00319 assert( pCutFanin );
00320 pCut->aFlow += pCutFanin->aFlow / pCut->ppLeaves[i]->nRefs;
00321 }
00322 return pCut->aFlow;
00323 }
00324
00336 float Fpga_CutGetAreaRefed( Fpga_Man_t * pMan, Fpga_Cut_t * pCut )
00337 {
00338 float aResult, aResult2;
00339 if ( pCut->nLeaves == 1 )
00340 return 0;
00341 aResult = Fpga_CutDeref( pMan, NULL, pCut, 0 );
00342 aResult2 = Fpga_CutRef( pMan, NULL, pCut, 0 );
00343 assert( Fpga_FloatEqual( pMan, aResult, aResult2 ) );
00344 return aResult;
00345 }
00346
00358 float Fpga_CutGetAreaDerefed( Fpga_Man_t * pMan, Fpga_Cut_t * pCut )
00359 {
00360 float aResult, aResult2;
00361 if ( pCut->nLeaves == 1 )
00362 return 0;
00363 aResult2 = Fpga_CutRef( pMan, NULL, pCut, 0 );
00364 aResult = Fpga_CutDeref( pMan, NULL, pCut, 0 );
00365 assert( Fpga_FloatEqual( pMan, aResult, aResult2 ) );
00366 return aResult;
00367 }
00368
00380 float Fpga_CutRef( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts )
00381 {
00382 Fpga_Node_t * pNodeChild;
00383 float aArea;
00384 int i;
00385
00386
00387
00388
00389
00390
00391 aArea = pMan->pLutLib->pLutAreas[pCut->nLeaves];
00392
00393 for ( i = 0; i < pCut->nLeaves; i++ )
00394 {
00395 pNodeChild = pCut->ppLeaves[i];
00396 assert( pNodeChild->nRefs >= 0 );
00397 if ( pNodeChild->nRefs++ > 0 )
00398 continue;
00399 if ( !Fpga_NodeIsAnd(pNodeChild) )
00400 continue;
00401 aArea += Fpga_CutRef( pMan, pNodeChild, pNodeChild->pCutBest, fFanouts );
00402 }
00403 return aArea;
00404 }
00405
00417 float Fpga_CutDeref( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts )
00418 {
00419 Fpga_Node_t * pNodeChild;
00420 float aArea;
00421 int i;
00422
00423
00424
00425
00426
00427
00428 aArea = pMan->pLutLib->pLutAreas[pCut->nLeaves];
00429
00430 for ( i = 0; i < pCut->nLeaves; i++ )
00431 {
00432 pNodeChild = pCut->ppLeaves[i];
00433 assert( pNodeChild->nRefs > 0 );
00434 if ( --pNodeChild->nRefs > 0 )
00435 continue;
00436 if ( !Fpga_NodeIsAnd(pNodeChild) )
00437 continue;
00438 aArea += Fpga_CutDeref( pMan, pNodeChild, pNodeChild->pCutBest, fFanouts );
00439 }
00440 return aArea;
00441 }
00442
00443
00455 void Fpga_MappingSetUsedCuts( Fpga_Man_t * pMan )
00456 {
00457 int i;
00458 for ( i = 0; i < pMan->vNodesAll->nSize; i++ )
00459 if ( pMan->vNodesAll->pArray[i]->pCutOld )
00460 {
00461 pMan->vNodesAll->pArray[i]->pCutBest = pMan->vNodesAll->pArray[i]->pCutOld;
00462 pMan->vNodesAll->pArray[i]->pCutOld = NULL;
00463 }
00464 }
00465
00469
00470