ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecChoice.c
Go to the documentation of this file.
1
20
21#include "cecInt.h"
22#include "aig/gia/giaAig.h"
23#include "proof/dch/dch.h"
24
26
27
31
32static void Cec_ManCombSpecReduce_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj );
33
34extern int Cec_ManResimulateCounterExamplesComb( Cec_ManSim_t * pSim, Vec_Int_t * vCexStore );
35extern int Gia_ManCheckRefinements( Gia_Man_t * p, Vec_Str_t * vStatus, Vec_Int_t * vOutputs, Cec_ManSim_t * pSim, int fRings );
36
40
52static inline int Cec_ManCombSpecReal( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj )
53{
54 assert( Gia_ObjIsAnd(pObj) );
55 Cec_ManCombSpecReduce_rec( pNew, p, Gia_ObjFanin0(pObj) );
56 Cec_ManCombSpecReduce_rec( pNew, p, Gia_ObjFanin1(pObj) );
57 return Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
58}
59
71void Cec_ManCombSpecReduce_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj )
72{
73 Gia_Obj_t * pRepr;
74 if ( ~pObj->Value )
75 return;
76 if ( (pRepr = Gia_ObjReprObj(p, Gia_ObjId(p, pObj))) )
77 {
78 Cec_ManCombSpecReduce_rec( pNew, p, pRepr );
79 pObj->Value = Abc_LitNotCond( pRepr->Value, Gia_ObjPhase(pRepr) ^ Gia_ObjPhase(pObj) );
80 return;
81 }
82 pObj->Value = Cec_ManCombSpecReal( pNew, p, pObj );
83}
84
96Gia_Man_t * Cec_ManCombSpecReduce( Gia_Man_t * p, Vec_Int_t ** pvOutputs, int fRings )
97{
98 Gia_Man_t * pNew, * pTemp;
99 Gia_Obj_t * pObj, * pRepr;
100 Vec_Int_t * vXorLits;
101 int i, iPrev, iObj, iPrevNew, iObjNew;
102 assert( p->pReprs != NULL );
105 pNew = Gia_ManStart( Gia_ManObjNum(p) );
106 pNew->pName = Abc_UtilStrsav( p->pName );
107 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
108 Gia_ManHashAlloc( pNew );
109 Gia_ManConst0(p)->Value = 0;
110 Gia_ManForEachCi( p, pObj, i )
111 pObj->Value = Gia_ManAppendCi(pNew);
112 *pvOutputs = Vec_IntAlloc( 1000 );
113 vXorLits = Vec_IntAlloc( 1000 );
114 if ( fRings )
115 {
116 Gia_ManForEachObj1( p, pObj, i )
117 {
118 if ( Gia_ObjIsConst( p, i ) )
119 {
120 iObjNew = Cec_ManCombSpecReal( pNew, p, pObj );
121 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) );
122 if ( iObjNew != 0 )
123 {
124 Vec_IntPush( *pvOutputs, 0 );
125 Vec_IntPush( *pvOutputs, i );
126 Vec_IntPush( vXorLits, iObjNew );
127 }
128 }
129 else if ( Gia_ObjIsHead( p, i ) )
130 {
131 iPrev = i;
132 Gia_ClassForEachObj1( p, i, iObj )
133 {
134 iPrevNew = Cec_ManCombSpecReal( pNew, p, Gia_ManObj(p, iPrev) );
135 iObjNew = Cec_ManCombSpecReal( pNew, p, Gia_ManObj(p, iObj) );
136 iPrevNew = Abc_LitNotCond( iPrevNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iPrev)) );
137 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iObj)) );
138 if ( iPrevNew != iObjNew && iPrevNew != 0 && iObjNew != 1 )
139 {
140 Vec_IntPush( *pvOutputs, iPrev );
141 Vec_IntPush( *pvOutputs, iObj );
142 Vec_IntPush( vXorLits, Gia_ManHashAnd(pNew, iPrevNew, Abc_LitNot(iObjNew)) );
143 }
144 iPrev = iObj;
145 }
146 iObj = i;
147 iPrevNew = Cec_ManCombSpecReal( pNew, p, Gia_ManObj(p, iPrev) );
148 iObjNew = Cec_ManCombSpecReal( pNew, p, Gia_ManObj(p, iObj) );
149 iPrevNew = Abc_LitNotCond( iPrevNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iPrev)) );
150 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pObj) ^ Gia_ObjPhase(Gia_ManObj(p, iObj)) );
151 if ( iPrevNew != iObjNew && iPrevNew != 0 && iObjNew != 1 )
152 {
153 Vec_IntPush( *pvOutputs, iPrev );
154 Vec_IntPush( *pvOutputs, iObj );
155 Vec_IntPush( vXorLits, Gia_ManHashAnd(pNew, iPrevNew, Abc_LitNot(iObjNew)) );
156 }
157 }
158 }
159 }
160 else
161 {
162 Gia_ManForEachObj1( p, pObj, i )
163 {
164 pRepr = Gia_ObjReprObj( p, Gia_ObjId(p,pObj) );
165 if ( pRepr == NULL )
166 continue;
167 iPrevNew = Gia_ObjIsConst(p, i)? 0 : Cec_ManCombSpecReal( pNew, p, pRepr );
168 iObjNew = Cec_ManCombSpecReal( pNew, p, pObj );
169 iObjNew = Abc_LitNotCond( iObjNew, Gia_ObjPhase(pRepr) ^ Gia_ObjPhase(pObj) );
170 if ( iPrevNew != iObjNew )
171 {
172 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pRepr) );
173 Vec_IntPush( *pvOutputs, Gia_ObjId(p, pObj) );
174 Vec_IntPush( vXorLits, Gia_ManHashXor(pNew, iPrevNew, iObjNew) );
175 }
176 }
177 }
178 Vec_IntForEachEntry( vXorLits, iObjNew, i )
179 Gia_ManAppendCo( pNew, iObjNew );
180 Vec_IntFree( vXorLits );
181 Gia_ManHashStop( pNew );
182//Abc_Print( 1, "Before sweeping = %d\n", Gia_ManAndNum(pNew) );
183 pNew = Gia_ManCleanup( pTemp = pNew );
184//Abc_Print( 1, "After sweeping = %d\n", Gia_ManAndNum(pNew) );
185 Gia_ManStop( pTemp );
186 return pNew;
187}
188
189
202{
203 int nItersMax = 1000;
204 Vec_Str_t * vStatus;
205 Vec_Int_t * vOutputs;
206 Vec_Int_t * vCexStore;
207 Cec_ParSim_t ParsSim, * pParsSim = &ParsSim;
208 Cec_ParSat_t ParsSat, * pParsSat = &ParsSat;
209 Cec_ManSim_t * pSim;
210 Gia_Man_t * pSrm;
211 int r, RetValue;
212 abctime clkSat = 0, clkSim = 0, clkSrm = 0, clkTotal = Abc_Clock();
213 abctime clk2, clk = Abc_Clock();
214 ABC_FREE( pAig->pReprs );
215 ABC_FREE( pAig->pNexts );
216 Gia_ManRandom( 1 );
217 // prepare simulation manager
218 Cec_ManSimSetDefaultParams( pParsSim );
219 pParsSim->nWords = pPars->nWords;
220 pParsSim->nFrames = pPars->nRounds;
221 pParsSim->fVerbose = pPars->fVerbose;
222 pParsSim->fLatchCorr = 0;
223 pParsSim->fSeqSimulate = 0;
224 // create equivalence classes of registers
225 pSim = Cec_ManSimStart( pAig, pParsSim );
226 Cec_ManSimClassesPrepare( pSim, -1 );
228 // prepare SAT solving
229 Cec_ManSatSetDefaultParams( pParsSat );
230 pParsSat->nBTLimit = pPars->nBTLimit;
231 pParsSat->fVerbose = pPars->fVerbose;
232 if ( pPars->fVerbose )
233 {
234 Abc_Print( 1, "Obj = %7d. And = %7d. Conf = %5d. Ring = %d. CSat = %d.\n",
235 Gia_ManObjNum(pAig), Gia_ManAndNum(pAig), pPars->nBTLimit, pPars->fUseRings, pPars->fUseCSat );
236 Cec_ManRefinedClassPrintStats( pAig, NULL, 0, Abc_Clock() - clk );
237 }
238 // perform refinement of equivalence classes
239 for ( r = 0; r < nItersMax; r++ )
240 {
241 clk = Abc_Clock();
242 // perform speculative reduction
243 clk2 = Abc_Clock();
244 pSrm = Cec_ManCombSpecReduce( pAig, &vOutputs, pPars->fUseRings );
245 assert( Gia_ManRegNum(pSrm) == 0 && Gia_ManCiNum(pSrm) == Gia_ManCiNum(pAig) );
246 clkSrm += Abc_Clock() - clk2;
247 if ( Gia_ManCoNum(pSrm) == 0 )
248 {
249 if ( pPars->fVerbose )
250 Cec_ManRefinedClassPrintStats( pAig, NULL, r+1, Abc_Clock() - clk );
251 Vec_IntFree( vOutputs );
252 Gia_ManStop( pSrm );
253 break;
254 }
255//Gia_DumpAiger( pSrm, "choicesrm", r, 2 );
256 // found counter-examples to speculation
257 clk2 = Abc_Clock();
258 if ( pPars->fUseCSat )
259 vCexStore = Cbs_ManSolveMiterNc( pSrm, pPars->nBTLimit, &vStatus, 0, 0 );
260 else
261 vCexStore = Cec_ManSatSolveMiter( pSrm, pParsSat, &vStatus );
262 Gia_ManStop( pSrm );
263 clkSat += Abc_Clock() - clk2;
264 if ( Vec_IntSize(vCexStore) == 0 )
265 {
266 if ( pPars->fVerbose )
267 Cec_ManRefinedClassPrintStats( pAig, vStatus, r+1, Abc_Clock() - clk );
268 Vec_IntFree( vCexStore );
269 Vec_StrFree( vStatus );
270 Vec_IntFree( vOutputs );
271 break;
272 }
273 // refine classes with these counter-examples
274 clk2 = Abc_Clock();
275 RetValue = Cec_ManResimulateCounterExamplesComb( pSim, vCexStore );
276 Vec_IntFree( vCexStore );
277 clkSim += Abc_Clock() - clk2;
278 Gia_ManCheckRefinements( pAig, vStatus, vOutputs, pSim, pPars->fUseRings );
279 if ( pPars->fVerbose )
280 Cec_ManRefinedClassPrintStats( pAig, vStatus, r+1, Abc_Clock() - clk );
281 Vec_StrFree( vStatus );
282 Vec_IntFree( vOutputs );
283//Gia_ManEquivPrintClasses( pAig, 1, 0 );
284 }
285 // check the overflow
286 if ( r == nItersMax )
287 Abc_Print( 1, "The refinement was not finished. The result may be incorrect.\n" );
288 Cec_ManSimStop( pSim );
289 clkTotal = Abc_Clock() - clkTotal;
290 // report the results
291 if ( pPars->fVerbose )
292 {
293 Abc_PrintTimeP( 1, "Srm ", clkSrm, clkTotal );
294 Abc_PrintTimeP( 1, "Sat ", clkSat, clkTotal );
295 Abc_PrintTimeP( 1, "Sim ", clkSim, clkTotal );
296 Abc_PrintTimeP( 1, "Other", clkTotal-clkSat-clkSrm-clkSim, clkTotal );
297 Abc_PrintTime( 1, "TOTAL", clkTotal );
298 }
299 return 0;
300}
301
314{
315 Gia_Man_t * pNew;
316 int RetValue;
317 // compute equivalences of the miter
318// pMiter = Gia_ManChoiceMiter( vGias );
319// Gia_ManSetRegNum( pMiter, 0 );
320 RetValue = Cec_ManChoiceComputation_int( pGia, pPars );
321 // derive AIG with choices
322 pNew = Gia_ManEquivToChoices( pGia, nGias );
323// Gia_ManHasChoices_very_old( pNew );
324// Gia_ManStop( pMiter );
325 // report the results
326 if ( pPars->fVerbose )
327 {
328// Abc_Print( 1, "NBeg = %d. NEnd = %d. (Gain = %6.2f %%). RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n",
329// Gia_ManAndNum(pAig), Gia_ManAndNum(pNew),
330// 100.0*(Gia_ManAndNum(pAig)-Gia_ManAndNum(pNew))/(Gia_ManAndNum(pAig)?Gia_ManAndNum(pAig):1),
331// Gia_ManRegNum(pAig), Gia_ManRegNum(pNew),
332// 100.0*(Gia_ManRegNum(pAig)-Gia_ManRegNum(pNew))/(Gia_ManRegNum(pAig)?Gia_ManRegNum(pAig):1) );
333 }
334 return pNew;
335}
336
349{
350// extern Aig_Man_t * Dar_ManChoiceNew( Aig_Man_t * pAig, Dch_Pars_t * pPars );
351 Dch_Pars_t Pars, * pPars = &Pars;
352 Aig_Man_t * pMan, * pManNew;
353 Gia_Man_t * pGia;
354 if ( 0 )
355 {
356 pGia = Cec_ManChoiceComputationVec( pAig, 3, pParsChc );
357 }
358 else
359 {
360 pMan = Gia_ManToAig( pAig, 0 );
362 pPars->fUseGia = 1;
363 pPars->nBTLimit = pParsChc->nBTLimit;
364 pPars->fUseCSat = pParsChc->fUseCSat;
365 pPars->fVerbose = pParsChc->fVerbose;
366 pManNew = Dar_ManChoiceNew( pMan, pPars );
367 pGia = Gia_ManFromAig( pManNew );
368 Aig_ManStop( pManNew );
369// Aig_ManStop( pMan );
370 }
371 return pGia;
372}
373
386{
387 Cec_ParChc_t ParsChc, * pParsChc = &ParsChc;
388 Aig_Man_t * pAig;
389 if ( pPars->fVerbose )
390 Abc_PrintTime( 1, "Synthesis time", pPars->timeSynth );
391 Cec_ManChcSetDefaultParams( pParsChc );
392 pParsChc->nBTLimit = pPars->nBTLimit;
393 pParsChc->fUseCSat = pPars->fUseCSat;
394 if ( pParsChc->fUseCSat && pParsChc->nBTLimit > 100 )
395 pParsChc->nBTLimit = 100;
396 pParsChc->fVerbose = pPars->fVerbose;
397 pGia = Cec_ManChoiceComputationVec( pGia, 3, pParsChc );
398 Gia_ManSetRegNum( pGia, Gia_ManRegNum(pGia) );
399 pAig = Gia_ManToAig( pGia, 1 );
400 Gia_ManStop( pGia );
401 return pAig;
402}
403
415Aig_Man_t * Cec_ComputeChoicesNew( Gia_Man_t * pGia, int nConfs, int fVerbose )
416{
417 extern void Cec4_ManSimulateTest2( Gia_Man_t * p, int nConfs, int fVerbose );
418 Aig_Man_t * pAig;
419 Cec4_ManSimulateTest2( pGia, nConfs, fVerbose );
420 pGia = Gia_ManEquivToChoices( pGia, 3 );
421 pAig = Gia_ManToAig( pGia, 1 );
422 Gia_ManStop( pGia );
423 return pAig;
424}
425Aig_Man_t * Cec_ComputeChoicesNew2( Gia_Man_t * pGia, int nConfs, int fVerbose )
426{
427 extern Gia_Man_t * Cec5_ManSimulateTest3( Gia_Man_t * p, int nBTLimit, int fVerbose );
428 Aig_Man_t * pAig;
429 Gia_Man_t * pNew = Cec5_ManSimulateTest3( pGia, nConfs, fVerbose );
430 Gia_ManStop( pNew );
431 pGia = Gia_ManEquivToChoices( pGia, 3 );
432 pAig = Gia_ManToAig( pGia, 1 );
433 Gia_ManStop( pGia );
434 return pAig;
435}
436
440
441
443
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
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_ManResimulateCounterExamplesComb(Cec_ManSim_t *pSim, Vec_Int_t *vCexStore)
Definition cecCorr.c:583
Gia_Man_t * Cec_ManCombSpecReduce(Gia_Man_t *p, Vec_Int_t **pvOutputs, int fRings)
Definition cecChoice.c:96
int Cec_ManChoiceComputation_int(Gia_Man_t *pAig, Cec_ParChc_t *pPars)
Definition cecChoice.c:201
Aig_Man_t * Cec_ComputeChoicesNew(Gia_Man_t *pGia, int nConfs, int fVerbose)
Definition cecChoice.c:415
Gia_Man_t * Cec_ManChoiceComputation(Gia_Man_t *pAig, Cec_ParChc_t *pParsChc)
Definition cecChoice.c:348
Aig_Man_t * Cec_ComputeChoices(Gia_Man_t *pGia, Dch_Pars_t *pPars)
Definition cecChoice.c:385
Gia_Man_t * Cec_ManChoiceComputationVec(Gia_Man_t *pGia, int nGias, Cec_ParChc_t *pPars)
Definition cecChoice.c:313
Aig_Man_t * Cec_ComputeChoicesNew2(Gia_Man_t *pGia, int nConfs, int fVerbose)
Definition cecChoice.c:425
int Gia_ManCheckRefinements(Gia_Man_t *p, Vec_Str_t *vStatus, Vec_Int_t *vOutputs, Cec_ManSim_t *pSim, int fRings)
Definition cecCorr.c:612
int Cec_ManSimClassesPrepare(Cec_ManSim_t *p, int LevelMax)
Definition cecClass.c:867
int Cec_ManSimClassesRefine(Cec_ManSim_t *p)
Definition cecClass.c:939
void Cec_ManRefinedClassPrintStats(Gia_Man_t *p, Vec_Str_t *vStatus, int iIter, abctime Time)
MACRO DEFINITIONS ///.
Definition cecCorr.c:725
void Cec_ManSimStop(Cec_ManSim_t *p)
Definition cecMan.c:233
Cec_ManSim_t * Cec_ManSimStart(Gia_Man_t *pAig, Cec_ParSim_t *pPars)
Definition cecMan.c:199
struct Cec_ManSim_t_ Cec_ManSim_t
Definition cecInt.h:113
Vec_Int_t * Cec_ManSatSolveMiter(Gia_Man_t *pAig, Cec_ParSat_t *pPars, Vec_Str_t **pvStatus)
Definition cecSolve.c:1070
void Cec4_ManSimulateTest2(Gia_Man_t *p, int nConfs, int fVerbose)
Definition cecSatG2.c:2066
Gia_Man_t * Cec5_ManSimulateTest3(Gia_Man_t *p, int nBTLimit, int fVerbose)
Definition cecSatG3.c:2326
void Cec_ManSatSetDefaultParams(Cec_ParSat_t *p)
DECLARATIONS ///.
Definition cecCore.c:45
void Cec_ManSimSetDefaultParams(Cec_ParSim_t *p)
Definition cecCore.c:71
typedefABC_NAMESPACE_HEADER_START struct Cec_ParSat_t_ Cec_ParSat_t
INCLUDES ///.
Definition cec.h:43
struct Cec_ParChc_t_ Cec_ParChc_t
Definition cec.h:175
struct Cec_ParSim_t_ Cec_ParSim_t
Definition cec.h:60
void Cec_ManChcSetDefaultParams(Cec_ParChc_t *p)
Definition cecCore.c:213
Aig_Man_t * Dar_ManChoiceNew(Aig_Man_t *pAig, Dch_Pars_t *pPars)
Definition darScript.c:849
typedefABC_NAMESPACE_HEADER_START struct Dch_Pars_t_ Dch_Pars_t
INCLUDES ///.
Definition dch.h:43
void Dch_ManSetDefaultParams(Dch_Pars_t *p)
DECLARATIONS ///.
Definition dchCore.c:45
Cube * p
Definition exorList.c:222
Gia_Man_t * Gia_ManFromAig(Aig_Man_t *p)
INCLUDES ///.
Definition giaAig.c:76
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
Definition giaAig.c:318
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
#define Gia_ClassForEachObj1(p, i, iObj)
Definition gia.h:1109
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:668
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
Vec_Int_t * Cbs_ManSolveMiterNc(Gia_Man_t *pGia, int nConfs, Vec_Str_t **pvStatus, int f0Proved, int fVerbose)
Definition giaCSat.c:1037
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
Gia_Man_t * Gia_ManEquivToChoices(Gia_Man_t *p, int nSnapshots)
Definition giaEquiv.c:2034
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
int fUseRings
Definition cec.h:181
int nWords
Definition cec.h:178
int fVerbose
Definition cec.h:184
int nBTLimit
Definition cec.h:180
int fUseCSat
Definition cec.h:182
int nRounds
Definition cec.h:179
int fVerbose
Definition cec.h:75
int fLatchCorr
Definition cec.h:72
int fSeqSimulate
Definition cec.h:71
int nFrames
Definition cec.h:64
int nWords
Definition cec.h:63
char * pSpec
Definition gia.h:100
Gia_Rpr_t * pReprs
Definition gia.h:126
int * pNexts
Definition gia.h:127
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54