30static inline unsigned * Cec_ManIsoInfo(
unsigned * pStore,
int nWords,
int Id ) {
return pStore +
nWords * Id; }
47static inline void Gia_ManIsoSimulate(
Gia_Obj_t * pObj,
int Id,
unsigned * pStore,
int nWords )
49 unsigned * pInfo = Cec_ManIsoInfo( pStore,
nWords, Id );
50 unsigned * pInfo0 = Cec_ManIsoInfo( pStore,
nWords, Gia_ObjFaninId0(pObj, Id) );
51 unsigned * pInfo1 = Cec_ManIsoInfo( pStore,
nWords, Gia_ObjFaninId1(pObj, Id) );
53 if ( Gia_ObjFaninC0(pObj) )
55 if ( Gia_ObjFaninC1(pObj) )
56 for ( w = 0; w <
nWords; w++ )
57 pInfo[w] = ~(pInfo0[w] | pInfo1[w]);
59 for ( w = 0; w <
nWords; w++ )
60 pInfo[w] = ~pInfo0[w] & pInfo1[w];
64 if ( Gia_ObjFaninC1(pObj) )
65 for ( w = 0; w <
nWords; w++ )
66 pInfo[w] = pInfo0[w] & ~pInfo1[w];
68 for ( w = 0; w <
nWords; w++ )
69 pInfo[w] = pInfo0[w] & pInfo1[w];
84static inline void Gia_ManIsoCopy(
int IdDest,
int IdSour,
unsigned * pStore,
int nWords )
86 unsigned * pInfo0 = Cec_ManIsoInfo( pStore,
nWords, IdDest );
87 unsigned * pInfo1 = Cec_ManIsoInfo( pStore,
nWords, IdSour );
89 for ( w = 0; w <
nWords; w++ )
90 pInfo0[w] = pInfo1[w];
104static inline int Gia_ManIsoEqual(
int Id0,
int Id1,
unsigned * pStore,
int nWords )
106 unsigned * pInfo0 = Cec_ManIsoInfo( pStore,
nWords, Id0 );
107 unsigned * pInfo1 = Cec_ManIsoInfo( pStore,
nWords, Id1 );
109 for ( w = 0; w <
nWords; w++ )
110 if ( pInfo0[w] != pInfo1[w] )
126static inline void Gia_ManIsoRandom(
int Id,
unsigned * pStore,
int nWords )
128 unsigned * pInfo0 = Cec_ManIsoInfo( pStore,
nWords, Id );
130 for ( w = 0; w <
nWords; w++ )
145static inline int Gia_ManIsoHashKey(
int Id,
unsigned * pStore,
int nWords,
int nTableSize )
147 static int s_Primes[16] = {
148 1291, 1699, 1999, 2357, 2953, 3313, 3907, 4177,
149 4831, 5147, 5647, 6343, 6899, 7103, 7873, 8147 };
150 unsigned * pInfo0 = Cec_ManIsoInfo( pStore,
nWords, Id );
153 for ( i = 0; i <
nWords; i++ )
154 uHash ^= pInfo0[i] * s_Primes[i & 0xf];
155 return (
int)(uHash % nTableSize);
170static inline void Gia_ManIsoTableAdd(
Gia_Man_t *
p,
int Id,
unsigned * pStore,
int nWords,
int * pTable,
int nTableSize )
173 int Key, Ent, Color = Gia_ObjColors(
p, Id );
174 assert( Color == 1 || Color == 2 );
175 Key = Gia_ManIsoHashKey( Id, pStore,
nWords, nTableSize );
176 for ( Ent = pTable[Key], pTemp = (Ent ? Gia_ManObj(
p, Ent) : NULL); pTemp;
177 Ent = pTemp->
Value, pTemp = (Ent ? Gia_ManObj(
p, Ent) : NULL) )
179 if ( Gia_ObjColors(
p, Ent ) != Color )
181 if ( !Gia_ManIsoEqual( Id, Ent, pStore,
nWords ) )
188 pTemp = Gia_ManObj(
p, Id );
191 pTemp->
Value = pTable[Key];
210 Vec_IntClear( vNodesA );
211 Vec_IntClear( vNodesB );
212 for ( Ent = Bin, pTemp = (Ent ? Gia_ManObj(
p, Ent) : NULL); pTemp;
213 Ent = pTemp->
Value, pTemp = (Ent ? Gia_ManObj(
p, Ent) : NULL) )
220 if ( Gia_ObjColors(
p, Ent ) == 1 )
221 Vec_IntPush( vNodesA, Ent );
223 Vec_IntPush( vNodesB, Ent );
225 return Vec_IntSize(vNodesA) > 0 && Vec_IntSize(vNodesB) > 0;
239static inline void Gia_ManIsoMatchNodes(
int * pIso,
unsigned * pStore,
int nWords,
Vec_Int_t * vNodesA,
Vec_Int_t * vNodesB )
241 int k0, k1, IdA, IdB;
245 if ( Gia_ManIsoEqual( IdA, IdB, pStore,
nWords ) )
272 assert(
p->pReprs &&
p->pNexts &&
p->pIso );
273 memset(
p->pReprs, 0,
sizeof(
int) * Gia_ManObjNum(
p) );
274 memset(
p->pNexts, 0,
sizeof(
int) * Gia_ManObjNum(
p) );
278 if (
p->pIso[i] &&
p->pIso[i] < i )
280 p->pReprs[i].iRepr =
p->pIso[i];
281 p->pNexts[
p->pIso[i]] = i;
302 unsigned * pStore, Counter;
303 int i, * pIso, * pTable, nTableSize;
308 if ( Gia_ObjIsCo(pObj) )
310 assert( Gia_ObjColors(
p, i) == 0 );
314 if ( Gia_ObjColors(
p, i) == 3 )
320 nTableSize = Abc_PrimeCudd( 100 + Gia_ManObjNum(
p)/2 );
325 if ( Gia_ObjIsCo(pObj) )
328 Gia_ManIsoSimulate( pObj, i, pStore,
nWords );
329 else if ( pIso[i] < i )
330 Gia_ManIsoCopy( i, pIso[i], pStore,
nWords );
332 Gia_ManIsoRandom( i, pStore,
nWords );
334 Gia_ManIsoTableAdd(
p, i, pStore,
nWords, pTable, nTableSize );
337 vNodesA = Vec_IntAlloc( 100 );
338 vNodesB = Vec_IntAlloc( 100 );
339 for ( i = 0; i < nTableSize; i++ )
340 if ( Gia_ManIsoExtractClasses(
p, pTable[i], pStore,
nWords, vNodesA, vNodesB ) )
341 Gia_ManIsoMatchNodes( pIso, pStore,
nWords, vNodesA, vNodesB );
342 Vec_IntFree( vNodesA );
343 Vec_IntFree( vNodesB );
348 Counter += (pIso[i] && pIso[i] < i);
360 Abc_Print( 1,
"Computed %d pairs of structurally equivalent nodes.\n", Counter );
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Cec_ManTransformClasses(Gia_Man_t *p)
int * Cec_ManDetectIsomorphism(Gia_Man_t *p)
struct Gia_Obj_t_ Gia_Obj_t
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObj1(p, pObj, i)
void Gia_ManCleanValue(Gia_Man_t *p)
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.