ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sscClass.c
Go to the documentation of this file.
1
20
21#include "sscInt.h"
22
24
25
29
33
45static 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
73static 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}
91static 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}
110static 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
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
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;
180 Ssc_GiaSimClassCreate( p, p->vClassOld );
181 Ssc_GiaSimClassCreate( p, p->vClassNew );
182 return 1;
183}
184
185
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;
215 Ssc_GiaSimClassCreate( p, p->vClassOld );
216 Ssc_GiaSimClassCreate( p, p->vClassNew );
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 ) )
251 ABC_FREE( pTable );
252}
253
266{
267 Gia_Obj_t * pObj;
268 int i;
269 assert( p->pReprs == NULL );
270 p->pReprs = ABC_CALLOC( Gia_Rpr_t, Gia_ManObjNum(p) );
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 assert( 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
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
323
324
326
int nWords
Definition abcNpn.c:127
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
struct Gia_Rpr_t_ Gia_Rpr_t
Definition gia.h:57
#define Gia_ManForEachCand(p, pObj, i)
Definition gia.h:1220
#define Gia_ClassForEachObj1(p, i, iObj)
Definition gia.h:1109
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
#define GIA_VOID
Definition gia.h:46
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
void Ssc_GiaSimProcessRefined(Gia_Man_t *p, Vec_Int_t *vRefined)
Definition sscClass.c:221
void Ssc_GiaClassesCheckPairs(Gia_Man_t *p, Vec_Int_t *vDisPairs)
Definition sscClass.c:309
int Ssc_GiaSimClassRefineOne(Gia_Man_t *p, int i)
Definition sscClass.c:197
void Ssc_GiaClassesInit(Gia_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition sscClass.c:265
void Ssc_GiaSimClassCreate(Gia_Man_t *p, Vec_Int_t *vClass)
Definition sscClass.c:128
int Ssc_GiaSimClassRefineOneBit(Gia_Man_t *p, int i)
Definition sscClass.c:162
int Ssc_GiaClassesRefine(Gia_Man_t *p)
Definition sscClass.c:279
unsigned fPhase
Definition gia.h:87
unsigned fMark0
Definition gia.h:81
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54