abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bmcCexCare.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [bmcCexCare.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT-based bounded model checking.]
8 
9  Synopsis [Computing care set of the counter-example.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: bmcCexCare.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "bmc.h"
22 #include "aig/gia/giaAig.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// FUNCTION DEFINITIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37  Synopsis [Backward propagation.]
38 
39  Description []
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
46 void Bmc_CexCarePropagateFwdOne( Gia_Man_t * p, Abc_Cex_t * pCex, int f, int fGrow )
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 }
80 void Bmc_CexCarePropagateFwd( Gia_Man_t * p, Abc_Cex_t * pCex, int fGrow, Vec_Int_t * vPrios )
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 }
95 
96 /**Function*************************************************************
97 
98  Synopsis [Forward propagation.]
99 
100  Description []
101 
102  SideEffects []
103 
104  SeeAlso []
105 
106 ***********************************************************************/
107 void Bmc_CexCarePropagateBwdOne( Gia_Man_t * p, Abc_Cex_t * pCex, int f, Abc_Cex_t * pCexMin )
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 }
143 Abc_Cex_t * Bmc_CexCarePropagateBwd( Gia_Man_t * p, Abc_Cex_t * pCex, Vec_Int_t * vPrios, int fGrow )
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 }
165 
166 /**Function*************************************************************
167 
168  Synopsis [Computes the care set of the counter-example.]
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176 ***********************************************************************/
177 Abc_Cex_t * Bmc_CexCareMinimizeAig( Gia_Man_t * p, Abc_Cex_t * pCex, int fCheck, int fVerbose )
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 }
255 Abc_Cex_t * Bmc_CexCareMinimize( Aig_Man_t * p, Abc_Cex_t * pCex, int fCheck, int fVerbose )
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 }
262 
263 /**Function*************************************************************
264 
265  Synopsis [Verifies the care set of the counter-example.]
266 
267  Description []
268 
269  SideEffects []
270 
271  SeeAlso []
272 
273 ***********************************************************************/
274 void Bmc_CexCareVerify( Aig_Man_t * p, Abc_Cex_t * pCex, Abc_Cex_t * pCexMin, int fVerbose )
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 }
290 
291 
292 ////////////////////////////////////////////////////////////////////////
293 /// END OF FILE ///
294 ////////////////////////////////////////////////////////////////////////
295 
296 
298 
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
#define Gia_ManForEachCo(p, pObj, i)
Definition: gia.h:1022
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_InfoHasBit(unsigned *p, int i)
Definition: abc_global.h:258
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition: utilCex.c:51
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
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
int Abc_CexCountOnes(Abc_Cex_t *p)
Definition: utilCex.c:548
void Bmc_CexCareVerify(Aig_Man_t *p, Abc_Cex_t *pCex, Abc_Cex_t *pCexMin, int fVerbose)
Definition: bmcCexCare.c:274
Gia_Man_t * Gia_ManFromAigSimple(Aig_Man_t *p)
Definition: giaAig.c:171
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
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: gia.h:1042
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
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
ABC_NAMESPACE_IMPL_START void Bmc_CexCarePropagateFwdOne(Gia_Man_t *p, Abc_Cex_t *pCex, int f, int fGrow)
DECLARATIONS ///.
Definition: bmcCexCare.c:46
#define Gia_ManForEachAndReverse(p, pObj, i)
Definition: gia.h:1010
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
void Abc_CexFreeP(Abc_Cex_t **p)
Definition: utilCex.c:350
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
#define Gia_ManForEachPi(p, pObj, i)
Definition: gia.h:1034
#define Gia_ManForEachCand(p, pObj, i)
Definition: gia.h:1008
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
unsigned fPhase
Definition: gia.h:85
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
Definition: gia.h:95
void Bmc_CexCarePropagateBwdOne(Gia_Man_t *p, Abc_Cex_t *pCex, int f, Abc_Cex_t *pCexMin)
Definition: bmcCexCare.c:107
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
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
#define Gia_ManForEachRo(p, pObj, i)
Definition: gia.h:1038
#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
#define Gia_ManForEachRi(p, pObj, i)
Definition: gia.h:1040
Abc_Cex_t * Bmc_CexCareMinimize(Aig_Man_t *p, Abc_Cex_t *pCex, int fCheck, int fVerbose)
Definition: bmcCexCare.c:255
void Bmc_CexPrint(Abc_Cex_t *pCex, int nInputs, int fVerbose)
Definition: bmcCexTools.c:307
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
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 void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387