abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sscClass.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [sscClass.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [SAT sweeping under constraints.]
8 
9  Synopsis [Equivalence classes.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 29, 2008.]
16 
17  Revision [$Id: sscClass.c,v 1.00 2008/07/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "sscInt.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Computes hash key of the simuation info.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 static inline int Ssc_GiaSimHashKey( Gia_Man_t * p, int iObj, int nTableSize )
46 {
47  static int s_Primes[16] = {
48  1291, 1699, 1999, 2357, 2953, 3313, 3907, 4177,
49  4831, 5147, 5647, 6343, 6899, 7103, 7873, 8147 };
50  word * pSim = Gia_ObjSim( p, iObj );
51  unsigned uHash = 0;
52  int i, nWords = Gia_ObjSimWords(p);
53  if ( pSim[0] & 1 )
54  for ( i = 0; i < nWords; i++ )
55  uHash ^= ~pSim[i] * s_Primes[i & 0xf];
56  else
57  for ( i = 0; i < nWords; i++ )
58  uHash ^= pSim[i] * s_Primes[i & 0xf];
59  return (int)(uHash % nTableSize);
60 }
61 
62 /**Function*************************************************************
63 
64  Synopsis [Returns 1 if sim patterns are equal up to the complement.]
65 
66  Description []
67 
68  SideEffects []
69 
70  SeeAlso []
71 
72 ***********************************************************************/
73 static inline int Ssc_GiaSimIsConst0( Gia_Man_t * p, int iObj0 )
74 {
75  int w, nWords = Gia_ObjSimWords(p);
76  word * pSim = Gia_ObjSim( p, iObj0 );
77  if ( pSim[0] & 1 )
78  {
79  for ( w = 0; w < nWords; w++ )
80  if ( ~pSim[w] )
81  return 0;
82  }
83  else
84  {
85  for ( w = 0; w < nWords; w++ )
86  if ( pSim[w] )
87  return 0;
88  }
89  return 1;
90 }
91 static inline int Ssc_GiaSimAreEqual( Gia_Man_t * p, int iObj0, int iObj1 )
92 {
93  int w, nWords = Gia_ObjSimWords(p);
94  word * pSim0 = Gia_ObjSim( p, iObj0 );
95  word * pSim1 = Gia_ObjSim( p, iObj1 );
96  if ( (pSim0[0] & 1) != (pSim1[0] & 1) )
97  {
98  for ( w = 0; w < nWords; w++ )
99  if ( pSim0[w] != ~pSim1[w] )
100  return 0;
101  }
102  else
103  {
104  for ( w = 0; w < nWords; w++ )
105  if ( pSim0[w] != pSim1[w] )
106  return 0;
107  }
108  return 1;
109 }
110 static inline int Ssc_GiaSimAreEqualBit( Gia_Man_t * p, int iObj0, int iObj1 )
111 {
112  Gia_Obj_t * pObj0 = Gia_ManObj( p, iObj0 );
113  Gia_Obj_t * pObj1 = Gia_ManObj( p, iObj1 );
114  return (pObj0->fPhase ^ pObj0->fMark0) == (pObj1->fPhase ^ pObj1->fMark0);
115 }
116 
117 /**Function*************************************************************
118 
119  Synopsis [Refines one equivalence class.]
120 
121  Description []
122 
123  SideEffects []
124 
125  SeeAlso []
126 
127 ***********************************************************************/
129 {
130  int Repr = GIA_VOID, EntPrev = -1, Ent, i;
131  assert( Vec_IntSize(vClass) > 0 );
132  Vec_IntForEachEntry( vClass, Ent, i )
133  {
134  if ( i == 0 )
135  {
136  Repr = Ent;
137  Gia_ObjSetRepr( p, Ent, GIA_VOID );
138  EntPrev = Ent;
139  }
140  else
141  {
142  assert( Repr < Ent );
143  Gia_ObjSetRepr( p, Ent, Repr );
144  Gia_ObjSetNext( p, EntPrev, Ent );
145  EntPrev = Ent;
146  }
147  }
148  Gia_ObjSetNext( p, EntPrev, 0 );
149 }
150 
151 /**Function*************************************************************
152 
153  Synopsis [Refines one equivalence class using individual bit-pattern.]
154 
155  Description []
156 
157  SideEffects []
158 
159  SeeAlso []
160 
161 ***********************************************************************/
163 {
164  Gia_Obj_t * pObj;
165  int Ent;
166  assert( Gia_ObjIsHead( p, i ) );
167  Vec_IntClear( p->vClassOld );
168  Vec_IntClear( p->vClassNew );
169  Vec_IntPush( p->vClassOld, i );
170  pObj = Gia_ManObj(p, i);
171  Gia_ClassForEachObj1( p, i, Ent )
172  {
173  if ( Ssc_GiaSimAreEqualBit( p, i, Ent ) )
174  Vec_IntPush( p->vClassOld, Ent );
175  else
176  Vec_IntPush( p->vClassNew, Ent );
177  }
178  if ( Vec_IntSize( p->vClassNew ) == 0 )
179  return 0;
182  return 1;
183 }
184 
185 
186 /**Function*************************************************************
187 
188  Synopsis [Refines one class using simulation patterns.]
189 
190  Description []
191 
192  SideEffects []
193 
194  SeeAlso []
195 
196 ***********************************************************************/
198 {
199  Gia_Obj_t * pObj;
200  int Ent;
201  assert( Gia_ObjIsHead( p, i ) );
202  Vec_IntClear( p->vClassOld );
203  Vec_IntClear( p->vClassNew );
204  Vec_IntPush( p->vClassOld, i );
205  pObj = Gia_ManObj(p, i);
206  Gia_ClassForEachObj1( p, i, Ent )
207  {
208  if ( Ssc_GiaSimAreEqual( p, i, Ent ) )
209  Vec_IntPush( p->vClassOld, Ent );
210  else
211  Vec_IntPush( p->vClassNew, Ent );
212  }
213  if ( Vec_IntSize( p->vClassNew ) == 0 )
214  return 0;
217  if ( Vec_IntSize(p->vClassNew) > 1 )
218  return 1 + Ssc_GiaSimClassRefineOne( p, Vec_IntEntry(p->vClassNew,0) );
219  return 1;
220 }
222 {
223  int * pTable, nTableSize, i, k, Key;
224  if ( Vec_IntSize(vRefined) == 0 )
225  return;
226  nTableSize = Abc_PrimeCudd( 100 + Vec_IntSize(vRefined) / 3 );
227  pTable = ABC_CALLOC( int, nTableSize );
228  Vec_IntForEachEntry( vRefined, i, k )
229  {
230  assert( !Ssc_GiaSimIsConst0( p, i ) );
231  Key = Ssc_GiaSimHashKey( p, i, nTableSize );
232  if ( pTable[Key] == 0 )
233  {
234  assert( Gia_ObjRepr(p, i) == 0 );
235  assert( Gia_ObjNext(p, i) == 0 );
236  Gia_ObjSetRepr( p, i, GIA_VOID );
237  }
238  else
239  {
240  Gia_ObjSetNext( p, pTable[Key], i );
241  Gia_ObjSetRepr( p, i, Gia_ObjRepr(p, pTable[Key]) );
242  if ( Gia_ObjRepr(p, i) == GIA_VOID )
243  Gia_ObjSetRepr( p, i, pTable[Key] );
244  assert( Gia_ObjRepr(p, i) > 0 );
245  }
246  pTable[Key] = i;
247  }
248  Vec_IntForEachEntry( vRefined, i, k )
249  if ( Gia_ObjIsHead( p, i ) )
250  Ssc_GiaSimClassRefineOne( p, i );
251  ABC_FREE( pTable );
252 }
253 
254 /**Function*************************************************************
255 
256  Synopsis [Refines equivalence classes.]
257 
258  Description []
259 
260  SideEffects []
261 
262  SeeAlso []
263 
264 ***********************************************************************/
266 {
267  Gia_Obj_t * pObj;
268  int i;
269  assert( p->pReprs == NULL );
271  p->pNexts = ABC_CALLOC( int, Gia_ManObjNum(p) );
272  Gia_ManForEachObj( p, pObj, i )
273  Gia_ObjSetRepr( p, i, Gia_ObjIsCand(pObj) ? 0 : GIA_VOID );
274  if ( p->vClassOld == NULL )
275  p->vClassOld = Vec_IntAlloc( 100 );
276  if ( p->vClassNew == NULL )
277  p->vClassNew = Vec_IntAlloc( 100 );
278 }
280 {
281  Vec_Int_t * vRefinedC;
282  Gia_Obj_t * pObj;
283  int i, Counter = 0;
284  if ( p->pReprs != NULL );
285  vRefinedC = Vec_IntAlloc( 100 );
286  Gia_ManForEachCand( p, pObj, i )
287  if ( Gia_ObjIsTail(p, i) )
288  Counter += Ssc_GiaSimClassRefineOne( p, Gia_ObjRepr(p, i) );
289  else if ( Gia_ObjIsConst(p, i) && !Ssc_GiaSimIsConst0(p, i) )
290  Vec_IntPush( vRefinedC, i );
291  Ssc_GiaSimProcessRefined( p, vRefinedC );
292  Counter += Vec_IntSize( vRefinedC );
293  Vec_IntFree( vRefinedC );
294  return Counter;
295 }
296 
297 
298 /**Function*************************************************************
299 
300  Synopsis [Check if the pairs have been disproved.]
301 
302  Description []
303 
304  SideEffects []
305 
306  SeeAlso []
307 
308 ***********************************************************************/
310 {
311  int i, iRepr, iObj, Result = 1;
312  Vec_IntForEachEntryDouble( vDisPairs, iRepr, iObj, i )
313  if ( iRepr == Gia_ObjRepr(p, iObj) )
314  printf( "Pair (%d, %d) are still equivalent.\n", iRepr, iObj ), Result = 0;
315 // if ( Result )
316 // printf( "Classes are refined correctly.\n" );
317 }
318 
319 
320 ////////////////////////////////////////////////////////////////////////
321 /// END OF FILE ///
322 ////////////////////////////////////////////////////////////////////////
323 
324 
326 
static int Abc_PrimeCudd(unsigned int p)
Definition: abc_global.h:383
int * pNexts
Definition: gia.h:122
static Llb_Mgr_t * p
Definition: llb3Image.c:950
int Ssc_GiaSimClassRefineOneBit(Gia_Man_t *p, int i)
Definition: sscClass.c:162
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Gia_ObjIsCand(Gia_Obj_t *pObj)
Definition: gia.h:429
Vec_Int_t * vClassOld
Definition: gia.h:179
static ABC_NAMESPACE_IMPL_START int Ssc_GiaSimHashKey(Gia_Man_t *p, int iObj, int nTableSize)
DECLARATIONS ///.
Definition: sscClass.c:45
void Ssc_GiaSimProcessRefined(Gia_Man_t *p, Vec_Int_t *vRefined)
Definition: sscClass.c:221
static int Gia_ObjIsHead(Gia_Man_t *p, int Id)
Definition: gia.h:916
int nWords
Definition: abcNpn.c:127
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
void Ssc_GiaClassesInit(Gia_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition: sscClass.c:265
int Ssc_GiaClassesRefine(Gia_Man_t *p)
Definition: sscClass.c:279
Vec_Int_t * vClassNew
Definition: gia.h:180
static void Gia_ObjSetRepr(Gia_Man_t *p, int Id, int Num)
Definition: gia.h:888
static int s_Primes[MAX_PRIMES]
Definition: fxuPair.c:30
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
static int Ssc_GiaSimAreEqualBit(Gia_Man_t *p, int iObj0, int iObj1)
Definition: sscClass.c:110
static int Ssc_GiaSimAreEqual(Gia_Man_t *p, int iObj0, int iObj1)
Definition: sscClass.c:91
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
static int Gia_ObjIsConst(Gia_Man_t *p, int Id)
Definition: gia.h:915
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Gia_ClassForEachObj1(p, i, iObj)
Definition: gia.h:933
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Counter
int Ssc_GiaSimClassRefineOne(Gia_Man_t *p, int i)
Definition: sscClass.c:197
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
#define Gia_ManForEachCand(p, pObj, i)
Definition: gia.h:1008
static int Gia_ObjNext(Gia_Man_t *p, int Id)
Definition: gia.h:912
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void Gia_ObjSetNext(Gia_Man_t *p, int Id, int Num)
Definition: gia.h:913
static int Gia_ObjIsTail(Gia_Man_t *p, int Id)
Definition: gia.h:918
unsigned fPhase
Definition: gia.h:85
#define GIA_VOID
Definition: gia.h:45
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
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
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
Gia_Rpr_t * pReprs
Definition: gia.h:121
#define assert(ex)
Definition: util_old.h:213
static word * Gia_ObjSim(Gia_Man_t *p, int Id)
Definition: gia.h:556
Definition: gia.h:56
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition: vecInt.h:54
static int Gia_ObjSimWords(Gia_Man_t *p)
Definition: gia.h:554
static int Ssc_GiaSimIsConst0(Gia_Man_t *p, int iObj0)
Definition: sscClass.c:73
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
static int Gia_ObjRepr(Gia_Man_t *p, int Id)
Definition: gia.h:887
void Ssc_GiaClassesCheckPairs(Gia_Man_t *p, Vec_Int_t *vDisPairs)
Definition: sscClass.c:309
void Ssc_GiaSimClassCreate(Gia_Man_t *p, Vec_Int_t *vClass)
Definition: sscClass.c:128