abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaCex.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaAbs.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [Counter-example-guided abstraction refinement.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaAbs.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28 
29 ////////////////////////////////////////////////////////////////////////
30 /// FUNCTION DEFINITIONS ///
31 ////////////////////////////////////////////////////////////////////////
32 
33 /**Function*************************************************************
34 
35  Synopsis [Resimulates the counter-example.]
36 
37  Description []
38 
39  SideEffects []
40 
41  SeeAlso []
42 
43 ***********************************************************************/
44 int Gia_ManVerifyCex( Gia_Man_t * pAig, Abc_Cex_t * p, int fDualOut )
45 {
46  Gia_Obj_t * pObj, * pObjRi, * pObjRo;
47  int RetValue, i, k, iBit = 0;
48  Gia_ManCleanMark0(pAig);
49  Gia_ManForEachRo( pAig, pObj, i )
50  pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
51  for ( i = 0; i <= p->iFrame; i++ )
52  {
53  Gia_ManForEachPi( pAig, pObj, k )
54  pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
55  Gia_ManForEachAnd( pAig, pObj, k )
56  pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) &
57  (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
58  Gia_ManForEachCo( pAig, pObj, k )
59  pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
60  if ( i == p->iFrame )
61  break;
62  Gia_ManForEachRiRo( pAig, pObjRi, pObjRo, k )
63  {
64  pObjRo->fMark0 = pObjRi->fMark0;
65  }
66  }
67  assert( iBit == p->nBits );
68  if ( fDualOut )
69  RetValue = Gia_ManPo(pAig, 2*p->iPo)->fMark0 ^ Gia_ManPo(pAig, 2*p->iPo+1)->fMark0;
70  else
71  RetValue = Gia_ManPo(pAig, p->iPo)->fMark0;
72  Gia_ManCleanMark0(pAig);
73  return RetValue;
74 }
75 
76 /**Function*************************************************************
77 
78  Synopsis [Resimulates the counter-example.]
79 
80  Description []
81 
82  SideEffects []
83 
84  SeeAlso []
85 
86 ***********************************************************************/
87 int Gia_ManFindFailedPoCex( Gia_Man_t * pAig, Abc_Cex_t * p, int nOutputs )
88 {
89  Gia_Obj_t * pObj, * pObjRi, * pObjRo;
90  int RetValue, i, k, iBit = 0;
91  assert( Gia_ManPiNum(pAig) == p->nPis );
92  Gia_ManCleanMark0(pAig);
93 // Gia_ManForEachRo( pAig, pObj, i )
94 // pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
95  iBit = p->nRegs;
96  for ( i = 0; i <= p->iFrame; i++ )
97  {
98  Gia_ManForEachPi( pAig, pObj, k )
99  pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
100  Gia_ManForEachAnd( pAig, pObj, k )
101  pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) &
102  (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
103  Gia_ManForEachCo( pAig, pObj, k )
104  pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
105  Gia_ManForEachRiRo( pAig, pObjRi, pObjRo, k )
106  pObjRo->fMark0 = pObjRi->fMark0;
107  }
108  assert( iBit == p->nBits );
109  // figure out the number of failed output
110  RetValue = -1;
111 // for ( i = Gia_ManPoNum(pAig) - 1; i >= nOutputs; i-- )
112  for ( i = nOutputs; i < Gia_ManPoNum(pAig); i++ )
113  {
114  if ( Gia_ManPo(pAig, i)->fMark0 )
115  {
116  RetValue = i;
117  break;
118  }
119  }
120  Gia_ManCleanMark0(pAig);
121  return RetValue;
122 }
123 
124 /**Function*************************************************************
125 
126  Synopsis [Determines the failed PO when its exact frame is not known.]
127 
128  Description []
129 
130  SideEffects []
131 
132  SeeAlso []
133 
134 ***********************************************************************/
136 {
137  Gia_Obj_t * pObj, * pObjRi, * pObjRo;
138  int i, k, iBit = 0;
139  assert( Gia_ManPiNum(pAig) == p->nPis );
140  Gia_ManCleanMark0(pAig);
141  p->iPo = -1;
142 // Gia_ManForEachRo( pAig, pObj, i )
143 // pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
144  iBit = p->nRegs;
145  for ( i = 0; i <= p->iFrame; i++ )
146  {
147  Gia_ManForEachPi( pAig, pObj, k )
148  pObj->fMark0 = Abc_InfoHasBit(p->pData, iBit++);
149  Gia_ManForEachAnd( pAig, pObj, k )
150  pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) &
151  (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
152  Gia_ManForEachCo( pAig, pObj, k )
153  pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
154  Gia_ManForEachRiRo( pAig, pObjRi, pObjRo, k )
155  pObjRo->fMark0 = pObjRi->fMark0;
156  // check the POs
157  Gia_ManForEachPo( pAig, pObj, k )
158  {
159  if ( !pObj->fMark0 )
160  continue;
161  p->iPo = k;
162  p->iFrame = i;
163  p->nBits = iBit;
164  break;
165  }
166  }
167  Gia_ManCleanMark0(pAig);
168  return p->iPo;
169 }
170 
171 
172 /**Function*************************************************************
173 
174  Synopsis [Starts the process of returning values for internal nodes.]
175 
176  Description [Should be called when pCex is available, before probing
177  any object for its value using Gia_ManCounterExampleValueLookup().]
178 
179  SideEffects []
180 
181  SeeAlso []
182 
183 ***********************************************************************/
185 {
186  Gia_Obj_t * pObj, * pObjRi, * pObjRo;
187  int Val0, Val1, nObjs, i, k, iBit = 0;
188  assert( Gia_ManRegNum(pGia) > 0 ); // makes sense only for sequential AIGs
189  assert( pGia->pData2 == NULL ); // if this fail, there may be a memory leak
190  // allocate memory to store simulation bits for internal nodes
191  pGia->pData2 = ABC_CALLOC( unsigned, Abc_BitWordNum( (pCex->iFrame + 1) * Gia_ManObjNum(pGia) ) );
192  // the register values in the counter-example should be zero
193  Gia_ManForEachRo( pGia, pObj, k )
194  assert( Abc_InfoHasBit(pCex->pData, iBit++) == 0 );
195  // iterate through the timeframes
196  nObjs = Gia_ManObjNum(pGia);
197  for ( i = 0; i <= pCex->iFrame; i++ )
198  {
199  // no need to set constant-0 node
200  // set primary inputs according to the counter-example
201  Gia_ManForEachPi( pGia, pObj, k )
202  if ( Abc_InfoHasBit(pCex->pData, iBit++) )
203  Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) );
204  // compute values for each node
205  Gia_ManForEachAnd( pGia, pObj, k )
206  {
207  Val0 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId0p(pGia, pObj) );
208  Val1 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId1p(pGia, pObj) );
209  if ( (Val0 ^ Gia_ObjFaninC0(pObj)) & (Val1 ^ Gia_ObjFaninC1(pObj)) )
210  Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) );
211  }
212  // derive values for combinational outputs
213  Gia_ManForEachCo( pGia, pObj, k )
214  {
215  Val0 = Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjFaninId0p(pGia, pObj) );
216  if ( Val0 ^ Gia_ObjFaninC0(pObj) )
217  Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObj) );
218  }
219  if ( i == pCex->iFrame )
220  continue;
221  // transfer values to the register output of the next frame
222  Gia_ManForEachRiRo( pGia, pObjRi, pObjRo, k )
223  if ( Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * i + Gia_ObjId(pGia, pObjRi) ) )
224  Abc_InfoSetBit( (unsigned *)pGia->pData2, nObjs * (i+1) + Gia_ObjId(pGia, pObjRo) );
225  }
226  assert( iBit == pCex->nBits );
227  // check that the counter-example is correct, that is, the corresponding output is asserted
228  assert( Abc_InfoHasBit( (unsigned *)pGia->pData2, nObjs * pCex->iFrame + Gia_ObjId(pGia, Gia_ManCo(pGia, pCex->iPo)) ) );
229 }
230 
231 /**Function*************************************************************
232 
233  Synopsis [Stops the process of returning values for internal nodes.]
234 
235  Description [Should be called when probing is no longer needed]
236 
237  SideEffects []
238 
239  SeeAlso []
240 
241 ***********************************************************************/
243 {
244  assert( pGia->pData2 != NULL ); // if this fail, we try to call this procedure more than once
245  ABC_FREE( pGia->pData2 );
246  pGia->pData2 = NULL;
247 }
248 
249 /**Function*************************************************************
250 
251  Synopsis [Returns the value of the given object in the given timeframe.]
252 
253  Description [Should be called to probe the value of an object with
254  the given ID (iFrame is a 0-based number of a time frame - should not
255  exceed the number of timeframes in the original counter-example).]
256 
257  SideEffects []
258 
259  SeeAlso []
260 
261 ***********************************************************************/
262 int Gia_ManCounterExampleValueLookup( Gia_Man_t * pGia, int Id, int iFrame )
263 {
264  assert( Id >= 0 && Id < Gia_ManObjNum(pGia) );
265  return Abc_InfoHasBit( (unsigned *)pGia->pData2, Gia_ManObjNum(pGia) * iFrame + Id );
266 }
267 
268 /**Function*************************************************************
269 
270  Synopsis [Procedure to test the above code.]
271 
272  Description []
273 
274  SideEffects []
275 
276  SeeAlso []
277 
278 ***********************************************************************/
280 {
281  Gia_Obj_t * pObj = Gia_ManObj( pGia, Gia_ManObjNum(pGia)/2 );
282  int iFrame = Abc_MaxInt( 0, pCex->iFrame - 1 );
283  printf( "\nUsing counter-example, which asserts output %d in frame %d.\n", pCex->iPo, pCex->iFrame );
284  Gia_ManCounterExampleValueStart( pGia, pCex );
285  printf( "Value of object %d in frame %d is %d.\n", Gia_ObjId(pGia, pObj), iFrame,
286  Gia_ManCounterExampleValueLookup(pGia, Gia_ObjId(pGia, pObj), iFrame) );
288 }
289 
290 
291 /**Function*************************************************************
292 
293  Synopsis [Returns CEX containing PI+CS values for each timeframe.]
294 
295  Description []
296 
297  SideEffects []
298 
299  SeeAlso []
300 
301 ***********************************************************************/
303 {
304  Abc_Cex_t * pNew;
305  Gia_Obj_t * pObj, * pObjRo, * pObjRi;
306  int i, k, iBit = 0;
307  assert( pCex->nRegs > 0 );
308  // start the counter-example
309  pNew = Abc_CexAlloc( 0, Gia_ManCiNum(p), pCex->iFrame + 1 );
310  pNew->iFrame = pCex->iFrame;
311  pNew->iPo = pCex->iPo;
312  // set const0
313  Gia_ManConst0(p)->fMark0 = 0;
314  // set init state
315  Gia_ManForEachRi( p, pObjRi, k )
316  pObjRi->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
317  assert( iBit == pCex->nRegs );
318  for ( i = 0; i <= pCex->iFrame; i++ )
319  {
320  Gia_ManForEachPi( p, pObj, k )
321  pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
322  Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
323  pObjRo->fMark0 = pObjRi->fMark0;
324  Gia_ManForEachCi( p, pObj, k )
325  if ( pObj->fMark0 )
326  Abc_InfoSetBit( pNew->pData, pNew->nPis * i + k );
327  Gia_ManForEachAnd( p, pObj, k )
328  pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) & (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
329  Gia_ManForEachCo( p, pObj, k )
330  pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
331  }
332  assert( iBit == pCex->nBits );
333  assert( Gia_ManPo(p, pCex->iPo)->fMark0 == 1 );
335  return pNew;
336 }
337 
338 /**Function*************************************************************
339 
340  Synopsis [Returns CEX containing all object valuess for each timeframe.]
341 
342  Description []
343 
344  SideEffects []
345 
346  SeeAlso []
347 
348 ***********************************************************************/
350 {
351  Abc_Cex_t * pNew;
352  Gia_Obj_t * pObj, * pObjRo, * pObjRi;
353  int i, k, iBit = 0;
354  assert( pCex->nRegs > 0 );
355  // start the counter-example
356  pNew = Abc_CexAlloc( 0, Gia_ManObjNum(p), pCex->iFrame + 1 );
357  pNew->iFrame = pCex->iFrame;
358  pNew->iPo = pCex->iPo;
359  // set const0
360  Gia_ManConst0(p)->fMark0 = 0;
361  // set init state
362  Gia_ManForEachRi( p, pObjRi, k )
363  pObjRi->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
364  assert( iBit == pCex->nRegs );
365  for ( i = 0; i <= pCex->iFrame; i++ )
366  {
367  Gia_ManForEachPi( p, pObj, k )
368  pObj->fMark0 = Abc_InfoHasBit(pCex->pData, iBit++);
369  Gia_ManForEachRiRo( p, pObjRi, pObjRo, k )
370  pObjRo->fMark0 = pObjRi->fMark0;
371  Gia_ManForEachObj( p, pObj, k )
372  if ( pObj->fMark0 )
373  Abc_InfoSetBit( pNew->pData, pNew->nPis * i + k );
374  Gia_ManForEachAnd( p, pObj, k )
375  pObj->fMark0 = (Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj)) & (Gia_ObjFanin1(pObj)->fMark0 ^ Gia_ObjFaninC1(pObj));
376  Gia_ManForEachCo( p, pObj, k )
377  pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
378  }
379  assert( iBit == pCex->nBits );
380  assert( Gia_ManPo(p, pCex->iPo)->fMark0 == 1 );
382  return pNew;
383 }
384 
385 
386 ////////////////////////////////////////////////////////////////////////
387 /// END OF FILE ///
388 ////////////////////////////////////////////////////////////////////////
389 
390 
392 
void Gia_ManCounterExampleValueStop(Gia_Man_t *pGia)
Definition: giaCex.c:242
#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
static Llb_Mgr_t * p
Definition: llb3Image.c:950
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
static Gia_Obj_t * Gia_ManPo(Gia_Man_t *p, int v)
Definition: gia.h:406
Abc_Cex_t * Gia_ManCexExtendToIncludeCurrentStates(Gia_Man_t *p, Abc_Cex_t *pCex)
Definition: giaCex.c:302
int Gia_ManCounterExampleValueLookup(Gia_Man_t *pGia, int Id, int iFrame)
Definition: giaCex.c:262
void Gia_ManCleanMark0(Gia_Man_t *p)
Definition: giaUtil.c:215
void Gia_ManCounterExampleValueStart(Gia_Man_t *pGia, Abc_Cex_t *pCex)
Definition: giaCex.c:184
static int Gia_ObjFaninId1p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:464
unsigned * pData2
Definition: gia.h:170
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
#define Gia_ManForEachCi(p, pObj, i)
Definition: gia.h:1016
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition: gia.h:1042
Abc_Cex_t * Gia_ManCexExtendToIncludeAllObjects(Gia_Man_t *p, Abc_Cex_t *pCex)
Definition: giaCex.c:349
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
int Gia_ManFindFailedPoCex(Gia_Man_t *pAig, Abc_Cex_t *p, int nOutputs)
Definition: giaCex.c:87
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
#define Gia_ManForEachPi(p, pObj, i)
Definition: gia.h:1034
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
static int Gia_ManCiNum(Gia_Man_t *p)
Definition: gia.h:383
void Gia_ManCounterExampleValueTest(Gia_Man_t *pGia, Abc_Cex_t *pCex)
Definition: giaCex.c:279
static Gia_Obj_t * Gia_ManCo(Gia_Man_t *p, int v)
Definition: gia.h:404
unsigned fMark0
Definition: gia.h:79
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static int Gia_ObjFaninId0p(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:463
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define Gia_ManForEachRo(p, pObj, i)
Definition: gia.h:1038
static int Abc_BitWordNum(int nBits)
Definition: abc_global.h:255
#define assert(ex)
Definition: util_old.h:213
ABC_NAMESPACE_IMPL_START int Gia_ManVerifyCex(Gia_Man_t *pAig, Abc_Cex_t *p, int fDualOut)
DECLARATIONS ///.
Definition: giaCex.c:44
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
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static int Gia_ManPiNum(Gia_Man_t *p)
Definition: gia.h:385
int Gia_ManSetFailedPoCex(Gia_Man_t *pAig, Abc_Cex_t *p)
Definition: giaCex.c:135
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387