abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bmcCexCare.c File Reference
#include "bmc.h"
#include "aig/gia/giaAig.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Bmc_CexCarePropagateFwdOne (Gia_Man_t *p, Abc_Cex_t *pCex, int f, int fGrow)
 DECLARATIONS ///. More...
 
void Bmc_CexCarePropagateFwd (Gia_Man_t *p, Abc_Cex_t *pCex, int fGrow, Vec_Int_t *vPrios)
 
void Bmc_CexCarePropagateBwdOne (Gia_Man_t *p, Abc_Cex_t *pCex, int f, Abc_Cex_t *pCexMin)
 
Abc_Cex_tBmc_CexCarePropagateBwd (Gia_Man_t *p, Abc_Cex_t *pCex, Vec_Int_t *vPrios, int fGrow)
 
Abc_Cex_tBmc_CexCareMinimizeAig (Gia_Man_t *p, Abc_Cex_t *pCex, int fCheck, int fVerbose)
 
Abc_Cex_tBmc_CexCareMinimize (Aig_Man_t *p, Abc_Cex_t *pCex, int fCheck, int fVerbose)
 
void Bmc_CexCareVerify (Aig_Man_t *p, Abc_Cex_t *pCex, Abc_Cex_t *pCexMin, int fVerbose)
 

Function Documentation

Abc_Cex_t* Bmc_CexCareMinimize ( Aig_Man_t p,
Abc_Cex_t pCex,
int  fCheck,
int  fVerbose 
)

Definition at line 255 of file bmcCexCare.c.

256 {
257  Gia_Man_t * pGia = Gia_ManFromAigSimple( p );
258  Abc_Cex_t * pCexMin = Bmc_CexCareMinimizeAig( pGia, pCex, fCheck, fVerbose );
259  Gia_ManStop( pGia );
260  return pCexMin;
261 }
Abc_Cex_t * Bmc_CexCareMinimizeAig(Gia_Man_t *p, Abc_Cex_t *pCex, int fCheck, int fVerbose)
Definition: bmcCexCare.c:177
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Gia_Man_t * Gia_ManFromAigSimple(Aig_Man_t *p)
Definition: giaAig.c:171
Definition: gia.h:95
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
Abc_Cex_t* Bmc_CexCareMinimizeAig ( Gia_Man_t p,
Abc_Cex_t pCex,
int  fCheck,
int  fVerbose 
)

Function*************************************************************

Synopsis [Computes the care set of the counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 177 of file bmcCexCare.c.

178 {
179  int nTryCexes = 4; // belongs to range [1;4]
180  Abc_Cex_t * pCexBest, * pCexMin[4] = {NULL};
181  int k, nOnesBest, nOnesCur;
182  Vec_Int_t * vPrios;
183  if ( pCex->nPis != Gia_ManPiNum(p) )
184  {
185  printf( "Given CEX does to have same number of inputs as the AIG.\n" );
186  return NULL;
187  }
188  if ( pCex->nRegs != Gia_ManRegNum(p) )
189  {
190  printf( "Given CEX does to have same number of flops as the AIG.\n" );
191  return NULL;
192  }
193  if ( !(pCex->iPo >= 0 && pCex->iPo < Gia_ManPoNum(p)) )
194  {
195  printf( "Given CEX has PO whose index is out of range for the AIG.\n" );
196  return NULL;
197  }
198  assert( pCex->nPis == Gia_ManPiNum(p) );
199  assert( pCex->nRegs == Gia_ManRegNum(p) );
200  assert( pCex->iPo >= 0 && pCex->iPo < Gia_ManPoNum(p) );
201  if ( fVerbose )
202  {
203  printf( "Original : " );
204  Bmc_CexPrint( pCex, Gia_ManPiNum(p), 0 );
205  }
206  vPrios = Vec_IntAlloc( pCex->nRegs * (pCex->iFrame + 1) );
207  for ( k = 0; k < nTryCexes; k++ )
208  {
209  Bmc_CexCarePropagateFwd(p, pCex, k, vPrios );
210  assert( Vec_IntSize(vPrios) == pCex->nRegs * (pCex->iFrame + 1) );
211  if ( !Abc_LitIsCompl(Gia_ManPo(p, pCex->iPo)->Value) )
212  {
213  printf( "Counter-example is invalid.\n" );
214  Vec_IntFree( vPrios );
215  return NULL;
216  }
217  pCexMin[k] = Bmc_CexCarePropagateBwd( p, pCex, vPrios, k );
218  if ( fVerbose )
219  {
220  if ( (k & 1) )
221  printf( "Decrease : " );
222  else
223  printf( "Increase : " );
224  Bmc_CexPrint( pCexMin[k], Gia_ManPiNum(p), 0 );
225  }
226  }
227  Vec_IntFree( vPrios );
228  // select the best one
229  pCexBest = pCexMin[0];
230  nOnesBest = Abc_CexCountOnes(pCexMin[0]);
231  for ( k = 1; k < nTryCexes; k++ )
232  {
233  nOnesCur = Abc_CexCountOnes(pCexMin[k]);
234  if ( nOnesBest > nOnesCur )
235  {
236  nOnesBest = nOnesCur;
237  pCexBest = pCexMin[k];
238  }
239  }
240  for ( k = 0; k < nTryCexes; k++ )
241  if ( pCexBest != pCexMin[k] )
242  Abc_CexFreeP( &pCexMin[k] );
243  // verify and return
244  if ( fVerbose )
245  {
246  printf( "Final : " );
247  Bmc_CexPrint( pCexBest, Gia_ManPiNum(p), 0 );
248  }
249  if ( !Bmc_CexVerify( p, pCex, pCexBest ) )
250  printf( "Counter-example verification has failed.\n" );
251  else if ( fCheck )
252  printf( "Counter-example verification succeeded.\n" );
253  return pCexBest;
254 }
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Bmc_CexCarePropagateFwd(Gia_Man_t *p, Abc_Cex_t *pCex, int fGrow, Vec_Int_t *vPrios)
Definition: bmcCexCare.c:80
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
int Abc_CexCountOnes(Abc_Cex_t *p)
Definition: utilCex.c:548
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void Abc_CexFreeP(Abc_Cex_t **p)
Definition: utilCex.c:350
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
int Bmc_CexVerify(Gia_Man_t *p, Abc_Cex_t *pCex, Abc_Cex_t *pCexCare)
Definition: bmcCexTools.c:346
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
void Bmc_CexPrint(Abc_Cex_t *pCex, int nInputs, int fVerbose)
Definition: bmcCexTools.c:307
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
Abc_Cex_t * Bmc_CexCarePropagateBwd(Gia_Man_t *p, Abc_Cex_t *pCex, Vec_Int_t *vPrios, int fGrow)
Definition: bmcCexCare.c:143
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387
Abc_Cex_t* Bmc_CexCarePropagateBwd ( Gia_Man_t p,
Abc_Cex_t pCex,
Vec_Int_t vPrios,
int  fGrow 
)

Definition at line 143 of file bmcCexCare.c.

144 {
145  Abc_Cex_t * pCexMin;
146  Gia_Obj_t * pObj, * pObjRo, * pObjRi;
147  int f, i;
148  pCexMin = Abc_CexAlloc( pCex->nRegs, pCex->nPis, pCex->iFrame + 1 );
149  pCexMin->iPo = pCex->iPo;
150  pCexMin->iFrame = pCex->iFrame;
151  Gia_ManForEachCo( p, pObj, i )
152  pObj->fPhase = 0;
153  for ( f = pCex->iFrame; f >= 0; f-- )
154  {
155  Gia_ManPo(p, pCex->iPo)->fPhase = (int)(f == pCex->iFrame);
156  Gia_ManForEachRo( p, pObj, i )
157  pObj->Value = Vec_IntEntry( vPrios, f * pCex->nRegs + i );
158  Bmc_CexCarePropagateFwdOne( p, pCex, f, fGrow );
159  Bmc_CexCarePropagateBwdOne( p, pCex, f, pCexMin );
160  Gia_ManForEachRiRo( p, pObjRi, pObjRo, i )
161  pObjRi->fPhase = pObjRo->fPhase;
162  }
163  return pCexMin;
164 }
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition: utilCex.c:51
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
for(p=first;p->value< newval;p=p->next)
Definition: gia.h:75
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: gia.h:1042
ABC_NAMESPACE_IMPL_START void Bmc_CexCarePropagateFwdOne(Gia_Man_t *p, Abc_Cex_t *pCex, int f, int fGrow)
DECLARATIONS ///.
Definition: bmcCexCare.c:46
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned fPhase
Definition: gia.h:85
void Bmc_CexCarePropagateBwdOne(Gia_Man_t *p, Abc_Cex_t *pCex, int f, Abc_Cex_t *pCexMin)
Definition: bmcCexCare.c:107
#define Gia_ManForEachRo(p, pObj, i)
Definition: gia.h:1038
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition: utilCex.h:39
void Bmc_CexCarePropagateBwdOne ( Gia_Man_t p,
Abc_Cex_t pCex,
int  f,
Abc_Cex_t pCexMin 
)

Function*************************************************************

Synopsis [Forward propagation.]

Description []

SideEffects []

SeeAlso []

Definition at line 107 of file bmcCexCare.c.

108 {
109  Gia_Obj_t * pObj;
110  int i, Phase0, Phase1;
111  Gia_ManForEachCand( p, pObj, i )
112  pObj->fPhase = 0;
113  Gia_ManForEachCo( p, pObj, i )
114  if ( pObj->fPhase )
115  Gia_ObjFanin0(pObj)->fPhase = 1;
116  Gia_ManForEachAndReverse( p, pObj, i )
117  {
118  if ( !pObj->fPhase )
119  continue;
120  Phase0 = Abc_LitIsCompl(Gia_ObjFanin0(pObj)->Value) ^ Gia_ObjFaninC0(pObj);
121  Phase1 = Abc_LitIsCompl(Gia_ObjFanin1(pObj)->Value) ^ Gia_ObjFaninC1(pObj);
122  if ( Phase0 && Phase1 )
123  {
124  Gia_ObjFanin0(pObj)->fPhase = 1;
125  Gia_ObjFanin1(pObj)->fPhase = 1;
126  }
127  else if ( Phase0 && !Phase1 )
128  Gia_ObjFanin1(pObj)->fPhase = 1;
129  else if ( !Phase0 && Phase1 )
130  Gia_ObjFanin0(pObj)->fPhase = 1;
131  else // if ( !Phase0 && !Phase1 )
132  {
133  if ( Abc_Lit2Var(Gia_ObjFanin0(pObj)->Value) <= Abc_Lit2Var(Gia_ObjFanin1(pObj)->Value) )
134  Gia_ObjFanin0(pObj)->fPhase = 1;
135  else
136  Gia_ObjFanin1(pObj)->fPhase = 1;
137  }
138  }
139  Gia_ManForEachPi( p, pObj, i )
140  if ( pObj->fPhase )
141  Abc_InfoSetBit( pCexMin->pData, pCexMin->nRegs + pCexMin->nPis * f + i );
142 }
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
Definition: gia.h:75
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition: gia.h:1010
if(last==0)
Definition: sparse_int.h:34
#define Gia_ManForEachPi(p, pObj, i)
Definition: gia.h:1034
#define Gia_ManForEachCand(p, pObj, i)
Definition: gia.h:1008
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
unsigned fPhase
Definition: gia.h:85
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
void Bmc_CexCarePropagateFwd ( Gia_Man_t p,
Abc_Cex_t pCex,
int  fGrow,
Vec_Int_t vPrios 
)

Definition at line 80 of file bmcCexCare.c.

81 {
82  Gia_Obj_t * pObj, * pObjRo, * pObjRi;
83  int f, i;
84  Gia_ManConst0( p )->Value = 0;
85  Gia_ManForEachRi( p, pObj, i )
86  pObj->Value = 0;
87  Vec_IntClear( vPrios );
88  for ( f = 0; f <= pCex->iFrame; f++ )
89  {
90  Gia_ManForEachRiRo( p, pObjRi, pObjRo, i )
91  Vec_IntPush( vPrios, (pObjRo->Value = pObjRi->Value) );
92  Bmc_CexCarePropagateFwdOne( p, pCex, f, fGrow );
93  }
94 }
for(p=first;p->value< newval;p=p->next)
Definition: gia.h:75
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: gia.h:1042
ABC_NAMESPACE_IMPL_START void Bmc_CexCarePropagateFwdOne(Gia_Man_t *p, Abc_Cex_t *pCex, int f, int fGrow)
DECLARATIONS ///.
Definition: bmcCexCare.c:46
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
unsigned Value
Definition: gia.h:87
#define Gia_ManForEachRi(p, pObj, i)
Definition: gia.h:1040
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_NAMESPACE_IMPL_START void Bmc_CexCarePropagateFwdOne ( Gia_Man_t p,
Abc_Cex_t pCex,
int  f,
int  fGrow 
)

DECLARATIONS ///.

CFile****************************************************************

FileName [bmcCexCare.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT-based bounded model checking.]

Synopsis [Computing care set of the counter-example.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
bmcCexCare.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Backward propagation.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file bmcCexCare.c.

47 {
48  Gia_Obj_t * pObj;
49  int Prio, Prio0, Prio1;
50  int i, Phase0, Phase1;
51  if ( (fGrow & 2) )
52  {
53  Gia_ManForEachPi( p, pObj, i )
54  pObj->Value = Abc_Var2Lit( f * pCex->nPis + (pCex->nPis-1-i) + 1, Abc_InfoHasBit(pCex->pData, pCex->nRegs + pCex->nPis * f + i) );
55  }
56  else
57  {
58  Gia_ManForEachPi( p, pObj, i )
59  pObj->Value = Abc_Var2Lit( f * pCex->nPis + i + 1, Abc_InfoHasBit(pCex->pData, pCex->nRegs + pCex->nPis * f + i) );
60  }
61  Gia_ManForEachAnd( p, pObj, i )
62  {
63  Prio0 = Abc_Lit2Var(Gia_ObjFanin0(pObj)->Value);
64  Prio1 = Abc_Lit2Var(Gia_ObjFanin1(pObj)->Value);
65  Phase0 = Abc_LitIsCompl(Gia_ObjFanin0(pObj)->Value) ^ Gia_ObjFaninC0(pObj);
66  Phase1 = Abc_LitIsCompl(Gia_ObjFanin1(pObj)->Value) ^ Gia_ObjFaninC1(pObj);
67  if ( Phase0 && Phase1 )
68  Prio = (fGrow & 1) ? Abc_MinInt(Prio0, Prio1) : Abc_MaxInt(Prio0, Prio1);
69  else if ( Phase0 && !Phase1 )
70  Prio = Prio1;
71  else if ( !Phase0 && Phase1 )
72  Prio = Prio0;
73  else // if ( !Phase0 && !Phase1 )
74  Prio = (fGrow & 1) ? Abc_MaxInt(Prio0, Prio1) : Abc_MinInt(Prio0, Prio1);
75  pObj->Value = Abc_Var2Lit( Prio, Phase0 & Phase1 );
76  }
77  Gia_ManForEachCo( p, pObj, i )
78  pObj->Value = Abc_LitNotCond( Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj) );
79 }
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Definition: gia.h:75
static int Abc_MinInt(int a, int b)
Definition: abc_global.h:239
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
else
Definition: sparse_int.h:55
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
#define Gia_ManForEachPi(p, pObj, i)
Definition: gia.h:1034
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
void Bmc_CexCareVerify ( Aig_Man_t p,
Abc_Cex_t pCex,
Abc_Cex_t pCexMin,
int  fVerbose 
)

Function*************************************************************

Synopsis [Verifies the care set of the counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 274 of file bmcCexCare.c.

275 {
276  Gia_Man_t * pGia = Gia_ManFromAigSimple( p );
277  if ( fVerbose )
278  {
279  printf( "Original : " );
280  Bmc_CexPrint( pCex, Gia_ManPiNum(pGia), 0 );
281  printf( "Minimized: " );
282  Bmc_CexPrint( pCexMin, Gia_ManPiNum(pGia), 0 );
283  }
284  if ( !Bmc_CexVerify( pGia, pCex, pCexMin ) )
285  printf( "Counter-example verification has failed.\n" );
286  else
287  printf( "Counter-example verification succeeded.\n" );
288  Gia_ManStop( pGia );
289 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Gia_Man_t * Gia_ManFromAigSimple(Aig_Man_t *p)
Definition: giaAig.c:171
int Bmc_CexVerify(Gia_Man_t *p, Abc_Cex_t *pCex, Abc_Cex_t *pCexCare)
Definition: bmcCexTools.c:346
Definition: gia.h:95
void Bmc_CexPrint(Abc_Cex_t *pCex, int nInputs, int fVerbose)
Definition: bmcCexTools.c:307
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385