abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
dchSimSat.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [dchSimSat.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Choice computation for tech-mapping.]
8 
9  Synopsis [Performs resimulation using counter-examples.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 29, 2008.]
16 
17  Revision [$Id: dchSimSat.c,v 1.00 2008/07/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "dchInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Collects internal nodes in the reverse DFS order.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
46 {
47  Aig_Obj_t * pFanout, * pRepr;
48  int iFanout = -1, i;
49  assert( !Aig_IsComplement(pObj) );
50  if ( Aig_ObjIsTravIdCurrent(p->pAigTotal, pObj) )
51  return;
53  // traverse the fanouts
54  Aig_ObjForEachFanout( p->pAigTotal, pObj, pFanout, iFanout, i )
55  Dch_ManCollectTfoCands_rec( p, pFanout );
56  // check if the given node has a representative
57  pRepr = Aig_ObjRepr( p->pAigTotal, pObj );
58  if ( pRepr == NULL )
59  return;
60  // pRepr is the constant 1 node
61  if ( pRepr == Aig_ManConst1(p->pAigTotal) )
62  {
63  Vec_PtrPush( p->vSimRoots, pObj );
64  return;
65  }
66  // pRepr is the representative of an equivalence class
67  if ( pRepr->fMarkA )
68  return;
69  pRepr->fMarkA = 1;
70  Vec_PtrPush( p->vSimClasses, pRepr );
71 }
72 
73 /**Function*************************************************************
74 
75  Synopsis [Collect equivalence classes and const1 cands in the TFO.]
76 
77  Description []
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
85 {
86  Aig_Obj_t * pObj;
87  int i;
88  Vec_PtrClear( p->vSimRoots );
92  Dch_ManCollectTfoCands_rec( p, pObj1 );
93  Dch_ManCollectTfoCands_rec( p, pObj2 );
94  Vec_PtrSort( p->vSimRoots, (int (*)(void))Aig_ObjCompareIdIncrease );
95  Vec_PtrSort( p->vSimClasses, (int (*)(void))Aig_ObjCompareIdIncrease );
96  Vec_PtrForEachEntry( Aig_Obj_t *, p->vSimClasses, pObj, i )
97  pObj->fMarkA = 0;
98 }
99 
100 /**Function*************************************************************
101 
102  Synopsis [Resimulates the cone of influence of the solved nodes.]
103 
104  Description []
105 
106  SideEffects []
107 
108  SeeAlso []
109 
110 ***********************************************************************/
112 {
113  if ( Aig_ObjIsTravIdCurrent(p->pAigTotal, pObj) )
114  return;
116  if ( Aig_ObjIsCi(pObj) )
117  {
118  Aig_Obj_t * pObjFraig;
119  int nVarNum;
120  pObjFraig = Dch_ObjFraig( pObj );
121  assert( !Aig_IsComplement(pObjFraig) );
122  nVarNum = Dch_ObjSatNum( p, pObjFraig );
123  // get the value from the SAT solver
124  // (account for the fact that some vars may be minimized away)
125  pObj->fMarkB = !nVarNum? 0 : sat_solver_var_value( p->pSat, nVarNum );
126 // pObj->fMarkB = !nVarNum? Aig_ManRandom(0) & 1 : sat_solver_var_value( p->pSat, nVarNum );
127  return;
128  }
131  pObj->fMarkB = ( Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj) )
132  & ( Aig_ObjFanin1(pObj)->fMarkB ^ Aig_ObjFaninC1(pObj) );
133  // count the cone size
134  if ( Dch_ObjSatNum( p, Aig_Regular(Dch_ObjFraig(pObj)) ) > 0 )
135  p->nConeThis++;
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis [Resimulates the cone of influence of the other nodes.]
141 
142  Description []
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
150 {
151  if ( Aig_ObjIsTravIdCurrent(p->pAigTotal, pObj) )
152  return;
154  if ( Aig_ObjIsCi(pObj) )
155  {
156  // set random value
157  pObj->fMarkB = Aig_ManRandom(0) & 1;
158  return;
159  }
162  pObj->fMarkB = ( Aig_ObjFanin0(pObj)->fMarkB ^ Aig_ObjFaninC0(pObj) )
163  & ( Aig_ObjFanin1(pObj)->fMarkB ^ Aig_ObjFaninC1(pObj) );
164 }
165 
166 /**Function*************************************************************
167 
168  Synopsis [Handle the counter-example.]
169 
170  Description []
171 
172  SideEffects []
173 
174  SeeAlso []
175 
176 ***********************************************************************/
178 {
179  Aig_Obj_t * pRoot, ** ppClass;
180  int i, k, nSize, RetValue1, RetValue2;
181  abctime clk = Abc_Clock();
182  // get the equivalence classes
183  Dch_ManCollectTfoCands( p, pObj, pRepr );
184  // resimulate the cone of influence of the solved nodes
185  p->nConeThis = 0;
188  Dch_ManResimulateSolved_rec( p, pObj );
189  Dch_ManResimulateSolved_rec( p, pRepr );
190  p->nConeMax = Abc_MaxInt( p->nConeMax, p->nConeThis );
191  // resimulate the cone of influence of the other nodes
192  Vec_PtrForEachEntry( Aig_Obj_t *, p->vSimRoots, pRoot, i )
193  Dch_ManResimulateOther_rec( p, pRoot );
194  // refine these nodes
195  RetValue1 = Dch_ClassesRefineConst1Group( p->ppClasses, p->vSimRoots, 0 );
196  // resimulate the cone of influence of the cand classes
197  RetValue2 = 0;
198  Vec_PtrForEachEntry( Aig_Obj_t *, p->vSimClasses, pRoot, i )
199  {
200  ppClass = Dch_ClassesReadClass( p->ppClasses, pRoot, &nSize );
201  for ( k = 0; k < nSize; k++ )
202  Dch_ManResimulateOther_rec( p, ppClass[k] );
203  // refine this class
204  RetValue2 += Dch_ClassesRefineOneClass( p->ppClasses, pRoot, 0 );
205  }
206  // make sure refinement happened
207  if ( Aig_ObjIsConst1(pRepr) )
208  assert( RetValue1 );
209  else
210  assert( RetValue2 );
211 p->timeSimSat += Abc_Clock() - clk;
212 }
213 
214 /**Function*************************************************************
215 
216  Synopsis [Handle the counter-example.]
217 
218  Description []
219 
220  SideEffects []
221 
222  SeeAlso []
223 
224 ***********************************************************************/
226 {
227  Aig_Obj_t * pRoot;
228  int i, RetValue;
229  abctime clk = Abc_Clock();
230  // get the equivalence class
231  if ( Dch_ObjIsConst1Cand(p->pAigTotal, pObj) )
233  else
235  // resimulate the cone of influence of the solved nodes
236  p->nConeThis = 0;
239  Dch_ManResimulateSolved_rec( p, pObj );
240  Dch_ManResimulateSolved_rec( p, pRepr );
241  p->nConeMax = Abc_MaxInt( p->nConeMax, p->nConeThis );
242  // resimulate the cone of influence of the other nodes
243  Vec_PtrForEachEntry( Aig_Obj_t *, p->vSimRoots, pRoot, i )
244  Dch_ManResimulateOther_rec( p, pRoot );
245  // refine this class
246  if ( Dch_ObjIsConst1Cand(p->pAigTotal, pObj) )
247  RetValue = Dch_ClassesRefineConst1Group( p->ppClasses, p->vSimRoots, 0 );
248  else
249  RetValue = Dch_ClassesRefineOneClass( p->ppClasses, pRepr, 0 );
250  assert( RetValue );
251 p->timeSimSat += Abc_Clock() - clk;
252 }
253 
254 ////////////////////////////////////////////////////////////////////////
255 /// END OF FILE ///
256 ////////////////////////////////////////////////////////////////////////
257 
258 
260 
int Aig_ObjCompareIdIncrease(Aig_Obj_t **pp1, Aig_Obj_t **pp2)
Definition: aigUtil.c:496
#define Aig_ObjForEachFanout(p, pObj, pFanout, iFan, i)
Definition: aig.h:427
static Aig_Obj_t * Aig_ObjRepr(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:330
static Llb_Mgr_t * p
Definition: llb3Image.c:950
abctime timeSimSat
Definition: dchInt.h:88
static int Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:295
unsigned int fMarkB
Definition: aig.h:80
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Dch_ObjIsConst1Cand(Aig_Man_t *pAig, Aig_Obj_t *pObj)
Definition: dchInt.h:108
void Dch_ManCollectTfoCands(Dch_Man_t *p, Aig_Obj_t *pObj1, Aig_Obj_t *pObj2)
Definition: dchSimSat.c:84
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
void Dch_ManResimulateCex(Dch_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pRepr)
Definition: dchSimSat.c:177
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
Definition: vecPtr.h:851
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
ABC_NAMESPACE_IMPL_START void Dch_ManCollectTfoCands_rec(Dch_Man_t *p, Aig_Obj_t *pObj)
DECLARATIONS ///.
Definition: dchSimSat.c:45
void Dch_ManResimulateSolved_rec(Dch_Man_t *p, Aig_Obj_t *pObj)
Definition: dchSimSat.c:111
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
unsigned int fMarkA
Definition: aig.h:79
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
Vec_Ptr_t * vSimRoots
Definition: dchInt.h:70
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static Aig_Obj_t * Aig_ObjFanin1(Aig_Obj_t *pObj)
Definition: aig.h:309
static void Aig_ObjSetTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:293
int nConeThis
Definition: dchInt.h:73
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
void Dch_ManResimulateCex2(Dch_Man_t *p, Aig_Obj_t *pObj, Aig_Obj_t *pRepr)
Definition: dchSimSat.c:225
void Aig_ManIncrementTravId(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigUtil.c:44
int Dch_ClassesRefineConst1Group(Dch_Cla_t *p, Vec_Ptr_t *vRoots, int fRecursive)
Definition: dchClass.c:570
Vec_Ptr_t * vSimClasses
Definition: dchInt.h:71
int Dch_ClassesRefineOneClass(Dch_Cla_t *p, Aig_Obj_t *pReprOld, int fRecursive)
Definition: dchClass.c:443
void Dch_ClassesCollectConst1Group(Dch_Cla_t *p, Aig_Obj_t *pObj, int nNodes, Vec_Ptr_t *vRoots)
Definition: dchClass.c:546
int nConeMax
Definition: dchInt.h:74
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Dch_Cla_t * ppClasses
Definition: dchInt.h:60
void Dch_ManResimulateOther_rec(Dch_Man_t *p, Aig_Obj_t *pObj)
Definition: dchSimSat.c:149
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
static Aig_Obj_t * Dch_ObjFraig(Aig_Obj_t *pObj)
Definition: dchInt.h:105
Definition: aig.h:69
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
static Aig_Obj_t * Aig_ManConst1(Aig_Man_t *p)
Definition: aig.h:264
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
sat_solver * pSat
Definition: dchInt.h:63
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
Aig_Man_t * pAigTotal
Definition: dchInt.h:57
Aig_Obj_t ** Dch_ClassesReadClass(Dch_Cla_t *p, Aig_Obj_t *pRepr, int *pnSize)
Definition: dchClass.c:222
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Dch_ClassesCollectOneClass(Dch_Cla_t *p, Aig_Obj_t *pRepr, Vec_Ptr_t *vRoots)
Definition: dchClass.c:525
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Dch_ObjSatNum(Dch_Man_t *p, Aig_Obj_t *pObj)
MACRO DEFINITIONS ///.
Definition: dchInt.h:102