00001
00021 #ifndef __IF_H__
00022 #define __IF_H__
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00031
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <assert.h>
00036 #include <time.h>
00037 #include "vec.h"
00038 #include "mem.h"
00039
00043
00044
00045 #define IF_MAX_LUTSIZE 32
00046
00047 #define IF_MAX_FUNC_LUTSIZE 15
00048
00049 #define IF_INFINITY 100000000
00050
00051 #define IF_COST_MAX ((1<<14)-1)
00052
00053
00054 typedef enum {
00055 IF_NONE,
00056 IF_CONST1,
00057 IF_CI,
00058 IF_CO,
00059 IF_AND,
00060 IF_VOID
00061 } If_Type_t;
00062
00066
00067 typedef struct If_Man_t_ If_Man_t;
00068 typedef struct If_Par_t_ If_Par_t;
00069 typedef struct If_Lib_t_ If_Lib_t;
00070 typedef struct If_Obj_t_ If_Obj_t;
00071 typedef struct If_Cut_t_ If_Cut_t;
00072 typedef struct If_Set_t_ If_Set_t;
00073
00074
00075 struct If_Par_t_
00076 {
00077
00078 int nLutSize;
00079 int nCutsMax;
00080 int nFlowIters;
00081 int nAreaIters;
00082 float DelayTarget;
00083 int fPreprocess;
00084 int fArea;
00085 int fFancy;
00086 int fExpRed;
00087 int fLatchPaths;
00088 int fSeqMap;
00089 int fVerbose;
00090
00091 int fAreaOnly;
00092 int fTruth;
00093 int fUsePerm;
00094 int fUseBdds;
00095 int fUseSops;
00096 int fUseCnfs;
00097 int fUseMv;
00098 int nLatches;
00099 int fLiftLeaves;
00100 If_Lib_t * pLutLib;
00101 float * pTimesArr;
00102 float * pTimesReq;
00103 int (* pFuncCost) (If_Cut_t *);
00104 int (* pFuncUser) (If_Man_t *, If_Obj_t *, If_Cut_t *);
00105 void * pReoMan;
00106 };
00107
00108
00109 struct If_Lib_t_
00110 {
00111 char * pName;
00112 int LutMax;
00113 int fVarPinDelays;
00114 float pLutAreas[IF_MAX_LUTSIZE+1];
00115 float pLutDelays[IF_MAX_LUTSIZE+1][IF_MAX_LUTSIZE+1];
00116 };
00117
00118
00119 struct If_Man_t_
00120 {
00121
00122 If_Par_t * pPars;
00123
00124 If_Obj_t * pConst1;
00125 Vec_Ptr_t * vCis;
00126 Vec_Ptr_t * vCos;
00127 Vec_Ptr_t * vObjs;
00128 Vec_Ptr_t * vMapped;
00129 Vec_Ptr_t * vTemp;
00130 int nObjs[IF_VOID];
00131
00132 int nLevelMax;
00133 float fEpsilon;
00134 float RequiredGlo;
00135 float RequiredGlo2;
00136 float AreaGlo;
00137 int nNets;
00138 int nCutsUsed;
00139 int nCutsMerged;
00140 unsigned * puTemp[4];
00141 int SortMode;
00142 int fNextRound;
00143 int nChoices;
00144
00145 Vec_Ptr_t * vLatchOrder;
00146 Vec_Int_t * vLags;
00147 int nAttempts;
00148 int nMaxIters;
00149 int Period;
00150
00151 int nTruthWords;
00152 int nPermWords;
00153 int nObjBytes;
00154 int nCutBytes;
00155 int nSetBytes;
00156 Mem_Fixed_t * pMemObj;
00157 Mem_Fixed_t * pMemSet;
00158 If_Set_t * pMemCi;
00159 If_Set_t * pMemAnd;
00160 If_Set_t * pFreeList;
00161 };
00162
00163
00164 struct If_Cut_t_
00165 {
00166 float Delay;
00167 float Area;
00168 float AveRefs;
00169 unsigned uSign;
00170 unsigned Cost : 14;
00171 unsigned fCompl : 1;
00172 unsigned fUser : 1;
00173 unsigned nLimit : 8;
00174 unsigned nLeaves : 8;
00175 int * pLeaves;
00176 char * pPerm;
00177 unsigned * pTruth;
00178 };
00179
00180
00181 struct If_Set_t_
00182 {
00183 short nCutsMax;
00184 short nCuts;
00185 If_Set_t * pNext;
00186 If_Cut_t ** ppCuts;
00187 };
00188
00189
00190 struct If_Obj_t_
00191 {
00192 unsigned Type : 4;
00193 unsigned fCompl0 : 1;
00194 unsigned fCompl1 : 1;
00195 unsigned fPhase : 1;
00196 unsigned fRepr : 1;
00197 unsigned fMark : 1;
00198 unsigned fVisit : 1;
00199 unsigned Level : 22;
00200 int Id;
00201 int nRefs;
00202 int nVisits;
00203 int nVisitsCopy;
00204 If_Obj_t * pFanin0;
00205 If_Obj_t * pFanin1;
00206 If_Obj_t * pEquiv;
00207 float EstRefs;
00208 float Required;
00209 float LValue;
00210 void * pCopy;
00211 If_Set_t * pCutSet;
00212 If_Cut_t CutBest;
00213 };
00214
00215 static inline If_Obj_t * If_Regular( If_Obj_t * p ) { return (If_Obj_t *)((unsigned long)(p) & ~01); }
00216 static inline If_Obj_t * If_Not( If_Obj_t * p ) { return (If_Obj_t *)((unsigned long)(p) ^ 01); }
00217 static inline If_Obj_t * If_NotCond( If_Obj_t * p, int c ) { return (If_Obj_t *)((unsigned long)(p) ^ (c)); }
00218 static inline int If_IsComplement( If_Obj_t * p ) { return (int )(((unsigned long)p) & 01); }
00219
00220 static inline int If_ManCiNum( If_Man_t * p ) { return p->nObjs[IF_CI]; }
00221 static inline int If_ManCoNum( If_Man_t * p ) { return p->nObjs[IF_CO]; }
00222 static inline int If_ManAndNum( If_Man_t * p ) { return p->nObjs[IF_AND]; }
00223 static inline int If_ManObjNum( If_Man_t * p ) { return Vec_PtrSize(p->vObjs); }
00224
00225 static inline If_Obj_t * If_ManConst1( If_Man_t * p ) { return p->pConst1; }
00226 static inline If_Obj_t * If_ManCi( If_Man_t * p, int i ) { return (If_Obj_t *)Vec_PtrEntry( p->vCis, i ); }
00227 static inline If_Obj_t * If_ManCo( If_Man_t * p, int i ) { return (If_Obj_t *)Vec_PtrEntry( p->vCos, i ); }
00228 static inline If_Obj_t * If_ManLi( If_Man_t * p, int i ) { return (If_Obj_t *)Vec_PtrEntry( p->vCos, If_ManCoNum(p) - p->pPars->nLatches + i ); }
00229 static inline If_Obj_t * If_ManLo( If_Man_t * p, int i ) { return (If_Obj_t *)Vec_PtrEntry( p->vCis, If_ManCiNum(p) - p->pPars->nLatches + i ); }
00230 static inline If_Obj_t * If_ManObj( If_Man_t * p, int i ) { return (If_Obj_t *)Vec_PtrEntry( p->vObjs, i ); }
00231
00232 static inline int If_ObjIsConst1( If_Obj_t * pObj ) { return pObj->Type == IF_CONST1; }
00233 static inline int If_ObjIsCi( If_Obj_t * pObj ) { return pObj->Type == IF_CI; }
00234 static inline int If_ObjIsCo( If_Obj_t * pObj ) { return pObj->Type == IF_CO; }
00235 static inline int If_ObjIsPi( If_Obj_t * pObj ) { return If_ObjIsCi(pObj) && pObj->pFanin0 == NULL; }
00236 static inline int If_ObjIsLatch( If_Obj_t * pObj ) { return If_ObjIsCi(pObj) && pObj->pFanin0 != NULL; }
00237 static inline int If_ObjIsAnd( If_Obj_t * pObj ) { return pObj->Type == IF_AND; }
00238
00239 static inline If_Obj_t * If_ObjFanin0( If_Obj_t * pObj ) { return pObj->pFanin0; }
00240 static inline If_Obj_t * If_ObjFanin1( If_Obj_t * pObj ) { return pObj->pFanin1; }
00241 static inline int If_ObjFaninC0( If_Obj_t * pObj ) { return pObj->fCompl0; }
00242 static inline int If_ObjFaninC1( If_Obj_t * pObj ) { return pObj->fCompl1; }
00243 static inline void * If_ObjCopy( If_Obj_t * pObj ) { return pObj->pCopy; }
00244 static inline void If_ObjSetCopy( If_Obj_t * pObj, void * pCopy ) { pObj->pCopy = pCopy; }
00245 static inline void If_ObjSetChoice( If_Obj_t * pObj, If_Obj_t * pEqu ) { pObj->pEquiv = pEqu; }
00246
00247 static inline If_Cut_t * If_ObjCutBest( If_Obj_t * pObj ) { return &pObj->CutBest; }
00248 static inline unsigned If_ObjCutSign( unsigned ObjId ) { return (1 << (ObjId % 31)); }
00249
00250 static inline float If_ObjArrTime( If_Obj_t * pObj ) { return If_ObjCutBest(pObj)->Delay; }
00251 static inline void If_ObjSetArrTime( If_Obj_t * pObj, float ArrTime ) { If_ObjCutBest(pObj)->Delay = ArrTime; }
00252
00253 static inline float If_ObjLValue( If_Obj_t * pObj ) { return pObj->LValue; }
00254 static inline void If_ObjSetLValue( If_Obj_t * pObj, float LValue ) { pObj->LValue = LValue; }
00255
00256 static inline void * If_CutData( If_Cut_t * pCut ) { return *(void **)pCut; }
00257 static inline void If_CutSetData( If_Cut_t * pCut, void * pData ) { *(void **)pCut = pData; }
00258
00259 static inline int If_CutLeaveNum( If_Cut_t * pCut ) { return pCut->nLeaves; }
00260 static inline unsigned * If_CutTruth( If_Cut_t * pCut ) { return pCut->pTruth; }
00261 static inline int If_CutTruthWords( int nVarsMax ) { return nVarsMax <= 5 ? 1 : (1 << (nVarsMax - 5)); }
00262 static inline int If_CutPermWords( int nVarsMax ) { return nVarsMax / sizeof(int) + ((nVarsMax % sizeof(int)) > 0); }
00263
00264 static inline float If_CutLutArea( If_Man_t * p, If_Cut_t * pCut ) { return pCut->fUser? (float)pCut->Cost : (p->pPars->pLutLib? p->pPars->pLutLib->pLutAreas[pCut->nLeaves] : (float)1.0); }
00265
00269
00270 #define IF_MIN(a,b) (((a) < (b))? (a) : (b))
00271 #define IF_MAX(a,b) (((a) > (b))? (a) : (b))
00272
00273
00274 #define IF_FLOAT_LARGE ((float)1.0e+20)
00275 #define IF_FLOAT_SMALL ((float)1.0e-20)
00276 #define IF_INT_LARGE (10000000)
00277
00278
00279 #define If_ManForEachCi( p, pObj, i ) \
00280 Vec_PtrForEachEntry( p->vCis, pObj, i )
00281
00282 #define If_ManForEachCo( p, pObj, i ) \
00283 Vec_PtrForEachEntry( p->vCos, pObj, i )
00284
00285 #define If_ManForEachPi( p, pObj, i ) \
00286 Vec_PtrForEachEntryStop( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )
00287
00288 #define If_ManForEachPo( p, pObj, i ) \
00289 Vec_PtrForEachEntryStop( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )
00290
00291 #define If_ManForEachLatchInput( p, pObj, i ) \
00292 Vec_PtrForEachEntryStart( p->vCos, pObj, i, If_ManCoNum(p) - p->pPars->nLatches )
00293 #define If_ManForEachLatchOutput( p, pObj, i ) \
00294 Vec_PtrForEachEntryStart( p->vCis, pObj, i, If_ManCiNum(p) - p->pPars->nLatches )
00295
00296 #define If_ManForEachObj( p, pObj, i ) \
00297 Vec_PtrForEachEntry( p->vObjs, pObj, i )
00298
00299 #define If_ManForEachNode( p, pObj, i ) \
00300 If_ManForEachObj( p, pObj, i ) if ( pObj->Type != IF_AND ) {} else
00301
00302 #define If_ObjForEachCut( pObj, pCut, i ) \
00303 for ( i = 0; (i < (pObj)->pCutSet->nCuts) && ((pCut) = (pObj)->pCutSet->ppCuts[i]); i++ )
00304
00305 #define If_CutForEachLeaf( p, pCut, pLeaf, i ) \
00306 for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i++ )
00307 #define If_CutForEachLeafReverse( p, pCut, pLeaf, i ) \
00308 for ( i = (int)(pCut)->nLeaves - 1; (i >= 0) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i])); i-- )
00309
00310
00311
00312 #define If_CutForEachLeafSeq( p, pCut, pLeaf, Shift, i ) \
00313 for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = If_ManObj(p, (pCut)->pLeaves[i] >> 8)) && (((Shift) = ((pCut)->pLeaves[i] & 255)) >= 0); i++ )
00314
00318
00319
00320 extern int If_ManPerformMapping( If_Man_t * p );
00321 extern int If_ManPerformMappingComb( If_Man_t * p );
00322
00323 extern float If_CutAreaDerefed( If_Man_t * p, If_Cut_t * pCut, int nLevels );
00324 extern float If_CutAreaRefed( If_Man_t * p, If_Cut_t * pCut, int nLevels );
00325 extern float If_CutDeref( If_Man_t * p, If_Cut_t * pCut, int nLevels );
00326 extern float If_CutRef( If_Man_t * p, If_Cut_t * pCut, int nLevels );
00327 extern void If_CutPrint( If_Man_t * p, If_Cut_t * pCut );
00328 extern void If_CutPrintTiming( If_Man_t * p, If_Cut_t * pCut );
00329 extern float If_CutFlow( If_Man_t * p, If_Cut_t * pCut );
00330 extern float If_CutAverageRefs( If_Man_t * p, If_Cut_t * pCut );
00331 extern int If_CutFilter( If_Set_t * pCutSet, If_Cut_t * pCut );
00332 extern void If_CutSort( If_Man_t * p, If_Set_t * pCutSet, If_Cut_t * pCut );
00333 extern int If_CutMerge( If_Cut_t * pCut0, If_Cut_t * pCut1, If_Cut_t * pCut );
00334 extern void If_CutLift( If_Cut_t * pCut );
00335 extern void If_CutCopy( If_Man_t * p, If_Cut_t * pCutDest, If_Cut_t * pCutSrc );
00336 extern void If_ManSortCuts( If_Man_t * p, int Mode );
00337
00338 extern If_Man_t * If_ManStart( If_Par_t * pPars );
00339 extern void If_ManRestart( If_Man_t * p );
00340 extern void If_ManStop( If_Man_t * p );
00341 extern If_Obj_t * If_ManCreateCi( If_Man_t * p );
00342 extern If_Obj_t * If_ManCreateCo( If_Man_t * p, If_Obj_t * pDriver );
00343 extern If_Obj_t * If_ManCreateAnd( If_Man_t * p, If_Obj_t * pFan0, If_Obj_t * pFan1 );
00344 extern If_Obj_t * If_ManCreateXor( If_Man_t * p, If_Obj_t * pFan0, If_Obj_t * pFan1 );
00345 extern If_Obj_t * If_ManCreateMux( If_Man_t * p, If_Obj_t * pFan0, If_Obj_t * pFan1, If_Obj_t * pCtrl );
00346 extern void If_ManCreateChoice( If_Man_t * p, If_Obj_t * pRepr );
00347 extern void If_ManSetupCutTriv( If_Man_t * p, If_Cut_t * pCut, int ObjId );
00348 extern void If_ManSetupCiCutSets( If_Man_t * p );
00349 extern If_Set_t * If_ManSetupNodeCutSet( If_Man_t * p, If_Obj_t * pObj );
00350 extern void If_ManDerefNodeCutSet( If_Man_t * p, If_Obj_t * pObj );
00351 extern void If_ManDerefChoiceCutSet( If_Man_t * p, If_Obj_t * pObj );
00352 extern void If_ManSetupSetAll( If_Man_t * p, int nCrossCut );
00353
00354 extern void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess );
00355 extern void If_ObjPerformMappingChoice( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess );
00356 extern int If_ManPerformMappingRound( If_Man_t * p, int nCutsUsed, int Mode, int fPreprocess, char * pLabel );
00357
00358 extern void If_ManImproveMapping( If_Man_t * p );
00359
00360 extern int If_ManPerformMappingSeq( If_Man_t * p );
00361
00362 extern float If_CutDelay( If_Man_t * p, If_Cut_t * pCut );
00363 extern void If_CutPropagateRequired( If_Man_t * p, If_Cut_t * pCut, float Required );
00364
00365 extern void If_CutComputeTruth( If_Man_t * p, If_Cut_t * pCut, If_Cut_t * pCut0, If_Cut_t * pCut1, int fCompl0, int fCompl1 );
00366
00367 extern void If_ManCleanNodeCopy( If_Man_t * p );
00368 extern void If_ManCleanCutData( If_Man_t * p );
00369 extern void If_ManCleanMarkV( If_Man_t * p );
00370 extern float If_ManDelayMax( If_Man_t * p, int fSeq );
00371 extern void If_ManComputeRequired( If_Man_t * p );
00372 extern float If_ManScanMapping( If_Man_t * p );
00373 extern float If_ManScanMappingSeq( If_Man_t * p );
00374 extern void If_ManResetOriginalRefs( If_Man_t * p );
00375 extern int If_ManCrossCut( If_Man_t * p );
00376
00377 #ifdef __cplusplus
00378 }
00379 #endif
00380
00381 #endif
00382
00386