00001
00019 #ifndef __MAPPER_INT_H__
00020 #define __MAPPER_INT_H__
00021
00025
00026
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <float.h>
00031 #include "cuddInt.h"
00032 #include "main.h"
00033 #include "mio.h"
00034 #include "mapper.h"
00035
00039
00040
00041
00042
00046
00047
00048 #define MAP_MASK(n) ((~((unsigned)0)) >> (32-(n)))
00049 #define MAP_FULL (~((unsigned)0))
00050 #define MAP_NO_VAR (-9999.0)
00051
00052
00053 #define MAP_MIN(a,b) (((a) < (b))? (a) : (b))
00054 #define MAP_MAX(a,b) (((a) > (b))? (a) : (b))
00055
00056
00057 #define MAP_FLOAT_LARGE ((float)(FLT_MAX/10))
00058 #define MAP_FLOAT_SMALL ((float)1.0e-03)
00059
00060
00061 #define MAP_RANDOM_UNSIGNED ((((unsigned)rand()) << 24) ^ (((unsigned)rand()) << 12) ^ ((unsigned)rand()))
00062
00063
00064 #define Map_CutIsComplement(p) (((int)((unsigned long) (p) & 01)))
00065 #define Map_CutRegular(p) ((Map_Cut_t *)((unsigned long)(p) & ~01))
00066 #define Map_CutNot(p) ((Map_Cut_t *)((unsigned long)(p) ^ 01))
00067 #define Map_CutNotCond(p,c) ((Map_Cut_t *)((unsigned long)(p) ^ (c)))
00068
00069
00070 #define Map_NodeReadRef(p) ((Map_Regular(p))->nRefs)
00071 #define Map_NodeRef(p) ((Map_Regular(p))->nRefs++)
00072
00073
00074 #define Map_InfoSetVar(p,i) (p[(i)>>5] |= (1<<((i) & 31)))
00075 #define Map_InfoRemVar(p,i) (p[(i)>>5] &= ~(1<<((i) & 31)))
00076 #define Map_InfoFlipVar(p,i) (p[(i)>>5] ^= (1<<((i) & 31)))
00077 #define Map_InfoReadVar(p,i) ((p[(i)>>5] & (1<<((i) & 31))) > 0)
00078
00079
00080 #define Map_NodeIsSimComplement(p) (Map_IsComplement(p)? !(Map_Regular(p)->fInv) : (p)->fInv)
00081
00085
00086
00087 struct Map_ManStruct_t_
00088 {
00089
00090 Map_Node_t ** pBins;
00091 int nBins;
00092 Map_Node_t ** pInputs;
00093 int nInputs;
00094 Map_Node_t ** pOutputs;
00095 int nOutputs;
00096 int nNodes;
00097 Map_Node_t * pConst1;
00098 Map_NodeVec_t * vAnds;
00099 Map_NodeVec_t * vNodesAll;
00100 Map_NodeVec_t * vNodesTemp;
00101 Map_NodeVec_t * vMapping;
00102
00103
00104 char ** ppOutputNames;
00105 Map_Time_t * pInputArrivals;
00106
00107
00108 int nVarsMax;
00109 int fAreaRecovery;
00110 int fVerbose;
00111 int fMappingMode;
00112 float fRequiredGlo;
00113 float fEpsilon;
00114 float AreaBase;
00115 float AreaFinal;
00116 int nIterations;
00117 bool fObeyFanoutLimits;
00118 float DelayTarget;
00119 int nTravIds;
00120 bool fSwitching;
00121
00122
00123 Map_SuperLib_t * pSuperLib;
00124 unsigned uTruths[6][2];
00125 unsigned uTruthsLarge[10][32];
00126 int nCounts[32];
00127 int nCountsBest[32];
00128 Map_NodeVec_t * vVisited;
00129
00130
00131 Extra_MmFixed_t * mmNodes;
00132 Extra_MmFixed_t * mmCuts;
00133
00134
00135 unsigned short * uCanons;
00136 char ** uPhases;
00137 char * pCounters;
00138
00139
00140 int nChoiceNodes;
00141 int nChoices;
00142 int nCanons;
00143 int nMatches;
00144 int nPhases;
00145 int nFanoutViolations;
00146
00147
00148 int timeToMap;
00149 int timeCuts;
00150 int timeTruth;
00151 int timeMatch;
00152 int timeArea;
00153 int timeSweep;
00154 int timeToNet;
00155 int timeTotal;
00156 int time1;
00157 int time2;
00158 int time3;
00159 };
00160
00161
00162 struct Map_SuperLibStruct_t_
00163 {
00164
00165 char * pName;
00166 Mio_Library_t * pGenlib;
00167
00168
00169 int nVarsMax;
00170 int nSupersAll;
00171 int nSupersReal;
00172 int nLines;
00173 bool fVerbose;
00174
00175
00176 Map_Super_t ** ppSupers;
00177 Map_HashTable_t * tTableC;
00178 Map_HashTable_t * tTable;
00179
00180
00181 unsigned uTruths[6][2];
00182 unsigned uMask[2];
00183
00184
00185 Mio_Gate_t * pGateInv;
00186 Map_Time_t tDelayInv;
00187 float AreaInv;
00188 float AreaBuf;
00189 Map_Super_t * pSuperInv;
00190
00191
00192 Extra_MmFixed_t * mmSupers;
00193 Extra_MmFixed_t * mmEntries;
00194 Extra_MmFlex_t * mmForms;
00195 };
00196
00197
00198 struct Map_NodeStruct_t_
00199 {
00200
00201 Map_Man_t * p;
00202 Map_Node_t * pNext;
00203 int Num;
00204 int TravId;
00205 int nRefs;
00206 unsigned fMark0 : 1;
00207 unsigned fMark1 : 1;
00208 unsigned fUsed : 1;
00209 unsigned fInv : 1;
00210 unsigned fInvert: 1;
00211 unsigned Level :16;
00212 unsigned NumTemp:10;
00213 int nRefAct[3];
00214 float nRefEst[3];
00215 float Switching;
00216
00217
00218 Map_Node_t * p1;
00219 Map_Node_t * p2;
00220 Map_Node_t * pNextE;
00221 Map_Node_t * pRepr;
00222
00223 #ifdef MAP_ALLOCATE_FANOUT
00224
00225 Map_Node_t * pFanPivot;
00226 Map_Node_t * pFanFanin1;
00227 Map_Node_t * pFanFanin2;
00228
00229 #endif
00230
00231
00232 Map_Time_t tArrival[2];
00233 Map_Time_t tRequired[2];
00234
00235
00236 Map_Cut_t * pCutBest[2];
00237 Map_Cut_t * pCuts;
00238 char * pData0;
00239 char * pData1;
00240 };
00241
00242
00243 struct Map_MatchStruct_t_
00244 {
00245
00246 Map_Super_t * pSupers;
00247 unsigned uPhase;
00248
00249 unsigned uPhaseBest;
00250 Map_Super_t * pSuperBest;
00251
00252 Map_Time_t tArrive;
00253 float AreaFlow;
00254 };
00255
00256
00257 struct Map_CutStruct_t_
00258 {
00259 Map_Cut_t * pNext;
00260 Map_Cut_t * pOne;
00261 Map_Cut_t * pTwo;
00262 Map_Node_t * ppLeaves[6];
00263 unsigned uTruth;
00264 char nLeaves;
00265 char nVolume;
00266 char fMark;
00267 char Phase;
00268 Map_Match_t M[2];
00269 };
00270
00271
00272 struct Map_SuperStruct_t_
00273 {
00274 int Num;
00275 unsigned fSuper : 1;
00276 unsigned fExclude: 1;
00277 unsigned nFanins : 3;
00278 unsigned nGates : 3;
00279 unsigned nFanLimit: 4;
00280 unsigned nSupers : 16;
00281 unsigned nPhases : 4;
00282 unsigned char uPhases[4];
00283 int nUsed;
00284 Map_Super_t * pFanins[6];
00285 Mio_Gate_t * pRoot;
00286 unsigned uTruth[2];
00287 Map_Time_t tDelaysR[6];
00288 Map_Time_t tDelaysF[6];
00289 Map_Time_t tDelayMax;
00290 float Area;
00291 char * pFormula;
00292 Map_Super_t * pNext;
00293 };
00294
00295
00296 struct Map_NodeVecStruct_t_
00297 {
00298 Map_Node_t ** pArray;
00299 int nSize;
00300 int nCap;
00301 };
00302
00303
00304 struct Map_HashTableStruct_t_
00305 {
00306 Map_HashEntry_t ** pBins;
00307 int nBins;
00308 int nEntries;
00309 Extra_MmFixed_t * mmMan;
00310 };
00311
00312
00313 struct Map_HashEntryStruct_t_
00314 {
00315 unsigned uTruth[2];
00316 unsigned uPhase;
00317 Map_Super_t * pGates;
00318 Map_HashEntry_t * pNext;
00319 };
00320
00321
00322 #define Map_NodeReadNextFanout( pNode, pFanout ) \
00323 ( ( pFanout == NULL )? NULL : \
00324 ((Map_Regular((pFanout)->p1) == (pNode))? \
00325 (pFanout)->pFanFanin1 : (pFanout)->pFanFanin2) )
00326
00327
00328 #define Map_NodeReadNextFanoutPlace( pNode, pFanout ) \
00329 ( (Map_Regular((pFanout)->p1) == (pNode))? \
00330 &(pFanout)->pFanFanin1 : &(pFanout)->pFanFanin2 )
00331
00332
00333 #define Map_NodeForEachFanout( pNode, pFanout ) \
00334 for ( pFanout = (pNode)->pFanPivot; pFanout; \
00335 pFanout = Map_NodeReadNextFanout(pNode, pFanout) )
00336
00337
00338 #define Map_NodeForEachFanoutSafe( pNode, pFanout, pFanout2 ) \
00339 for ( pFanout = (pNode)->pFanPivot, \
00340 pFanout2 = Map_NodeReadNextFanout(pNode, pFanout); \
00341 pFanout; \
00342 pFanout = pFanout2, \
00343 pFanout2 = Map_NodeReadNextFanout(pNode, pFanout) )
00344
00348
00352
00353
00354
00355 extern void Map_MappingCuts( Map_Man_t * p );
00356 extern int Map_MappingCountAllCuts( Map_Man_t * p );
00357
00358 extern void Map_ComputeDcs( Map_Man_t * p );
00359 extern unsigned Map_ComputeIsop_rec( Map_Man_t * p, unsigned uF, unsigned uFD, int iVar, int nVars, int fDir );
00360
00361 extern Map_Cut_t * Map_CutAlloc( Map_Man_t * p );
00362 extern void Map_CutFree( Map_Man_t * p, Map_Cut_t * pCut );
00363 extern void Map_CutPrint( Map_Man_t * p, Map_Node_t * pRoot, Map_Cut_t * pCut, int fPhase );
00364 extern float Map_CutGetRootArea( Map_Cut_t * pCut, int fPhase );
00365 extern int Map_CutGetLeafPhase( Map_Cut_t * pCut, int fPhase, int iLeaf );
00366 extern int Map_NodeGetLeafPhase( Map_Node_t * pNode, int fPhase, int iLeaf );
00367 extern Map_Cut_t * Map_CutListAppend( Map_Cut_t * pSetAll, Map_Cut_t * pSets );
00368 extern void Map_CutListRecycle( Map_Man_t * p, Map_Cut_t * pSetList, Map_Cut_t * pSave );
00369 extern int Map_CutListCount( Map_Cut_t * pSets );
00370 extern void Map_CutRemoveFanouts( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00371 extern void Map_CutInsertFanouts( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00372
00373 extern void Map_NodeAddFaninFanout( Map_Node_t * pFanin, Map_Node_t * pFanout );
00374 extern void Map_NodeRemoveFaninFanout( Map_Node_t * pFanin, Map_Node_t * pFanoutToRemove );
00375 extern int Map_NodeGetFanoutNum( Map_Node_t * pNode );
00376
00377 extern Map_SuperLib_t * Map_SuperLibCreate( char * pFileName, char * pExcludeFile, bool fAlgorithm, bool fVerbose );
00378 extern void Map_SuperLibFree( Map_SuperLib_t * p );
00379
00380 extern int Map_MappingMatches( Map_Man_t * p );
00381 extern float Map_MappingCombinePhases( Map_Man_t * p );
00382 extern void Map_MatchClean( Map_Match_t * pMatch );
00383 extern int Map_MatchCompare( Map_Man_t * pMan, Map_Match_t * pM1, Map_Match_t * pM2, int fDoingArea );
00384
00385 extern float Map_SwitchCutGetDerefed( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00386 extern float Map_SwitchCutRef( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00387 extern float Map_SwitchCutDeref( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00388 extern float Map_MappingGetSwitching( Map_Man_t * pMan, Map_NodeVec_t * vMapping );
00389
00390 extern int Map_NodeReadRefPhaseAct( Map_Node_t * pNode, int fPhase );
00391 extern float Map_NodeReadRefPhaseEst( Map_Node_t * pNode, int fPhase );
00392 extern void Map_MappingEstimateRefsInit( Map_Man_t * p );
00393 extern void Map_MappingEstimateRefs( Map_Man_t * p );
00394 extern float Map_CutGetAreaFlow( Map_Cut_t * pCut, int fPhase );
00395 extern float Map_CutGetAreaRefed( Map_Cut_t * pCut, int fPhase );
00396 extern float Map_CutGetAreaDerefed( Map_Cut_t * pCut, int fPhase );
00397 extern float Map_CutRef( Map_Cut_t * pCut, int fPhase );
00398 extern float Map_CutDeref( Map_Cut_t * pCut, int fPhase );
00399 extern void Map_MappingSetRefs( Map_Man_t * pMan );
00400 extern float Map_MappingGetArea( Map_Man_t * pMan, Map_NodeVec_t * vMapping );
00401
00402 extern void Map_MappingShow( Map_Man_t * pMan, char * pFileName );
00403
00404 extern int Map_LibraryReadTree( Map_SuperLib_t * pLib, char * pFileName, char * pExcludeFile );
00405 extern void Map_LibraryPrintTree( Map_SuperLib_t * pLib );
00406
00407 extern int Map_LibraryRead( Map_SuperLib_t * p, char * pFileName );
00408 extern void Map_LibraryPrintSupergate( Map_Super_t * pGate );
00409
00410 extern Map_HashTable_t * Map_SuperTableCreate( Map_SuperLib_t * pLib );
00411 extern void Map_SuperTableFree( Map_HashTable_t * p );
00412 extern int Map_SuperTableInsertC( Map_HashTable_t * pLib, unsigned uTruthC[], Map_Super_t * pGate );
00413 extern int Map_SuperTableInsert( Map_HashTable_t * pLib, unsigned uTruth[], Map_Super_t * pGate, unsigned uPhase );
00414 extern Map_Super_t * Map_SuperTableLookup( Map_HashTable_t * p, unsigned uTruth[], unsigned * puPhase );
00415 extern void Map_SuperTableSortSupergates( Map_HashTable_t * p, int nSupersMax );
00416 extern void Map_SuperTableSortSupergatesByDelay( Map_HashTable_t * p, int nSupersMax );
00417
00418 extern float Map_TimeCutComputeArrival( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase, float tWorstCaseLimit );
00419 extern void Map_TimeCutComputeArrival_rec( Map_Cut_t * pCut, int fPhase );
00420 extern float Map_TimeComputeArrivalMax( Map_Man_t * p );
00421 extern void Map_TimeComputeRequiredGlobal( Map_Man_t * p );
00422 extern void Map_TimeComputeRequired( Map_Man_t * p, float fRequired );
00423 extern float Map_TimeNodeFanoutDelay( Map_Node_t * pNode, int fPhase );
00424 extern float Map_TimeCutFanoutDelay( Map_Node_t * pNode, Map_Cut_t * pCut, int fPhase );
00425 extern float Map_TimeMatchWithInverter( Map_Man_t * p, Map_Match_t * pMatch );
00426
00427 extern void Map_MappingTruths( Map_Man_t * pMan );
00428 extern int Map_TruthsCutDontCare( Map_Man_t * pMan, Map_Cut_t * pCut, unsigned * uTruthDc );
00429 extern int Map_TruthCountOnes( unsigned * uTruth, int nLeaves );
00430 extern int Map_TruthDetectTwoFirst( unsigned * uTruth, int nLeaves );
00431
00432 extern Map_NodeVec_t * Map_MappingDfs( Map_Man_t * pMan, int fCollectEquiv );
00433 extern Map_NodeVec_t * Map_MappingDfsNodes( Map_Man_t * pMan, Map_Node_t ** ppNodes, int nNodes, int fEquiv );
00434
00435 extern void Map_MappingDfsMarked1_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, int fFirst );
00436 extern void Map_MappingDfsMarked2_rec( Map_Node_t * pNode, Map_NodeVec_t * vNodes, Map_NodeVec_t * vBoundary, int fFirst );
00437
00438 extern int Map_MappingCountLevels( Map_Man_t * pMan );
00439 extern void Map_MappingUnmark( Map_Man_t * pMan );
00440 extern void Map_MappingMark_rec( Map_Node_t * pNode );
00441 extern void Map_MappingUnmark_rec( Map_Node_t * pNode );
00442 extern void Map_MappingPrintOutputArrivals( Map_Man_t * p );
00443 extern void Map_MappingSetupMask( unsigned uMask[], int nVarsMax );
00444 extern int Map_MappingNodeIsViolator( Map_Node_t * pNode, Map_Cut_t * pCut, int fPosPol );
00445 extern float Map_MappingGetAreaFlow( Map_Man_t * p );
00446 extern void Map_MappingSortByLevel( Map_Man_t * pMan, Map_NodeVec_t * vNodes );
00447 extern int Map_MappingCountDoubles( Map_Man_t * pMan, Map_NodeVec_t * vNodes );
00448 extern void Map_MappingExpandTruth( unsigned uTruth[2], int nVars );
00449 extern float Map_MappingPrintSwitching( Map_Man_t * pMan );
00450 extern void Map_MappingSetPlacementInfo( Map_Man_t * p );
00451 extern float Map_MappingPrintWirelength( Map_Man_t * p );
00452 extern void Map_MappingWireReport( Map_Man_t * p );
00453 extern float Map_MappingComputeDelayWithFanouts( Map_Man_t * p );
00454 extern int Map_MappingGetMaxLevel( Map_Man_t * pMan );
00455 extern void Map_MappingSetChoiceLevels( Map_Man_t * pMan );
00456 extern void Map_MappingReportChoices( Map_Man_t * pMan );
00457
00458 extern Map_NodeVec_t * Map_NodeVecAlloc( int nCap );
00459 extern void Map_NodeVecFree( Map_NodeVec_t * p );
00460 extern Map_Node_t ** Map_NodeVecReadArray( Map_NodeVec_t * p );
00461 extern int Map_NodeVecReadSize( Map_NodeVec_t * p );
00462 extern void Map_NodeVecGrow( Map_NodeVec_t * p, int nCapMin );
00463 extern void Map_NodeVecShrink( Map_NodeVec_t * p, int nSizeNew );
00464 extern void Map_NodeVecClear( Map_NodeVec_t * p );
00465 extern void Map_NodeVecPush( Map_NodeVec_t * p, Map_Node_t * Entry );
00466 extern int Map_NodeVecPushUnique( Map_NodeVec_t * p, Map_Node_t * Entry );
00467 extern Map_Node_t * Map_NodeVecPop( Map_NodeVec_t * p );
00468 extern void Map_NodeVecRemove( Map_NodeVec_t * p, Map_Node_t * Entry );
00469 extern void Map_NodeVecWriteEntry( Map_NodeVec_t * p, int i, Map_Node_t * Entry );
00470 extern Map_Node_t * Map_NodeVecReadEntry( Map_NodeVec_t * p, int i );
00471 extern void Map_NodeVecSortByLevel( Map_NodeVec_t * p );
00472
00473 #endif
00474