ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
gia.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "misc/util/utilTruth.h"
23
25
26
30
31typedef struct Slv_Man_t_ Slv_Man_t;
42
43static inline int Slv_ManObjNum ( Slv_Man_t * p ) { return Vec_IntSize(&p->vFanins)/2; }
44
45static inline int Slv_ObjFaninLit ( Slv_Man_t * p, int iObj, int f ) { return Vec_IntEntry(&p->vFanins, Abc_Var2Lit(iObj, f)); }
46static inline int Slv_ObjFanin ( Slv_Man_t * p, int iObj, int f ) { return Abc_Lit2Var(Slv_ObjFaninLit(p, iObj, f)); }
47static inline int Slv_ObjFaninC ( Slv_Man_t * p, int iObj, int f ) { return Abc_LitIsCompl(Slv_ObjFaninLit(p, iObj, f)); }
48
49static inline int Slv_ObjIsCi ( Slv_Man_t * p, int iObj ) { return !Slv_ObjFaninLit(p, iObj, 0) && Slv_ObjFaninLit(p, iObj, 1); }
50static inline int Slv_ObjIsCo ( Slv_Man_t * p, int iObj ) { return Slv_ObjFaninLit(p, iObj, 0) && !Slv_ObjFaninLit(p, iObj, 1); }
51static inline int Slv_ObjIsAnd ( Slv_Man_t * p, int iObj ) { return Slv_ObjFaninLit(p, iObj, 0) && Slv_ObjFaninLit(p, iObj, 1); }
52
53static inline int Slv_ObjFanout0 ( Slv_Man_t * p, int iObj ) { return Vec_IntEntry(&p->vFanout0, iObj); }
54static inline void Slv_ObjSetFanout0 ( Slv_Man_t * p, int iObj, int iLit ) { Vec_IntWriteEntry(&p->vFanout0, iObj, iLit); }
55
56static inline int Slv_ObjNextFanout ( Slv_Man_t * p, int iLit ) { return Vec_IntEntry(&p->vFanoutN, iLit); }
57static inline void Slv_ObjSetNextFanout( Slv_Man_t * p, int iLit, int iLitF ) { Vec_IntWriteEntry(&p->vFanoutN, iLit, iLitF); }
58
59static inline int Slv_ObjCopyLit ( Slv_Man_t * p, int iObj ) { return Vec_IntEntry(&p->vCopies, iObj); }
60static inline void Slv_ObjSetCopyLit ( Slv_Man_t * p, int iObj, int iLit ) { Vec_IntWriteEntry(&p->vCopies, iObj, iLit); }
61
62#define Slv_ManForEachObj( p, iObj ) \
63 for ( iObj = 1; iObj < Slv_ManObjNum(p); iObj++ )
64
65#define Slv_ObjForEachFanout( p, iObj, iFanLit ) \
66 for ( iFanLit = Slv_ObjFanout0(p, iObj); iFanLit; iFanLit = Slv_ObjNextFanout(p, iFanLit) )
67
71
83Slv_Man_t * Slv_ManAlloc( int nObjs )
84{
86 Vec_IntGrow( &p->vCis, 100 );
87 Vec_IntGrow( &p->vCos, 100 );
88 Vec_IntGrow( &p->vFanins, 2*nObjs );
89 Vec_IntGrow( &p->vFanoutN, 2*nObjs );
90 Vec_IntGrow( &p->vFanout0, nObjs );
91 Vec_StrGrow( &p->vValues, nObjs );
92 // constant node
93 Vec_IntFill( &p->vFanins, 2, 0 );
94 Vec_IntFill( &p->vFanoutN, 2, 0 );
95 Vec_IntFill( &p->vFanout0, 1, 0 );
96 return p;
97}
99{
100 Vec_IntErase( &p->vCis );
101 Vec_IntErase( &p->vCos );
102 Vec_IntErase( &p->vFanins );
103 Vec_IntErase( &p->vFanoutN );
104 Vec_IntErase( &p->vFanout0 );
105 Vec_StrErase( &p->vValues );
106 Vec_IntErase( &p->vCopies );
107 ABC_FREE( p );
108}
110{
111 int iObj, iFanLit;
112 Slv_ManForEachObj( p, iObj )
113 {
114 printf( "Fanouts of node %d: ", iObj );
115 Slv_ObjForEachFanout( p, iObj, iFanLit )
116 printf( "%d ", Abc_Lit2Var(iFanLit) );
117 printf( "\n" );
118 }
119}
120static inline int Slv_ManAppendObj( Slv_Man_t * p, int iLit0, int iLit1 )
121{
122 int iObj = Slv_ManObjNum(p);
123 Vec_StrPush( &p->vValues, 0 );
124 Vec_IntPush( &p->vFanout0, 0 );
125 Vec_IntPushTwo( &p->vFanoutN, 0, 0 );
126 if ( !iLit0 ) // primary input
127 assert(!iLit1), iLit1 = Vec_IntSize(&p->vCis)+1, Vec_IntPush(&p->vCis, iObj);
128 else if ( !iLit1 ) // primary output
129 assert(iLit0), Vec_IntPush(&p->vCos, iObj);
130 else
131 {
132 Slv_ObjSetNextFanout( p, Abc_Var2Lit(iObj, 0), Slv_ObjFanout0(p, Abc_Lit2Var(iLit0)) );
133 Slv_ObjSetNextFanout( p, Abc_Var2Lit(iObj, 1), Slv_ObjFanout0(p, Abc_Lit2Var(iLit1)) );
134 Slv_ObjSetFanout0( p, Abc_Lit2Var(iLit0), Abc_Var2Lit(iObj, 0) );
135 Slv_ObjSetFanout0( p, Abc_Lit2Var(iLit1), Abc_Var2Lit(iObj, 1) );
136 }
137 Vec_IntPushTwo( &p->vFanins, iLit0, iLit1 );
138 return Abc_Var2Lit( iObj, 0 );
139}
140
153{
154 Gia_Obj_t * pObj; int i;
155 Slv_Man_t * pNew = Slv_ManAlloc( Gia_ManObjNum(p) );
156 Gia_ManConst0(p)->Value = 0;
157 Gia_ManForEachObj1( p, pObj, i )
158 {
159 if ( Gia_ObjIsAnd(pObj) )
160 pObj->Value = Slv_ManAppendObj( pNew, Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj)), Abc_LitNotCond(Gia_ObjFanin1(pObj)->Value, Gia_ObjFaninC1(pObj)) );
161 else if ( Gia_ObjIsCo(pObj) )
162 pObj->Value = Slv_ManAppendObj( pNew, Abc_LitNotCond(Gia_ObjFanin0(pObj)->Value, Gia_ObjFaninC0(pObj)), 0 );
163 else if ( Gia_ObjIsCi(pObj) )
164 pObj->Value = Slv_ManAppendObj( pNew, 0, 0 );
165 else
166 assert( 0 );
167 }
168 assert( Gia_ManObjNum(p) == Slv_ManObjNum(pNew) );
169 return pNew;
170}
172{
173 int iObj;
174 Gia_Man_t * pNew = Gia_ManStart( Slv_ManObjNum(p) );
175 Vec_IntFill( &p->vCopies, Slv_ManObjNum(p), 0 );
176 Slv_ManForEachObj( p, iObj )
177 if ( Slv_ObjIsCi(p, iObj) )
178 Slv_ObjSetCopyLit( p, iObj, Gia_ManAppendCi(pNew) );
179 else if ( Slv_ObjIsCo(p, iObj) )
180 {
181 int iLit0 = Abc_LitNotCond( Slv_ObjCopyLit(p, Slv_ObjFanin(p, iObj, 0)), Slv_ObjFaninC(p, iObj, 0) );
182 Slv_ObjSetCopyLit( p, iObj, Gia_ManAppendCo(pNew, iLit0) );
183 }
184 else if ( Slv_ObjIsAnd(p, iObj) )
185 {
186 int iLit0 = Abc_LitNotCond( Slv_ObjCopyLit(p, Slv_ObjFanin(p, iObj, 0)), Slv_ObjFaninC(p, iObj, 0) );
187 int iLit1 = Abc_LitNotCond( Slv_ObjCopyLit(p, Slv_ObjFanin(p, iObj, 1)), Slv_ObjFaninC(p, iObj, 1) );
188 Slv_ObjSetCopyLit( p, iObj, Gia_ManAppendAnd(pNew, iLit0, iLit1) );
189 }
190 else assert(0);
191 assert( Gia_ManObjNum(pNew) == Slv_ManObjNum(p) );
192 return pNew;
193}
194
196{
197 Slv_Man_t * p = Slv_ManFromGia( pGia );
198 Gia_Man_t * pNew = Slv_ManToGia( p );
199 pNew->pName = Abc_UtilStrsav( pGia->pName );
200 pNew->pSpec = Abc_UtilStrsav( pGia->pSpec );
202 Slv_ManFree( p );
203 return pNew;
204}
205
206
207
220{
221 Gia_Man_t * pNew, * pTemp;
222 Gia_Obj_t * pObj; int i, m;
223 pNew = Gia_ManStart( 1000 );
224 pNew->pName = Abc_UtilStrsav( p->pName );
225 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
226 Gia_ManForEachPi( p, pObj, i )
227 Gia_ManAppendCi( pNew );
228 Gia_ManHashStart( pNew );
229 for ( m = 0; m < (1 << nVars); m++ )
230 {
232 Gia_ManConst0(p)->Value = 0;
233 Gia_ManForEachPi( p, pObj, i )
234 {
235 if ( i < nVars )
236 pObj->Value = (m >> i) & 1;
237 else
238 pObj->Value = Gia_ObjToLit(pNew, Gia_ManCi(pNew, i));
239 }
240 Gia_ManForEachAnd( p, pObj, i )
241 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
242 Gia_ManForEachPo( p, pObj, i )
243 Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
244 }
245 Gia_ManHashStop( pNew );
246 pNew = Gia_ManCleanup( pTemp = pNew );
247 Gia_ManStop( pTemp );
248 return pNew;
249}
250
251
252
265{
266 extern int Cec_ManVerifyTwo( Gia_Man_t * p0, Gia_Man_t * p1, int fVerbose );
267 Gia_Man_t * pTemp, * pUsed;
268 Vec_Ptr_t * vGias = Vec_PtrAlloc( 100 );
269 Gia_Obj_t * pObj; int i, k;
270 Gia_ManForEachCo( p, pObj, i )
271 {
272 int iFan0 = Gia_ObjFaninId0p(p, pObj);
273 pTemp = Gia_ManDupAndCones( p, &iFan0, 1, 1 );
274 Vec_PtrForEachEntry( Gia_Man_t *, vGias, pUsed, k )
275 if ( Gia_ManCiNum(pTemp) == Gia_ManCiNum(pUsed) && Cec_ManVerifyTwo(pTemp, pUsed, 0) == 1 )
276 {
277 ABC_SWAP( void *, Vec_PtrArray(vGias)[0], Vec_PtrArray(vGias)[k] );
278 break;
279 }
280 else
281 ABC_FREE( pTemp->pCexComb );
282
283 printf( "\nOut %6d : ", i );
284 if ( k == Vec_PtrSize(vGias) )
285 printf( "Equiv to none " );
286 else
287 printf( "Equiv to %6d ", k );
288 Gia_ManPrintStats( pTemp, NULL );
289
290 if ( k == Vec_PtrSize(vGias) )
291 Vec_PtrPush( vGias, pTemp );
292 else
293 Gia_ManStop( pTemp );
294 }
295 printf( "\nComputed %d classes.\n\n", Vec_PtrSize(vGias) );
296 Vec_PtrForEachEntry( Gia_Man_t *, vGias, pTemp, i )
297 Gia_ManStop( pTemp );
298 Vec_PtrFree( vGias );
299}
300
312int Gia_EnumFirstUnused( int * pUsed, int nVars )
313{
314 int i;
315 for ( i = 0; i < nVars; i++ )
316 if ( pUsed[i] == 0 )
317 return i;
318 return -1;
319}
320void Gia_EnumPerms_rec( int * pUsed, int nVars, int * pPerm, int nPerm, int * pCount, FILE * pFile, int nLogVars )
321{
322 int i, k, New;
323 if ( nPerm == nVars )
324 {
325 if ( pFile )
326 {
327 for ( i = 0; i < nLogVars; i++ )
328 fprintf( pFile, "%c", '0' + ((*pCount) >> (nLogVars-1-i) & 1) );
329 fprintf( pFile, " " );
330 for ( i = 0; i < nVars; i++ )
331 for ( k = 0; k < nVars; k++ )
332 fprintf( pFile, "%c", '0' + (pPerm[i] == k) );
333 fprintf( pFile, "\n" );
334 }
335 else
336 {
337 if ( *pCount < 20 )
338 {
339 printf( "%5d : ", (*pCount) );
340 for ( i = 0; i < nVars; i += 2 )
341 printf( "%d %d ", pPerm[i], pPerm[i+1] );
342 printf( "\n" );
343 }
344 }
345 (*pCount)++;
346 return;
347 }
348 New = Gia_EnumFirstUnused( pUsed, nVars );
349 assert( New >= 0 );
350 pPerm[nPerm] = New;
351 assert( pUsed[New] == 0 );
352 pUsed[New] = 1;
353 // try remaining ones
354 for ( i = 0; i < nVars; i++ )
355 {
356 if ( pUsed[i] == 1 )
357 continue;
358 pPerm[nPerm+1] = i;
359 assert( pUsed[i] == 0 );
360 pUsed[i] = 1;
361 Gia_EnumPerms_rec( pUsed, nVars, pPerm, nPerm+2, pCount, pFile, nLogVars );
362 assert( pUsed[i] == 1 );
363 pUsed[i] = 0;
364 }
365 assert( pUsed[New] == 1 );
366 pUsed[New] = 0;
367}
368void Gia_EnumPerms( int nVars )
369{
370 int nLogVars = 0, Count = 0;
371 int * pUsed = ABC_CALLOC( int, nVars );
372 int * pPerm = ABC_CALLOC( int, nVars );
373 FILE * pFile = fopen( "pairset.pla", "wb" );
374 assert( nVars % 2 == 0 );
375
376 printf( "Printing sets of pairs for %d objects:\n", nVars );
377 Gia_EnumPerms_rec( pUsed, nVars, pPerm, 0, &Count, NULL, -1 );
378 if ( Count > 20 )
379 printf( "...\n" );
380 printf( "Finished enumerating %d sets of pairs.\n", Count );
381
382 nLogVars = Abc_Base2Log( Count );
383 printf( "Need %d variables to encode %d sets.\n", nLogVars, Count );
384 Count = 0;
385 fprintf( pFile, ".i %d\n", nLogVars );
386 fprintf( pFile, ".o %d\n", nVars*nVars );
387 Gia_EnumPerms_rec( pUsed, nVars, pPerm, 0, &Count, pFile, nLogVars );
388 fprintf( pFile, ".e\n" );
389 fclose( pFile );
390 printf( "Finished dumping file \"%s\".\n", "pairset.pla" );
391
392 ABC_FREE( pUsed );
393 ABC_FREE( pPerm );
394}
395
399
400
402
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
#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
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
int Cec_ManVerifyTwo(Gia_Man_t *p0, Gia_Man_t *p1, int fVerbose)
Definition cecCec.c:453
Cube * p
Definition exorList.c:222
void Slv_ManFree(Slv_Man_t *p)
Definition gia.c:98
void Gia_ManStructExperiment(Gia_Man_t *p)
Definition gia.c:264
Gia_Man_t * Slv_ManToAig(Gia_Man_t *pGia)
Definition gia.c:195
#define Slv_ObjForEachFanout(p, iObj, iFanLit)
Definition gia.c:65
void Gia_EnumPerms(int nVars)
Definition gia.c:368
typedefABC_NAMESPACE_IMPL_START struct Slv_Man_t_ Slv_Man_t
DECLARATIONS ///.
Definition gia.c:31
#define Slv_ManForEachObj(p, iObj)
Definition gia.c:62
void Gia_EnumPerms_rec(int *pUsed, int nVars, int *pPerm, int nPerm, int *pCount, FILE *pFile, int nLogVars)
Definition gia.c:320
Slv_Man_t * Slv_ManFromGia(Gia_Man_t *p)
Definition gia.c:152
Gia_Man_t * Slv_ManToGia(Slv_Man_t *p)
Definition gia.c:171
int Gia_EnumFirstUnused(int *pUsed, int nVars)
Definition gia.c:312
void Slv_ManPrintFanouts(Slv_Man_t *p)
Definition gia.c:109
Gia_Man_t * Gia_ManCofPisVars(Gia_Man_t *p, int nVars)
Definition gia.c:219
Slv_Man_t * Slv_ManAlloc(int nObjs)
FUNCTION DEFINITIONS ///.
Definition gia.c:83
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
void Gia_ManHashStart(Gia_Man_t *p)
Definition giaHash.c:125
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition giaMan.c:495
Gia_Man_t * Gia_ManDupAndCones(Gia_Man_t *p, int *pAnds, int nAnds, int fTrimPis)
Definition giaDup.c:3941
char * pSpec
Definition gia.h:100
Abc_Cex_t * pCexComb
Definition gia.h:149
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
Vec_Int_t vFanout0
Definition gia.c:38
Vec_Int_t vCos
Definition gia.c:35
Vec_Int_t vFanins
Definition gia.c:36
Vec_Int_t vCis
Definition gia.c:34
Vec_Str_t vValues
Definition gia.c:39
Vec_Int_t vFanoutN
Definition gia.c:37
Vec_Int_t vCopies
Definition gia.c:40
#define assert(ex)
Definition util_old.h:213
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55