00001
00021 #include "fra.h"
00022
00026
00027
00028 struct Fra_Bmc_t_
00029 {
00030
00031 int nPref;
00032 int nDepth;
00033 int nFramesAll;
00034
00035 Vec_Int_t * vImps;
00036
00037 Aig_Man_t * pAig;
00038 Aig_Man_t * pAigFrames;
00039 Aig_Man_t * pAigFraig;
00040
00041 Aig_Obj_t ** pObjToFrames;
00042 Aig_Obj_t ** pObjToFraig;
00043 };
00044
00045 static inline Aig_Obj_t * Bmc_ObjFrames( Aig_Obj_t * pObj, int i ) { return ((Fra_Man_t *)pObj->pData)->pBmc->pObjToFrames[((Fra_Man_t *)pObj->pData)->pBmc->nFramesAll*pObj->Id + i]; }
00046 static inline void Bmc_ObjSetFrames( Aig_Obj_t * pObj, int i, Aig_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pBmc->pObjToFrames[((Fra_Man_t *)pObj->pData)->pBmc->nFramesAll*pObj->Id + i] = pNode; }
00047
00048 static inline Aig_Obj_t * Bmc_ObjFraig( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pBmc->pObjToFraig[pObj->Id]; }
00049 static inline void Bmc_ObjSetFraig( Aig_Obj_t * pObj, Aig_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pBmc->pObjToFraig[pObj->Id] = pNode; }
00050
00051 static inline Aig_Obj_t * Bmc_ObjChild0Frames( Aig_Obj_t * pObj, int i ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin0(pObj)? Aig_NotCond(Bmc_ObjFrames(Aig_ObjFanin0(pObj),i), Aig_ObjFaninC0(pObj)) : NULL; }
00052 static inline Aig_Obj_t * Bmc_ObjChild1Frames( Aig_Obj_t * pObj, int i ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? Aig_NotCond(Bmc_ObjFrames(Aig_ObjFanin1(pObj),i), Aig_ObjFaninC1(pObj)) : NULL; }
00053
00057
00069 int Fra_BmcNodesAreEqual( Aig_Obj_t * pObj0, Aig_Obj_t * pObj1 )
00070 {
00071 Fra_Man_t * p = pObj0->pData;
00072 Aig_Obj_t * pObjFrames0, * pObjFrames1;
00073 Aig_Obj_t * pObjFraig0, * pObjFraig1;
00074 int i;
00075 for ( i = p->pBmc->nPref; i < p->pBmc->nFramesAll; i++ )
00076 {
00077 pObjFrames0 = Aig_Regular( Bmc_ObjFrames(pObj0, i) );
00078 pObjFrames1 = Aig_Regular( Bmc_ObjFrames(pObj1, i) );
00079 if ( pObjFrames0 == pObjFrames1 )
00080 continue;
00081 pObjFraig0 = Aig_Regular( Bmc_ObjFraig(pObjFrames0) );
00082 pObjFraig1 = Aig_Regular( Bmc_ObjFraig(pObjFrames1) );
00083 if ( pObjFraig0 != pObjFraig1 )
00084 return 0;
00085 }
00086 return 1;
00087 }
00088
00100 int Fra_BmcNodeIsConst( Aig_Obj_t * pObj )
00101 {
00102 Fra_Man_t * p = pObj->pData;
00103 return Fra_BmcNodesAreEqual( pObj, Aig_ManConst1(p->pManAig) );
00104 }
00105
00118 void Fra_BmcFilterImplications( Fra_Man_t * p, Fra_Bmc_t * pBmc )
00119 {
00120 Aig_Obj_t * pLeft, * pRight;
00121 Aig_Obj_t * pLeftT, * pRightT;
00122 Aig_Obj_t * pLeftF, * pRightF;
00123 int i, f, Imp, Left, Right;
00124 int fComplL, fComplR;
00125 assert( p->nFramesAll == 1 );
00126 assert( p->pManAig == pBmc->pAigFrames );
00127 Vec_IntForEachEntry( pBmc->vImps, Imp, i )
00128 {
00129 if ( Imp == 0 )
00130 continue;
00131 Left = Fra_ImpLeft(Imp);
00132 Right = Fra_ImpRight(Imp);
00133
00134 pLeft = Aig_ManObj( pBmc->pAig, Left );
00135 pRight = Aig_ManObj( pBmc->pAig, Right );
00136
00137 for ( f = pBmc->nPref; f < pBmc->nFramesAll; f++ )
00138 {
00139
00140 pLeftT = Bmc_ObjFrames( pLeft, f );
00141 pRightT = Bmc_ObjFrames( pRight, f );
00142
00143 pLeftF = Fra_ObjFraig( Aig_Regular(pLeftT), 0 );
00144 pRightF = Fra_ObjFraig( Aig_Regular(pRightT), 0 );
00145
00146 fComplL = pLeft->fPhase ^ Aig_IsComplement(pLeftF) ^ Aig_IsComplement(pLeftT);
00147 fComplR = pRight->fPhase ^ Aig_IsComplement(pRightF) ^ Aig_IsComplement(pRightT);
00148
00149 if ( Aig_Regular(pLeftF) == Aig_Regular(pRightF) )
00150 {
00151 if ( fComplL == fComplR )
00152 continue;
00153 assert( fComplL != fComplR );
00154
00155
00156
00157
00158
00159 if ( Aig_ObjIsConst1(Aig_Regular(pLeftF)) && fComplL )
00160 continue;
00161
00162 Vec_IntWriteEntry( pBmc->vImps, i, 0 );
00163 break;
00164 }
00165
00166 if ( Fra_NodesAreImp( p, Aig_Regular(pLeftF), Aig_Regular(pRightF), fComplL, fComplR ) != 1 )
00167 {
00168 Vec_IntWriteEntry( pBmc->vImps, i, 0 );
00169 break;
00170 }
00171 }
00172 }
00173 Fra_ImpCompactArray( pBmc->vImps );
00174 }
00175
00176
00188 Fra_Bmc_t * Fra_BmcStart( Aig_Man_t * pAig, int nPref, int nDepth )
00189 {
00190 Fra_Bmc_t * p;
00191 p = ALLOC( Fra_Bmc_t, 1 );
00192 memset( p, 0, sizeof(Fra_Bmc_t) );
00193 p->pAig = pAig;
00194 p->nPref = nPref;
00195 p->nDepth = nDepth;
00196 p->nFramesAll = nPref + nDepth;
00197 p->pObjToFrames = ALLOC( Aig_Obj_t *, p->nFramesAll * Aig_ManObjNumMax(pAig) );
00198 memset( p->pObjToFrames, 0, sizeof(Aig_Obj_t *) * p->nFramesAll * Aig_ManObjNumMax(pAig) );
00199 return p;
00200 }
00201
00213 void Fra_BmcStop( Fra_Bmc_t * p )
00214 {
00215 Aig_ManStop( p->pAigFrames );
00216 Aig_ManStop( p->pAigFraig );
00217 free( p->pObjToFrames );
00218 free( p->pObjToFraig );
00219 free( p );
00220 }
00221
00233 Aig_Man_t * Fra_BmcFrames( Fra_Bmc_t * p )
00234 {
00235 Aig_Man_t * pAigFrames;
00236 Aig_Obj_t * pObj, * pObjNew;
00237 Aig_Obj_t ** pLatches;
00238 int i, k, f;
00239
00240
00241 pAigFrames = Aig_ManStart( Aig_ManObjNumMax(p->pAig) * p->nFramesAll );
00242 pAigFrames->pName = Aig_UtilStrsav( p->pAig->pName );
00243
00244 for ( f = 0; f < p->nFramesAll; f++ )
00245 Bmc_ObjSetFrames( Aig_ManConst1(p->pAig), f, Aig_ManConst1(pAigFrames) );
00246 for ( f = 0; f < p->nFramesAll; f++ )
00247 Aig_ManForEachPiSeq( p->pAig, pObj, i )
00248 Bmc_ObjSetFrames( pObj, f, Aig_ObjCreatePi(pAigFrames) );
00249
00250 Aig_ManForEachLoSeq( p->pAig, pObj, i )
00251 Bmc_ObjSetFrames( pObj, 0, Aig_ManConst0(pAigFrames) );
00252
00253
00254 pLatches = ALLOC( Aig_Obj_t *, Aig_ManRegNum(p->pAig) );
00255 for ( f = 0; f < p->nFramesAll; f++ )
00256 {
00257
00258 Aig_ManForEachNode( p->pAig, pObj, i )
00259 {
00260 pObjNew = Aig_And( pAigFrames, Bmc_ObjChild0Frames(pObj,f), Bmc_ObjChild1Frames(pObj,f) );
00261 Bmc_ObjSetFrames( pObj, f, pObjNew );
00262 }
00263 if ( f == p->nFramesAll - 1 )
00264 break;
00265
00266 k = 0;
00267 Aig_ManForEachLiSeq( p->pAig, pObj, i )
00268 pLatches[k++] = Bmc_ObjChild0Frames(pObj,f);
00269 assert( k == Aig_ManRegNum(p->pAig) );
00270
00271 k = 0;
00272 Aig_ManForEachLoSeq( p->pAig, pObj, i )
00273 Bmc_ObjSetFrames( pObj, f+1, pLatches[k++] );
00274 assert( k == Aig_ManRegNum(p->pAig) );
00275 }
00276 free( pLatches );
00277
00278 Aig_ManForEachObj( pAigFrames, pObjNew, i )
00279 if ( Aig_ObjIsNode(pObjNew) && pObjNew->nRefs == 0 )
00280 Aig_ObjCreatePo( pAigFrames, pObjNew );
00281
00282
00283 return pAigFrames;
00284 }
00285
00297 void Fra_BmcPerform( Fra_Man_t * p, int nPref, int nDepth )
00298 {
00299 Aig_Obj_t * pObj;
00300 int i, nImpsOld, clk = clock();
00301 assert( p->pBmc == NULL );
00302
00303 p->pBmc = Fra_BmcStart( p->pManAig, nPref, nDepth );
00304 p->pBmc->pAigFrames = Fra_BmcFrames( p->pBmc );
00305
00306 if ( p->pCla->vImps )
00307 {
00308 p->pBmc->pAigFrames->pImpFunc = Fra_BmcFilterImplications;
00309 p->pBmc->pAigFrames->pImpData = p->pBmc;
00310 p->pBmc->vImps = p->pCla->vImps;
00311 nImpsOld = Vec_IntSize(p->pCla->vImps);
00312 }
00313 p->pBmc->pAigFraig = Fra_FraigEquivence( p->pBmc->pAigFrames, 1000000 );
00314 p->pBmc->pObjToFraig = p->pBmc->pAigFrames->pObjCopies;
00315 p->pBmc->pAigFrames->pObjCopies = NULL;
00316
00317 Aig_ManForEachObj( p->pBmc->pAigFrames, pObj, i )
00318 pObj->pData = p;
00319
00320 if ( p->pPars->fVerbose )
00321 {
00322 printf( "Original AIG = %d. Init %d frames = %d. Fraig = %d. ",
00323 Aig_ManNodeNum(p->pBmc->pAig), p->pBmc->nFramesAll,
00324 Aig_ManNodeNum(p->pBmc->pAigFrames), Aig_ManNodeNum(p->pBmc->pAigFraig) );
00325 PRT( "Time", clock() - clk );
00326 printf( "Before BMC: " );
00327
00328 printf( "Const = %5d. Class = %5d. Lit = %5d. ",
00329 Vec_PtrSize(p->pCla->vClasses1), Vec_PtrSize(p->pCla->vClasses), Fra_ClassesCountLits(p->pCla) );
00330 if ( p->pCla->vImps )
00331 printf( "Imp = %5d. ", nImpsOld );
00332 printf( "\n" );
00333 }
00334
00335 p->pCla->pFuncNodeIsConst = Fra_BmcNodeIsConst;
00336 p->pCla->pFuncNodesAreEqual = Fra_BmcNodesAreEqual;
00337 Fra_ClassesRefine( p->pCla );
00338 Fra_ClassesRefine1( p->pCla, 1, NULL );
00339 p->pCla->pFuncNodeIsConst = Fra_SmlNodeIsConst;
00340 p->pCla->pFuncNodesAreEqual = Fra_SmlNodesAreEqual;
00341
00342 if ( p->pPars->fVerbose )
00343 {
00344 printf( "After BMC: " );
00345
00346 printf( "Const = %5d. Class = %5d. Lit = %5d. ",
00347 Vec_PtrSize(p->pCla->vClasses1), Vec_PtrSize(p->pCla->vClasses), Fra_ClassesCountLits(p->pCla) );
00348 if ( p->pCla->vImps )
00349 printf( "Imp = %5d. ", Vec_IntSize(p->pCla->vImps) );
00350 printf( "\n" );
00351 }
00352
00353 Fra_BmcStop( p->pBmc );
00354 p->pBmc = NULL;
00355 }
00356
00357
00361
00362