abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
aigJust.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [aigJust.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG package.]
8 
9  Synopsis [Justification of node values.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: aigJust.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "aig.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 #define AIG_VAL0 1
31 #define AIG_VAL1 2
32 #define AIG_VALX 3
33 
34 // storing ternary values
35 static inline int Aig_ObjSetTerValue( Aig_Obj_t * pNode, int Value )
36 {
37  assert( Value );
38  pNode->fMarkA = (Value & 1);
39  pNode->fMarkB = ((Value >> 1) & 1);
40  return Value;
41 }
42 static inline int Aig_ObjGetTerValue( Aig_Obj_t * pNode )
43 {
44  return (pNode->fMarkB << 1) | pNode->fMarkA;
45 }
46 
47 // working with ternary values
48 static inline int Aig_ObjNotTerValue( int Value )
49 {
50  if ( Value == AIG_VAL1 )
51  return AIG_VAL0;
52  if ( Value == AIG_VAL0 )
53  return AIG_VAL1;
54  return AIG_VALX;
55 }
56 static inline int Aig_ObjAndTerValue( int Value0, int Value1 )
57 {
58  if ( Value0 == AIG_VAL0 || Value1 == AIG_VAL0 )
59  return AIG_VAL0;
60  if ( Value0 == AIG_VAL1 && Value1 == AIG_VAL1 )
61  return AIG_VAL1;
62  return AIG_VALX;
63 }
64 static inline int Aig_ObjNotCondTerValue( int Value, int Cond )
65 {
66  return Cond ? Aig_ObjNotTerValue( Value ) : Value;
67 }
68 
69 ////////////////////////////////////////////////////////////////////////
70 /// FUNCTION DEFINITIONS ///
71 ////////////////////////////////////////////////////////////////////////
72 
73 /**Function*************************************************************
74 
75  Synopsis [Returns value (0 or 1) or X if unassigned.]
76 
77  Description []
78 
79  SideEffects []
80 
81  SeeAlso []
82 
83 ***********************************************************************/
84 static inline int Aig_ObjSatValue( Aig_Man_t * pAig, Aig_Obj_t * pNode, int fCompl )
85 {
86  if ( Aig_ObjIsTravIdCurrent(pAig, pNode) )
87  return (pNode->fMarkA ^ fCompl) ? AIG_VAL1 : AIG_VAL0;
88  return AIG_VALX;
89 }
90 
91 /**Function*************************************************************
92 
93  Synopsis [Recursively searched for a satisfying assignment.]
94 
95  Description []
96 
97  SideEffects []
98 
99  SeeAlso []
100 
101 ***********************************************************************/
102 int Aig_NtkFindSatAssign_rec( Aig_Man_t * pAig, Aig_Obj_t * pNode, int Value, Vec_Int_t * vSuppLits, int Heur )
103 {
104  int Value0, Value1;
105 // ++Heur;
106  if ( Aig_ObjIsConst1(pNode) )
107  return 1;
108  if ( Aig_ObjIsTravIdCurrent(pAig, pNode) )
109  return ((int)pNode->fMarkA == Value);
110  Aig_ObjSetTravIdCurrent(pAig, pNode);
111  pNode->fMarkA = Value;
112  if ( Aig_ObjIsCi(pNode) )
113  {
114 // if ( Aig_ObjId(pNode) % 1000 == 0 )
115 // Value ^= 1;
116  if ( vSuppLits )
117  Vec_IntPush( vSuppLits, Abc_Var2Lit( Aig_ObjCioId(pNode), !Value ) );
118  return 1;
119  }
120  assert( Aig_ObjIsNode(pNode) );
121  // propagation
122  if ( Value )
123  {
124  if ( !Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin0(pNode), !Aig_ObjFaninC0(pNode), vSuppLits, Heur) )
125  return 0;
126  return Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin1(pNode), !Aig_ObjFaninC1(pNode), vSuppLits, Heur);
127  }
128  // justification
129  Value0 = Aig_ObjSatValue( pAig, Aig_ObjFanin0(pNode), Aig_ObjFaninC0(pNode) );
130  if ( Value0 == AIG_VAL0 )
131  return 1;
132  Value1 = Aig_ObjSatValue( pAig, Aig_ObjFanin1(pNode), Aig_ObjFaninC1(pNode) );
133  if ( Value1 == AIG_VAL0 )
134  return 1;
135  if ( Value0 == AIG_VAL1 && Value1 == AIG_VAL1 )
136  return 0;
137  if ( Value0 == AIG_VAL1 )
138  return Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin1(pNode), Aig_ObjFaninC1(pNode), vSuppLits, Heur);
139  if ( Value1 == AIG_VAL1 )
140  return Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin0(pNode), Aig_ObjFaninC0(pNode), vSuppLits, Heur);
141  assert( Value0 == AIG_VALX && Value1 == AIG_VALX );
142  // decision making
143 // if ( rand() % 10 == Heur )
144 // if ( Aig_ObjId(pNode) % 8 == Heur )
145  if ( ++Heur % 8 == 0 )
146  return Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin1(pNode), Aig_ObjFaninC1(pNode), vSuppLits, Heur);
147  else
148  return Aig_NtkFindSatAssign_rec(pAig, Aig_ObjFanin0(pNode), Aig_ObjFaninC0(pNode), vSuppLits, Heur);
149 }
150 
151 /**Function*************************************************************
152 
153  Synopsis [Returns 1 if SAT assignment is found; 0 otherwise.]
154 
155  Description []
156 
157  SideEffects []
158 
159  SeeAlso []
160 
161 ***********************************************************************/
162 int Aig_ObjFindSatAssign( Aig_Man_t * pAig, Aig_Obj_t * pNode, int Value, Vec_Int_t * vSuppLits )
163 {
164  int i;
165  if ( Aig_ObjIsCo(pNode) )
166  return Aig_ObjFindSatAssign( pAig, Aig_ObjFanin0(pNode), Value ^ Aig_ObjFaninC0(pNode), vSuppLits );
167  for ( i = 0; i < 8; i++ )
168  {
169  Vec_IntClear( vSuppLits );
170  Aig_ManIncrementTravId( pAig );
171  if ( Aig_NtkFindSatAssign_rec( pAig, pNode, Value, vSuppLits, i ) )
172  return 1;
173  }
174  return 0;
175 }
176 
177 /**Function*************************************************************
178 
179  Synopsis []
180 
181  Description []
182 
183  SideEffects []
184 
185  SeeAlso []
186 
187 ***********************************************************************/
189 {
190  int Value0, Value1;
191  if ( Aig_ObjIsConst1(pNode) )
192  return AIG_VAL1;
193  if ( Aig_ObjIsTravIdCurrent(pAig, pNode) )
194  return Aig_ObjGetTerValue( pNode );
195  Aig_ObjSetTravIdCurrent( pAig, pNode );
196  if ( Aig_ObjIsCi(pNode) )
197  return Aig_ObjSetTerValue( pNode, AIG_VALX );
199  if ( Aig_ObjIsCo(pNode) || Value0 == AIG_VAL0 )
200  return Aig_ObjSetTerValue( pNode, Value0 );
201  assert( Aig_ObjIsNode(pNode) );
203  return Aig_ObjSetTerValue( pNode, Aig_ObjAndTerValue(Value0, Value1) );
204 }
205 
206 /**Function*************************************************************
207 
208  Synopsis [Returns value of the object under input assignment.]
209 
210  Description []
211 
212  SideEffects []
213 
214  SeeAlso []
215 
216 ***********************************************************************/
217 int Aig_ObjTerSimulate( Aig_Man_t * pAig, Aig_Obj_t * pNode, Vec_Int_t * vSuppLits )
218 {
219  Aig_Obj_t * pObj;
220  int i, Entry;
221  Aig_ManIncrementTravId( pAig );
222  Vec_IntForEachEntry( vSuppLits, Entry, i )
223  {
224  pObj = Aig_ManCi( pAig, Abc_Lit2Var(Entry) );
226  Aig_ObjSetTravIdCurrent( pAig, pObj );
227 //printf( "%d ", Entry );
228  }
229 //printf( "\n" );
230  return Aig_ObjTerSimulate_rec( pAig, pNode );
231 }
232 
233 
236 extern void Aig_ManPackStop( Aig_ManPack_t * p );
237 extern void Aig_ManPackAddPattern( Aig_ManPack_t * p, Vec_Int_t * vLits );
239 
240 /**Function*************************************************************
241 
242  Synopsis [Testing of the framework.]
243 
244  Description []
245 
246  SideEffects []
247 
248  SeeAlso []
249 
250 ***********************************************************************/
252 {
253  Aig_ManPack_t * pPack;
254  Vec_Int_t * vSuppLits, * vNodes;
255  Aig_Obj_t * pObj;
256  int i;
257  abctime clk = Abc_Clock();
258  int Count0 = 0, Count0f = 0, Count1 = 0, Count1f = 0;
259  int nTotalLits = 0;
260  vSuppLits = Vec_IntAlloc( 100 );
261  pPack = Aig_ManPackStart( pAig );
262  vNodes = Aig_ManPackConstNodes( pPack );
263 // Aig_ManForEachCo( pAig, pObj, i )
264  Aig_ManForEachObjVec( vNodes, pAig, pObj, i )
265  {
266  if ( pObj->fPhase ) // const 1
267  {
268  if ( Aig_ObjFindSatAssign(pAig, pObj, 0, vSuppLits) )
269  {
270 // assert( Aig_ObjTerSimulate(pAig, pObj, vSuppLits) == AIG_VAL0 );
271 // if ( Aig_ObjTerSimulate(pAig, pObj, vSuppLits) != AIG_VAL0 )
272 // printf( "Justification error!\n" );
273  Count0++;
274  nTotalLits += Vec_IntSize(vSuppLits);
275  Aig_ManPackAddPattern( pPack, vSuppLits );
276  }
277  else
278  Count0f++;
279  }
280  else
281  {
282  if ( Aig_ObjFindSatAssign(pAig, pObj, 1, vSuppLits) )
283  {
284 // assert( Aig_ObjTerSimulate(pAig, pObj, vSuppLits) == AIG_VAL1 );
285 // if ( Aig_ObjTerSimulate(pAig, pObj, vSuppLits) != AIG_VAL1 )
286 // printf( "Justification error!\n" );
287  Count1++;
288  nTotalLits += Vec_IntSize(vSuppLits);
289  Aig_ManPackAddPattern( pPack, vSuppLits );
290  }
291  else
292  Count1f++;
293  }
294  }
295  Vec_IntFree( vSuppLits );
296  printf( "PO =%6d. C0 =%6d. C0f =%6d. C1 =%6d. C1f =%6d. (%6.2f %%) Ave =%4.1f ",
297  Aig_ManCoNum(pAig), Count0, Count0f, Count1, Count1f, 100.0*(Count0+Count1)/Aig_ManCoNum(pAig), 1.0*nTotalLits/(Count0+Count1) );
298  Abc_PrintTime( 1, "T", Abc_Clock() - clk );
299  Aig_ManCleanMarkAB( pAig );
300  Aig_ManPackStop( pPack );
301  Vec_IntFree( vNodes );
302 }
303 
304 
305 
306 
307 
308 
309 
310 ////////////////////////////////////////////////////////////////////////
311 /// END OF FILE ///
312 ////////////////////////////////////////////////////////////////////////
313 
314 
316 
#define AIG_VAL1
Definition: aigJust.c:31
static int Aig_ObjSatValue(Aig_Man_t *pAig, Aig_Obj_t *pNode, int fCompl)
FUNCTION DEFINITIONS ///.
Definition: aigJust.c:84
#define Aig_ManForEachObjVec(vIds, p, pObj, i)
Definition: aig.h:408
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static int Aig_ObjAndTerValue(int Value0, int Value1)
Definition: aigJust.c:56
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 Aig_ObjIsTravIdCurrent(Aig_Man_t *p, Aig_Obj_t *pObj)
Definition: aig.h:295
unsigned int fMarkB
Definition: aig.h:80
int Aig_ObjFindSatAssign(Aig_Man_t *pAig, Aig_Obj_t *pNode, int Value, Vec_Int_t *vSuppLits)
Definition: aigJust.c:162
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
unsigned int fMarkA
Definition: aig.h:79
static int Aig_ObjNotCondTerValue(int Value, int Cond)
Definition: aigJust.c:64
int Aig_ObjTerSimulate_rec(Aig_Man_t *pAig, Aig_Obj_t *pNode)
Definition: aigJust.c:188
static abctime Abc_Clock()
Definition: abc_global.h:279
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
#define AIG_VAL0
DECLARATIONS ///.
Definition: aigJust.c:30
Aig_Man_t * pAig
Definition: aigPack.c:34
void Aig_ManIncrementTravId(Aig_Man_t *p)
DECLARATIONS ///.
Definition: aigUtil.c:44
static void Abc_PrintTime(int level, const char *pStr, abctime time)
Definition: abc_global.h:367
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static int Abc_LitIsCompl(int Lit)
Definition: abc_global.h:265
void Aig_ManPackStop(Aig_ManPack_t *p)
Definition: aigPack.c:391
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static Aig_Obj_t * Aig_ManCi(Aig_Man_t *p, int i)
Definition: aig.h:266
static int Aig_ObjNotTerValue(int Value)
Definition: aigJust.c:48
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static int Aig_ObjIsConst1(Aig_Obj_t *pObj)
Definition: aig.h:274
Definition: aig.h:69
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Aig_ObjFaninC0(Aig_Obj_t *pObj)
Definition: aig.h:306
void Aig_ManPackAddPattern(Aig_ManPack_t *p, Vec_Int_t *vLits)
Definition: aigPack.c:326
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define AIG_VALX
Definition: aigJust.c:32
Vec_Int_t * Aig_ManPackConstNodes(Aig_ManPack_t *p)
Definition: aigPack.c:264
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
unsigned int fPhase
Definition: aig.h:78
void Aig_ManCleanMarkAB(Aig_Man_t *p)
Definition: aigUtil.c:186
static int Aig_ObjSetTerValue(Aig_Obj_t *pNode, int Value)
Definition: aigJust.c:35
static int Abc_Lit2Var(int Lit)
Definition: abc_global.h:264
static int Aig_ObjFaninC1(Aig_Obj_t *pObj)
Definition: aig.h:307
void Aig_ManJustExperiment(Aig_Man_t *pAig)
Definition: aigJust.c:251
int Aig_ObjTerSimulate(Aig_Man_t *pAig, Aig_Obj_t *pNode, Vec_Int_t *vSuppLits)
Definition: aigJust.c:217
#define assert(ex)
Definition: util_old.h:213
Aig_ManPack_t * Aig_ManPackStart(Aig_Man_t *pAig)
Definition: aigPack.c:370
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static int Aig_ObjIsCi(Aig_Obj_t *pObj)
Definition: aig.h:275
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
int Aig_NtkFindSatAssign_rec(Aig_Man_t *pAig, Aig_Obj_t *pNode, int Value, Vec_Int_t *vSuppLits, int Heur)
Definition: aigJust.c:102
static int Aig_ObjIsCo(Aig_Obj_t *pObj)
Definition: aig.h:276
static int Aig_ObjGetTerValue(Aig_Obj_t *pNode)
Definition: aigJust.c:42
static int Aig_ObjCioId(Aig_Obj_t *pObj)
Definition: aig.h:285