ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcDress3.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "base/io/ioAbc.h"
23#include "proof/cec/cec.h"
24
26
27
31
35
48{
49 assert( !Hop_IsComplement(pObj) );
50 if ( !Hop_ObjIsNode(pObj) || Hop_ObjIsMarkA(pObj) )
51 return;
52 Abc_ConvertHopToGia_rec1( p, Hop_ObjFanin0(pObj) );
53 Abc_ConvertHopToGia_rec1( p, Hop_ObjFanin1(pObj) );
54 pObj->iData = Gia_ManHashAnd( p, Hop_ObjChild0CopyI(pObj), Hop_ObjChild1CopyI(pObj) );
55 assert( !Hop_ObjIsMarkA(pObj) ); // loop detection
56 Hop_ObjSetMarkA( pObj );
57}
59{
60 assert( !Hop_IsComplement(pObj) );
61 if ( !Hop_ObjIsNode(pObj) || !Hop_ObjIsMarkA(pObj) )
62 return;
63 Abc_ConvertHopToGia_rec2( Hop_ObjFanin0(pObj) );
64 Abc_ConvertHopToGia_rec2( Hop_ObjFanin1(pObj) );
65 assert( Hop_ObjIsMarkA(pObj) ); // loop detection
66 Hop_ObjClearMarkA( pObj );
67}
69{
70 assert( !Hop_IsComplement(pRoot) );
71 if ( Hop_ObjIsConst1( pRoot ) )
72 return 1;
75 return pRoot->iData;
76}
77
90{
91 Hop_Man_t * pHopMan;
92 Hop_Obj_t * pHopObj;
93 Vec_Ptr_t * vNodes;
94 Abc_Obj_t * pNode, * pFanin;
95 int i, k;
96 assert( Abc_NtkIsAigLogic(pNtk) );
97 pHopMan = (Hop_Man_t *)pNtk->pManFunc;
98 Hop_ManConst1(pHopMan)->iData = 1;
99 // image primary inputs
100 Abc_NtkCleanCopy( pNtk );
101 Abc_NtkForEachCi( pNtk, pNode, i )
102 pNode->iTemp = Gia_ManCiLit(p, Vec_IntEntry(vMap, i));
103 // iterate through nodes used in the mapping
104 vNodes = Abc_NtkDfs( pNtk, 1 );
105 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
106 {
107 Abc_ObjForEachFanin( pNode, pFanin, k )
108 Hop_ManPi(pHopMan, k)->iData = pFanin->iTemp;
109 pHopObj = Hop_Regular( (Hop_Obj_t *)pNode->pData );
110 assert( Abc_ObjFaninNum(pNode) <= Hop_ManPiNum(pHopMan) );
111 if ( Hop_DagSize(pHopObj) > 0 )
112 Abc_ConvertHopToGia( p, pHopObj );
113 pNode->iTemp = Abc_LitNotCond( pHopObj->iData, Hop_IsComplement( (Hop_Obj_t *)pNode->pData ) );
114 }
115 Vec_PtrFree( vNodes );
116 // create primary outputs
117 Abc_NtkForEachCo( pNtk, pNode, i )
118 Gia_ManAppendCo( p, Abc_ObjFanin0(pNode)->iTemp );
119}
120Gia_Man_t * Abc_NtkAigToGiaTwo( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int fByName )
121{
122 Gia_Man_t * p;
123 Gia_Obj_t * pObj;
124 Abc_Obj_t * pNode;
125 Vec_Int_t * vMap1, * vMap2;
126 int i, Index = 0;
127 assert( Abc_NtkIsAigLogic(pNtk1) );
128 assert( Abc_NtkIsAigLogic(pNtk2) );
129 // find common variables
130 if ( fByName )
131 {
132 int nCommon = 0;
133 vMap1 = Vec_IntStartNatural( Abc_NtkCiNum(pNtk1) );
134 vMap2 = Vec_IntAlloc( Abc_NtkCiNum(pNtk2) );
135 Abc_NtkForEachCi( pNtk1, pNode, i )
136 pNode->iTemp = Index++;
137 assert( Index == Abc_NtkCiNum(pNtk1) );
138 Abc_NtkForEachCi( pNtk2, pNode, i )
139 {
140 int Num = Nm_ManFindIdByName( pNtk1->pManName, Abc_ObjName(pNode), ABC_OBJ_PI );
141 if ( Num < 0 )
142 Num = Nm_ManFindIdByName( pNtk1->pManName, Abc_ObjName(pNode), ABC_OBJ_BO );
143 assert( Num < 0 || Abc_ObjIsCi(Abc_NtkObj(pNtk1, Num)) );
144 if ( Num >= 0 )
145 Vec_IntPush( vMap2, Abc_NtkObj(pNtk1, Num)->iTemp ), nCommon++;
146 else
147 Vec_IntPush( vMap2, Index++ );
148 }
149 // report
150 printf( "Matched %d vars by name.", nCommon );
151 if ( nCommon != Abc_NtkCiNum(pNtk1) )
152 printf( " Netlist1 has %d unmatched vars.", Abc_NtkCiNum(pNtk1) - nCommon );
153 if ( nCommon != Abc_NtkCiNum(pNtk2) )
154 printf( " Netlist2 has %d unmatched vars.", Abc_NtkCiNum(pNtk2) - nCommon );
155 printf( "\n" );
156 }
157 else
158 {
159 vMap1 = Vec_IntStartNatural( Abc_NtkCiNum(pNtk1) );
160 vMap2 = Vec_IntStartNatural( Abc_NtkCiNum(pNtk2) );
161 Index = Abc_MaxInt( Vec_IntSize(vMap1), Vec_IntSize(vMap2) );
162 // report
163 printf( "Matched %d vars by order.", Abc_MinInt(Abc_NtkCiNum(pNtk1), Abc_NtkCiNum(pNtk2)) );
164 if ( Abc_NtkCiNum(pNtk1) < Abc_NtkCiNum(pNtk2) )
165 printf( " The last %d vars of Netlist2 are unmatched vars.", Abc_NtkCiNum(pNtk2) - Abc_NtkCiNum(pNtk1) );
166 if ( Abc_NtkCiNum(pNtk1) > Abc_NtkCiNum(pNtk2) )
167 printf( " The last %d vars of Netlist1 are unmatched vars.", Abc_NtkCiNum(pNtk1) - Abc_NtkCiNum(pNtk2) );
168 printf( "\n" );
169 }
170 // create new manager
171 p = Gia_ManStart( 10000 );
172 p->pName = Abc_UtilStrsav( Abc_NtkName(pNtk1) );
173 p->pSpec = Abc_UtilStrsav( Abc_NtkSpec(pNtk1) );
174 for ( i = 0; i < Index; i++ )
175 Gia_ManAppendCi(p);
176 // add logic
178 Abc_NtkAigToGiaOne( p, pNtk1, vMap1 );
179 Abc_NtkAigToGiaOne( p, pNtk2, vMap2 );
181 Vec_IntFree( vMap1 );
182 Vec_IntFree( vMap2 );
183 // add extra POs to dangling nodes
185 Gia_ManForEachAnd( p, pObj, i )
186 if ( pObj->Value == 0 )
187 Gia_ManAppendCo( p, Abc_Var2Lit(i, 0) );
188 return p;
189}
190
204static inline void Abc_NtkCollectAddOne( int iNtk, int iObj, int iGiaLit, Gia_Man_t * pGia, Vec_Int_t * vGia2Cla, Vec_Int_t * vNexts[2] )
205{
206 int iRepr = Gia_ObjReprSelf( pGia, Abc_Lit2Var(iGiaLit) );
207 int Compl = Abc_LitIsCompl(iGiaLit) ^ Gia_ObjPhase(Gia_ManObj(pGia, iRepr)) ^ Gia_ObjPhase(Gia_ManObj(pGia, Abc_Lit2Var(iGiaLit)));
208 int Added = Abc_Var2Lit( Abc_Var2Lit(iObj, Compl), iNtk );
209 int Entry = Vec_IntEntry( vGia2Cla, iRepr );
210 Vec_IntWriteEntry( vNexts[iNtk], iObj, Entry );
211 Vec_IntWriteEntry( vGia2Cla, iRepr, Added );
212}
214{
215 Vec_Int_t * vClass = Vec_IntAlloc( 100 );
216 Vec_Int_t * vClasses = Vec_IntAlloc( 1000 );
217 Vec_Int_t * vGia2Cla = Vec_IntStartFull( Gia_ManObjNum(pGia) ); // mapping objId into classId
218 Vec_Int_t * vNexts[2] = { Vec_IntStartFull(Abc_NtkObjNumMax(pNtks[0])), Vec_IntStartFull(Abc_NtkObjNumMax(pNtks[1])) };
219 Abc_Obj_t * pObj;
220 int n, i, k, Entry, fCompl;
221 Abc_NtkForEachCi( pNtks[0], pObj, i )
222 Abc_NtkCollectAddOne( 0, Abc_ObjId(pObj), pObj->iTemp, pGia, vGia2Cla, vNexts );
223 for ( n = 0; n < 2; n++ )
224 Abc_NtkForEachNode( pNtks[n], pObj, i )
225 Abc_NtkCollectAddOne( n, Abc_ObjId(pObj), pObj->iTemp, pGia, vGia2Cla, vNexts );
226 Vec_IntForEachEntry( vGia2Cla, Entry, i )
227 {
228 Vec_IntClear( vClass );
229 for ( ; Entry >= 0; Entry = Vec_IntEntry(vNexts[Entry&1], Entry>>2) )
230 Vec_IntPush( vClass, Entry );
231 if ( Vec_IntSize(vClass) < 2 )
232 continue;
233 Vec_IntReverseOrder( vClass );
234 fCompl = 2 & Vec_IntEntry( vClass, 0 );
235 Vec_IntForEachEntry( vClass, Entry, k )
236 Vec_IntWriteEntry( vClass, k, Entry ^ fCompl );
237 Vec_IntPush( vClasses, Vec_IntSize(vClass) );
238 Vec_IntAppend( vClasses, vClass );
239 }
240 Vec_IntFree( vGia2Cla );
241 Vec_IntFree( vNexts[0] );
242 Vec_IntFree( vNexts[1] );
243 Vec_IntFree( vClass );
244 return vClasses;
245}
246
258void Abc_NtkDumpEquivFile( char * pFileName, Vec_Int_t * vClasses, Abc_Ntk_t * pNtks[2] )
259{
260 int i, c, k, Entry;
261 FILE * pFile = fopen( pFileName, "wb" );
262 if ( pFile == NULL ) { printf( "Cannot open file %s for writing.\n", pFileName ); return; }
263 fprintf( pFile, "# Node equivalences computed by ABC for networks \"%s\" and \"%s\" on %s\n\n", Abc_NtkName(pNtks[0]), Abc_NtkName(pNtks[1]), Extra_TimeStamp() );
264 for ( i = c = 0; i < Vec_IntSize(vClasses); c++, i += 1 + Vec_IntEntry(vClasses, i) )
265 {
266 Vec_IntForEachEntryStartStop( vClasses, Entry, k, i + 1, i + 1 + Vec_IntEntry(vClasses, i) )
267 {
268 Abc_Ntk_t * pNtk = pNtks[Entry & 1];
269 char * pObjName = Abc_ObjName( Abc_NtkObj(pNtk, Entry>>2) );
270 fprintf( pFile, "%d:%s:%s%s\n", c+1, Abc_NtkName(pNtk), (Entry&2) ? "NOT:":"", pObjName );
271 }
272 fprintf( pFile, "\n" );
273 }
274 fclose( pFile );
275}
276
277
289void Abc_NtkDumpEquiv( Abc_Ntk_t * pNtks[2], char * pFileName, int nConfs, int fByName, int fVerbose )
290{
291 //abctime clk = Abc_Clock();
292 Gia_Man_t * pTemp;
293 Vec_Int_t * vClasses;
294 // derive shared AIG for the two networks
295 Gia_Man_t * pGia = Abc_NtkAigToGiaTwo( pNtks[0], pNtks[1], fByName );
296 if ( fVerbose )
297 printf( "Computing equivalences for networks \"%s\" and \"%s\" with conflict limit %d.\n", Abc_NtkName(pNtks[0]), Abc_NtkName(pNtks[1]), nConfs );
298 // compute equivalences in this AIG
299 pTemp = Gia_ManComputeGiaEquivs( pGia, nConfs, fVerbose );
300 Gia_ManStop( pTemp );
301 //if ( fVerbose )
302 // Abc_PrintTime( 1, "Equivalence computation time", Abc_Clock() - clk );
303 if ( fVerbose )
304 Gia_ManPrintStats( pGia, NULL );
305 // collect equivalence class information
306 vClasses = Abc_NtkCollectEquivClasses( pNtks, pGia );
307 Gia_ManStop( pGia );
308 // dump information into the output file
309 Abc_NtkDumpEquivFile( pFileName, vClasses, pNtks );
310 Vec_IntFree( vClasses );
311}
312
313
317
318
320
Gia_Man_t * Abc_NtkAigToGiaTwo(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int fByName)
Definition abcDress3.c:120
ABC_NAMESPACE_IMPL_START void Abc_ConvertHopToGia_rec1(Gia_Man_t *p, Hop_Obj_t *pObj)
DECLARATIONS ///.
Definition abcDress3.c:47
void Abc_NtkDumpEquivFile(char *pFileName, Vec_Int_t *vClasses, Abc_Ntk_t *pNtks[2])
Definition abcDress3.c:258
void Abc_ConvertHopToGia_rec2(Hop_Obj_t *pObj)
Definition abcDress3.c:58
void Abc_NtkDumpEquiv(Abc_Ntk_t *pNtks[2], char *pFileName, int nConfs, int fByName, int fVerbose)
Definition abcDress3.c:289
void Abc_NtkAigToGiaOne(Gia_Man_t *p, Abc_Ntk_t *pNtk, Vec_Int_t *vMap)
Definition abcDress3.c:89
Vec_Int_t * Abc_NtkCollectEquivClasses(Abc_Ntk_t *pNtks[2], Gia_Man_t *pGia)
Definition abcDress3.c:213
int Abc_ConvertHopToGia(Gia_Man_t *p, Hop_Obj_t *pRoot)
Definition abcDress3.c:68
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
@ ABC_OBJ_BO
Definition abc.h:92
@ ABC_OBJ_PI
Definition abc.h:89
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#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
char * Extra_TimeStamp()
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManCreateValueRefs(Gia_Man_t *p)
Definition giaUtil.c:750
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Gia_ManComputeGiaEquivs(Gia_Man_t *pGia, int nConfs, int fVerbose)
Definition giaEquiv.c:183
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
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
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
int Hop_DagSize(Hop_Obj_t *pObj)
Definition hopDfs.c:279
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
int Nm_ManFindIdByName(Nm_Man_t *p, char *pName, int Type)
Definition nmApi.c:219
void * pManFunc
Definition abc.h:191
Nm_Man_t * pManName
Definition abc.h:160
void * pData
Definition abc.h:145
int iTemp
Definition abc.h:149
unsigned Value
Definition gia.h:89
int iData
Definition hop.h:69
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStartStop(vVec, Entry, i, Start, Stop)
Definition vecInt.h:60
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