00001
00019 #ifndef __FPGA_INT_H__
00020 #define __FPGA_INT_H__
00021
00025
00026
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include "extra.h"
00031 #include "fpga.h"
00032
00036
00037
00038
00039
00043
00044 #ifdef _WIN32
00045 #define inline __inline // compatible with MS VS 6.0
00046 #endif
00047
00048
00049 #define FPGA_MAX_LEAVES 6
00050
00051
00052 #define FPGA_MASK(n) ((~((unsigned)0)) >> (32-(n)))
00053 #define FPGA_FULL (~((unsigned)0))
00054 #define FPGA_NO_VAR (-9999.0)
00055 #define FPGA_NUM_BYTES(n) (((n)/16 + (((n)%16) > 0))*16)
00056
00057
00058 #define FPGA_MIN(a,b) (((a) < (b))? (a) : (b))
00059 #define FPGA_MAX(a,b) (((a) > (b))? (a) : (b))
00060
00061
00062 #define FPGA_FLOAT_LARGE ((float)1.0e+20)
00063 #define FPGA_FLOAT_SMALL ((float)1.0e-20)
00064 #define FPGA_INT_LARGE (10000000)
00065
00066
00067 #define FPGA_SEQ_SIGN(p) (1 << (((unsigned)p)%31));
00068
00069
00070 #define Fpga_CutIsComplement(p) (((int)((unsigned long) (p) & 01)))
00071 #define Fpga_CutRegular(p) ((Fpga_Cut_t *)((unsigned long)(p) & ~01))
00072 #define Fpga_CutNot(p) ((Fpga_Cut_t *)((unsigned long)(p) ^ 01))
00073 #define Fpga_CutNotCond(p,c) ((Fpga_Cut_t *)((unsigned long)(p) ^ (c)))
00074
00075
00076 #define Fpga_SeqIsComplement( p ) (((int)((unsigned long) (p) & 01)))
00077 #define Fpga_SeqRegular( p ) ((Fpga_Node_t *)((unsigned long)(p) & ~015))
00078 #define Fpga_SeqIndex( p ) ((((unsigned long)(p)) >> 1) & 07)
00079 #define Fpga_SeqIndexCreate( p, Ind ) (((unsigned long)(p)) | (1 << (((unsigned)(Ind)) & 07)))
00080
00081
00082 #define Fpga_NodeReadRef(p) ((Fpga_Regular(p))->nRefs)
00083 #define Fpga_NodeRef(p) ((Fpga_Regular(p))->nRefs++)
00084
00085
00086 #define Fpga_NodeIsSimComplement(p) (Fpga_IsComplement(p)? !(Fpga_Regular(p)->fInv) : (p)->fInv)
00087
00088
00089 #define FPGA_RANDOM_UNSIGNED ((((unsigned)rand()) << 24) ^ (((unsigned)rand()) << 12) ^ ((unsigned)rand()))
00090
00091
00092 #define PRT(a,t) printf("%s = ", (a)); printf("%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC))
00093
00097
00098
00099 struct Fpga_ManStruct_t_
00100 {
00101
00102 Fpga_Node_t ** pBins;
00103 int nBins;
00104 Fpga_Node_t ** pInputs;
00105 int nInputs;
00106 Fpga_Node_t ** pOutputs;
00107 int nOutputs;
00108 int nNodes;
00109 int nLatches;
00110 Fpga_Node_t * pConst1;
00111 Fpga_NodeVec_t * vNodesAll;
00112 Fpga_NodeVec_t * vAnds;
00113 Fpga_NodeVec_t * vMapping;
00114
00115
00116 char * pFileName;
00117 char ** ppOutputNames;
00118 float * pInputArrivals;
00119
00120
00121 int nVarsMax;
00122 int fAreaRecovery;
00123 int fVerbose;
00124 int fSwitching;
00125 int fLatchPaths;
00126 int nTravIds;
00127 float DelayTarget;
00128
00129
00130 int nChoiceNodes;
00131 int nChoices;
00132
00133 int nCanons;
00134 int nMatches;
00135
00136
00137 Fpga_LutLib_t * pLutLib;
00138
00139
00140 Extra_MmFixed_t * mmNodes;
00141 Extra_MmFixed_t * mmCuts;
00142
00143
00144 int fResynthesis;
00145 float fRequiredGlo;
00146 float fRequiredShift;
00147 float fRequiredStart;
00148 float fRequiredGain;
00149 float fAreaGlo;
00150 float fAreaGain;
00151 float fEpsilon;
00152 float fDelayWindow;
00153 float DelayLimit;
00154 float AreaLimit;
00155 float TimeLimit;
00156
00157
00158 int timeToMap;
00159 int timeCuts;
00160 int timeTruth;
00161 int timeMatch;
00162 int timeRecover;
00163 int timeToNet;
00164 int timeTotal;
00165 int time1;
00166 int time2;
00167 };
00168
00169
00170 struct Fpga_LutLibStruct_t_
00171 {
00172 char * pName;
00173 int LutMax;
00174 int fVarPinDelays;
00175 float pLutAreas[FPGA_MAX_LUTSIZE+1];
00176 float pLutDelays[FPGA_MAX_LUTSIZE+1][FPGA_MAX_LUTSIZE+1];
00177 };
00178
00179
00180 struct Fpga_NodeStruct_t_
00181 {
00182
00183 Fpga_Node_t * pNext;
00184 Fpga_Node_t * pLevel;
00185 int Num;
00186 int NumA;
00187 short Num2;
00188 short nRefs;
00189 unsigned fMark0 : 1;
00190 unsigned fMark1 : 1;
00191 unsigned fInv : 1;
00192 unsigned Value : 2;
00193 unsigned fUsed : 1;
00194 unsigned fTemp : 1;
00195 unsigned Level :11;
00196 unsigned uData :14;
00197 int TravId;
00198
00199
00200 Fpga_Node_t * p1;
00201 Fpga_Node_t * p2;
00202 Fpga_Node_t * pNextE;
00203 Fpga_Node_t * pRepr;
00204
00205 #ifdef FPGA_ALLOCATE_FANOUT
00206
00207 Fpga_Node_t * pFanPivot;
00208 Fpga_Node_t * pFanFanin1;
00209 Fpga_Node_t * pFanFanin2;
00210
00211 #endif
00212
00213
00214 float tRequired;
00215 float aEstFanouts;
00216 float Switching;
00217 int LValue;
00218 short nLatches1;
00219 short nLatches2;
00220
00221
00222 Fpga_Cut_t * pCutBest;
00223 Fpga_Cut_t * pCutOld;
00224 Fpga_Cut_t * pCuts;
00225 Fpga_Cut_t * pCutsN;
00226
00227
00228 char * pData0;
00229 };
00230
00231
00232 struct Fpga_CutStruct_t_
00233 {
00234 Fpga_Cut_t * pOne;
00235 Fpga_Cut_t * pTwo;
00236 Fpga_Node_t * pRoot;
00237 Fpga_Node_t * ppLeaves[FPGA_MAX_LEAVES+1];
00238 float fLevel;
00239 unsigned uSign;
00240 char fMark;
00241 char Phase;
00242 char nLeaves;
00243 char nVolume;
00244 float tArrival;
00245 float aFlow;
00246 Fpga_Cut_t * pNext;
00247 };
00248
00249
00250 struct Fpga_NodeVecStruct_t_
00251 {
00252 Fpga_Node_t ** pArray;
00253 int nSize;
00254 int nCap;
00255 };
00256
00257
00258 #define Fpga_NodeReadNextFanout( pNode, pFanout ) \
00259 ( ( pFanout == NULL )? NULL : \
00260 ((Fpga_Regular((pFanout)->p1) == (pNode))? \
00261 (pFanout)->pFanFanin1 : (pFanout)->pFanFanin2) )
00262
00263
00264 #define Fpga_NodeReadNextFanoutPlace( pNode, pFanout ) \
00265 ( (Fpga_Regular((pFanout)->p1) == (pNode))? \
00266 &(pFanout)->pFanFanin1 : &(pFanout)->pFanFanin2 )
00267
00268
00269 #define Fpga_NodeForEachFanout( pNode, pFanout ) \
00270 for ( pFanout = (pNode)->pFanPivot; pFanout; \
00271 pFanout = Fpga_NodeReadNextFanout(pNode, pFanout) )
00272
00273
00274 #define Fpga_NodeForEachFanoutSafe( pNode, pFanout, pFanout2 ) \
00275 for ( pFanout = (pNode)->pFanPivot, \
00276 pFanout2 = Fpga_NodeReadNextFanout(pNode, pFanout); \
00277 pFanout; \
00278 pFanout = pFanout2, \
00279 pFanout2 = Fpga_NodeReadNextFanout(pNode, pFanout) )
00280
00281 static inline Fpga_FloatMoreThan( Fpga_Man_t * p, float Arg1, float Arg2 ) { return Arg1 > Arg2 + p->fEpsilon; }
00282 static inline Fpga_FloatLessThan( Fpga_Man_t * p, float Arg1, float Arg2 ) { return Arg1 < Arg2 - p->fEpsilon; }
00283 static inline Fpga_FloatEqual( Fpga_Man_t * p, float Arg1, float Arg2 ) { return Arg1 > Arg2 - p->fEpsilon && Arg1 < Arg2 + p->fEpsilon; }
00284
00288
00292
00293
00294 extern void Fpga_MappingCuts( Fpga_Man_t * p );
00295 extern void Fpga_MappingCreatePiCuts( Fpga_Man_t * p );
00296 extern int Fpga_CutCountAll( Fpga_Man_t * pMan );
00297
00298 extern Fpga_Cut_t * Fpga_CutAlloc( Fpga_Man_t * p );
00299 extern Fpga_Cut_t * Fpga_CutDup( Fpga_Man_t * p, Fpga_Cut_t * pCutOld );
00300 extern void Fpga_CutFree( Fpga_Man_t * p, Fpga_Cut_t * pCut );
00301 extern void Fpga_CutPrint( Fpga_Man_t * p, Fpga_Node_t * pRoot, Fpga_Cut_t * pCut );
00302 extern Fpga_Cut_t * Fpga_CutCreateSimple( Fpga_Man_t * p, Fpga_Node_t * pNode );
00303 extern float Fpga_CutGetRootArea( Fpga_Man_t * p, Fpga_Cut_t * pCut );
00304 extern Fpga_Cut_t * Fpga_CutListAppend( Fpga_Cut_t * pSetAll, Fpga_Cut_t * pSets );
00305 extern void Fpga_CutListRecycle( Fpga_Man_t * p, Fpga_Cut_t * pSetList, Fpga_Cut_t * pSave );
00306 extern int Fpga_CutListCount( Fpga_Cut_t * pSets );
00307 extern void Fpga_CutRemoveFanouts( Fpga_Man_t * p, Fpga_Node_t * pNode, Fpga_Cut_t * pCut );
00308 extern void Fpga_CutInsertFanouts( Fpga_Man_t * p, Fpga_Node_t * pNode, Fpga_Cut_t * pCut );
00309 extern float Fpga_CutGetAreaRefed( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00310 extern float Fpga_CutGetAreaDerefed( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00311 extern float Fpga_CutRef( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts );
00312 extern float Fpga_CutDeref( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts );
00313 extern float Fpga_CutGetAreaFlow( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00314 extern void Fpga_CutGetParameters( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00315
00316 extern void Fpga_NodeAddFaninFanout( Fpga_Node_t * pFanin, Fpga_Node_t * pFanout );
00317 extern void Fpga_NodeRemoveFaninFanout( Fpga_Node_t * pFanin, Fpga_Node_t * pFanoutToRemove );
00318 extern int Fpga_NodeGetFanoutNum( Fpga_Node_t * pNode );
00319
00320 extern Fpga_LutLib_t * Fpga_LutLibCreate( char * FileName, int fVerbose );
00321 extern void Fpga_LutLibFree( Fpga_LutLib_t * p );
00322 extern void Fpga_LutLibPrint( Fpga_LutLib_t * pLutLib );
00323 extern int Fpga_LutLibDelaysAreDiscrete( Fpga_LutLib_t * pLutLib );
00324
00325 extern int Fpga_MappingMatches( Fpga_Man_t * p, int fDelayOriented );
00326 extern int Fpga_MappingMatchesArea( Fpga_Man_t * p );
00327 extern int Fpga_MappingMatchesSwitch( Fpga_Man_t * p );
00328
00329 extern void Fpga_MappingShow( Fpga_Man_t * pMan, char * pFileName );
00330 extern void Fpga_MappingShowNodes( Fpga_Man_t * pMan, Fpga_Node_t ** ppRoots, int nRoots, char * pFileName );
00331
00332 extern float Fpga_CutGetSwitchDerefed( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut );
00333 extern float Fpga_CutRefSwitch( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts );
00334 extern float Fpga_CutDerefSwitch( Fpga_Man_t * pMan, Fpga_Node_t * pNode, Fpga_Cut_t * pCut, int fFanouts );
00335 extern float Fpga_MappingGetSwitching( Fpga_Man_t * pMan, Fpga_NodeVec_t * vMapping );
00336
00337 extern float Fpga_TimeCutComputeArrival( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00338 extern float Fpga_TimeCutComputeArrival_rec( Fpga_Man_t * pMan, Fpga_Cut_t * pCut );
00339 extern float Fpga_TimeComputeArrivalMax( Fpga_Man_t * p );
00340 extern void Fpga_TimeComputeRequiredGlobal( Fpga_Man_t * p, int fFirstTime );
00341 extern void Fpga_TimeComputeRequired( Fpga_Man_t * p, float fRequired );
00342 extern void Fpga_TimePropagateRequired( Fpga_Man_t * p, Fpga_NodeVec_t * vNodes );
00343 extern void Fpga_TimePropagateArrival( Fpga_Man_t * p );
00344
00345 extern Fpga_NodeVec_t * Fpga_NodeVecAlloc( int nCap );
00346 extern void Fpga_NodeVecFree( Fpga_NodeVec_t * p );
00347 extern Fpga_Node_t ** Fpga_NodeVecReadArray( Fpga_NodeVec_t * p );
00348 extern int Fpga_NodeVecReadSize( Fpga_NodeVec_t * p );
00349 extern void Fpga_NodeVecGrow( Fpga_NodeVec_t * p, int nCapMin );
00350 extern void Fpga_NodeVecShrink( Fpga_NodeVec_t * p, int nSizeNew );
00351 extern void Fpga_NodeVecClear( Fpga_NodeVec_t * p );
00352 extern void Fpga_NodeVecPush( Fpga_NodeVec_t * p, Fpga_Node_t * Entry );
00353 extern int Fpga_NodeVecPushUnique( Fpga_NodeVec_t * p, Fpga_Node_t * Entry );
00354 extern Fpga_Node_t * Fpga_NodeVecPop( Fpga_NodeVec_t * p );
00355 extern void Fpga_NodeVecWriteEntry( Fpga_NodeVec_t * p, int i, Fpga_Node_t * Entry );
00356 extern Fpga_Node_t * Fpga_NodeVecReadEntry( Fpga_NodeVec_t * p, int i );
00357 extern void Fpga_NodeVecSortByLevel( Fpga_NodeVec_t * p );
00358 extern void Fpga_SortNodesByArrivalTimes( Fpga_NodeVec_t * p );
00359 extern void Fpga_NodeVecUnion( Fpga_NodeVec_t * p, Fpga_NodeVec_t * p1, Fpga_NodeVec_t * p2 );
00360 extern void Fpga_NodeVecPushOrder( Fpga_NodeVec_t * vNodes, Fpga_Node_t * pNode, int fIncreasing );
00361 extern void Fpga_NodeVecReverse( Fpga_NodeVec_t * vNodes );
00362
00363
00364 extern Fpga_NodeVec_t * Fpga_MappingDfs( Fpga_Man_t * pMan, int fCollectEquiv );
00365 extern Fpga_NodeVec_t * Fpga_MappingDfsNodes( Fpga_Man_t * pMan, Fpga_Node_t ** ppNodes, int nNodes, int fEquiv );
00366 extern int Fpga_CountLevels( Fpga_Man_t * pMan );
00367 extern float Fpga_MappingGetAreaFlow( Fpga_Man_t * p );
00368 extern float Fpga_MappingArea( Fpga_Man_t * pMan );
00369 extern float Fpga_MappingAreaTrav( Fpga_Man_t * pMan );
00370 extern float Fpga_MappingSetRefsAndArea( Fpga_Man_t * pMan );
00371 extern void Fpga_MappingPrintOutputArrivals( Fpga_Man_t * p );
00372 extern void Fpga_MappingSetupTruthTables( unsigned uTruths[][2] );
00373 extern void Fpga_MappingSetupMask( unsigned uMask[], int nVarsMax );
00374 extern void Fpga_MappingSortByLevel( Fpga_Man_t * pMan, Fpga_NodeVec_t * vNodes, int fIncreasing );
00375 extern Fpga_NodeVec_t * Fpga_DfsLim( Fpga_Man_t * pMan, Fpga_Node_t * pNode, int nLevels );
00376 extern Fpga_NodeVec_t * Fpga_MappingLevelize( Fpga_Man_t * pMan, Fpga_NodeVec_t * vNodes );
00377 extern int Fpga_MappingMaxLevel( Fpga_Man_t * pMan );
00378 extern void Fpga_ManReportChoices( Fpga_Man_t * pMan );
00379 extern void Fpga_MappingSetChoiceLevels( Fpga_Man_t * pMan );
00380
00381
00382 extern unsigned int Cudd_Prime( unsigned int p );
00383
00384 #endif
00385