ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecSatG2.c
Go to the documentation of this file.
1
20
21#include "aig/gia/gia.h"
22#include "misc/util/utilTruth.h"
23#include "cec.h"
24#include "bdd/extrab/extraBdd.h"
25#include "base/abc/abc.h"
26#include "map/if/if.h"
27
28#define USE_GLUCOSE2
29
30#ifdef USE_GLUCOSE2
31
33
34#define sat_solver bmcg2_sat_solver
35#define sat_solver_start bmcg2_sat_solver_start
36#define sat_solver_stop bmcg2_sat_solver_stop
37#define sat_solver_addclause bmcg2_sat_solver_addclause
38#define sat_solver_add_and bmcg2_sat_solver_add_and
39#define sat_solver_add_xor bmcg2_sat_solver_add_xor
40#define sat_solver_addvar bmcg2_sat_solver_addvar
41#define sat_solver_read_cex_varvalue bmcg2_sat_solver_read_cex_varvalue
42#define sat_solver_reset bmcg2_sat_solver_reset
43#define sat_solver_set_conflict_budget bmcg2_sat_solver_set_conflict_budget
44#define sat_solver_conflictnum bmcg2_sat_solver_conflictnum
45#define sat_solver_solve bmcg2_sat_solver_solve
46#define sat_solver_read_cex_varvalue bmcg2_sat_solver_read_cex_varvalue
47#define sat_solver_read_cex bmcg2_sat_solver_read_cex
48#define sat_solver_jftr bmcg2_sat_solver_jftr
49#define sat_solver_set_jftr bmcg2_sat_solver_set_jftr
50#define sat_solver_set_var_fanin_lit bmcg2_sat_solver_set_var_fanin_lit
51#define sat_solver_start_new_round bmcg2_sat_solver_start_new_round
52#define sat_solver_mark_cone bmcg2_sat_solver_mark_cone
53
54#else
55
57
58#define sat_solver bmcg_sat_solver
59#define sat_solver_start bmcg_sat_solver_start
60#define sat_solver_stop bmcg_sat_solver_stop
61#define sat_solver_addclause bmcg_sat_solver_addclause
62#define sat_solver_add_and bmcg_sat_solver_add_and
63#define sat_solver_add_xor bmcg_sat_solver_add_xor
64#define sat_solver_addvar bmcg_sat_solver_addvar
65#define sat_solver_read_cex_varvalue bmcg_sat_solver_read_cex_varvalue
66#define sat_solver_reset bmcg_sat_solver_reset
67#define sat_solver_set_conflict_budget bmcg_sat_solver_set_conflict_budget
68#define sat_solver_conflictnum bmcg_sat_solver_conflictnum
69#define sat_solver_solve bmcg_sat_solver_solve
70#define sat_solver_read_cex_varvalue bmcg_sat_solver_read_cex_varvalue
71#define sat_solver_read_cex bmcg_sat_solver_read_cex
72#define sat_solver_jftr bmcg_sat_solver_jftr
73#define sat_solver_set_jftr bmcg_sat_solver_set_jftr
74#define sat_solver_set_var_fanin_lit bmcg_sat_solver_set_var_fanin_lit
75#define sat_solver_start_new_round bmcg_sat_solver_start_new_round
76#define sat_solver_mark_cone bmcg_sat_solver_mark_cone
77
78#endif
79
81
82
86
87// SAT solving manager
88typedef struct Cec4_Man_t_ Cec4_Man_t;
144
145static inline int Cec4_ObjSatId( Gia_Man_t * p, Gia_Obj_t * pObj ) { return Gia_ObjCopy2Array(p, Gia_ObjId(p, pObj)); }
146static inline int Cec4_ObjSetSatId( Gia_Man_t * p, Gia_Obj_t * pObj, int Num ) { assert(Cec4_ObjSatId(p, pObj) == -1); Gia_ObjSetCopy2Array(p, Gia_ObjId(p, pObj), Num); Vec_IntPush(&p->vSuppVars, Gia_ObjId(p, pObj)); if ( Gia_ObjIsCi(pObj) ) Vec_IntPushTwo(&p->vCopiesTwo, Gia_ObjId(p, pObj), Num); assert(Vec_IntSize(&p->vVarMap) == Num); Vec_IntPush(&p->vVarMap, Gia_ObjId(p, pObj)); return Num; }
147static inline void Cec4_ObjCleanSatId( Gia_Man_t * p, Gia_Obj_t * pObj ) { assert(Cec4_ObjSatId(p, pObj) != -1); Gia_ObjSetCopy2Array(p, Gia_ObjId(p, pObj), -1); }
148
152
164Vec_Wrd_t * Cec4_EvalCombine( Vec_Int_t * vPats, int nPats, int nInputs, int nWords )
165{
166 //Vec_Wrd_t * vSimsPi = Vec_WrdStart( nInputs * nWords );
167 Vec_Wrd_t * vSimsPi = Vec_WrdStartRandom( nInputs * nWords );
168 int i, k, iLit, iPat = 0; word * pSim;
169 for ( i = 0; i < Vec_IntSize(vPats); i += Vec_IntEntry(vPats, i), iPat++ )
170 for ( k = 1; k < Vec_IntEntry(vPats, i)-1; k++ )
171 if ( (iLit = Vec_IntEntry(vPats, i+k)) )
172 {
173 assert( Abc_Lit2Var(iLit) > 0 && Abc_Lit2Var(iLit) <= nInputs );
174 pSim = Vec_WrdEntryP( vSimsPi, (Abc_Lit2Var(iLit)-1)*nWords );
175 if ( Abc_InfoHasBit( (unsigned*)pSim, iPat ) != Abc_LitIsCompl(iLit) )
176 Abc_InfoXorBit( (unsigned*)pSim, iPat );
177 }
178 assert( iPat == nPats );
179 return vSimsPi;
180}
181void Cec4_EvalPatterns( Gia_Man_t * p, Vec_Int_t * vPats, int nPats )
182{
183 int nWords = Abc_Bit6WordNum(nPats);
184 Vec_Wrd_t * vSimsPi = Cec4_EvalCombine( vPats, nPats, Gia_ManCiNum(p), nWords );
185 Vec_Wrd_t * vSimsPo = Gia_ManSimPatSimOut( p, vSimsPi, 1 );
186 int i, Count = 0, nErrors = 0;
187 for ( i = 0; i < Gia_ManCoNum(p); i++ )
188 {
189 int CountThis = Abc_TtCountOnesVec( Vec_WrdEntryP(vSimsPo, i*nWords), nWords );
190 if ( CountThis == 0 )
191 continue;
192 printf( "%d ", CountThis );
193 nErrors += CountThis;
194 Count++;
195 }
196 printf( "\nDetected %d error POs with %d errors (average %.2f).\n", Count, nErrors, 1.0*nErrors/Abc_MaxInt(1, Count) );
197 Vec_WrdFree( vSimsPi );
198 Vec_WrdFree( vSimsPo );
199}
200
213{
214 memset( pPars, 0, sizeof(Cec_ParFra_t) );
215 pPars->jType = 2; // solver type
216 pPars->fSatSweeping = 1; // conflict limit at a node
217 pPars->nWords = 4; // simulation words
218 pPars->nRounds = 10; // simulation rounds
219 pPars->nItersMax = 2000; // this is a miter
220 pPars->nBTLimit = 1000000; // use logic cones
221 pPars->nBTLimitPo = 0; // use logic outputs
222 pPars->nSatVarMax = 1000; // the max number of SAT variables before recycling SAT solver
223 pPars->nCallsRecycle = 500; // calls to perform before recycling SAT solver
224 pPars->nGenIters = 100; // pattern generation iterations
225 pPars->fBMiterInfo = 0; // printing BMiter information
226}
227
240{
241 memset( pPars, 0, sizeof(Cec_ParSimGen_t) );
242 pPars->fVerbose = 0; // verbose output
243 pPars->fVeryVerbose = 0; // verbose output and outputs files
244 pPars->bitwidthOutgold = 2; // bitwidth of the output golden model
245 pPars->nSimWords = 4; // number of words in a round of random simulation
246 pPars->expId = 1; // experiment ID
247 pPars->nMaxIter = -1; // the maximum number of rounds of random simulation
248 pPars->timeOutSim = 1000.0; // the timeout for simulation in sec
249 pPars->fUseWatchlist = 0; // use watchlist
250 pPars->fImplicationTime = 0.0; // time spent in implication
251 pPars->nImplicationExecution = 0; // the number of implication executions
252 pPars->nImplicationSuccess = 0; // the number of implication successes
253 pPars->nImplicationTotalChecks = 0; // the number of implication checks
254 pPars->nImplicationSuccessChecks = 0; // the number of implication successful checks
255 pPars->pFileName = NULL; // file name to dump simulation vectors
256}
257
270{
272 memset( p, 0, sizeof(Cec4_Man_t) );
273 p->timeStart = Abc_Clock();
274 p->pPars = pPars;
275 p->pAig = pAig;
276 p->pSat = sat_solver_start();
277 sat_solver_set_jftr( p->pSat, pPars->jType );
278 p->vFrontier = Vec_PtrAlloc( 1000 );
279 p->vFanins = Vec_PtrAlloc( 100 );
280 p->vCexMin = Vec_IntAlloc( 100 );
281 p->vClassUpdates = Vec_IntAlloc( 100 );
282 p->vCexStamps = Vec_IntStart( Gia_ManObjNum(pAig) );
283 p->vCands = Vec_IntAlloc( 100 );
284 p->vVisit = Vec_IntAlloc( 100 );
285 p->vPat = Vec_IntAlloc( 100 );
286 p->vDisprPairs = Vec_IntAlloc( 100 );
287 p->vFails = Vec_BitStart( Gia_ManObjNum(pAig) );
288 p->vPairs = pPars->fUseCones ? Vec_IntAlloc( 100 ) : NULL;
289 //pAig->pData = p->pSat; // point AIG manager to the solver
290 //Vec_IntFreeP( &p->pAig->vPats );
291 //p->pAig->vPats = Vec_IntAlloc( 1000 );
292 if ( pPars->nBTLimitPo )
293 {
294 int i, Driver;
295 p->vCoDrivers = Vec_BitStart( Gia_ManObjNum(pAig) );
296 Gia_ManForEachCoDriverId( pAig, Driver, i )
297 Vec_BitWriteEntry( p->vCoDrivers, Driver, 1 );
298 }
299 return p;
300}
302{
303 if ( p->pPars->fVerbose )
304 {
305 abctime timeTotal = Abc_Clock() - p->timeStart;
306 abctime timeSat = p->timeSatSat0 + p->timeSatSat + p->timeSatUnsat0 + p->timeSatUnsat + p->timeSatUndec;
307 abctime timeOther = timeTotal - timeSat - p->timeSim - p->timeRefine - p->timeResimLoc - p->timeGenPats;// - p->timeResimGlo;
308 ABC_PRTP( "SAT solving ", timeSat, timeTotal );
309 ABC_PRTP( " sat(easy) ", p->timeSatSat0, timeTotal );
310 ABC_PRTP( " sat ", p->timeSatSat, timeTotal );
311 ABC_PRTP( " unsat(easy)", p->timeSatUnsat0, timeTotal );
312 ABC_PRTP( " unsat ", p->timeSatUnsat, timeTotal );
313 ABC_PRTP( " fail ", p->timeSatUndec, timeTotal );
314 ABC_PRTP( "Generate CNF ", p->timeCnf, timeTotal );
315 ABC_PRTP( "Generate pats", p->timeGenPats, timeTotal );
316 ABC_PRTP( "Simulation ", p->timeSim, timeTotal );
317 ABC_PRTP( "Refinement ", p->timeRefine, timeTotal );
318 ABC_PRTP( "Resim global ", p->timeResimGlo, timeTotal );
319 ABC_PRTP( "Resim local ", p->timeResimLoc, timeTotal );
320 ABC_PRTP( "Other ", timeOther, timeTotal );
321 ABC_PRTP( "TOTAL ", timeTotal, timeTotal );
322 fflush( stdout );
323 }
324 //printf( "Recorded %d patterns with %d literals (average %.2f).\n",
325 // p->pAig->nBitPats, Vec_IntSize(p->pAig->vPats) - 2*p->pAig->nBitPats, 1.0*Vec_IntSize(p->pAig->vPats)/Abc_MaxInt(1, p->pAig->nBitPats)-2 );
326 //Cec4_EvalPatterns( p->pAig, p->pAig->vPats, p->pAig->nBitPats );
327 //Vec_IntFreeP( &p->pAig->vPats );
328 Vec_WrdFreeP( &p->pAig->vSims );
329 Vec_WrdFreeP( &p->pAig->vSimsPi );
330 Gia_ManCleanMark01( p->pAig );
331 sat_solver_stop( p->pSat );
332 Gia_ManStopP( &p->pNew );
333 Vec_PtrFreeP( &p->vFrontier );
334 Vec_PtrFreeP( &p->vFanins );
335 Vec_IntFreeP( &p->vCexMin );
336 Vec_IntFreeP( &p->vClassUpdates );
337 Vec_IntFreeP( &p->vCexStamps );
338 Vec_IntFreeP( &p->vCands );
339 Vec_IntFreeP( &p->vVisit );
340 Vec_IntFreeP( &p->vPat );
341 Vec_IntFreeP( &p->vDisprPairs );
342 Vec_BitFreeP( &p->vFails );
343 Vec_IntFreeP( &p->vPairs );
344 Vec_BitFreeP( &p->vCoDrivers );
345 Vec_IntFreeP( &p->vRefClasses );
346 Vec_IntFreeP( &p->vRefNodes );
347 Vec_IntFreeP( &p->vRefBins );
348 ABC_FREE( p->pTable );
349 ABC_FREE( p );
350}
352{
353 Gia_Obj_t * pObj; int i;
354 Gia_Man_t * pNew = Gia_ManStart( Gia_ManObjNum(pAig) );
355 pNew->pName = Abc_UtilStrsav( pAig->pName );
356 pNew->pSpec = Abc_UtilStrsav( pAig->pSpec );
357 if ( pAig->pMuxes )
358 pNew->pMuxes = ABC_CALLOC( unsigned, pNew->nObjsAlloc );
359 Gia_ManFillValue( pAig );
360 Gia_ManConst0(pAig)->Value = 0;
361 Gia_ManForEachCi( pAig, pObj, i )
362 pObj->Value = Gia_ManAppendCi( pNew );
363 Gia_ManHashAlloc( pNew );
364 Vec_IntFill( &pNew->vCopies2, Gia_ManObjNum(pAig), -1 );
365 Gia_ManSetRegNum( pNew, Gia_ManRegNum(pAig) );
366 return pNew;
367}
368
381{
382 int fPolarFlip = 0;
383 Gia_Obj_t * pNodeI, * pNodeT, * pNodeE;
384 int pLits[4], RetValue, VarF, VarI, VarT, VarE, fCompT, fCompE;
385
386 assert( !Gia_IsComplement( pNode ) );
387 assert( pNode->fMark0 );
388 // get nodes (I = if, T = then, E = else)
389 pNodeI = Gia_ObjRecognizeMux( pNode, &pNodeT, &pNodeE );
390 // get the variable numbers
391 VarF = Cec4_ObjSatId(p, pNode);
392 VarI = Cec4_ObjSatId(p, pNodeI);
393 VarT = Cec4_ObjSatId(p, Gia_Regular(pNodeT));
394 VarE = Cec4_ObjSatId(p, Gia_Regular(pNodeE));
395 // get the complementation flags
396 fCompT = Gia_IsComplement(pNodeT);
397 fCompE = Gia_IsComplement(pNodeE);
398
399 // f = ITE(i, t, e)
400
401 // i' + t' + f
402 // i' + t + f'
403 // i + e' + f
404 // i + e + f'
405
406 // create four clauses
407 pLits[0] = Abc_Var2Lit(VarI, 1);
408 pLits[1] = Abc_Var2Lit(VarT, 1^fCompT);
409 pLits[2] = Abc_Var2Lit(VarF, 0);
410 if ( fPolarFlip )
411 {
412 if ( pNodeI->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
413 if ( Gia_Regular(pNodeT)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
414 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
415 }
416 RetValue = sat_solver_addclause( pSat, pLits, 3 );
417 assert( RetValue );
418 pLits[0] = Abc_Var2Lit(VarI, 1);
419 pLits[1] = Abc_Var2Lit(VarT, 0^fCompT);
420 pLits[2] = Abc_Var2Lit(VarF, 1);
421 if ( fPolarFlip )
422 {
423 if ( pNodeI->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
424 if ( Gia_Regular(pNodeT)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
425 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
426 }
427 RetValue = sat_solver_addclause( pSat, pLits, 3 );
428 assert( RetValue );
429 pLits[0] = Abc_Var2Lit(VarI, 0);
430 pLits[1] = Abc_Var2Lit(VarE, 1^fCompE);
431 pLits[2] = Abc_Var2Lit(VarF, 0);
432 if ( fPolarFlip )
433 {
434 if ( pNodeI->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
435 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
436 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
437 }
438 RetValue = sat_solver_addclause( pSat, pLits, 3 );
439 assert( RetValue );
440 pLits[0] = Abc_Var2Lit(VarI, 0);
441 pLits[1] = Abc_Var2Lit(VarE, 0^fCompE);
442 pLits[2] = Abc_Var2Lit(VarF, 1);
443 if ( fPolarFlip )
444 {
445 if ( pNodeI->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
446 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
447 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
448 }
449 RetValue = sat_solver_addclause( pSat, pLits, 3 );
450 assert( RetValue );
451
452 // two additional clauses
453 // t' & e' -> f'
454 // t & e -> f
455
456 // t + e + f'
457 // t' + e' + f
458
459 if ( VarT == VarE )
460 {
461// assert( fCompT == !fCompE );
462 return;
463 }
464
465 pLits[0] = Abc_Var2Lit(VarT, 0^fCompT);
466 pLits[1] = Abc_Var2Lit(VarE, 0^fCompE);
467 pLits[2] = Abc_Var2Lit(VarF, 1);
468 if ( fPolarFlip )
469 {
470 if ( Gia_Regular(pNodeT)->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
471 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
472 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
473 }
474 RetValue = sat_solver_addclause( pSat, pLits, 3 );
475 assert( RetValue );
476 pLits[0] = Abc_Var2Lit(VarT, 1^fCompT);
477 pLits[1] = Abc_Var2Lit(VarE, 1^fCompE);
478 pLits[2] = Abc_Var2Lit(VarF, 0);
479 if ( fPolarFlip )
480 {
481 if ( Gia_Regular(pNodeT)->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
482 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
483 if ( pNode->fPhase ) pLits[2] = Abc_LitNot( pLits[2] );
484 }
485 RetValue = sat_solver_addclause( pSat, pLits, 3 );
486 assert( RetValue );
487}
488void Cec4_AddClausesSuper( Gia_Man_t * p, Gia_Obj_t * pNode, Vec_Ptr_t * vSuper, sat_solver * pSat )
489{
490 int fPolarFlip = 0;
491 Gia_Obj_t * pFanin;
492 int * pLits, nLits, RetValue, i;
493 assert( !Gia_IsComplement(pNode) );
494 assert( Gia_ObjIsAnd( pNode ) );
495 // create storage for literals
496 nLits = Vec_PtrSize(vSuper) + 1;
497 pLits = ABC_ALLOC( int, nLits );
498 // suppose AND-gate is A & B = C
499 // add !A => !C or A + !C
500 Vec_PtrForEachEntry( Gia_Obj_t *, vSuper, pFanin, i )
501 {
502 pLits[0] = Abc_Var2Lit(Cec4_ObjSatId(p, Gia_Regular(pFanin)), Gia_IsComplement(pFanin));
503 pLits[1] = Abc_Var2Lit(Cec4_ObjSatId(p, pNode), 1);
504 if ( fPolarFlip )
505 {
506 if ( Gia_Regular(pFanin)->fPhase ) pLits[0] = Abc_LitNot( pLits[0] );
507 if ( pNode->fPhase ) pLits[1] = Abc_LitNot( pLits[1] );
508 }
509 RetValue = sat_solver_addclause( pSat, pLits, 2 );
510 assert( RetValue );
511 }
512 // add A & B => C or !A + !B + C
513 Vec_PtrForEachEntry( Gia_Obj_t *, vSuper, pFanin, i )
514 {
515 pLits[i] = Abc_Var2Lit(Cec4_ObjSatId(p, Gia_Regular(pFanin)), !Gia_IsComplement(pFanin));
516 if ( fPolarFlip )
517 {
518 if ( Gia_Regular(pFanin)->fPhase ) pLits[i] = Abc_LitNot( pLits[i] );
519 }
520 }
521 pLits[nLits-1] = Abc_Var2Lit(Cec4_ObjSatId(p, pNode), 0);
522 if ( fPolarFlip )
523 {
524 if ( pNode->fPhase ) pLits[nLits-1] = Abc_LitNot( pLits[nLits-1] );
525 }
526 RetValue = sat_solver_addclause( pSat, pLits, nLits );
527 assert( RetValue );
528 ABC_FREE( pLits );
529}
530
542void Cec4_CollectSuper_rec( Gia_Obj_t * pObj, Vec_Ptr_t * vSuper, int fFirst, int fUseMuxes )
543{
544 // if the new node is complemented or a PI, another gate begins
545 if ( Gia_IsComplement(pObj) || Gia_ObjIsCi(pObj) ||
546 (!fFirst && Gia_ObjValue(pObj) > 1) ||
547 (fUseMuxes && pObj->fMark0) )
548 {
549 Vec_PtrPushUnique( vSuper, pObj );
550 return;
551 }
552 // go through the branches
553 Cec4_CollectSuper_rec( Gia_ObjChild0(pObj), vSuper, 0, fUseMuxes );
554 Cec4_CollectSuper_rec( Gia_ObjChild1(pObj), vSuper, 0, fUseMuxes );
555}
556void Cec4_CollectSuper( Gia_Obj_t * pObj, int fUseMuxes, Vec_Ptr_t * vSuper )
557{
558 assert( !Gia_IsComplement(pObj) );
559 assert( !Gia_ObjIsCi(pObj) );
560 Vec_PtrClear( vSuper );
561 Cec4_CollectSuper_rec( pObj, vSuper, 1, fUseMuxes );
562}
563void Cec4_ObjAddToFrontier( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Ptr_t * vFrontier, sat_solver * pSat )
564{
565 assert( !Gia_IsComplement(pObj) );
566 assert( !Gia_ObjIsConst0(pObj) );
567 if ( Cec4_ObjSatId(p, pObj) >= 0 )
568 return;
569 assert( Cec4_ObjSatId(p, pObj) == -1 );
570 Cec4_ObjSetSatId( p, pObj, sat_solver_addvar(pSat) );
571 if ( Gia_ObjIsAnd(pObj) )
572 Vec_PtrPush( vFrontier, pObj );
573}
575{
576 int fUseSimple = 1; // enable simple CNF
577 int fUseMuxes = 1; // enable MUXes when using complex CNF
578 Gia_Obj_t * pNode, * pFanin;
579 Gia_Obj_t * pObj = Gia_ManObj(p->pNew, iObj);
580 int i, k;
581 // quit if CNF is ready
582 if ( Cec4_ObjSatId(p->pNew,pObj) >= 0 )
583 return Cec4_ObjSatId(p->pNew,pObj);
584 assert( iObj > 0 );
585 if ( Gia_ObjIsCi(pObj) )
586 return Cec4_ObjSetSatId( p->pNew, pObj, sat_solver_addvar(p->pSat) );
587 assert( Gia_ObjIsAnd(pObj) );
588 if ( fUseSimple )
589 {
590 Gia_Obj_t * pFan0, * pFan1;
591 //if ( Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1) )
592 // printf( "%d", (Gia_IsComplement(pFan1) << 1) + Gia_IsComplement(pFan0) );
593 if ( p->pNew->pMuxes == NULL && Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1) && Gia_IsComplement(pFan0) == Gia_IsComplement(pFan1) )
594 {
595 int iVar0 = Cec4_ObjGetCnfVar( p, Gia_ObjId(p->pNew, Gia_Regular(pFan0)) );
596 int iVar1 = Cec4_ObjGetCnfVar( p, Gia_ObjId(p->pNew, Gia_Regular(pFan1)) );
597 int iVar = Cec4_ObjSetSatId( p->pNew, pObj, sat_solver_addvar(p->pSat) );
598 if ( p->pPars->jType < 2 )
599 sat_solver_add_xor( p->pSat, iVar, iVar0, iVar1, 0 );
600 if ( p->pPars->jType > 0 )
601 {
602 int Lit0 = Abc_Var2Lit( iVar0, 0 );
603 int Lit1 = Abc_Var2Lit( iVar1, 0 );
604 if ( Lit0 < Lit1 )
605 Lit1 ^= Lit0, Lit0 ^= Lit1, Lit1 ^= Lit0;
606 assert( Lit0 > Lit1 );
607 sat_solver_set_var_fanin_lit( p->pSat, iVar, Lit0, Lit1 );
608 p->nGates[1]++;
609 }
610 }
611 else
612 {
613 int iVar0 = Cec4_ObjGetCnfVar( p, Gia_ObjFaninId0(pObj, iObj) );
614 int iVar1 = Cec4_ObjGetCnfVar( p, Gia_ObjFaninId1(pObj, iObj) );
615 int iVar = Cec4_ObjSetSatId( p->pNew, pObj, sat_solver_addvar(p->pSat) );
616 if ( p->pPars->jType < 2 )
617 {
618 if ( Gia_ObjIsXor(pObj) )
619 sat_solver_add_xor( p->pSat, iVar, iVar0, iVar1, Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pObj) );
620 else
621 sat_solver_add_and( p->pSat, iVar, iVar0, iVar1, Gia_ObjFaninC0(pObj), Gia_ObjFaninC1(pObj), 0 );
622 }
623 if ( p->pPars->jType > 0 )
624 {
625 int Lit0 = Abc_Var2Lit( iVar0, Gia_ObjFaninC0(pObj) );
626 int Lit1 = Abc_Var2Lit( iVar1, Gia_ObjFaninC1(pObj) );
627 if ( (Lit0 > Lit1) ^ Gia_ObjIsXor(pObj) )
628 Lit1 ^= Lit0, Lit0 ^= Lit1, Lit1 ^= Lit0;
629 sat_solver_set_var_fanin_lit( p->pSat, iVar, Lit0, Lit1 );
630 p->nGates[Gia_ObjIsXor(pObj)]++;
631 }
632 }
633 return Cec4_ObjSatId( p->pNew, pObj );
634 }
635 assert( !Gia_ObjIsXor(pObj) );
636 // start the frontier
637 Vec_PtrClear( p->vFrontier );
638 Cec4_ObjAddToFrontier( p->pNew, pObj, p->vFrontier, p->pSat );
639 // explore nodes in the frontier
640 Vec_PtrForEachEntry( Gia_Obj_t *, p->vFrontier, pNode, i )
641 {
642 // create the supergate
643 assert( Cec4_ObjSatId(p->pNew,pNode) >= 0 );
644 if ( fUseMuxes && pNode->fMark0 )
645 {
646 Vec_PtrClear( p->vFanins );
647 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin0( Gia_ObjFanin0(pNode) ) );
648 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin0( Gia_ObjFanin1(pNode) ) );
649 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin1( Gia_ObjFanin0(pNode) ) );
650 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin1( Gia_ObjFanin1(pNode) ) );
651 Vec_PtrForEachEntry( Gia_Obj_t *, p->vFanins, pFanin, k )
652 Cec4_ObjAddToFrontier( p->pNew, Gia_Regular(pFanin), p->vFrontier, p->pSat );
653 Cec4_AddClausesMux( p->pNew, pNode, p->pSat );
654 }
655 else
656 {
657 Cec4_CollectSuper( pNode, fUseMuxes, p->vFanins );
658 Vec_PtrForEachEntry( Gia_Obj_t *, p->vFanins, pFanin, k )
659 Cec4_ObjAddToFrontier( p->pNew, Gia_Regular(pFanin), p->vFrontier, p->pSat );
660 Cec4_AddClausesSuper( p->pNew, pNode, p->vFanins, p->pSat );
661 }
662 assert( Vec_PtrSize(p->vFanins) > 1 );
663 }
664 return Cec4_ObjSatId(p->pNew,pObj);
665}
666
667
679static inline word * Cec4_ObjSim( Gia_Man_t * p, int iObj )
680{
681 return Vec_WrdEntryP( p->vSims, p->nSimWords * iObj );
682}
683static inline int Cec4_ObjSimEqual( Gia_Man_t * p, int iObj0, int iObj1 )
684{
685 int w;
686 word * pSim0 = Cec4_ObjSim( p, iObj0 );
687 word * pSim1 = Cec4_ObjSim( p, iObj1 );
688 if ( (pSim0[0] & 1) == (pSim1[0] & 1) )
689 {
690 for ( w = 0; w < p->nSimWords; w++ )
691 if ( pSim0[w] != pSim1[w] )
692 return 0;
693 return 1;
694 }
695 else
696 {
697 for ( w = 0; w < p->nSimWords; w++ )
698 if ( pSim0[w] != ~pSim1[w] )
699 return 0;
700 return 1;
701 }
702}
703int Cec4_ManSimHashKey( word * pSim, int nSims, int nTableSize )
704{
705 static int s_Primes[16] = {
706 1291, 1699, 1999, 2357, 2953, 3313, 3907, 4177,
707 4831, 5147, 5647, 6343, 6899, 7103, 7873, 8147 };
708 unsigned uHash = 0, * pSimU = (unsigned *)pSim;
709 int i, nSimsU = 2 * nSims;
710 if ( pSimU[0] & 1 )
711 for ( i = 0; i < nSimsU; i++ )
712 uHash ^= ~pSimU[i] * s_Primes[i & 0xf];
713 else
714 for ( i = 0; i < nSimsU; i++ )
715 uHash ^= pSimU[i] * s_Primes[i & 0xf];
716 return (int)(uHash % nTableSize);
717
718}
720{
721 int iObj, iPrev = iRepr, iPrev2, iRepr2;
722 assert( Gia_ObjRepr(p, iRepr) == GIA_VOID );
723 assert( Gia_ObjNext(p, iRepr) > 0 );
724 Gia_ClassForEachObj1( p, iRepr, iRepr2 )
725 if ( Cec4_ObjSimEqual(p, iRepr, iRepr2) )
726 iPrev = iRepr2;
727 else
728 break;
729 if ( iRepr2 <= 0 ) // no refinement
730 return;
731 // relink remaining nodes of the class
732 // nodes that are equal to iRepr, remain in the class of iRepr
733 // nodes that are not equal to iRepr, move to the class of iRepr2
734 Gia_ObjSetRepr( p, iRepr2, GIA_VOID );
735 iPrev2 = iRepr2;
736 for ( iObj = Gia_ObjNext(p, iRepr2); iObj > 0; iObj = Gia_ObjNext(p, iObj) )
737 {
738 if ( Cec4_ObjSimEqual(p, iRepr, iObj) ) // remains with iRepr
739 {
740 Gia_ObjSetNext( p, iPrev, iObj );
741 iPrev = iObj;
742 }
743 else // moves to iRepr2
744 {
745 Gia_ObjSetRepr( p, iObj, iRepr2 );
746 Gia_ObjSetNext( p, iPrev2, iObj );
747 iPrev2 = iObj;
748 }
749 }
750 Gia_ObjSetNext( p, iPrev, -1 );
751 Gia_ObjSetNext( p, iPrev2, -1 );
752 // refine incrementally
753 if ( Gia_ObjNext(p, iRepr2) > 0 )
754 Cec4_RefineOneClassIter( p, iRepr2 );
755}
757{
758 int k, iObj, Bin;
759 Vec_IntClear( pMan->vRefBins );
760 Vec_IntForEachEntryReverse( vNodes, iObj, k )
761 {
762 int Key = Cec4_ManSimHashKey( Cec4_ObjSim(p, iObj), p->nSimWords, pMan->nTableSize );
763 assert( Key >= 0 && Key < pMan->nTableSize );
764 if ( pMan->pTable[Key] == -1 )
765 Vec_IntPush( pMan->vRefBins, Key );
766 p->pNexts[iObj] = pMan->pTable[Key];
767 pMan->pTable[Key] = iObj;
768 }
769 Vec_IntForEachEntry( pMan->vRefBins, Bin, k )
770 {
771 int iRepr = pMan->pTable[Bin];
772 pMan->pTable[Bin] = -1;
773 assert( p->pReprs[iRepr].iRepr == GIA_VOID );
774 assert( p->pNexts[iRepr] != 0 );
775 if ( p->pNexts[iRepr] == -1 )
776 continue;
777 for ( iObj = p->pNexts[iRepr]; iObj > 0; iObj = p->pNexts[iObj] )
778 p->pReprs[iObj].iRepr = iRepr;
779 Cec4_RefineOneClassIter( p, iRepr );
780 }
781 Vec_IntClear( pMan->vRefBins );
782}
783void Cec4_RefineClasses( Gia_Man_t * p, Cec4_Man_t * pMan, Vec_Int_t * vClasses )
784{
785 if ( Vec_IntSize(pMan->vRefClasses) == 0 )
786 return;
787 if ( Vec_IntSize(pMan->vRefNodes) > 0 )
788 Cec4_RefineOneClass( p, pMan, pMan->vRefNodes );
789 else
790 {
791 int i, k, iObj, iRepr;
792 Vec_IntForEachEntry( pMan->vRefClasses, iRepr, i )
793 {
794 assert( p->pReprs[iRepr].fColorA );
795 p->pReprs[iRepr].fColorA = 0;
796 Vec_IntClear( pMan->vRefNodes );
797 Vec_IntPush( pMan->vRefNodes, iRepr );
798 Gia_ClassForEachObj1( p, iRepr, k )
799 Vec_IntPush( pMan->vRefNodes, k );
800 Vec_IntForEachEntry( pMan->vRefNodes, iObj, k )
801 {
802 p->pReprs[iObj].iRepr = GIA_VOID;
803 p->pNexts[iObj] = -1;
804 }
805 Cec4_RefineOneClass( p, pMan, pMan->vRefNodes );
806 }
807 }
808 Vec_IntClear( pMan->vRefClasses );
809 Vec_IntClear( pMan->vRefNodes );
810}
812{
813 Gia_Obj_t * pObj; int i;
814 ABC_FREE( p->pReprs );
815 ABC_FREE( p->pNexts );
816 p->pReprs = ABC_CALLOC( Gia_Rpr_t, Gia_ManObjNum(p) );
817 p->pNexts = ABC_FALLOC( int, Gia_ManObjNum(p) );
818 pMan->nTableSize = Abc_PrimeCudd( Gia_ManObjNum(p) );
819 pMan->pTable = ABC_FALLOC( int, pMan->nTableSize );
820 pMan->vRefNodes = Vec_IntAlloc( Gia_ManObjNum(p) );
821 Gia_ManForEachObj( p, pObj, i )
822 {
823 p->pReprs[i].iRepr = GIA_VOID;
824 if ( !Gia_ObjIsCo(pObj) && (!pMan->pPars->nLevelMax || Gia_ObjLevel(p, pObj) <= pMan->pPars->nLevelMax) )
825 Vec_IntPush( pMan->vRefNodes, i );
826 }
827 pMan->vRefBins = Vec_IntAlloc( Gia_ManObjNum(p)/2 );
828 pMan->vRefClasses = Vec_IntAlloc( Gia_ManObjNum(p)/2 );
829 Vec_IntPush( pMan->vRefClasses, 0 );
830}
831
832
844static inline void Cec4_ObjSimSetInputBit( Gia_Man_t * p, int iObj, int Bit )
845{
846 word * pSim = Cec4_ObjSim( p, iObj );
847 if ( Abc_InfoHasBit( (unsigned*)pSim, p->iPatsPi ) != Bit )
848 Abc_InfoXorBit( (unsigned*)pSim, p->iPatsPi );
849}
850static inline int Cec4_ObjSimGetInputBit( Gia_Man_t * p, int iObj )
851{
852 word * pSim = Cec4_ObjSim( p, iObj );
853 return Abc_InfoHasBit( (unsigned*)pSim, p->iPatsPi );
854}
855static inline void Cec4_ObjSimRo( Gia_Man_t * p, int iObj )
856{
857 int w;
858 word * pSimRo = Cec4_ObjSim( p, iObj );
859 word * pSimRi = Cec4_ObjSim( p, Gia_ObjRoToRiId(p, iObj) );
860 for ( w = 0; w < p->nSimWords; w++ )
861 pSimRo[w] = pSimRi[w];
862}
863static inline void Cec4_ObjSimCo( Gia_Man_t * p, int iObj )
864{
865 int w;
866 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
867 word * pSimCo = Cec4_ObjSim( p, iObj );
868 word * pSimDri = Cec4_ObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
869 if ( Gia_ObjFaninC0(pObj) )
870 for ( w = 0; w < p->nSimWords; w++ )
871 pSimCo[w] = ~pSimDri[w];
872 else
873 for ( w = 0; w < p->nSimWords; w++ )
874 pSimCo[w] = pSimDri[w];
875}
876static inline void Cec4_ObjSimAnd( Gia_Man_t * p, int iObj )
877{
878 int w;
879 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
880 word * pSim = Cec4_ObjSim( p, iObj );
881 word * pSim0 = Cec4_ObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
882 word * pSim1 = Cec4_ObjSim( p, Gia_ObjFaninId1(pObj, iObj) );
883 if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
884 for ( w = 0; w < p->nSimWords; w++ )
885 pSim[w] = ~pSim0[w] & ~pSim1[w];
886 else if ( Gia_ObjFaninC0(pObj) && !Gia_ObjFaninC1(pObj) )
887 for ( w = 0; w < p->nSimWords; w++ )
888 pSim[w] = ~pSim0[w] & pSim1[w];
889 else if ( !Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
890 for ( w = 0; w < p->nSimWords; w++ )
891 pSim[w] = pSim0[w] & ~pSim1[w];
892 else
893 for ( w = 0; w < p->nSimWords; w++ )
894 pSim[w] = pSim0[w] & pSim1[w];
895}
896static inline void Cec4_ObjSimXor( Gia_Man_t * p, int iObj )
897{
898 int w;
899 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
900 word * pSim = Cec4_ObjSim( p, iObj );
901 word * pSim0 = Cec4_ObjSim( p, Gia_ObjFaninId0(pObj, iObj) );
902 word * pSim1 = Cec4_ObjSim( p, Gia_ObjFaninId1(pObj, iObj) );
903 if ( Gia_ObjFaninC0(pObj) ^ Gia_ObjFaninC1(pObj) )
904 for ( w = 0; w < p->nSimWords; w++ )
905 pSim[w] = ~pSim0[w] ^ pSim1[w];
906 else
907 for ( w = 0; w < p->nSimWords; w++ )
908 pSim[w] = pSim0[w] ^ pSim1[w];
909}
910static inline void Cec4_ObjSimCi( Gia_Man_t * p, int iObj )
911{
912 int w;
913 word * pSim = Cec4_ObjSim( p, iObj );
914 for ( w = 0; w < p->nSimWords; w++ )
915 pSim[w] = Abc_RandomW( 0 );
916 pSim[0] <<= 1;
917}
918static inline void Cec4_ObjClearSimCi( Gia_Man_t * p, int iObj )
919{
920 int w;
921 word * pSim = Cec4_ObjSim( p, iObj );
922 for ( w = 0; w < p->nSimWords; w++ )
923 pSim[w] = 0;
924}
926{
927 int i, Id;
928 Gia_ManForEachCiId( p, Id, i )
929 Cec4_ObjSimCi( p, Id );
930 p->iPatsPi = 0;
931}
933{
934 int i, Id;
935 Gia_ManForEachCiId( p, Id, i )
936 Cec4_ObjClearSimCi( p, Id );
937 p->iPatsPi = 0;
938}
939Abc_Cex_t * Cec4_ManDeriveCex( Gia_Man_t * p, int iOut, int iPat )
940{
941 Abc_Cex_t * pCex;
942 int i, Id;
943 pCex = Abc_CexAlloc( 0, Gia_ManCiNum(p), 1 );
944 pCex->iPo = iOut;
945 if ( iPat == -1 )
946 return pCex;
947 Gia_ManForEachCiId( p, Id, i )
948 if ( Abc_InfoHasBit((unsigned *)Cec4_ObjSim(p, Id), iPat) )
949 Abc_InfoSetBit( pCex->pData, i );
950 return pCex;
951}
953{
954 int i, Id;
955 // check outputs and generate CEX if they fail
956 Gia_ManForEachCoId( p, Id, i )
957 {
958 Cec4_ObjSimCo( p, Id );
959 if ( Cec4_ObjSimEqual(p, Id, 0) )
960 continue;
961 p->pCexSeq = Cec4_ManDeriveCex( p, i, Abc_TtFindFirstBit2(Cec4_ObjSim(p, Id), p->nSimWords) );
962 return 0;
963 }
964 return 1;
965}
967{
968 abctime clk = Abc_Clock();
969 Gia_Obj_t * pObj; int i;
970 pMan->nSimulates++;
971 if ( pMan->pTable == NULL )
972 Cec4_RefineInit( p, pMan );
973 else
974 assert( Vec_IntSize(pMan->vRefClasses) == 0 );
975 Gia_ManForEachAnd( p, pObj, i )
976 {
977 int iRepr = Gia_ObjRepr( p, i );
978 if ( Gia_ObjIsXor(pObj) )
979 Cec4_ObjSimXor( p, i );
980 else
981 Cec4_ObjSimAnd( p, i );
982 if ( iRepr == GIA_VOID || p->pReprs[iRepr].fColorA || Cec4_ObjSimEqual(p, iRepr, i) )
983 continue;
984 p->pReprs[iRepr].fColorA = 1;
985 Vec_IntPush( pMan->vRefClasses, iRepr );
986 }
987 pMan->timeSim += Abc_Clock() - clk;
988 clk = Abc_Clock();
989 Cec4_RefineClasses( p, pMan, pMan->vRefClasses );
990 pMan->timeRefine += Abc_Clock() - clk;
991}
992void Cec4_ManSimulate_rec( Gia_Man_t * p, Cec4_Man_t * pMan, int iObj )
993{
994 Gia_Obj_t * pObj;
995 if ( !iObj || Vec_IntEntry(pMan->vCexStamps, iObj) == p->iPatsPi )
996 return;
997 Vec_IntWriteEntry( pMan->vCexStamps, iObj, p->iPatsPi );
998 pObj = Gia_ManObj(p, iObj);
999 if ( Gia_ObjIsCi(pObj) )
1000 return;
1001 assert( Gia_ObjIsAnd(pObj) );
1002 Cec4_ManSimulate_rec( p, pMan, Gia_ObjFaninId0(pObj, iObj) );
1003 Cec4_ManSimulate_rec( p, pMan, Gia_ObjFaninId1(pObj, iObj) );
1004 if ( Gia_ObjIsXor(pObj) )
1005 Cec4_ObjSimXor( p, iObj );
1006 else
1007 Cec4_ObjSimAnd( p, iObj );
1008}
1010{
1011 Vec_WrdFreeP( &p->vSims );
1012 Vec_WrdFreeP( &p->vSimsPi );
1013 p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * nWords );
1014 p->vSimsPi = Vec_WrdStart( (Gia_ManCiNum(p) + 1) * nWords );
1015 p->nSimWords = nWords;
1016}
1017
1018
1031{
1032 Vec_Int_t * vRoots = Vec_IntAlloc( 100 );
1033 Vec_Int_t * vNodes = Vec_IntAlloc( 100 );
1034 Vec_Int_t * vLeaves = Vec_IntAlloc( 100 );
1035 int i, k;
1037 {
1038 Vec_IntClear( vRoots );
1039 if ( i % 100 != 0 )
1040 continue;
1041 Vec_IntPush( vRoots, i );
1042 Gia_ClassForEachObj1( p, i, k )
1043 Vec_IntPush( vRoots, k );
1044 Gia_ManCollectTfi( p, vRoots, vNodes );
1045 printf( "Class %6d : ", i );
1046 printf( "Roots = %6d ", Vec_IntSize(vRoots) );
1047 printf( "Nodes = %6d ", Vec_IntSize(vNodes) );
1048 printf( "\n" );
1049 }
1050 Vec_IntFree( vRoots );
1051 Vec_IntFree( vNodes );
1052 Vec_IntFree( vLeaves );
1053}
1054void Cec4_ManPrintStats( Gia_Man_t * p, Cec_ParFra_t * pPars, Cec4_Man_t * pMan, int fSim )
1055{
1056 static abctime clk = 0;
1057 abctime clkThis = 0;
1058 int i, nLits, Counter = 0, Counter0 = 0, CounterX = 0;
1059 if ( !pPars->fVerbose )
1060 return;
1061 if ( pMan->nItersSim + pMan->nItersSat )
1062 clkThis = Abc_Clock() - clk;
1063 clk = Abc_Clock();
1064 for ( i = 0; i < Gia_ManObjNum(p); i++ )
1065 {
1066 if ( Gia_ObjIsHead(p, i) )
1067 Counter++;
1068 else if ( Gia_ObjIsConst(p, i) )
1069 Counter0++;
1070 else if ( Gia_ObjIsNone(p, i) )
1071 CounterX++;
1072 }
1073 nLits = Gia_ManObjNum(p) - Counter - CounterX;
1074 if ( fSim )
1075 {
1076 printf( "Sim %4d : ", pMan->nItersSim++ + pMan->nItersSat );
1077 printf( "%6.2f %% ", 100.0*nLits/Gia_ManCandNum(p) );
1078 }
1079 else
1080 {
1081 printf( "SAT %4d : ", pMan->nItersSim + pMan->nItersSat++ );
1082 printf( "%6.2f %% ", 100.0*pMan->nAndNodes/Gia_ManAndNum(p) );
1083 }
1084 printf( "P =%7d ", pMan ? pMan->nSatUnsat : 0 );
1085 printf( "D =%7d ", pMan ? pMan->nSatSat : 0 );
1086 printf( "F =%8d ", pMan ? pMan->nSatUndec : 0 );
1087 //printf( "Last =%6d ", pMan ? pMan->iLastConst : 0 );
1088 Abc_Print( 1, "cst =%9d cls =%8d lit =%9d ", Counter0, Counter, nLits );
1089 Abc_PrintTime( 1, "Time", clkThis );
1090}
1092{
1093 int i, k;
1095 {
1096 printf( "Class %d : ", i );
1097 Gia_ClassForEachObj1( p, i, k )
1098 printf( "%d ", k );
1099 printf( "\n" );
1100 }
1101}
1103{
1104 int k, Count = 0;
1105 Gia_ClassForEachObj1( p, 0, k )
1106 Count++;
1107 printf( "Const0 class has %d entries.\n", Count );
1108}
1109
1110
1122int Cec4_ManVerify_rec( Gia_Man_t * p, int iObj, sat_solver * pSat )
1123{
1124 int Value0, Value1;
1125 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
1126 if ( iObj == 0 ) return 0;
1127 if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
1128 return pObj->fMark1;
1129 Gia_ObjSetTravIdCurrentId(p, iObj);
1130 if ( Gia_ObjIsCi(pObj) )
1131 return pObj->fMark1 = sat_solver_read_cex_varvalue(pSat, Cec4_ObjSatId(p, pObj));
1132 assert( Gia_ObjIsAnd(pObj) );
1133 Value0 = Cec4_ManVerify_rec( p, Gia_ObjFaninId0(pObj, iObj), pSat ) ^ Gia_ObjFaninC0(pObj);
1134 Value1 = Cec4_ManVerify_rec( p, Gia_ObjFaninId1(pObj, iObj), pSat ) ^ Gia_ObjFaninC1(pObj);
1135 return pObj->fMark1 = Gia_ObjIsXor(pObj) ? Value0 ^ Value1 : Value0 & Value1;
1136}
1137void Cec4_ManVerify( Gia_Man_t * p, int iObj0, int iObj1, int fPhase, sat_solver * pSat )
1138{
1139 int Value0, Value1;
1141 Value0 = Cec4_ManVerify_rec( p, iObj0, pSat );
1142 Value1 = Cec4_ManVerify_rec( p, iObj1, pSat );
1143 if ( (Value0 ^ Value1) == fPhase )
1144 printf( "CEX verification FAILED for obj %d and obj %d.\n", iObj0, iObj1 );
1145// else
1146// printf( "CEX verification succeeded for obj %d and obj %d.\n", iObj0, iObj1 );;
1147}
1148
1149
1162{
1163 int Value0, Value1;
1164 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
1165 if ( iObj == 0 ) return 0;
1166 if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
1167 return pObj->fMark1;
1168 Gia_ObjSetTravIdCurrentId(p, iObj);
1169 if ( Gia_ObjIsCi(pObj) )
1170 return pObj->fMark1 = Cec4_ObjSimGetInputBit(p, iObj);
1171 assert( Gia_ObjIsAnd(pObj) );
1172 Value0 = Cec4_ManCexVerify_rec( p, Gia_ObjFaninId0(pObj, iObj) ) ^ Gia_ObjFaninC0(pObj);
1173 Value1 = Cec4_ManCexVerify_rec( p, Gia_ObjFaninId1(pObj, iObj) ) ^ Gia_ObjFaninC1(pObj);
1174 return pObj->fMark1 = Gia_ObjIsXor(pObj) ? Value0 ^ Value1 : Value0 & Value1;
1175}
1176void Cec4_ManCexVerify( Gia_Man_t * p, int iObj0, int iObj1, int fPhase )
1177{
1178 int Value0, Value1;
1180 Value0 = Cec4_ManCexVerify_rec( p, iObj0 );
1181 Value1 = Cec4_ManCexVerify_rec( p, iObj1 );
1182 if ( (Value0 ^ Value1) == fPhase )
1183 printf( "CEX verification FAILED for obj %d and obj %d.\n", iObj0, iObj1 );
1184// else
1185// printf( "CEX verification succeeded for obj %d and obj %d.\n", iObj0, iObj1 );;
1186}
1187
1199void Cec4_ManPackAddPatterns( Gia_Man_t * p, int iBit, Vec_Int_t * vLits )
1200{
1201 int k, Limit = Abc_MinInt( Vec_IntSize(vLits), 64 * p->nSimWords - 1 );
1202 for ( k = 0; k < Limit; k++ )
1203 {
1204 int i, Lit, iBitLocal = (iBit + k + 1) % Limit + 1;
1205 assert( iBitLocal > 0 && iBitLocal < 64 * p->nSimWords );
1206 Vec_IntForEachEntry( vLits, Lit, i )
1207 {
1208 word * pInfo = Vec_WrdEntryP( p->vSims, p->nSimWords * Abc_Lit2Var(Lit) );
1209 word * pPres = Vec_WrdEntryP( p->vSimsPi, p->nSimWords * Abc_Lit2Var(Lit) );
1210 if ( Abc_InfoHasBit( (unsigned *)pPres, iBitLocal ) )
1211 continue;
1212 if ( Abc_InfoHasBit( (unsigned *)pInfo, iBitLocal ) != Abc_LitIsCompl(Lit ^ (i == k)) )
1213 Abc_InfoXorBit( (unsigned *)pInfo, iBitLocal );
1214 }
1215 }
1216}
1218{
1219 int i, Lit;
1220 assert( p->iPatsPi > 0 && p->iPatsPi < 64 * p->nSimWords );
1221 Vec_IntForEachEntry( vLits, Lit, i )
1222 {
1223 word * pInfo = Vec_WrdEntryP( p->vSims, p->nSimWords * Abc_Lit2Var(Lit) );
1224 word * pPres = Vec_WrdEntryP( p->vSimsPi, p->nSimWords * Abc_Lit2Var(Lit) );
1225 if ( Abc_InfoHasBit( (unsigned *)pPres, iBit ) &&
1226 Abc_InfoHasBit( (unsigned *)pInfo, iBit ) != Abc_LitIsCompl(Lit) )
1227 return 0;
1228 }
1229 Vec_IntForEachEntry( vLits, Lit, i )
1230 {
1231 word * pInfo = Vec_WrdEntryP( p->vSims, p->nSimWords * Abc_Lit2Var(Lit) );
1232 word * pPres = Vec_WrdEntryP( p->vSimsPi, p->nSimWords * Abc_Lit2Var(Lit) );
1233 Abc_InfoSetBit( (unsigned *)pPres, iBit );
1234 if ( Abc_InfoHasBit( (unsigned *)pInfo, iBit ) != Abc_LitIsCompl(Lit) )
1235 Abc_InfoXorBit( (unsigned *)pInfo, iBit );
1236 }
1237 return 1;
1238}
1239int Cec4_ManPackAddPattern( Gia_Man_t * p, Vec_Int_t * vLits, int fExtend )
1240{
1241 int k;
1242 for ( k = 1; k < 64 * p->nSimWords - 1; k++ )
1243 {
1244 if ( ++p->iPatsPi == 64 * p->nSimWords - 1 )
1245 p->iPatsPi = 1;
1246 if ( Cec4_ManPackAddPatternTry( p, p->iPatsPi, vLits ) )
1247 {
1248 if ( fExtend )
1249 Cec4_ManPackAddPatterns( p, p->iPatsPi, vLits );
1250 break;
1251 }
1252 }
1253 if ( k == 64 * p->nSimWords - 1 )
1254 {
1255 p->iPatsPi = k;
1256 if ( !Cec4_ManPackAddPatternTry( p, p->iPatsPi, vLits ) )
1257 printf( "Internal error.\n" );
1258 else if ( fExtend )
1259 Cec4_ManPackAddPatterns( p, p->iPatsPi, vLits );
1260 return 64 * p->nSimWords;
1261 }
1262 return k;
1263}
1264
1276static inline int Cec4_ObjFan0IsAssigned( Gia_Obj_t * pObj )
1277{
1278 return Gia_ObjFanin0(pObj)->fMark0 || Gia_ObjFanin0(pObj)->fMark1;
1279}
1280static inline int Cec4_ObjFan1IsAssigned( Gia_Obj_t * pObj )
1281{
1282 return Gia_ObjFanin1(pObj)->fMark0 || Gia_ObjFanin1(pObj)->fMark1;
1283}
1284static inline int Cec4_ObjFan0HasValue( Gia_Obj_t * pObj, int v )
1285{
1286 return (v ^ Gia_ObjFaninC0(pObj)) ? Gia_ObjFanin0(pObj)->fMark1 : Gia_ObjFanin0(pObj)->fMark0;
1287}
1288static inline int Cec4_ObjFan1HasValue( Gia_Obj_t * pObj, int v )
1289{
1290 return (v ^ Gia_ObjFaninC1(pObj)) ? Gia_ObjFanin1(pObj)->fMark1 : Gia_ObjFanin1(pObj)->fMark0;
1291}
1292static inline int Cec4_ObjObjIsImpliedValue( Gia_Obj_t * pObj, int v )
1293{
1294 assert( !pObj->fMark0 && !pObj->fMark1 ); // not visited
1295 if ( v )
1296 return Cec4_ObjFan0HasValue(pObj, 1) && Cec4_ObjFan1HasValue(pObj, 1);
1297 return Cec4_ObjFan0HasValue(pObj, 0) || Cec4_ObjFan1HasValue(pObj, 0);
1298}
1299static inline int Cec4_ObjFan0IsImpliedValue( Gia_Obj_t * pObj, int v )
1300{
1301 return Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) && Cec4_ObjObjIsImpliedValue( Gia_ObjFanin0(pObj), v ^ Gia_ObjFaninC0(pObj) );
1302}
1303static inline int Cec4_ObjFan1IsImpliedValue( Gia_Obj_t * pObj, int v )
1304{
1305 return Gia_ObjIsAnd(Gia_ObjFanin1(pObj)) && Cec4_ObjObjIsImpliedValue( Gia_ObjFanin1(pObj), v ^ Gia_ObjFaninC1(pObj) );
1306}
1307int Cec4_ManGeneratePatterns_rec( Gia_Man_t * p, Gia_Obj_t * pObj, int Value, Vec_Int_t * vPat, Vec_Int_t * vVisit )
1308{
1309 Gia_Obj_t * pFan0, * pFan1;
1310 assert( !pObj->fMark0 && !pObj->fMark1 ); // not visited
1311 if ( Value ) pObj->fMark1 = 1; else pObj->fMark0 = 1;
1312 Vec_IntPush( vVisit, Gia_ObjId(p, pObj) );
1313 if ( Gia_ObjIsCi(pObj) )
1314 {
1315 Vec_IntPush( vPat, Abc_Var2Lit(Gia_ObjId(p, pObj), Value) );
1316 return 1;
1317 }
1318 assert( Gia_ObjIsAnd(pObj) );
1319 pFan0 = Gia_ObjFanin0(pObj);
1320 pFan1 = Gia_ObjFanin1(pObj);
1321 if ( Gia_ObjIsXor(pObj) )
1322 {
1323 int Ass0 = Cec4_ObjFan0IsAssigned(pObj);
1324 int Ass1 = Cec4_ObjFan1IsAssigned(pObj);
1325 assert( Gia_ObjFaninC0(pObj) == 0 && Gia_ObjFaninC1(pObj) == 0 );
1326 if ( Ass0 && Ass1 )
1327 return Value == (Cec4_ObjFan0HasValue(pObj, 1) ^ Cec4_ObjFan1HasValue(pObj, 1));
1328 if ( Ass0 )
1329 {
1330 int ValueInt = Value ^ Cec4_ObjFan0HasValue(pObj, 1);
1331 if ( !Cec4_ManGeneratePatterns_rec(p, pFan1, ValueInt, vPat, vVisit) )
1332 return 0;
1333 }
1334 else if ( Ass1 )
1335 {
1336 int ValueInt = Value ^ Cec4_ObjFan1HasValue(pObj, 1);
1337 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, ValueInt, vPat, vVisit) )
1338 return 0;
1339 }
1340 else if ( Abc_Random(0) & 1 )
1341 {
1342 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, 0, vPat, vVisit) )
1343 return 0;
1344 if ( Cec4_ObjFan1HasValue(pObj, !Value) || (!Cec4_ObjFan1HasValue(pObj, Value) && !Cec4_ManGeneratePatterns_rec(p, pFan1, Value, vPat, vVisit)) )
1345 return 0;
1346 }
1347 else
1348 {
1349 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, 1, vPat, vVisit) )
1350 return 0;
1351 if ( Cec4_ObjFan1HasValue(pObj, Value) || (!Cec4_ObjFan1HasValue(pObj, !Value) && !Cec4_ManGeneratePatterns_rec(p, pFan1, !Value, vPat, vVisit)) )
1352 return 0;
1353 }
1354 assert( Value == (Cec4_ObjFan0HasValue(pObj, 1) ^ Cec4_ObjFan1HasValue(pObj, 1)) );
1355 return 1;
1356 }
1357 else if ( Value )
1358 {
1359 if ( Cec4_ObjFan0HasValue(pObj, 0) || Cec4_ObjFan1HasValue(pObj, 0) )
1360 return 0;
1361 if ( !Cec4_ObjFan0HasValue(pObj, 1) && !Cec4_ManGeneratePatterns_rec(p, pFan0, !Gia_ObjFaninC0(pObj), vPat, vVisit) )
1362 return 0;
1363 if ( !Cec4_ObjFan1HasValue(pObj, 1) && !Cec4_ManGeneratePatterns_rec(p, pFan1, !Gia_ObjFaninC1(pObj), vPat, vVisit) )
1364 return 0;
1365 assert( Cec4_ObjFan0HasValue(pObj, 1) && Cec4_ObjFan1HasValue(pObj, 1) );
1366 return 1;
1367 }
1368 else
1369 {
1370 if ( Cec4_ObjFan0HasValue(pObj, 1) && Cec4_ObjFan1HasValue(pObj, 1) )
1371 return 0;
1372 if ( Cec4_ObjFan0HasValue(pObj, 0) || Cec4_ObjFan1HasValue(pObj, 0) )
1373 return 1;
1374 if ( Cec4_ObjFan0HasValue(pObj, 1) )
1375 {
1376 if ( !Cec4_ManGeneratePatterns_rec(p, pFan1, Gia_ObjFaninC1(pObj), vPat, vVisit) )
1377 return 0;
1378 }
1379 else if ( Cec4_ObjFan1HasValue(pObj, 1) )
1380 {
1381 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, Gia_ObjFaninC0(pObj), vPat, vVisit) )
1382 return 0;
1383 }
1384 else
1385 {
1386 if ( Cec4_ObjFan0IsImpliedValue( pObj, 0 ) )
1387 {
1388 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, Gia_ObjFaninC0(pObj), vPat, vVisit) )
1389 return 0;
1390 }
1391 else if ( Cec4_ObjFan1IsImpliedValue( pObj, 0 ) )
1392 {
1393 if ( !Cec4_ManGeneratePatterns_rec(p, pFan1, Gia_ObjFaninC1(pObj), vPat, vVisit) )
1394 return 0;
1395 }
1396 else if ( Cec4_ObjFan0IsImpliedValue( pObj, 1 ) )
1397 {
1398 if ( !Cec4_ManGeneratePatterns_rec(p, pFan1, Gia_ObjFaninC1(pObj), vPat, vVisit) )
1399 return 0;
1400 }
1401 else if ( Cec4_ObjFan1IsImpliedValue( pObj, 1 ) )
1402 {
1403 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, Gia_ObjFaninC0(pObj), vPat, vVisit) )
1404 return 0;
1405 }
1406 else if ( Abc_Random(0) & 1 )
1407 {
1408 if ( !Cec4_ManGeneratePatterns_rec(p, pFan1, Gia_ObjFaninC1(pObj), vPat, vVisit) )
1409 return 0;
1410 }
1411 else
1412 {
1413 if ( !Cec4_ManGeneratePatterns_rec(p, pFan0, Gia_ObjFaninC0(pObj), vPat, vVisit) )
1414 return 0;
1415 }
1416 }
1417 assert( Cec4_ObjFan0HasValue(pObj, 0) || Cec4_ObjFan1HasValue(pObj, 0) );
1418 return 1;
1419 }
1420}
1421int Cec4_ManGeneratePatternOne( Gia_Man_t * p, int iRepr, int iReprVal, int iCand, int iCandVal, Vec_Int_t * vPat, Vec_Int_t * vVisit )
1422{
1423 int Res, k;
1424 Gia_Obj_t * pObj;
1425 assert( iCand > 0 );
1426 if ( !iRepr && iReprVal )
1427 return 0;
1428 Vec_IntClear( vPat );
1429 Vec_IntClear( vVisit );
1430 //Gia_ManForEachObj( p, pObj, k )
1431 // assert( !pObj->fMark0 && !pObj->fMark1 );
1432 Res = (!iRepr || Cec4_ManGeneratePatterns_rec(p, Gia_ManObj(p, iRepr), iReprVal, vPat, vVisit)) && Cec4_ManGeneratePatterns_rec(p, Gia_ManObj(p, iCand), iCandVal, vPat, vVisit);
1433 Gia_ManForEachObjVec( vVisit, p, pObj, k )
1434 pObj->fMark0 = pObj->fMark1 = 0;
1435 return Res;
1436}
1438{
1439 int i, * pArray;
1440 assert( p->iPosWrite == 0 );
1441 assert( p->iPosRead == 0 );
1442 assert( Vec_IntSize(p->vCands) == 0 );
1443 for ( i = 1; i < Gia_ManObjNum(p->pAig); i++ )
1444 if ( Gia_ObjRepr(p->pAig, i) != GIA_VOID )
1445 Vec_IntPush( p->vCands, i );
1446 pArray = Vec_IntArray( p->vCands );
1447 for ( i = 0; i < Vec_IntSize(p->vCands); i++ )
1448 {
1449 int iNew = Abc_Random(0) % Vec_IntSize(p->vCands);
1450 ABC_SWAP( int, pArray[i], pArray[iNew] );
1451 }
1452}
1454{
1455 while ( Vec_IntSize(p->vCands) > 0 )
1456 {
1457 int fStop, iCand = Vec_IntEntry( p->vCands, p->iPosRead );
1458 if ( (fStop = (Gia_ObjRepr(p->pAig, iCand) != GIA_VOID)) )
1459 Vec_IntWriteEntry( p->vCands, p->iPosWrite++, iCand );
1460 if ( ++p->iPosRead == Vec_IntSize(p->vCands) )
1461 {
1462 Vec_IntShrink( p->vCands, p->iPosWrite );
1463 p->iPosWrite = 0;
1464 p->iPosRead = 0;
1465 }
1466 if ( fStop )
1467 return iCand;
1468 }
1469 return 0;
1470}
1472{
1473 abctime clk = Abc_Clock();
1474 int i, iCand, nPats = 100 * 64 * p->pAig->nSimWords, CountPat = 0, Packs = 0;
1475 //int iRepr;
1476 //Vec_IntForEachEntryDouble( p->vDisprPairs, iRepr, iCand, i )
1477 // if ( iRepr == Gia_ObjRepr(p->pAig, iCand) )
1478 // printf( "Pair %6d (%6d, %6d) (new repr = %9d) is FAILED to disprove.\n", i, iRepr, iCand, Gia_ObjRepr(p->pAig, iCand) );
1479 // else
1480 // printf( "Pair %6d (%6d, %6d) (new repr = %9d) is disproved.\n", i, iRepr, iCand, Gia_ObjRepr(p->pAig, iCand) );
1481 //Vec_IntClear( p->vDisprPairs );
1482 p->pAig->iPatsPi = 0;
1483 Vec_WrdFill( p->pAig->vSimsPi, Vec_WrdSize(p->pAig->vSimsPi), 0 );
1484 for ( i = 0; i < nPats; i++ )
1485 if ( (iCand = Cec4_ManCandIterNext(p)) )
1486 {
1487 int iRepr = Gia_ObjRepr( p->pAig, iCand );
1488 int iCandVal = Gia_ManObj(p->pAig, iCand)->fPhase;
1489 int iReprVal = Gia_ManObj(p->pAig, iRepr)->fPhase;
1490 int Res = Cec4_ManGeneratePatternOne( p->pAig, iRepr, iReprVal, iCand, !iCandVal, p->vPat, p->vVisit );
1491 if ( !Res )
1492 Res = Cec4_ManGeneratePatternOne( p->pAig, iRepr, !iReprVal, iCand, iCandVal, p->vPat, p->vVisit );
1493 if ( Res )
1494 {
1495 int Ret = Cec4_ManPackAddPattern( p->pAig, p->vPat, 1 );
1496 if ( p->pAig->vPats )
1497 {
1498 Vec_IntPush( p->pAig->vPats, Vec_IntSize(p->vPat)+2 );
1499 Vec_IntAppend( p->pAig->vPats, p->vPat );
1500 Vec_IntPush( p->pAig->vPats, -1 );
1501 }
1502 //Vec_IntPushTwo( p->vDisprPairs, iRepr, iCand );
1503 Packs += Ret;
1504 if ( Ret == 64 * p->pAig->nSimWords )
1505 break;
1506 if ( ++CountPat == 8 * 64 * p->pAig->nSimWords )
1507 break;
1508 //Cec4_ManCexVerify( p->pAig, iRepr, iCand, iReprVal ^ iCandVal );
1509 //Gia_ManCleanMark01( p->pAig );
1510 }
1511 }
1512 p->timeGenPats += Abc_Clock() - clk;
1513 p->nSatSat += CountPat;
1514 //printf( "%3d : %6.2f %% : Generated %6d CEXs after trying %6d pairs. Ave packs = %9.2f Ave tries = %9.2f (Limit = %9.2f)\n",
1515 // p->nItersSim++, 100.0*Vec_IntSize(p->vCands)/Gia_ManAndNum(p->pAig),
1516 // CountPat, i, (float)Packs / Abc_MaxInt(1, CountPat), (float)i / Abc_MaxInt(1, CountPat), (float)nPats / p->pPars->nItersMax );
1517 return CountPat >= i / p->pPars->nItersMax;
1518}
1519
1520
1533{
1534 Gia_Obj_t * pObj;
1535 int i;
1536 //printf( "Solver size = %d.\n", sat_solver_varnum(p->pSat) );
1537 p->nRecycles++;
1538 p->nCallsSince = 0;
1539 sat_solver_reset( p->pSat );
1540 // clean mapping of AigIds into SatIds
1541 Gia_ManForEachObjVec( &p->pNew->vSuppVars, p->pNew, pObj, i )
1542 Cec4_ObjCleanSatId( p->pNew, pObj );
1543 Vec_IntClear( &p->pNew->vSuppVars ); // AigIds for which SatId is defined
1544 Vec_IntClear( &p->pNew->vCopiesTwo ); // pairs (CiAigId, SatId)
1545 Vec_IntClear( &p->pNew->vVarMap ); // mapping of SatId into AigId
1546}
1547int Cec4_ManSolveTwo( Cec4_Man_t * p, int iObj0, int iObj1, int fPhase, int * pfEasy, int fVerbose, int fEffort )
1548{
1549 abctime clk;
1550 int nBTLimit = fEffort ? p->pPars->nBTLimitPo : (Vec_BitEntry(p->vFails, iObj0) || Vec_BitEntry(p->vFails, iObj1)) ? Abc_MaxInt(1, p->pPars->nBTLimit/10) : p->pPars->nBTLimit;
1551 int nConfEnd, nConfBeg, status, iVar0, iVar1, Lits[2];
1552 int UnsatConflicts[3] = {0};
1553 //printf( "%d ", nBTLimit );
1554 if ( iObj1 < iObj0 )
1555 iObj1 ^= iObj0, iObj0 ^= iObj1, iObj1 ^= iObj0;
1556 assert( iObj0 < iObj1 );
1557 *pfEasy = 0;
1558 // check if SAT solver needs recycling
1559 p->nCallsSince++;
1560 if ( p->nCallsSince > p->pPars->nCallsRecycle &&
1561 Vec_IntSize(&p->pNew->vSuppVars) > p->pPars->nSatVarMax && p->pPars->nSatVarMax )
1563 // add more logic to the solver
1564 if ( !iObj0 && Cec4_ObjSatId(p->pNew, Gia_ManConst0(p->pNew)) == -1 )
1565 Cec4_ObjSetSatId( p->pNew, Gia_ManConst0(p->pNew), sat_solver_addvar(p->pSat) );
1566 clk = Abc_Clock();
1567 iVar0 = Cec4_ObjGetCnfVar( p, iObj0 );
1568 iVar1 = Cec4_ObjGetCnfVar( p, iObj1 );
1569 if( p->pPars->jType > 0 )
1570 {
1572 sat_solver_mark_cone( p->pSat, Cec4_ObjSatId(p->pNew, Gia_ManObj(p->pNew, iObj0)) );
1573 sat_solver_mark_cone( p->pSat, Cec4_ObjSatId(p->pNew, Gia_ManObj(p->pNew, iObj1)) );
1574 }
1575 p->timeCnf += Abc_Clock() - clk;
1576 // perform solving
1577 Lits[0] = Abc_Var2Lit(iVar0, 1);
1578 Lits[1] = Abc_Var2Lit(iVar1, fPhase);
1579 sat_solver_set_conflict_budget( p->pSat, nBTLimit );
1580 nConfBeg = sat_solver_conflictnum( p->pSat );
1581 status = sat_solver_solve( p->pSat, Lits, 2 );
1582 nConfEnd = sat_solver_conflictnum( p->pSat );
1583 assert( nConfEnd >= nConfBeg );
1584 if ( fVerbose )
1585 {
1586 if ( status == GLUCOSE_SAT )
1587 {
1588 p->nConflicts[0][0] += nConfEnd == nConfBeg;
1589 p->nConflicts[0][1] += nConfEnd - nConfBeg;
1590 p->nConflicts[0][2] = Abc_MaxInt(p->nConflicts[0][2], nConfEnd - nConfBeg);
1591 *pfEasy = nConfEnd == nConfBeg;
1592 }
1593 else if ( status == GLUCOSE_UNSAT )
1594 {
1595 if ( iObj0 > 0 )
1596 {
1597 UnsatConflicts[0] = nConfEnd == nConfBeg;
1598 UnsatConflicts[1] = nConfEnd - nConfBeg;
1599 UnsatConflicts[2] = Abc_MaxInt(p->nConflicts[1][2], nConfEnd - nConfBeg);
1600 }
1601 else
1602 {
1603 p->nConflicts[1][0] += nConfEnd == nConfBeg;
1604 p->nConflicts[1][1] += nConfEnd - nConfBeg;
1605 p->nConflicts[1][2] = Abc_MaxInt(p->nConflicts[1][2], nConfEnd - nConfBeg);
1606 *pfEasy = nConfEnd == nConfBeg;
1607 }
1608 }
1609 }
1610 if ( status == GLUCOSE_UNSAT && iObj0 > 0 )
1611 {
1612 Lits[0] = Abc_Var2Lit(iVar0, 0);
1613 Lits[1] = Abc_Var2Lit(iVar1, !fPhase);
1614 sat_solver_set_conflict_budget( p->pSat, nBTLimit );
1615 nConfBeg = sat_solver_conflictnum( p->pSat );
1616 status = sat_solver_solve( p->pSat, Lits, 2 );
1617 nConfEnd = sat_solver_conflictnum( p->pSat );
1618 assert( nConfEnd >= nConfBeg );
1619 if ( fVerbose )
1620 {
1621 if ( status == GLUCOSE_SAT )
1622 {
1623 p->nConflicts[0][0] += nConfEnd == nConfBeg;
1624 p->nConflicts[0][1] += nConfEnd - nConfBeg;
1625 p->nConflicts[0][2] = Abc_MaxInt(p->nConflicts[0][2], nConfEnd - nConfBeg);
1626 *pfEasy = nConfEnd == nConfBeg;
1627 }
1628 else if ( status == GLUCOSE_UNSAT )
1629 {
1630 UnsatConflicts[0] &= nConfEnd == nConfBeg;
1631 UnsatConflicts[1] += nConfEnd - nConfBeg;
1632 UnsatConflicts[2] = Abc_MaxInt(p->nConflicts[1][2], nConfEnd - nConfBeg);
1633
1634 p->nConflicts[1][0] += UnsatConflicts[0];
1635 p->nConflicts[1][1] += UnsatConflicts[1];
1636 p->nConflicts[1][2] = Abc_MaxInt(p->nConflicts[1][2], UnsatConflicts[2]);
1637 *pfEasy = UnsatConflicts[0];
1638 }
1639 }
1640 }
1641 //if ( status == GLUCOSE_UNDEC )
1642 // printf( "* " );
1643 return status;
1644}
1645int Cec4_ManSweepNode( Cec4_Man_t * p, int iObj, int iRepr )
1646{
1647 abctime clk = Abc_Clock();
1648 int i, IdAig, IdSat, status, fEasy, RetValue = 1;
1649 Gia_Obj_t * pObj = Gia_ManObj( p->pAig, iObj );
1650 Gia_Obj_t * pRepr = Gia_ManObj( p->pAig, iRepr );
1651 int fCompl = Abc_LitIsCompl(pObj->Value) ^ Abc_LitIsCompl(pRepr->Value) ^ pObj->fPhase ^ pRepr->fPhase;
1652 int fEffort = p->vCoDrivers ? Vec_BitEntry(p->vCoDrivers, iObj) || Vec_BitEntry(p->vCoDrivers, iRepr) : 0;
1653 status = Cec4_ManSolveTwo( p, Abc_Lit2Var(pRepr->Value), Abc_Lit2Var(pObj->Value), fCompl, &fEasy, p->pPars->fVerbose, fEffort );
1654 if ( status == GLUCOSE_SAT )
1655 {
1656 int iLit;
1657 //int iPatsOld = p->pAig->iPatsPi;
1658 //printf( "Disproved: %d == %d.\n", Abc_Lit2Var(pRepr->Value), Abc_Lit2Var(pObj->Value) );
1659 p->nSatSat++;
1660 p->nPatterns++;
1661 Vec_IntClear( p->vPat );
1662 if ( p->pPars->jType == 0 )
1663 {
1664 Vec_IntForEachEntryDouble( &p->pNew->vCopiesTwo, IdAig, IdSat, i )
1665 Vec_IntPush( p->vPat, Abc_Var2Lit(IdAig, sat_solver_read_cex_varvalue(p->pSat, IdSat)) );
1666 }
1667 else
1668 {
1669 int * pCex = sat_solver_read_cex( p->pSat );
1670 int * pMap = Vec_IntArray(&p->pNew->vVarMap);
1671 for ( i = 0; i < pCex[0]; )
1672 Vec_IntPush( p->vPat, Abc_Lit2LitV(pMap, Abc_LitNot(pCex[++i])) );
1673 }
1674 assert( p->pAig->iPatsPi >= 0 && p->pAig->iPatsPi < 64 * p->pAig->nSimWords - 1 );
1675 p->pAig->iPatsPi++;
1676 Vec_IntForEachEntry( p->vPat, iLit, i )
1677 Cec4_ObjSimSetInputBit( p->pAig, Abc_Lit2Var(iLit), Abc_LitIsCompl(iLit) );
1678 if ( p->pAig->vPats )
1679 {
1680 Vec_IntPush( p->pAig->vPats, Vec_IntSize(p->vPat)+2 );
1681 Vec_IntAppend( p->pAig->vPats, p->vPat );
1682 Vec_IntPush( p->pAig->vPats, -1 );
1683 }
1684 //Cec4_ManPackAddPattern( p->pAig, p->vPat, 0 );
1685 //assert( iPatsOld + 1 == p->pAig->iPatsPi );
1686 if ( fEasy )
1687 p->timeSatSat0 += Abc_Clock() - clk;
1688 else
1689 p->timeSatSat += Abc_Clock() - clk;
1690 RetValue = 0;
1691 // this is not needed, but we keep it here anyway, because it takes very little time
1692 //Cec4_ManVerify( p->pNew, Abc_Lit2Var(pRepr->Value), Abc_Lit2Var(pObj->Value), fCompl, p->pSat );
1693 // resimulated once in a while
1694 if ( p->pAig->iPatsPi == 64 * p->pAig->nSimWords - 2 )
1695 {
1696 abctime clk2 = Abc_Clock();
1697 Cec4_ManSimulate( p->pAig, p );
1698 //printf( "FasterSmall = %d. FasterBig = %d.\n", p->nFaster[0], p->nFaster[1] );
1699 p->nFaster[0] = p->nFaster[1] = 0;
1700 //if ( p->nSatSat && p->nSatSat % 100 == 0 )
1701 Cec4_ManPrintStats( p->pAig, p->pPars, p, 0 );
1702 Vec_IntFill( p->vCexStamps, Gia_ManObjNum(p->pAig), 0 );
1703 p->pAig->iPatsPi = 0;
1704 Vec_WrdFill( p->pAig->vSimsPi, Vec_WrdSize(p->pAig->vSimsPi), 0 );
1705 p->timeResimGlo += Abc_Clock() - clk2;
1706 }
1707 }
1708 else if ( status == GLUCOSE_UNSAT )
1709 {
1710 //printf( "Proved: %d == %d.\n", Abc_Lit2Var(pRepr->Value), Abc_Lit2Var(pObj->Value) );
1711 p->nSatUnsat++;
1712 pObj->Value = Abc_LitNotCond( pRepr->Value, fCompl );
1713 Gia_ObjSetProved( p->pAig, iObj );
1714 if ( iRepr == 0 )
1715 p->iLastConst = iObj;
1716 if ( fEasy )
1717 p->timeSatUnsat0 += Abc_Clock() - clk;
1718 else
1719 p->timeSatUnsat += Abc_Clock() - clk;
1720 RetValue = 1;
1721 }
1722 else
1723 {
1724 p->nSatUndec++;
1725 assert( status == GLUCOSE_UNDEC );
1726 if ( p->vPairs ) // speculate
1727 {
1728 Vec_IntPushTwo( p->vPairs, Abc_Var2Lit(iRepr, 0), Abc_Var2Lit(iObj, fCompl) );
1729 p->timeSatUndec += Abc_Clock() - clk;
1730 // mark as proved
1731 pObj->Value = Abc_LitNotCond( pRepr->Value, fCompl );
1732 Gia_ObjSetProved( p->pAig, iObj );
1733 if ( iRepr == 0 )
1734 p->iLastConst = iObj;
1735 RetValue = 1;
1736 }
1737 else
1738 {
1739 Gia_ObjSetFailed( p->pAig, iObj );
1740 Vec_BitWriteEntry( p->vFails, iObj, 1 );
1741 //if ( iRepr )
1742 //Vec_BitWriteEntry( p->vFails, iRepr, 1 );
1743 p->timeSatUndec += Abc_Clock() - clk;
1744 RetValue = 2;
1745 }
1746 }
1747 return RetValue;
1748}
1750{
1751 abctime clk = Abc_Clock();
1752 int iMem, iRepr;
1753 assert( Gia_ObjHasRepr(p, iObj) );
1754 assert( !Gia_ObjProved(p, iObj) );
1755 iRepr = Gia_ObjRepr(p, iObj);
1756 assert( iRepr != iObj );
1757 assert( !Gia_ObjProved(p, iRepr) );
1758 Cec4_ManSimulate_rec( p, pMan, iObj );
1759 Cec4_ManSimulate_rec( p, pMan, iRepr );
1760 if ( Cec4_ObjSimEqual(p, iObj, iRepr) )
1761 {
1762 pMan->timeResimLoc += Abc_Clock() - clk;
1763 return Gia_ManObj(p, iRepr);
1764 }
1765 Gia_ClassForEachObj1( p, iRepr, iMem )
1766 {
1767 if ( iObj == iMem )
1768 break;
1769 if ( Gia_ObjProved(p, iMem) || Gia_ObjFailed(p, iMem) )
1770 continue;
1771 Cec4_ManSimulate_rec( p, pMan, iMem );
1772 if ( Cec4_ObjSimEqual(p, iObj, iMem) )
1773 {
1774 pMan->nFaster[0]++;
1775 pMan->timeResimLoc += Abc_Clock() - clk;
1776 return Gia_ManObj(p, iMem);
1777 }
1778 }
1779 pMan->nFaster[1]++;
1780 pMan->timeResimLoc += Abc_Clock() - clk;
1781 return NULL;
1782}
1784{
1785 int i = 0, iObj, iPrev, Counter = 0;
1786 for ( iPrev = i, iObj = Gia_ObjNext(p, i); -1 < iObj; iObj = Gia_ObjNext(p, iPrev) )
1787 {
1788 Gia_Obj_t * pRepr = Gia_ObjReprObj(p, iObj);
1789 assert( pRepr == Gia_ManConst0(p) );
1790 if( !Gia_ObjFailed(p,iObj) && Abc_Lit2Var(Gia_ManObj(p,iObj)->Value) == Abc_Lit2Var(pRepr->Value) )
1791 {
1792 iPrev = iObj;
1793 continue;
1794 }
1795 Gia_ObjSetRepr( p, iObj, GIA_VOID );
1796 Gia_ObjSetNext( p, iPrev, Gia_ObjNext(p, iObj) );
1797 Gia_ObjSetNext( p, iObj, 0 );
1798 Counter++;
1799 }
1801 {
1802 for ( iPrev = i, iObj = Gia_ObjNext(p, i); -1 < iObj; iObj = Gia_ObjNext(p, iPrev) )
1803 {
1804 Gia_Obj_t * pRepr = Gia_ObjReprObj(p, iObj);
1805 if( !Gia_ObjFailed(p,iObj) && Abc_Lit2Var(Gia_ManObj(p,iObj)->Value) == Abc_Lit2Var(pRepr->Value) )
1806 {
1807 iPrev = iObj;
1808 continue;
1809 }
1810 Gia_ObjSetRepr( p, iObj, GIA_VOID );
1811 Gia_ObjSetNext( p, iPrev, Gia_ObjNext(p, iObj) );
1812 Gia_ObjSetNext( p, iObj, 0 );
1813 Counter++;
1814 }
1815 }
1816 //Abc_Print( 1, "Removed %d wrong choices.\n", Counter );
1817}
1818
1820{
1821 Gia_Obj_t * pObj; int i, k, nWords = pMan->pAig->nSimWords, nOuts[2] = {0};
1822 Vec_Wrd_t * vSims = NULL, * vSimsPi = NULL;
1823 FILE * pFile = fopen( pMan->pPars->pDumpName, "wb" );
1824 if ( pFile == NULL ) {
1825 printf( "Cannot open file \"%s\" for writing primary output information.\n", pMan->pPars->pDumpName );
1826 return;
1827 }
1828 vSimsPi = Vec_WrdDup( pMan->pAig->vSimsPi );
1829 memmove( Vec_WrdArray(vSimsPi), Vec_WrdArray(vSimsPi) + nWords, Gia_ManCiNum(pMan->pAig) * nWords );
1830 Vec_WrdShrink( vSimsPi, Gia_ManCiNum(pMan->pAig) * nWords );
1831 if ( Abc_TtIsConst0(Vec_WrdArray(vSimsPi), Gia_ManCiNum(pMan->pAig) * nWords) ) {
1832 Vec_WrdFree( vSimsPi );
1833 vSimsPi = Vec_WrdStartRandom( Gia_ManCiNum(pMan->pAig) * nWords );
1834 }
1835 vSims = Gia_ManSimPatSimOut( pMan->pAig, vSimsPi, 1 );
1836 assert( nWords * Gia_ManCiNum(pMan->pAig) == Vec_WrdSize(vSimsPi) );
1837 Gia_ManForEachCo( pMan->pAig, pObj, i )
1838 {
1839 void Extra_PrintHex2( FILE * pFile, unsigned * pTruth, int nVars );
1840 word * pSims = Vec_WrdEntryP( vSims, nWords*i );
1841 //Extra_PrintHex2( stdout, (unsigned *)pSims, 8 ); printf( "\n" );
1842 fprintf( pFile, "%d ", i );
1843 if ( Gia_ObjFaninLit0p(pMan->pNew, Gia_ManCo(pMan->pNew, i)) == 0 )
1844 nOuts[0]++;
1845 else if ( Abc_TtIsConst0(pSims, nWords) )
1846 fprintf( pFile, "-" );
1847 else {
1848 int iPat = Abc_TtFindFirstBit2(pSims, nWords);
1849 for ( k = 0; k < Gia_ManPiNum(pMan->pAig); k++ )
1850 fprintf( pFile, "%d", Abc_TtGetBit(Vec_WrdEntryP(vSimsPi, nWords*k), iPat) );
1851 nOuts[1]++;
1852 }
1853 fprintf( pFile, "\n" );
1854 }
1855 printf( "Information about %d sat, %d unsat, and %d undecided primary outputs was written into file \"%s\".\n",
1856 nOuts[1], nOuts[0], Gia_ManCoNum(pMan->pAig)-nOuts[1]-nOuts[0], pMan->pPars->pDumpName );
1857 fclose( pFile );
1858 Vec_WrdFree( vSims );
1859 Vec_WrdFree( vSimsPi );
1860}
1861int Cec4_ManPerformSweeping( Gia_Man_t * p, Cec_ParFra_t * pPars, Gia_Man_t ** ppNew, int fSimOnly )
1862{
1863
1864 Cec4_Man_t * pMan = Cec4_ManCreate( p, pPars );
1865 Gia_Obj_t * pObj, * pRepr;
1866 int i, fSimulate = 1, Id;
1867 if ( pPars->fVerbose )
1868 printf( "Solver type = %d. Simulate %d words in %d rounds. SAT with %d confs. Recycle after %d SAT calls.\n",
1869 pPars->jType, pPars->nWords, pPars->nRounds, pPars->nBTLimit, pPars->nCallsRecycle );
1870
1871 // this is currently needed to have a correct mapping
1872 Gia_ManForEachCi( p, pObj, i )
1873 assert( Gia_ObjId(p, pObj) == i+1 );
1874
1875 // check if any output trivially fails under all-0 pattern
1876 Abc_Random( 1 );
1877 Gia_ManSetPhase( p );
1878 if ( pPars->nLevelMax )
1880 //Gia_ManStaticFanoutStart( p );
1881 if ( pPars->fCheckMiter )
1882 {
1883 Gia_ManForEachCo( p, pObj, i )
1884 if ( pObj->fPhase )
1885 {
1886 p->pCexSeq = Cec4_ManDeriveCex( p, i, -1 );
1887 goto finalize;
1888 }
1889 }
1890
1891 if( p->vSimsPi && p->nSimWords > 0){ // if the simulation pis are already set, do not generate new ones
1892 pPars->nWords = p->nSimWords;
1893 Vec_WrdFreeP( &p->vSims );
1894 p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * pPars->nWords);
1895 assert( Vec_WrdSize(p->vSimsPi) == Gia_ManCiNum(p) * p->nSimWords );
1896 Gia_ManForEachCiId(p, Id, i){
1897 memmove( Vec_WrdEntryP(p->vSims, Id*p->nSimWords), Vec_WrdEntryP(p->vSimsPi, i*p->nSimWords), sizeof(word)*p->nSimWords );
1898 }
1899 Cec4_ManSimulate( p, pMan );
1900 if ( pPars->fCheckMiter && !Cec4_ManSimulateCos(p) ) // cex detected
1901 goto finalize;
1902 if ( fSimOnly )
1903 goto finalize;
1904 goto execute_sat;
1905 }
1906
1907 // simulate one round and create classes
1908 Cec4_ManSimAlloc( p, pPars->nWords );
1910 Cec4_ManSimulate( p, pMan );
1911 if ( pPars->fCheckMiter && !Cec4_ManSimulateCos(p) ) // cex detected
1912 goto finalize;
1913 if ( pPars->fVerbose )
1914 Cec4_ManPrintStats( p, pPars, pMan, 1 );
1915
1916 // perform simulation
1917 for ( i = 0; i < pPars->nRounds; i++ )
1918 {
1920 Cec4_ManSimulate( p, pMan );
1921 if ( pPars->fCheckMiter && !Cec4_ManSimulateCos(p) ) // cex detected
1922 goto finalize;
1923 if ( i && i % (pPars->nRounds / 5) == 0 && pPars->fVerbose )
1924 Cec4_ManPrintStats( p, pPars, pMan, 1 );
1925 }
1926 if ( fSimOnly )
1927 goto finalize;
1928
1929 // perform additional simulation
1930 Cec4_ManCandIterStart( pMan );
1931 for ( i = 0; fSimulate && i < pPars->nGenIters; i++ )
1932 {
1934 fSimulate = Cec4_ManGeneratePatterns( pMan );
1935 Cec4_ManSimulate( p, pMan );
1936 if ( pPars->fCheckMiter && !Cec4_ManSimulateCos(p) ) // cex detected
1937 goto finalize;
1938 if ( i && i % 5 == 0 && pPars->fVerbose )
1939 Cec4_ManPrintStats( p, pPars, pMan, 1 );
1940 }
1941 execute_sat:
1942 if ( i && i % 5 && pPars->fVerbose )
1943 Cec4_ManPrintStats( p, pPars, pMan, 1 );
1944
1945 p->iPatsPi = 0;
1946 Vec_WrdFill( p->vSimsPi, Vec_WrdSize(p->vSimsPi), 0 );
1947 pMan->nSatSat = 0;
1948 pMan->pNew = Cec4_ManStartNew( p );
1949 Gia_ManForEachAnd( p, pObj, i )
1950 {
1951 Gia_Obj_t * pObjNew;
1952 pMan->nAndNodes++;
1953 if ( Gia_ObjIsXor(pObj) )
1954 pObj->Value = Gia_ManHashXorReal( pMan->pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1955 else
1956 pObj->Value = Gia_ManHashAnd( pMan->pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1957 if ( pPars->nLevelMax && Gia_ObjLevel(p, pObj) > pPars->nLevelMax )
1958 continue;
1959 pObjNew = Gia_ManObj( pMan->pNew, Abc_Lit2Var(pObj->Value) );
1960 if ( Gia_ObjIsAnd(pObjNew) )
1961 if ( Vec_BitEntry(pMan->vFails, Gia_ObjFaninId0(pObjNew, Abc_Lit2Var(pObj->Value))) ||
1962 Vec_BitEntry(pMan->vFails, Gia_ObjFaninId1(pObjNew, Abc_Lit2Var(pObj->Value))) )
1963 Vec_BitWriteEntry( pMan->vFails, Abc_Lit2Var(pObjNew->Value), 1 );
1964 //if ( Gia_ObjIsAnd(pObjNew) )
1965 // Gia_ObjSetAndLevel( pMan->pNew, pObjNew );
1966 // select representative based on candidate equivalence classes
1967 pRepr = Gia_ObjReprObj( p, i );
1968 if ( pRepr == NULL )
1969 continue;
1970 if ( 1 ) // select representative based on recent counter-examples
1971 {
1972 pRepr = Cec4_ManFindRepr( p, pMan, i );
1973 if ( pRepr == NULL )
1974 continue;
1975 }
1976 int id_obj = Gia_ObjId( p, pObj );
1977 int id_repr = Gia_ObjId( p, pRepr );
1978
1979 if ( Abc_Lit2Var(pObj->Value) == Abc_Lit2Var(pRepr->Value) )
1980 {
1981 if ( pPars->fBMiterInfo )
1982 {
1983 Bnd_ManMerge( id_repr, id_obj, pObj->fPhase ^ pRepr->fPhase );
1984 }
1985
1986 assert( (pObj->Value ^ pRepr->Value) == (pObj->fPhase ^ pRepr->fPhase) );
1987 Gia_ObjSetProved( p, i );
1988 if ( Gia_ObjId(p, pRepr) == 0 )
1989 pMan->iLastConst = i;
1990 continue;
1991 }
1992 if ( Cec4_ManSweepNode(pMan, i, Gia_ObjId(p, pRepr)) && Gia_ObjProved(p, i) )
1993 {
1994 if (pPars->fBMiterInfo){
1995
1996 Bnd_ManMerge( id_repr, id_obj, pObj->fPhase ^ pRepr->fPhase );
1997 // printf( "proven %d merged into %d (phase : %d)\n", Gia_ObjId(p, pObj), Gia_ObjId(p,pRepr), pObj->fPhase ^ pRepr -> fPhase );
1998
1999 }
2000 pObj->Value = Abc_LitNotCond( pRepr->Value, pObj->fPhase ^ pRepr->fPhase );
2001
2002
2003 }
2004 }
2005
2006 if ( pPars->fBMiterInfo )
2007 {
2008 // print
2010 // Bnd_ManPrintMappings();
2011 }
2012
2013 if ( p->iPatsPi > 0 )
2014 {
2015 abctime clk2 = Abc_Clock();
2016 Cec4_ManSimulate( p, pMan );
2017 p->iPatsPi = 0;
2018 Vec_IntFill( pMan->vCexStamps, Gia_ManObjNum(p), 0 );
2019 pMan->timeResimGlo += Abc_Clock() - clk2;
2020 }
2021 if ( pPars->fVerbose )
2022 Cec4_ManPrintStats( p, pPars, pMan, 0 );
2023 if ( ppNew )
2024 {
2025 Gia_ManForEachCo( p, pObj, i )
2026 pObj->Value = Gia_ManAppendCo( pMan->pNew, Gia_ObjFanin0Copy(pObj) );
2027 *ppNew = Gia_ManCleanup( pMan->pNew );
2028 }
2029finalize:
2030 if ( pPars->fVerbose )
2031 printf( "SAT calls = %d: P = %d (0=%d a=%.2f m=%d) D = %d (0=%d a=%.2f m=%d) F = %d Sim = %d Recyc = %d Xor = %.2f %%\n",
2032 pMan->nSatUnsat + pMan->nSatSat + pMan->nSatUndec,
2033 pMan->nSatUnsat, pMan->nConflicts[1][0], (float)pMan->nConflicts[1][1]/Abc_MaxInt(1, pMan->nSatUnsat-pMan->nConflicts[1][0]), pMan->nConflicts[1][2],
2034 pMan->nSatSat, pMan->nConflicts[0][0], (float)pMan->nConflicts[0][1]/Abc_MaxInt(1, pMan->nSatSat -pMan->nConflicts[0][0]), pMan->nConflicts[0][2],
2035 pMan->nSatUndec,
2036 pMan->nSimulates, pMan->nRecycles, 100.0*pMan->nGates[1]/Abc_MaxInt(1, pMan->nGates[0]+pMan->nGates[1]) );
2037 if ( pMan->vPairs && Vec_IntSize(pMan->vPairs) )
2038 {
2039 extern char * Extra_FileNameGeneric( char * FileName );
2040 char pFileName[1000], * pBase = Extra_FileNameGeneric(p->pName);
2041 extern Gia_Man_t * Gia_ManDupMiterCones( Gia_Man_t * p, Vec_Int_t * vPairs );
2042 Gia_Man_t * pM = Gia_ManDupMiterCones( p, pMan->vPairs );
2043 sprintf( pFileName, "%s_sm.aig", pBase );
2044 Gia_AigerWrite( pM, pFileName, 0, 0, 0 );
2045 Gia_ManStop( pM );
2046 ABC_FREE( pBase );
2047 printf( "Dumped miter \"%s\" with %d pairs.\n", pFileName, pMan->vPairs ? Vec_IntSize(pMan->vPairs)/2 : -1 );
2048 }
2049 if ( pPars->pDumpName )
2051 Cec4_ManDestroy( pMan );
2052 //Gia_ManStaticFanoutStop( p );
2053 //Gia_ManEquivPrintClasses( p, 1, 0 );
2054 if ( ppNew && *ppNew == NULL )
2055 *ppNew = Gia_ManDup(p);
2056 if ( p->pNexts ) Gia_ManRemoveWrongChoices( p );
2057 return p->pCexSeq ? 0 : 1;
2058}
2060{
2061 Gia_Man_t * pNew = NULL;
2062 Cec4_ManPerformSweeping( p, pPars, &pNew, 0 );
2063
2064 return pNew;
2065}
2066void Cec4_ManSimulateTest2( Gia_Man_t * p, int nConfs, int fVerbose )
2067{
2068 abctime clk = Abc_Clock();
2069 Cec_ParFra_t ParsFra, * pPars = &ParsFra;
2070 Cec4_ManSetParams( pPars );
2071 pPars->fVerbose = fVerbose;
2072 pPars->nBTLimit = nConfs;
2073 Cec4_ManPerformSweeping( p, pPars, NULL, 0 );
2074 if ( fVerbose )
2075 Abc_PrintTime( 1, "New choice computation time", Abc_Clock() - clk );
2076}
2077Gia_Man_t * Cec4_ManSimulateTest3( Gia_Man_t * p, int nBTLimit, int fVerbose )
2078{
2079 Gia_Man_t * pNew = NULL;
2080 Cec_ParFra_t ParsFra, * pPars = &ParsFra;
2081 Cec4_ManSetParams( pPars );
2082 pPars->fVerbose = fVerbose;
2083 pPars->nBTLimit = nBTLimit;
2084 Cec4_ManPerformSweeping( p, pPars, &pNew, 0 );
2085 return pNew;
2086}
2087Gia_Man_t * Cec4_ManSimulateTest4( Gia_Man_t * p, int nBTLimit, int nBTLimitPo, int fVerbose )
2088{
2089 Gia_Man_t * pNew = NULL;
2090 Cec_ParFra_t ParsFra, * pPars = &ParsFra;
2091 Cec4_ManSetParams( pPars );
2092 pPars->fVerbose = fVerbose;
2093 pPars->nBTLimit = nBTLimit;
2094 pPars->nBTLimitPo = nBTLimitPo;
2095 Cec4_ManPerformSweeping( p, pPars, &pNew, 0 );
2096 return pNew;
2097}
2099{
2100 Cec_ParFra_t ParsFra, * pPars = &ParsFra;
2101 Cec4_ManSetParams( pPars );
2102 pPars->fVerbose = fVerbose;
2103 return Cec4_ManPerformSweeping( p, pPars, NULL, 1 );
2104}
2105
2117void Cec4_ManSimulateTest5Int( Gia_Man_t * p, int nConfs, int fVerbose )
2118{
2119 abctime clk = Abc_Clock();
2120 Cec_ParFra_t ParsFra, * pPars = &ParsFra;
2121 Cec4_ManSetParams( pPars );
2122 pPars->fVerbose = fVerbose;
2123 pPars->nBTLimit = nConfs;
2124 Cec4_ManPerformSweeping( p, pPars, NULL, 0 );
2125 if ( fVerbose )
2126 Abc_PrintTime( 1, "Equivalence detection time", Abc_Clock() - clk );
2127}
2129{
2130 Gia_Man_t * pNew, * pTemp;
2131 Gia_Obj_t * pObj;
2132 int i;
2133 pNew = Gia_ManStart( Gia_ManObjNum(p) );
2134 Gia_ManHashAlloc( pNew );
2135 Gia_ManConst0(p)->Value = 0;
2136 Gia_ManForEachObj1( p, pObj, i )
2137 {
2138 if ( Gia_ObjIsAnd(pObj) )
2139 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
2140 else if ( Gia_ObjIsCi(pObj) )
2141 pObj->Value = Gia_ManAppendCi( pNew );
2142 else if ( Gia_ObjIsCo(pObj) )
2143 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
2144 }
2145 Gia_ManHashStop( pNew );
2146 pNew = Gia_ManCleanup( pTemp = pNew );
2147 Gia_ManForEachObj1( p, pObj, i )
2148 {
2149 int iLitNew = Gia_ManObj(pTemp, Abc_Lit2Var(pObj->Value))->Value;
2150 if ( iLitNew == ~0 )
2151 pObj->Value = iLitNew;
2152 else
2153 pObj->Value = Abc_LitNotCond(iLitNew, Abc_LitIsCompl(pObj->Value));
2154 }
2155 Gia_ManStop( pTemp );
2156 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
2157 return pNew;
2158}
2160{
2161 Gia_Obj_t * pObj;
2162 Vec_Int_t * vReprs = Vec_IntStartFull( Gia_ManObjNum(p) );
2163 int * pAig2Abc = ABC_FALLOC( int, Gia_ManObjNum(pAig) );
2164 int i, nConsts = 0, nReprs = 0;
2165 pAig2Abc[0] = 0;
2166 Gia_ManForEachCand( p, pObj, i )
2167 {
2168 int iLitGia = pObj->Value, iReprGia;
2169 if ( iLitGia == -1 )
2170 continue;
2171 iReprGia = Gia_ObjReprSelf( pAig, Abc_Lit2Var(iLitGia) );
2172 if ( pAig2Abc[iReprGia] == -1 )
2173 pAig2Abc[iReprGia] = i;
2174 else
2175 {
2176 int iLitGia2 = Gia_ManObj(p, pAig2Abc[iReprGia] )->Value;
2177 assert( Gia_ObjReprSelf(pAig, Abc_Lit2Var(iLitGia)) == Gia_ObjReprSelf(pAig, Abc_Lit2Var(iLitGia2)) );
2178 assert( i > pAig2Abc[iReprGia] );
2179 Vec_IntWriteEntry( vReprs, i, pAig2Abc[iReprGia] );
2180 if ( pAig2Abc[iReprGia] == 0 )
2181 nConsts++;
2182 else
2183 nReprs++;
2184 }
2185 }
2186 ABC_FREE( pAig2Abc );
2187 if ( fVerbose )
2188 printf( "Found %d const reprs and %d other reprs.\n", nConsts, nReprs );
2189 return vReprs;
2190}
2191void Cec4_ManVerifyEquivs( Gia_Man_t * p, Vec_Int_t * vRes, int fVerbose )
2192{
2193 int i, iRepr, nWords = 4; word * pSim0, * pSim1;
2194 Vec_Wrd_t * vSimsCi = Vec_WrdStartRandom( Gia_ManCiNum(p) * nWords );
2195 int nObjs = Vec_WrdShiftOne( vSimsCi, nWords ), nFails = 0;
2196 Vec_Wrd_t * vSims = Gia_ManSimPatSimOut( p, vSimsCi, 0 );
2197 assert( Vec_IntSize(vRes) == Gia_ManObjNum(p) );
2198 assert( nObjs == Gia_ManCiNum(p) );
2199 Vec_IntForEachEntry( vRes, iRepr, i )
2200 {
2201 if ( iRepr == -1 )
2202 continue;
2203 assert( i > iRepr );
2204 pSim0 = Vec_WrdEntryP( vSims, nWords*i );
2205 pSim1 = Vec_WrdEntryP( vSims, nWords*iRepr );
2206 if ( (pSim0[0] ^ pSim1[0]) & 1 )
2207 nFails += !Abc_TtOpposite(pSim0, pSim1, nWords);
2208 else
2209 nFails += !Abc_TtEqual(pSim0, pSim1, nWords);
2210 }
2211 Vec_WrdFree( vSimsCi );
2212 Vec_WrdFree( vSims );
2213 if ( nFails )
2214 printf( "Verification failed at %d nodes.\n", nFails );
2215 else if ( fVerbose )
2216 printf( "Verification succeeded for all (%d) nodes.\n", Gia_ManCandNum(p) );
2217}
2219{
2220 Gia_Obj_t * pObj; int i, iRepr;
2221 Gia_ManSetPhase( p );
2222 Gia_ManForEachObj( p, pObj, i )
2223 if ( (iRepr = Vec_IntEntry(vRes, i)) >= 0 )
2224 Vec_IntWriteEntry( vRes, i, Abc_Var2Lit(iRepr, Gia_ManObj(p, iRepr)->fPhase ^ pObj->fPhase) );
2225}
2226void Cec4_ManSimulateTest5( Gia_Man_t * p, int nConfs, int fVerbose )
2227{
2228 Vec_Int_t * vRes = NULL;
2229 Gia_Man_t * pAig = Gia_ManLocalRehash( p );
2230 Cec4_ManSimulateTest5Int( pAig, nConfs, fVerbose );
2231 vRes = Cec4_ManComputeMapping( p, pAig, fVerbose );
2232 Cec4_ManVerifyEquivs( p, vRes, fVerbose );
2233 Cec4_ManConvertToLits( p, vRes );
2234 Vec_IntDumpBin( "_temp_.equiv", vRes, fVerbose );
2235 Vec_IntFree( vRes );
2236 Gia_ManStop( pAig );
2237}
2238
2250
2251void getISOPObjId( Gia_Man_t * pMan, int ObjId, char * pSop[2] , int nCubes[2] ){
2252
2253 assert( Gia_ObjIsLut(pMan, ObjId));
2254 char * pSopInfo = pMan->vTTISOPs->pArray + Vec_IntEntry( pMan->vTTLut, ObjId );
2255 int k;
2256 // get the ISOPs positive polarity
2257 for(k = 0; k < 2; k++ ){
2258 nCubes[k] = *pSopInfo;
2259 pSopInfo++;
2260 if(nCubes[k] == 0){
2261 pSop[k] = NULL;
2262 continue;
2263 }
2264 pSop[k] = pSopInfo;
2265 pSopInfo += nCubes[k] * 2;
2266 }
2267}
2268
2269
2281
2282Vec_Str_t * encodeSOP(char * pSop, int nFanins, int nCubes){
2283
2284 Vec_Str_t * vSop = Vec_StrAlloc( nCubes * 2 );
2285 char pEncodeCube = 0;
2286 char pDCs = 0;
2287 int fanin=0;
2288 while( *pSop != '\0'){
2289 if( *pSop == '\0')
2290 continue;
2291 if ( *pSop == '-' ){
2292 //pDCs |= ( 1 << (nFanins - fanin - 1) );
2293 pDCs |= ( 1 << fanin );
2294 } else if ( *pSop == '1' ){
2295 //pEncodeCube |= ( 1 << (nFanins - fanin - 1) );
2296 pEncodeCube |= ( 1 << fanin );
2297 }
2298 fanin++;
2299 if(fanin == nFanins){
2300 Vec_StrPush( vSop, pEncodeCube );
2301 Vec_StrPush( vSop, pDCs );
2302 pEncodeCube = 0;
2303 pDCs = 0;
2304 fanin = 0;
2305 pSop += 3;
2306 }
2307 pSop++;
2308 }
2309 return vSop;
2310
2311}
2312
2324
2325char * extractSOP( DdManager * dd, DdNode * bFunc, int nFanins, int polarity, int * _nCubes){
2326
2327 extern int Abc_CountZddCubes( DdManager * dd, DdNode * zCover );
2328 extern int Abc_ConvertZddToSop( DdManager * dd, DdNode * zCover, char * pSop, int nFanins, Vec_Str_t * vCube, int fPhase );
2329
2330 Vec_Str_t * vCube = Vec_StrAlloc( 100 );
2331 int nCubes; char * pSop;
2332 DdNode * bCover, * zCover;
2333 if( polarity == 0){
2334 bCover = Cudd_zddIsop( dd, Cudd_Not(bFunc), Cudd_Not(bFunc), &zCover );
2335 } else {
2336 bCover = Cudd_zddIsop( dd, bFunc, bFunc, &zCover );
2337 }
2338 Cudd_Ref( zCover );
2339 Cudd_Ref( bCover );
2340 Cudd_RecursiveDeref( dd, bCover );
2341 nCubes = Abc_CountZddCubes( dd, zCover );
2342 pSop = ABC_ALLOC( char, (nFanins + 3) * nCubes + 1 );
2343 pSop[(nFanins + 3) * nCubes] = 0;
2344 // create the SOP
2345 Vec_StrFill( vCube, nFanins, '-' );
2346 Vec_StrPush( vCube, '\0' );
2347 Abc_ConvertZddToSop( dd, zCover, pSop, nFanins, vCube, polarity );
2348 Cudd_RecursiveDerefZdd( dd, zCover );
2349
2350 if ( pSop == NULL || nFanins != Abc_SopGetVarNum( pSop )){
2351 if ( pSop == NULL )
2352 printf("SOP generation failed.\n");
2353 else {
2354 ABC_FREE( pSop );
2355 printf( "Node has %d fanins but its SOP has support size %d.\n", nFanins, Abc_SopGetVarNum( pSop ));
2356 }
2357 fflush( stdout );
2358 Vec_StrFree( vCube );
2359 return NULL;
2360 }
2361
2362 Vec_StrFree( vCube );
2363 *_nCubes = nCubes;
2364 return pSop;
2365}
2366
2378
2379void computeISOPs( Gia_Man_t * p, Abc_Ntk_t * pNtkNew ){
2380
2381 Abc_Obj_t * pObjNew;
2382 DdManager * dd = (DdManager *)pNtkNew->pManFunc;
2383 DdNode * bFunc;
2384 char * pSop;
2385 int nCubes, i, jjj;
2386 Vec_Str_t * encodedSop;
2387 // compute SOP sizes
2388 Vec_Int_t * vGuide = Vec_IntAlloc( Abc_NtkObjNumMax(pNtkNew) );
2389 Vec_IntFill( vGuide, Abc_NtkObjNumMax(pNtkNew), -1 );
2390 // Collect BDDs in array
2391 Vec_Ptr_t * vFuncs = Vec_PtrStart( Abc_NtkObjNumMax(pNtkNew) );
2392 assert( !Cudd_ReorderingStatus(dd, (Cudd_ReorderingType *)&nCubes) );
2393 Abc_NtkForEachNode( pNtkNew, pObjNew, i )
2394 if ( !Abc_ObjIsBarBuf(pObjNew) )
2395 Vec_PtrWriteEntry( vFuncs, i, pObjNew->pData );
2396 // compute the number of cubes in the ISOPs and detemine polarity
2397 nCubes = Extra_bddCountCubes( dd, (DdNode **)Vec_PtrArray(vFuncs), Vec_PtrSize(vFuncs), -1, ABC_INFINITY, Vec_IntArray(vGuide) );
2398 Vec_PtrFree( vFuncs );
2399 assert( Abc_NtkHasBdd(pNtkNew) );
2400 if ( dd->size > 0 )
2401 Cudd_zddVarsFromBddVars( dd, 2 );
2402
2403 // go through the objects
2404 Abc_NtkForEachNode( pNtkNew, pObjNew, i )
2405 {
2406 // derive ISOPs in both polarities
2407 if ( Abc_ObjIsBarBuf(pObjNew) )
2408 continue;
2409 assert( pObjNew->pData );
2410 bFunc = (DdNode *)pObjNew->pData;
2411 int nFanins = Abc_ObjFaninNum(pObjNew);
2412 assert( nFanins <= 8); // we only support 8 fanins due to the data structure of vTTISOPs
2413 // Check if node function is constant
2414 if ( Cudd_IsConstant(bFunc) ){
2415 pSop = ABC_ALLOC( char, nFanins + 4 );
2416 pSop[0] = ' ';
2417 pSop[1] = '0' + (int)(bFunc == Cudd_ReadOne(dd));
2418 pSop[2] = '\n';
2419 pSop[3] = '\0';
2420 ABC_FREE( pSop );
2421 // it's not a LUT, it should be skipped
2422 continue;
2423 }
2424 // save location of the ISOP info in vTTISOPs
2425 Vec_IntInsert( p->vTTLut, pObjNew->iTemp , p->vTTISOPs->nSize );
2426
2427 // get the ZDD of the negative polarity
2428 pSop = extractSOP( dd, bFunc, nFanins, 0 , &nCubes);
2429 if ( pSop == NULL )
2430 goto cleanup;
2431 // encode the sop and save it in the vTTISOPs
2432 encodedSop = encodeSOP( pSop, nFanins, nCubes );
2433 Vec_StrPush( p->vTTISOPs, (char) nCubes );
2434 if (nCubes > 0){
2435 for (jjj = 0; jjj < nCubes; jjj++){
2436 Vec_StrPush( p->vTTISOPs, encodedSop->pArray[jjj*2] ); Vec_StrPush( p->vTTISOPs, encodedSop->pArray[jjj*2+1] );
2437 }
2438 }
2439 Vec_StrFree( encodedSop );
2440 ABC_FREE( pSop );
2441
2442 // get the ZDD of the positive polarity
2443 pSop = extractSOP( dd, bFunc, nFanins, 1 , &nCubes);
2444 if ( pSop == NULL )
2445 goto cleanup;
2446 // encode the sop and save it in the vTTISOPs
2447 encodedSop = encodeSOP( pSop, nFanins, nCubes );
2448 Vec_StrPush( p->vTTISOPs, (char) nCubes );
2449 if (nCubes > 0){
2450 for (jjj = 0; jjj < nCubes; jjj++){
2451 Vec_StrPush( p->vTTISOPs, encodedSop->pArray[jjj*2] ); Vec_StrPush( p->vTTISOPs, encodedSop->pArray[jjj*2+1] );
2452 }
2453 }
2454 Vec_StrFree( encodedSop );
2455 ABC_FREE( pSop );
2456
2457 }
2458
2459
2460cleanup:
2461 // free all used memory to generate SOPs
2462 Vec_IntFree( vGuide );
2463 Abc_NtkDelete( pNtkNew );
2464 return;
2465}
2466
2467
2479
2481
2482 extern Hop_Obj_t * Abc_ObjHopFromGia( Hop_Man_t * pHopMan, Gia_Man_t * p, int GiaId, Vec_Ptr_t * vCopies );
2483
2484 // generate the structure to contain LUT ids and their corresponding TTISOPS
2485 int nCountLuts = Gia_ManLutNum(p);
2486 p->vTTISOPs = Vec_StrAlloc( nCountLuts * 10);
2487 p->vTTLut = Vec_IntAlloc( Gia_ManObjNum(p) );
2488 Vec_IntFill( p->vTTLut, Gia_ManObjNum(p), -1 );
2489
2490 // Transform the Gia into a HOP network
2491 Abc_Ntk_t * pNtkNew;
2492 Abc_Obj_t * pObjNew, * pObjNewLi, * pObjNewLo, * pConst0 = NULL;
2493 Gia_Obj_t * pObj, * pObjLi, * pObjLo;
2494 Vec_Ptr_t * vReflect = Vec_PtrStart( Gia_ManObjNum(p) );
2495 int i, k, iFan;
2496 assert( Gia_ManHasMapping(p) );
2497 pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_AIG, 1 );
2498 // duplicate the name and the spec
2499 pNtkNew->pName = Extra_UtilStrsav(p->pName);
2500 pNtkNew->pSpec = Extra_UtilStrsav(p->pSpec);
2502 // create constant
2503 pConst0 = Abc_NtkCreateNodeConst0( pNtkNew );
2504 Gia_ManConst0(p)->Value = Abc_ObjId(pConst0);
2505 // create PIs
2506 Gia_ManForEachPi( p, pObj, i )
2507 pObj->Value = Abc_ObjId( Abc_NtkCreatePi( pNtkNew ) );
2508 // create POs
2509 Gia_ManForEachPo( p, pObj, i )
2510 pObj->Value = Abc_ObjId( Abc_NtkCreatePo( pNtkNew ) );
2511 // create as many latches as there are registers in the manager
2512 Gia_ManForEachRiRo( p, pObjLi, pObjLo, i )
2513 {
2514 pObjNew = Abc_NtkCreateLatch( pNtkNew );
2515 pObjNewLi = Abc_NtkCreateBi( pNtkNew );
2516 pObjNewLo = Abc_NtkCreateBo( pNtkNew );
2517 Abc_ObjAddFanin( pObjNew, pObjNewLi );
2518 Abc_ObjAddFanin( pObjNewLo, pObjNew );
2519 pObjLi->Value = Abc_ObjId( pObjNewLi );
2520 pObjLo->Value = Abc_ObjId( pObjNewLo );
2521 Abc_LatchSetInit0( pObjNew );
2522 }
2523 Gia_ManForEachLut( p, i )
2524 {
2525 pObj = Gia_ManObj(p, i);
2526 assert( pObj->Value == ~0 );
2527 if ( Gia_ObjLutSize(p, i) == 0 )
2528 {
2529 pObj->Value = Abc_ObjId(pConst0);
2530 continue;
2531 }
2532 pObjNew = Abc_NtkCreateNode( pNtkNew );
2533 Gia_LutForEachFanin( p, i, iFan, k )
2534 Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtkNew, Gia_ObjValue(Gia_ManObj(p, iFan))) );
2535 pObjNew->pData = Abc_ObjHopFromGia( (Hop_Man_t *)pNtkNew->pManFunc, p, i, vReflect );
2536 pObjNew->fPersist = 0;
2537 pObj->Value = Abc_ObjId( pObjNew );
2538 pObjNew->iTemp = i;
2539 }
2540
2541 Vec_PtrFree( vReflect );
2542
2543 // HOP -> BDD
2544 Abc_NtkAigToBdd(pNtkNew);
2545
2546 // Determine both polarity ISOPs
2547 computeISOPs( p, pNtkNew );
2548
2549 return;
2550
2551}
2552
2564
2565int evaluate_mffc(Gia_Man_t * p, int rootId, int fanId, Vec_Int_t * vLeaves){
2566
2567 int quality = 0, jMFFCLeaf;
2568 int nLeaves = Vec_IntSize(vLeaves);
2569 for(jMFFCLeaf = 0; jMFFCLeaf < nLeaves ; jMFFCLeaf++){
2570 int idMFFCLeaf = Vec_IntEntry(vLeaves, jMFFCLeaf);
2571 int level_leaf = Gia_ObjLevelId(p, idMFFCLeaf) ;
2572 int level_root = Gia_ObjLevelId(p, fanId) ;
2573 quality += level_root - level_leaf;
2574 }
2575 if( quality != 0 && nLeaves > 0)
2576 quality /= nLeaves;
2577 return quality;
2578
2579}
2580
2592
2594
2595
2596 int i, ith_fan, iFan;
2597 Vec_Int_t * vNodes, * vLeaves, * vInners;
2598 vNodes = Vec_IntAlloc( 100 );
2599 vLeaves = Vec_IntAlloc( 10 );
2600 vInners = Vec_IntAlloc( 100 );
2601 Vec_Int_t * vNodesNew, * vLeavesNew, * vInnersNew;
2602 vNodesNew = Vec_IntAlloc( 100 );
2603 vLeavesNew = Vec_IntAlloc( 10 );
2604 vInnersNew = Vec_IntAlloc( 100 );
2605 p->vMFFCsLuts = Vec_IntStartFull( Gia_ManObjNum(p) );
2606 //Vec_IntFill( p->vMFFCsLuts, Gia_ManObjNum(p), -1 );
2607 p->vMFFCsInfo = Vec_IntAlloc( Gia_ManLutNum(p) * 5 );
2609 Gia_ManForEachLut( p, i )
2610 {
2611 Gia_Obj_t * pObj = Gia_ManObj( p, i );
2612
2613 if ( !Gia_ObjRefNum(p, pObj) )
2614 continue;
2615 if ( !Gia_ObjCheckMffc(p, pObj, 10000, vNodes, vLeaves, vInners) )
2616 continue;
2617
2618 Vec_IntInsert( p->vMFFCsLuts, i , Vec_IntSize(p->vMFFCsInfo) );
2619 Gia_LutForEachFanin( p, i, iFan, ith_fan ){
2620 if (Vec_IntFind(vNodes, iFan) != -1){
2621 if(Gia_ObjIsCi(Gia_ManObj(p, iFan)) == 1){
2622 Vec_IntPush(p->vMFFCsInfo, Gia_ObjLevelId(p, i) ); // push the level of the CI
2623 continue;
2624 }
2625 Gia_Obj_t * pObjFanin = Gia_ManObj( p, iFan );
2626 if ( !Gia_ObjRefNum(p, pObjFanin) ){
2627 Vec_IntPush(p->vMFFCsInfo, 0);
2628 continue;
2629 }
2630 if ( !Gia_ObjCheckMffc(p, pObjFanin, 10000, vNodesNew, vLeavesNew, vInnersNew)){
2631 Vec_IntPush(p->vMFFCsInfo, 0);
2632 continue;
2633 }
2634 assert( Vec_IntSize(vLeavesNew) > 0);
2635 int quality = evaluate_mffc(p, i, iFan, vLeavesNew);
2636 Vec_IntPush(p->vMFFCsInfo, quality);
2637
2638 } else {
2639 Vec_IntPush( p->vMFFCsInfo, 0 );
2640 }
2641
2642 }
2643 }
2644 Vec_IntFree( vNodes );
2645 Vec_IntFree( vLeaves );
2646 Vec_IntFree( vInners );
2647 Vec_IntFree( vNodesNew );
2648 Vec_IntFree( vLeavesNew );
2649 Vec_IntFree( vInnersNew );
2650
2651}
2652
2653
2665
2666int extract_quality_mffc(Gia_Man_t * p, int ObjId, char pDCs){
2667
2668 if( Vec_IntEntry( p->vMFFCsLuts, ObjId ) == -1)
2669 return 0;
2670 assert( Vec_IntEntry( p->vMFFCsLuts, ObjId ) != -1);
2671 int * pMFFC = p->vMFFCsInfo->pArray + Vec_IntEntry( p->vMFFCsLuts, ObjId );
2672 int iFan, ith_fan, quality = 0;
2673 //int nFanins = Gia_ObjLutSize(p, ObjId);
2674 Gia_LutForEachFanin( p, ObjId, iFan, ith_fan ){
2675 int qualityMFFC = *pMFFC;
2676 if (qualityMFFC == 0 || (pDCs & (1 << ith_fan)) > 0){ // count the cones without don't cares
2677 pMFFC++;
2678 continue;
2679 }
2680 quality += qualityMFFC;
2681 pMFFC++;
2682 }
2683 return quality;
2684
2685}
2686
2698
2699int * sortArray( int * array, int n ){
2700
2701 int i, j, temp;
2702 int * positions = (int *) malloc( n * sizeof(int) );
2703 for(i = 0; i < n; i++)
2704 positions[i] = i;
2705 for(i = 0; i < n; i++){
2706 for(j = i+1; j < n; j++){
2707 if(array[i] < array[j]){
2708 temp = array[i];
2709 array[i] = array[j];
2710 array[j] = temp;
2711 temp = positions[i];
2712 positions[i] = positions[j];
2713 positions[j] = temp;
2714 }
2715 }
2716 }
2717 return positions;
2718
2719}
2720
2722
2723 p->vLutsRankings = Vec_PtrStart( Gia_ManObjNum(p) );
2724 Vec_Int_t * vLutsRankingsTmp = Vec_IntAlloc( Gia_ManLutNum(p) * 5 );
2725 int LutId, iii, k, jjj;
2726 char * pSop[2]; int nCubes[2]; int nFanins;
2727 int * ranks, * fanins;
2728 Gia_ManForEachLut( p, LutId )
2729 {
2730 nFanins = Gia_ObjLutSize(p, LutId);
2731 Vec_PtrInsert( p->vLutsRankings, LutId, vLutsRankingsTmp->pArray + Vec_IntSize(vLutsRankingsTmp) );
2732 assert( nFanins > 0 );
2733 ranks = (int*) malloc( nFanins * sizeof(int) );
2734 fanins = (int*) malloc( nFanins * sizeof(int) );
2735 Gia_LutForEachFanin( p, LutId, k, iii ){
2736 fanins[iii] = k;
2737 ranks[iii] = 0;
2738 }
2739
2740 nFanins = Gia_ObjLutSize(p, LutId);
2741 getISOPObjId( p, LutId, pSop, nCubes );
2742 for(k = 0; k < 2; k++){
2743 for(iii = 0; iii < nCubes[k]; iii++){
2744 //char pCube = pSop[k][iii*2];
2745 char pDCs = pSop[k][iii*2+1];
2746 for(jjj = 0; jjj < nFanins; jjj++){
2747 if ( (pDCs & (1 << jjj)) == 0 )
2748 ranks[jjj]++;
2749 }
2750 }
2751 }
2752 int * positions = sortArray( ranks, nFanins );
2753 for(jjj = 0; jjj < nFanins; jjj++){
2754 Vec_IntPush( vLutsRankingsTmp, fanins[positions[jjj]] );
2755 }
2756 free( positions );
2757 free( ranks );
2758 free( fanins );
2759 }
2760 //Vec_IntFree( vLutsRankingsTmp );
2761}
2762
2774
2776
2777 Vec_Ptr_t * vWatchList = Vec_PtrStart( Gia_ManObjNum(p) );
2778 int LutId;
2779 Gia_ManForEachLut( p, LutId )
2780 {
2781 int * ranking = (int *) Vec_PtrEntry( p->vLutsRankings, LutId );
2782 int nodeId = ranking[0];
2783 if( Vec_PtrEntry( vWatchList, nodeId ) == NULL ){
2784 Vec_Int_t * vWatchListTmp = Vec_IntAlloc( 5 );
2785 Vec_PtrWriteEntry( vWatchList, nodeId, vWatchListTmp );
2786 Vec_IntPush( vWatchListTmp, LutId );
2787 //Vec_IntFree( vWatchListTmp );
2788 } else {
2789 Vec_IntPush( (Vec_Int_t *) Vec_PtrEntry( vWatchList, nodeId ), LutId );
2790 }
2791 }
2792 return vWatchList;
2793}
2794
2806
2808{
2809 int iObj, iFanin, k;
2810 assert( Gia_ManHasMapping(p) );
2811 Vec_WecFreeP( &p->vFanouts2 );
2812 p->vFanouts2 = Vec_WecStart( Gia_ManObjNum(p) );
2813 Gia_ManForEachLut( p, iObj )
2814 {
2815 Gia_LutForEachFanin( p, iObj, iFanin, k )
2816 {
2817 Vec_WecPush( p->vFanouts2, iFanin, iObj );
2818 }
2819 }
2820}
2821
2833
2835
2836 int i, iRepr, kElement, firstLutId, prevLutId;
2837 Vec_Int_t * vLutIds = Vec_IntAlloc( Gia_ManObjNum(p) );
2838 Gia_ManForEachClass0( p, iRepr )
2839 {
2840 Gia_ClassForEachObj1( p, iRepr, kElement ){
2841 Vec_IntPush( vLutIds, kElement );
2842 }
2843
2844 firstLutId = -1; prevLutId = -1;
2845 if( !Gia_ObjIsLut(p, iRepr) ){
2846 Gia_ObjSetRepr( p, iRepr, GIA_VOID );
2847 Gia_ObjSetNext( p, iRepr, 0 );
2848 } else {
2849 firstLutId = iRepr;
2850 prevLutId = iRepr;
2851 }
2852 Vec_IntForEachEntry( vLutIds, kElement, i ){
2853
2854 if( !Gia_ObjIsLut(p, kElement) ){
2855 Gia_ObjSetRepr( p, kElement, GIA_VOID );
2856 Gia_ObjSetNext( p, kElement, 0 );
2857 continue;
2858 }
2859 if(firstLutId == -1){
2860 Gia_ObjSetRepr( p, kElement, GIA_VOID );
2861 firstLutId = kElement;
2862 prevLutId = kElement;
2863 } else {
2864 Gia_ObjSetRepr( p, kElement, firstLutId );
2865 Gia_ObjSetNext( p, prevLutId , kElement );
2866 prevLutId = kElement;
2867 }
2868 }
2869 Vec_IntClear( vLutIds );
2870 // no lut found
2871 if(firstLutId == -1){
2872 continue;
2873 }
2874 Gia_ObjSetNext( p, prevLutId, 0 );
2875
2876 }
2877 Vec_IntFree( vLutIds );
2878}
2879
2891
2893
2894 int i, k;
2895 int quality = 0;
2897 {
2898 Gia_ClassForEachObj1( p, i, k ){
2899 quality++;
2900 }
2901 }
2902
2903 if (verbose)
2904 printf("**Quality = %d\n", quality);
2905
2906 return quality;
2907}
2908
2909
2921
2923 int iRepr;
2924 int numClasses = 0;
2925 Gia_ManForEachClass0( p, iRepr ){
2926 numClasses++;
2927 }
2928 return numClasses;
2929}
2930
2942
2943void saveSimVectors( Gia_Man_t * p, Vec_Ptr_t * pValues, int bitLength, int jth_word, int kth_bit){
2944
2945 int i, Id;
2946 int nWords = bitLength / 64;
2947 assert(nWords == 0); // Not considering case with large outgold values
2948 Gia_ManForEachCiId( p, Id, i ){
2949 Vec_Wrd_t * pValuesPi = (Vec_Wrd_t *) Vec_PtrEntry( pValues, i );
2950 word pValuePiJWord = 0;
2951 if(kth_bit == 0){
2952 Vec_WrdPush( pValuesPi, 0 );
2953 } else {
2954 pValuePiJWord = Vec_WrdEntry( pValuesPi, jth_word );
2955 }
2956 word * pSim = Cec4_ObjSim( p, Id );
2957 pValuePiJWord = (pSim[0] << kth_bit) ^ pValuePiJWord;
2958 Vec_WrdWriteEntry( pValuesPi, jth_word, pValuePiJWord );
2959 }
2960}
2961
2973
2974void executeRandomSim( Gia_Man_t * p, Cec4_Man_t * pMan , int dynSim, int nMaxIter , Vec_Ptr_t * vSimSave, int verbose ){
2975
2976 clock_t start_time = clock();
2977 int i, j, k, Id;
2978 int numClass = 100000;
2979 int oldNumClass = 0, iMaxNumber = 200, iNumber = 0;
2980 if(dynSim){
2981 while (numClass != oldNumClass && iNumber < iMaxNumber)
2982 {
2983 oldNumClass = numClass;
2985 Cec4_ManSimulate( p, pMan );
2986 int quality = evaluate_equiv_classes(p, 0);
2987 if (verbose)
2988 printf("Time elapsed: %f (classes size: %d)\n", (float)(clock() - start_time)/CLOCKS_PER_SEC, quality);
2989 numClass = totalNumClasses(p);
2990 iNumber++;
2991 Gia_ManForEachCiId( p, Id, j ){
2992 Vec_Wrd_t * vSimPI = (Vec_Wrd_t *) Vec_PtrEntry( vSimSave, j );
2993 word * pSim = Cec4_ObjSim( p, Id );
2994 for( k = 0; k < p->nSimWords; k++ ){
2995 Vec_WrdPush( vSimPI, pSim[k] );
2996 }
2997 }
2998 }
2999
3000
3001 } else {
3002 for(i = 0; i < nMaxIter; i++){
3004 Cec4_ManSimulate( p, pMan );
3005 int quality = evaluate_equiv_classes(p, 0);
3007 if (verbose)
3008 printf("Time elapsed: %f (classes size: %d)\n", (float)(clock() - start_time)/CLOCKS_PER_SEC, quality);
3009 Gia_ManForEachCiId( p, Id, j ){
3010 Vec_Wrd_t * vSimPI = (Vec_Wrd_t *) Vec_PtrEntry( vSimSave, j );
3011 word * pSim = Cec4_ObjSim( p, Id );
3012 for( k = 0; k < p->nSimWords; k++ ){
3013 Vec_WrdPush( vSimPI, pSim[k] );
3014 }
3015 }
3016 }
3017 }
3018}
3019
3020
3032
3034
3035 FILE * pFile;
3036 pFile = fopen( filename, "wb" );
3037 int i, j, iii = 0;
3039 {
3040 fprintf( pFile, "Class %d: %d ", iii , i);
3041 Gia_ClassForEachObj1( p, i, j ){
3042 fprintf( pFile, " %d ", j );
3043 }
3044 fprintf(pFile, "\n");
3045 iii++;
3046 }
3047 fclose( pFile );
3048
3049
3050}
3051
3052
3053
3065
3067
3068 char * pOutGold = (char *) malloc( sizeof(char) * Gia_ManObjNum(p) );
3069 int i, k;
3070 int cnt = 85; // 0b01010101
3071 Gia_ManForEachLut( p, i ){
3072 pOutGold[i] = (char) 0;
3073 }
3074 Gia_ManForEachClass0( p, i ){
3075 pOutGold[i] = (char) cnt;
3076 cnt ^= 1;
3077 Gia_ClassForEachObj1( p, i, k ){
3078 pOutGold[k] = (char) cnt;
3079 cnt ^= 1;
3080 }
3081 }
3082 return pOutGold;
3083
3084}
3085
3097
3099 int iRepr;
3100 Gia_ManForEachClass0( p, iRepr ){
3101 return 1;
3102 }
3103 return 0;
3104}
3105
3117
3119
3120 Vec_Int_t * vClass = Vec_IntAlloc( Gia_ManLutNum(p) );
3121 int iRepr, jLut;
3122 Gia_ManForEachClass0( p, iRepr ){
3123 if(nth_class == 0){
3124 Vec_IntPush(vClass, iRepr);
3125 Gia_ClassForEachObj1( p, iRepr, jLut )
3126 Vec_IntPush(vClass, jLut);
3127 break;
3128 }
3129 nth_class--;
3130 }
3131 assert(Vec_IntSize(vClass) > 0);
3132 return vClass;
3133
3134}
3135
3147
3148Vec_Int_t * computeLutsOrder(Gia_Man_t * p, int reorder_type){
3149
3150 Vec_Int_t * luts_order = Vec_IntAlloc( Gia_ManLutNum(p) );
3151 int * luts_tmp = (int *) malloc( sizeof(int) * Gia_ManLutNum(p));
3152 int iRepr, jLut, iii, jjj, kkk;
3153 Gia_ManForEachClass0( p, iRepr ){
3154 luts_tmp[ 0 ] = iRepr;
3155 iii = 1;
3156 Gia_ClassForEachObj1( p, iRepr, jLut ){
3157 if(reorder_type == 0){ // decreasing level order
3158 int found = 0;
3159 for(jjj = 0; jjj < iii; jjj++){
3160 if(Gia_ObjLevelId(p, jLut) <= Gia_ObjLevelId(p, luts_tmp[jjj])){
3161 for (kkk = iii; kkk > jjj; kkk--) {
3162 luts_tmp[kkk] = luts_tmp[kkk - 1];
3163 }
3164 luts_tmp[jjj] = jLut;
3165 found = 1;
3166 break;
3167 }
3168 }
3169 if(!found){
3170 luts_tmp[iii] = jLut;
3171 }
3172 iii++;
3173 } else if(reorder_type == 1) { // increasing level order
3174 int found = 0;
3175 for(jjj = 0; jjj < iii; jjj++){
3176 if(Gia_ObjLevelId(p, jLut) >= Gia_ObjLevelId(p, luts_tmp[jjj])){
3177 for (kkk = iii; kkk > jjj; kkk--) {
3178 luts_tmp[kkk] = luts_tmp[kkk - 1];
3179 }
3180 luts_tmp[jjj] = jLut;
3181 found = 1;
3182 break;
3183 }
3184 }
3185 if(!found){
3186 luts_tmp[iii] = jLut;
3187 }
3188 iii++;
3189 }
3190 }
3191 for(kkk = 0; kkk < iii; kkk++)
3192 Vec_IntPush(luts_order, luts_tmp[kkk] );
3193 }
3194 free(luts_tmp);
3195 return luts_order;
3196
3197}
3198
3199
3211
3212void computeFaninCones_rec(Gia_Man_t * p, int ObjId, Vec_Int_t * vLutsFaninCones ){
3213
3214 int FaninId, jth_fanin;
3215 Gia_LutForEachFanin( p, ObjId, FaninId, jth_fanin ){
3216 if( Vec_IntEntry( vLutsFaninCones, FaninId ) == 0 ){
3217 Vec_IntWriteEntry( vLutsFaninCones, FaninId, 1 );
3218 if( Gia_ObjIsCi( Gia_ManObj(p, FaninId) ) == 0 )
3219 computeFaninCones_rec( p, FaninId, vLutsFaninCones );
3220 }
3221 }
3222}
3223
3225
3226 int i, jth_fanin;
3227 Vec_Int_t * vLutsFaninCones = Vec_IntStart(Gia_ManObjNum(p));
3228 Vec_IntForEachEntry( vLuts, i, jth_fanin ){
3229 computeFaninCones_rec( p, i, vLutsFaninCones );
3230 }
3231 return vLutsFaninCones;
3232
3233}
3234
3235
3247
3248int checkCompatibilityCube( Gia_Man_t * pMan, char * pCube, int nFanins, char * pCubeGold ){
3249
3250 char pCubeOnes = *pCube; char pDCs = *(pCube+1);
3251 char pCubeGoldOnes = *pCubeGold; char pCubeNotAssigned = *(pCubeGold+1);
3252
3253 char pSkipBits = pDCs | pCubeNotAssigned;
3254 char pConflictBits = pCubeOnes ^ pCubeGoldOnes;
3255 char isConflict = ~pSkipBits & pConflictBits;
3256 if ( isConflict )
3257 return 0;
3258
3259 return 1;
3260
3261}
3262
3263
3275
3276int compute_quality_sop(Gia_Man_t * p , char * pSop, int ObjId ,int nFanins, int experimentID){
3277
3278 int quality = 0;
3279 //char pValues = *pSop;
3280 pSop++;
3281 char pDCs = *(pSop);
3282 switch (experimentID){
3283 case 1: // Reverse Simulation
3284 case 2: // Simple Implication
3285 case 3: // Advanced Implication
3286 break;
3287 case 4: // Advanced Implication + Count DCs
3288 while (pDCs > 0){
3289 if((pDCs & 1) == 1)
3290 quality += p->nLevels * 5; // the presence of DCs is more important than mffc
3291 pDCs = pDCs >> 1;
3292 }
3293 break;
3294 case 5: // Advanced Implication + Count DC + FFC
3295 while (pDCs > 0){
3296 if((pDCs & 1) == 1)
3297 quality += p->nLevels * 5; // the presence of DCs is more important than mffc
3298 pDCs = pDCs >> 1;
3299 }
3300 pDCs = *(pSop);
3301 quality += extract_quality_mffc(p, ObjId, pDCs);
3302 break;
3303 default:
3304 break;
3305 }
3306 return quality;
3307}
3308
3309
3321
3322int rouletteWheel( Vec_Int_t * vQualitySops, int numValid){
3323
3324 int i, max_int = 0xffffffff;
3325 float totalSum;
3326 totalSum = 0.0;
3327 for ( i = 0; i < numValid; i++ )
3328 totalSum += (float) Vec_IntEntry(vQualitySops, i);
3329
3330 unsigned int randValue = Gia_ManRandom(0);
3331 float randValueNormalized = (float) ((float)randValue / max_int);
3332 float randomNum = randValueNormalized * totalSum;
3333
3334 // Select the index based on inverse proportional probability
3335 float cumulativeProbability = 0.0;
3336 for ( i = 0; i < numValid; i++ ) {
3337 cumulativeProbability += Vec_IntEntry(vQualitySops, i);
3338 if (cumulativeProbability > randomNum) {
3339 return i;
3340 }
3341 }
3342 return -1;
3343}
3344
3356
3357int selectSop( Vec_Int_t * vQualitySops, int ith_max_quality, int experimentID){
3358
3359 assert(experimentID > 0); // random simulation should not be used here
3360 int numValid = Vec_IntSize(vQualitySops);
3361 int idSelected = -1;
3362 switch (experimentID){
3363 //case 1:
3364 // idSelected = Aig_ManRandom(0) % numValid;
3365 // break;
3366 default:
3367 idSelected = rouletteWheel( vQualitySops, numValid);
3368 break;
3369 }
3370 if(idSelected == -1){
3371 idSelected = ith_max_quality;
3372 }
3373 assert( idSelected != -1);
3374 return idSelected;
3375}
3376
3388
3389int check_implication( Gia_Man_t * p, int ObjId , int validBit , int fanoutValue, int fanoutNotSet, char * inputsFaninsValues, char * networkValues1s, char * networkValuesNotSet , int experimentID){
3390
3391 assert(experimentID > 1);
3392 int ith_cube, jjj;
3393 int nFanins = Gia_ObjLutSize(p, ObjId);
3394 char * pSopBoth[2]; int nCubesBoth[2];
3395 getISOPObjId( p, ObjId, pSopBoth, nCubesBoth );
3396
3397 if (fanoutNotSet == 0){
3398 // case in which the output is set // backward implication
3399 char * pSop = pSopBoth[fanoutValue];
3400 int nCubes = nCubesBoth[fanoutValue];
3401 int compatible = 0;
3402 int lastCube = 0;
3403 for(ith_cube = 0; ith_cube < nCubes; ith_cube++){
3404 if(checkCompatibilityCube( p, pSop + ith_cube * 2, nFanins, inputsFaninsValues ) ){
3405 compatible++;
3406 lastCube = ith_cube;
3407 }
3408 }
3409
3410
3411 if(compatible == 1){
3412 //char selectedSop = *(pSop + lastCube * 2);
3413 //char selectedDCs = *(pSop + lastCube * 2 + 1);
3414 assert(0); // TODO: implement the case in which the output is set
3415 return 1;
3416 } else if (compatible == 0){
3417 return -1;
3418 }
3419
3420 return 0;
3421 }
3422 // forward implication
3423 int compatible[2];
3424 compatible[0] = 0;
3425 compatible[1] = 0;
3426 for(jjj = 0; jjj < 2; jjj++){
3427
3428 char * pSop = pSopBoth[jjj];
3429 int nCubes = nCubesBoth[jjj];
3430 for(ith_cube = 0; ith_cube < nCubes; ith_cube++){
3431 if(checkCompatibilityCube( p, pSop + ith_cube * 2, nFanins, inputsFaninsValues ) ){
3432 compatible[jjj]++;
3433 if(compatible[jjj] > 1)
3434 break;
3435 }
3436 }
3437 }
3438
3439 if(compatible[0] > 0 && compatible[1] > 0){
3440 return 0;
3441 } else if (compatible[0] == 0 && compatible[1] == 0){
3442 return -1;
3443 }
3444
3445 if(experimentID == 2){
3446 // simple implication
3447 if(compatible[0] > 1 || compatible[1] > 1){
3448 return 0;
3449 }
3450 char mask = 1 << validBit;
3451 if(compatible[0] == 1){
3452 networkValuesNotSet[ObjId] &= (~mask);
3453 } else {
3454 networkValues1s[ObjId] |= (1 << validBit);
3455 networkValuesNotSet[ObjId] &= (~mask);
3456 }
3457 return 1;
3458 } else if (experimentID > 2){
3459 // advanced implication
3460 char mask = 1 << validBit;
3461 if(compatible[0] >= 1){
3462 networkValuesNotSet[ObjId] &= (~mask);
3463 } else {
3464 networkValues1s[ObjId] |= (1 << validBit);
3465 networkValuesNotSet[ObjId] &= (~mask);
3466 }
3467 return 1;
3468 }
3469
3470 assert(0);
3471 // In C++ assert(0) doesn't count as a proper exit.
3472 // needs to return a value to compile.
3473 return -1;
3474}
3475
3476
3488
3489int checkCompatibilityImplication( Gia_Man_t * p, Cec_ParSimGen_t * pPars, char * netValid, int objId, char * networkValues1s, char * networkValuesNotSet , Vec_Int_t * vLuts2Imply, Vec_Int_t * vLutsValidity , int experimentID){
3490
3491
3492 char _valid_vecs = *netValid;
3493 char inputsFaninsValues[2] = {0, 0};
3494 int firstElement = 0;
3495 int iii = -1, FaninId, jjj;
3496 pPars->nImplicationTotalChecks++;
3497 while (_valid_vecs > 0){
3498 iii++;
3499 if( (_valid_vecs & 1) == 0){
3500 _valid_vecs = _valid_vecs >> 1;
3501 continue;
3502 }
3503 // retrieve value of the fanout
3504 char mask = 1 << iii;
3505 int fanoutValue = (networkValues1s[objId] & mask) >> iii;
3506 int fanoutNotSet = (networkValuesNotSet[objId] & mask) >> iii;
3507
3508 if(fanoutNotSet == 0){
3509 // disable backward implication in this function
3510 _valid_vecs = _valid_vecs >> 1;
3511 continue;
3512 }
3513 // re-arrange fanin values format
3514 Gia_LutForEachFanin( p, objId, FaninId, jjj ){
3515 char valueFanin = networkValues1s[FaninId];
3516 char valueFaninNotSet = networkValuesNotSet[FaninId];
3517 inputsFaninsValues[0] |= ( ((valueFanin & mask) >> iii) << jjj);
3518 inputsFaninsValues[1] |= ( ((valueFaninNotSet & mask) >> iii) << jjj);
3519 }
3520
3521
3522 if(fanoutNotSet == 0 && inputsFaninsValues[1] == 0){
3523 _valid_vecs = _valid_vecs >> 1;
3524 continue;
3525 }
3526
3527 int status = check_implication( p, objId, iii, fanoutValue, fanoutNotSet, inputsFaninsValues, networkValues1s, networkValuesNotSet , experimentID);
3528 if(status == -1){
3529 *netValid = *netValid & ~(1 << iii);
3530 } else if( status == 1){
3531 if(firstElement == 0){
3533 Vec_IntPush( vLutsValidity, 1 << iii );
3534 Vec_IntPush( vLuts2Imply, objId );
3535 } else {
3536 Vec_IntWriteEntry( vLutsValidity, Vec_IntSize(vLutsValidity) - 1, Vec_IntEntry(vLutsValidity, Vec_IntSize(vLutsValidity) - 1) | (1 << iii) );
3537 }
3538 }
3539
3540 _valid_vecs = _valid_vecs >> 1;
3541 }
3542
3543 if( *netValid == 0){
3544 return 0;
3545 }
3546
3547 return 1;
3548}
3549
3561
3562int computeLutsToImply( Gia_Man_t * p, Cec_ParSimGen_t * pPars, char * netValid, int ObjId, char * networkValues1s, char * networkValuesNotSet , Vec_Int_t * vLutsFaninCones, Vec_Int_t * vLuts2Imply, Vec_Int_t * vLutsValidity , Vec_Ptr_t * vNodesWatchlist, int experimentID){
3563
3564 int i, FanoutId, jth_fanout, LutId, k;
3565
3566 if(vNodesWatchlist == NULL){
3567 // Option 1: iterate through fanouts to check if there can be an implication and if yes, apply it
3568 Gia_LutForEachFanout2( p, ObjId, FanoutId, jth_fanout ){
3569 if( Vec_IntEntry(vLutsFaninCones, FanoutId) == 0){
3570 // if the lut FanoutId is not in any cone, it shouldn't be considered
3571 continue;
3572 }
3573 int status = checkCompatibilityImplication( p, pPars, netValid, FanoutId, networkValues1s, networkValuesNotSet, vLuts2Imply, vLutsValidity, experimentID);
3574 if(status <= 0){
3575 return status;
3576 }
3577 }
3578 } else {
3579 // Option 2: iterate through the watchlist to check if there can be an implication and if yes, apply it
3580 Vec_Int_t * vWatchlist = (Vec_Int_t *) Vec_PtrEntry( vNodesWatchlist, ObjId );
3581 if(vWatchlist == NULL){
3582 return 1;
3583 }
3584 Vec_IntForEachEntry( vWatchlist, FanoutId, i ){
3585 if( Vec_IntEntry(vLutsFaninCones, FanoutId) == 0){
3586 // if the lut FanoutId is not in any cone, it shouldn't be considered
3587 continue;
3588 }
3589 int status = checkCompatibilityImplication( p, pPars, netValid, FanoutId, networkValues1s, networkValuesNotSet, vLuts2Imply, vLutsValidity, experimentID);
3590 if(status <= 0){
3591 return status;
3592 }
3593 }
3594 // update watchlist of LUTs
3595 Vec_IntForEachEntry( vWatchlist, LutId, i ){
3596 int * ranking = (int *) Vec_PtrEntry( p->vLutsRankings, LutId );
3597 int FaninSize = Gia_ObjLutSize( p, LutId ), newWatchK = -1;
3598 for(k = 0; k < FaninSize ; k++){
3599 if(ranking[k] == ObjId){
3600 newWatchK = k+1;
3601 break;
3602 }
3603 }
3604 assert(newWatchK != -1);
3605 if(newWatchK >= FaninSize){ // the LUT is already fully watched
3606 continue;
3607 }
3608 int newWatch = ranking[newWatchK];
3609 Vec_Int_t * vNewWatch = (Vec_Int_t *) Vec_PtrEntry( vNodesWatchlist, newWatch );
3610 if(vNewWatch == NULL){ // case in which there was no watch for a certain variable
3611 vNewWatch = Vec_IntAlloc( 10 );
3612 Vec_PtrWriteEntry( vNodesWatchlist, newWatch, vNewWatch );
3613 Vec_IntPush( vNewWatch, LutId );
3614 } else {
3615 if(Vec_IntFind(vNewWatch, LutId) == -1){
3616 Vec_IntPush( vNewWatch, LutId );
3617 }
3618 }
3619 }
3620
3621 }
3622 return 1;
3623
3624}
3625
3637
3638int executeImplications( Gia_Man_t * p, Cec_ParSimGen_t * pPars, char * netValid, int ObjId, char * networkValues1s, char * networkValuesNotSet , Vec_Int_t * vLutsFaninCones, Vec_Ptr_t * vNodesWatchlist , int experimentID){
3639
3640 assert( *netValid > 0);
3641 pPars->nImplicationExecution++;
3642 int iii = -1, FanoutId;
3643 Vec_Int_t * vLuts2Imply = Vec_IntAlloc( 10 );
3644 Vec_Int_t * vLutsValidity = Vec_IntAlloc( 10 );
3645
3646 // first compute the list of luts to imply
3647 int status = computeLutsToImply( p, pPars, netValid, ObjId, networkValues1s, networkValuesNotSet, vLutsFaninCones, vLuts2Imply, vLutsValidity, vNodesWatchlist , experimentID);
3648 if(status <= 0){
3649 Vec_IntFree( vLuts2Imply );
3650 Vec_IntFree( vLutsValidity );
3651 return status;
3652 }
3653
3654 // second recursively go through the implied luts if there is any implication that can be applied
3655 Vec_IntForEachEntry( vLuts2Imply, FanoutId, iii ){
3656 pPars->nImplicationSuccess++;
3657 char validFanoutId = Vec_IntEntry(vLutsValidity, iii);
3658 status = executeImplications( p, pPars, &validFanoutId, FanoutId, networkValues1s, networkValuesNotSet, vLutsFaninCones, vNodesWatchlist ,experimentID);
3659 if (status == -1){
3660 Vec_IntFree( vLuts2Imply );
3661 Vec_IntFree( vLutsValidity );
3662 return -1;
3663 }
3664 }
3665
3666
3667 Vec_IntFree( vLuts2Imply );
3668 Vec_IntFree( vLutsValidity );
3669 return 1;
3670}
3671
3683
3684int computeNetworkValues(Gia_Man_t * p, Cec_ParSimGen_t * pPars, int ObjId , char * netValid, char lutValues1s, char * networkValues1s, char * networkValuesNotSet , Vec_Int_t * modifiedLuts , Vec_Int_t * vLutsFaninCones , Vec_Ptr_t * vNodesWatchlist , int experimentID ){
3685
3686 assert(experimentID > 0);
3687 assert( *netValid > 0 );
3688
3689 if( Gia_ObjIsCi( Gia_ManObj(p, ObjId) ) ){
3690 printf("[ERROR] It is not possible to call computeNetworkValues for PIs");
3691 return -1;
3692 }
3693 char * pSopBoth[2]; int nCubesBoth[2];
3694 char * pSop; int nCube, ith_cube, jth_fanin, FaninId;
3695 getISOPObjId( p, ObjId, pSopBoth, nCubesBoth );
3696 Vec_Ptr_t * vSops = Vec_PtrAlloc( 8 ); // for now consider only 8 parallalel SOPs due to char size
3697 Vec_Int_t * vQualitySops = Vec_IntAlloc( 8 ); // compute qualities of SOPs
3698 Vec_Int_t * vCubeId = Vec_IntAlloc( 8 ); // save ids of the selected cubes
3699 char _valid_vecs = *netValid;
3700 char _desired_values = lutValues1s;
3701 int iii = -1, max_quality, ith_max_quality, validNum =0;
3702 int nFanins = Gia_ObjLutSize(p, ObjId);
3703 // first compute all SOPs that are available
3704 while (_valid_vecs > 0){
3705 iii++;
3706 if( (_valid_vecs & 1) == 0){
3707 _valid_vecs = _valid_vecs >> 1;
3708 _desired_values = _desired_values >> 1;
3709 continue;
3710 }
3711 validNum++;
3712 if( (_desired_values & 1) == 0){
3713 // negative polarity
3714 pSop = pSopBoth[0];
3715 nCube = nCubesBoth[0];
3716 } else {
3717 // positive polarity
3718 pSop = pSopBoth[1];
3719 nCube = nCubesBoth[1];
3720 }
3721 Vec_IntClear(vQualitySops); // reset the quality of the SOPs
3722 Vec_IntClear(vCubeId); // reset the ids of the cubes
3723 char valuesFaninsMasked[2] = {0, 0}; // re-arrange all the fanin values for a specific iteration
3724 Gia_LutForEachFanin( p, ObjId, FaninId, jth_fanin ){
3725 char valuesFanin = networkValues1s[FaninId];
3726 char valueFaninNotSet = networkValuesNotSet[FaninId];
3727 char mask = 1 << iii;
3728 valuesFaninsMasked[0] |= ( ((valuesFanin & mask) >> iii) << jth_fanin);
3729 valuesFaninsMasked[1] |= ( ((valueFaninNotSet & mask) >> iii) << jth_fanin);
3730 }
3731 max_quality = 0;
3732 ith_max_quality = -1;
3733 for(ith_cube = 0; ith_cube < nCube; ith_cube++){
3734 if(checkCompatibilityCube( p, pSop + ith_cube * 2, nFanins, valuesFaninsMasked ) ){
3735 int quality = 1;
3736 quality += compute_quality_sop(p, pSop + ith_cube * 2, ObjId , nFanins, experimentID);
3737 if(quality > max_quality){
3738 max_quality = quality;
3739 ith_max_quality = ith_cube;
3740 }
3741 Vec_IntPush(vQualitySops, quality);
3742 Vec_IntPush(vCubeId, ith_cube);
3743 }
3744 }
3745 if(ith_max_quality == -1){ // no cube found that respects the values of the fanins
3746 // the vector is not valid
3747 validNum--;
3748 *netValid = *netValid & ~(1 << iii);
3749 } else {
3750 int _idCube = selectSop(vQualitySops, ith_max_quality, experimentID);
3751 int idSop = Vec_IntEntry(vCubeId, _idCube);
3752 Vec_PtrPush( vSops, pSop + idSop * 2 );
3753 }
3754 _valid_vecs = _valid_vecs >> 1;
3755 _desired_values = _desired_values >> 1;
3756 }
3757 Vec_IntFree( vQualitySops );
3758 Vec_IntFree( vCubeId );
3759 assert( validNum == Vec_PtrSize(vSops) );
3760 _valid_vecs = *netValid;
3761 // if not SOP available is valid return 0 ( not -1 since the valid vector might have been modified to skip DCs // there might be some valid SOPs for the next fanin)
3762 if( _valid_vecs == 0){
3763 //printInfoLutValues( p, ObjId, netValid, lutValues1s, networkValues1s, networkValuesNotSet);
3764 //printf("[WARNING] No valid SOPs found for node %d\n", ObjId);
3765 Vec_PtrFree( vSops );
3766 return 0;
3767 }
3768 Vec_IntPush( modifiedLuts, ObjId );
3769 // second traverse the graph applying the selected SOPs
3770 Gia_LutForEachFanin( p, ObjId, FaninId, jth_fanin ){
3771 // re-arrange SOPs as luts values across multiple iterations for each fanin
3772 iii = -1;
3773 validNum = -1;
3774 _valid_vecs = *netValid;
3775 char valuesFanin1s = 0;
3776 char valuesFaninDCs = 0;
3777 while (_valid_vecs > 0){
3778 iii++;
3779 if( (_valid_vecs & 1) == 0){
3780 _valid_vecs = _valid_vecs >> 1;
3781 continue;
3782 }
3783 validNum++;
3784 char mask_fanin = 1 << jth_fanin;
3785
3786 pSop = (char *) Vec_PtrEntry(vSops, validNum);
3787 char pSop1s = *pSop;
3788 pSop++;
3789 char pSopDCs = *pSop;
3790 valuesFanin1s |= ( (pSop1s & mask_fanin) >> jth_fanin) << iii;
3791 valuesFaninDCs |= ( (pSopDCs & mask_fanin) >> jth_fanin) << iii;
3792 _valid_vecs = _valid_vecs >> 1;
3793 }
3794
3795 // compute the values of the fanin
3796 char prevNetValue = networkValues1s[FaninId];
3797 char prevNetValueNotSet = networkValuesNotSet[FaninId];
3798 char values2propagate = ~valuesFaninDCs & *netValid & prevNetValueNotSet;
3799 networkValues1s[FaninId] |= valuesFanin1s & values2propagate;
3800 networkValuesNotSet[FaninId] &= valuesFaninDCs & *netValid;
3801
3802 if(values2propagate == 0){
3803 continue; // no value 2 propagate
3804 }
3805
3806 // apply implications
3807 char tmp_values2propagate = values2propagate;
3808 int status;
3809 char difference_valid;
3810 if(experimentID > 1){
3811 clock_t start_time = clock();
3812 status = executeImplications(p, pPars, &values2propagate, FaninId, networkValues1s, networkValuesNotSet , vLutsFaninCones, vNodesWatchlist , experimentID);
3813 pPars->fImplicationTime += (float)(clock() - start_time)/CLOCKS_PER_SEC;
3814 if( status == -1){
3815 networkValues1s[FaninId] = prevNetValue;
3816 networkValuesNotSet[FaninId] = prevNetValueNotSet;
3817 Vec_PtrFree( vSops );
3818 return -1;
3819 }
3820 assert( tmp_values2propagate >= values2propagate );
3821 // remove the values that are not valid
3822 difference_valid = tmp_values2propagate ^ values2propagate;
3823 if( difference_valid ){
3824 // some values are not valid
3825 networkValuesNotSet[FaninId] &= ~difference_valid;
3826 *netValid &= ~difference_valid;
3827 // update also the validity signal and corresponding values
3828 values2propagate = ~valuesFaninDCs & *netValid & prevNetValueNotSet;
3829 networkValues1s[FaninId] |= valuesFanin1s & values2propagate;
3830 networkValuesNotSet[FaninId] &= valuesFaninDCs & *netValid;
3831 tmp_values2propagate = values2propagate;
3832 }
3833 values2propagate = tmp_values2propagate;
3834 if(values2propagate == 0){
3835 continue; // no value 2 propagate
3836 }
3837 }
3838
3839 if( !Gia_ObjIsCi( Gia_ManObj(p, FaninId) ) ){
3840 //printf("***********************\n");
3841 //printInfoLutValues( p, ObjId, netValid, lutValues1s, networkValues1s, networkValuesNotSet);
3842 status = computeNetworkValues(p, pPars, FaninId, &values2propagate, valuesFanin1s, networkValues1s, networkValuesNotSet, modifiedLuts, vLutsFaninCones, vNodesWatchlist , experimentID);
3843 if(status == -1){
3844 networkValues1s[FaninId] = prevNetValue;
3845 networkValuesNotSet[FaninId] = prevNetValueNotSet;
3846 Vec_PtrFree( vSops );
3847 return -1;
3848 }
3849 assert( tmp_values2propagate >= values2propagate );
3850 difference_valid = tmp_values2propagate ^ values2propagate;
3851 if( difference_valid ){
3852 // some values are not valid
3853 networkValuesNotSet[FaninId] &= ~difference_valid;
3854 *netValid &= ~difference_valid;
3855 }
3856 }
3857 }
3858
3859 Vec_PtrFree( vSops );
3860
3861 return 1;
3862}
3863
3864
3876
3877void saveInputVectors( Gia_Man_t * p, Cec4_Man_t * pMan, char * pValues){
3878
3879 int i, Id, w;
3880 Gia_ManForEachCiId( p, Id, i ){
3881 word * pSim = Cec4_ObjSim( p, Id );
3882 for ( w = 0; w < p->nSimWords; w++ )
3883 pSim[w] = (word)pValues[ Id ];
3884 pSim[0] <<= 1;
3885 }
3886}
3887
3899
3901{
3902 FILE * pFile;
3903 pFile = fopen( filename, "wb" );
3904 Gia_Obj_t * pObj; int i, j;
3905 Gia_ManForEachObj( p, pObj, i )
3906 {
3907 word * pSim = Cec4_ObjSim( p, i );
3908 fprintf( pFile, "Obj %d ", i );
3909 for(j = 0; j < p->nSimWords; j++){
3910 fprintf( pFile, "[%d]: %lu ", j, pSim[j] );
3911 }
3912 fprintf(pFile, "\n");
3913 }
3914 fclose( pFile );
3915}
3916
3928
3929int computeInputVectors(Gia_Man_t * p, Cec4_Man_t * pMan, Cec_ParSimGen_t * pPars , Vec_Int_t * vLuts , char * outGold, int outGold_bitwidth , Vec_Int_t * vLutsFaninCones , Vec_Ptr_t * vNodesWatchlist , Vec_Ptr_t * vSimSave ,int experimentID){
3930
3931 char * networkValues1s, * networkValuesNotSet; // data structure containing the values inside the network
3932 char networkValid = (char) (1 << outGold_bitwidth) - 1; // keeps track which array out of the 8 is valid
3933 int jLut, mainLoop_condition, iii, numLuts;
3934
3935 numLuts = Vec_IntSize(vLuts);
3936 assert(numLuts > 0);
3937
3938 networkValues1s = (char *) malloc( Gia_ManObjNum(p));
3939 memset(networkValues1s, 0, sizeof(char) * Gia_ManObjNum(p));
3940 networkValuesNotSet = (char *) malloc( Gia_ManObjNum(p));
3941 memset(networkValuesNotSet, 0xFF, sizeof(char) * Gia_ManObjNum(p));
3942 mainLoop_condition = numLuts > 0;
3943 iii = 0;
3944 int success = 0, lastjGold = -1;
3945 while ( mainLoop_condition ){
3946 jLut = Vec_IntEntry(vLuts, iii);
3947 char jLutGold = outGold[jLut];
3948
3949 // TODO: Dynamic outgold
3950
3951 // check if the value of the lut has been set already or not
3952 char lutValueNotSet = networkValuesNotSet[jLut];
3953 char lutValues1s = networkValues1s[jLut];
3954 if( lutValueNotSet & networkValid){
3955
3956 char netValid = networkValid & lutValueNotSet;
3957 char * networkValues1sCopy = (char *) malloc( Gia_ManObjNum(p));
3958 memcpy(networkValues1sCopy, networkValues1s, sizeof(char) * Gia_ManObjNum(p));
3959 char * networkValuesNotSetCopy = (char *) malloc( Gia_ManObjNum(p));
3960 memcpy(networkValuesNotSetCopy, networkValuesNotSet, sizeof(char) * Gia_ManObjNum(p));
3961 Vec_Int_t * modifiedLuts = Vec_IntAlloc( Gia_ManLutNum(p) );
3962 // add the first lut to the modified luts
3963 Vec_IntPush(modifiedLuts, jLut);
3964 networkValues1sCopy[jLut] |= jLutGold & netValid;
3965 networkValuesNotSetCopy[jLut] &= ~netValid;
3966 // traverse the graph to retrieve values in the middle of the network
3967 int status = computeNetworkValues(p, pPars, jLut , &netValid, jLutGold, networkValues1sCopy, networkValuesNotSetCopy, modifiedLuts, vLutsFaninCones, vNodesWatchlist , experimentID);
3968 if( status == -1 ){
3969 Vec_IntFree(modifiedLuts);
3970 free(networkValues1sCopy);
3971 free(networkValuesNotSetCopy);
3972 goto exit_cond;
3973 }
3974
3975 char orig_netValid = networkValid & lutValueNotSet;
3976 char difference_valid = orig_netValid ^ netValid;
3977 if( difference_valid == orig_netValid){
3978 if(pPars->fVeryVerbose)
3979 printf("FAILED 0 out of %d - node %d (gold = %d valid = %d)\n", outGold_bitwidth, jLut, jLutGold, netValid);
3980 } else if( difference_valid != 0){
3981 int jjj = 0, iLut;
3982 Vec_IntForEachEntry( modifiedLuts, iLut, jjj ){
3983 networkValues1sCopy[jLut] = networkValues1s[iLut];
3984 networkValuesNotSetCopy[jLut] = networkValuesNotSet[iLut];
3985 }
3986 memcpy(networkValues1s, networkValues1sCopy, sizeof(char) * Gia_ManObjNum(p));
3987 memcpy(networkValuesNotSet, networkValuesNotSetCopy, sizeof(char) * Gia_ManObjNum(p));
3988
3989 int different = 0;
3990 while (difference_valid != 0) {
3991 if (difference_valid & 1) {
3992 different++;
3993 }
3994 difference_valid >>= 1;
3995 }
3996 if( outGold_bitwidth - different >= 2){ // at least 2 bits should be respected
3997 if(lastjGold != jLutGold){
3998 success += 1;
3999 lastjGold = jLutGold;
4000 }
4001 }
4002 if(pPars->fVeryVerbose)
4003 printf("SUCCESSFUL %d out of %d - node %d (gold = %d valid = %d)\n", outGold_bitwidth - different, outGold_bitwidth, jLut, jLutGold, netValid);
4004 } else {
4005 if(lastjGold != jLutGold){
4006 success += 1;
4007 lastjGold = jLutGold;
4008 }
4009 memcpy(networkValues1s, networkValues1sCopy, sizeof(char) * Gia_ManObjNum(p));
4010 memcpy(networkValuesNotSet, networkValuesNotSetCopy, sizeof(char) * Gia_ManObjNum(p));
4011 if(pPars->fVeryVerbose)
4012 printf("SUCCESSFUL %d out of %d - node %d (gold = %d valid = %d)\n", outGold_bitwidth, outGold_bitwidth, jLut, jLutGold, netValid);
4013 }
4014
4015
4016 free(networkValues1sCopy);
4017 free(networkValuesNotSetCopy);
4018 Vec_IntFree(modifiedLuts);
4019
4020
4021 } else { // all the different values that are still valid have been set
4022 char luts_values = lutValues1s & networkValid;
4023 char out_gold_values = jLutGold & networkValid;
4024 char validAssignments = ~( luts_values ^ out_gold_values ) & networkValid;
4025 char numOnes = 0;
4026 if (validAssignments != 0){
4027 while (validAssignments != 0) {
4028 if (validAssignments & 1) {
4029 numOnes++;
4030 }
4031 validAssignments >>= 1;
4032 }
4033 }
4034 validAssignments = ~( luts_values ^ out_gold_values ) & networkValid;
4035 if(pPars->fVeryVerbose)
4036 printf("(1) SUCCESSFUL %d out of %d - node %d (gold = %d valid = %d)\n", numOnes, outGold_bitwidth, jLut, jLutGold, validAssignments);
4037 }
4038
4039 iii++;
4040 mainLoop_condition = (iii < numLuts);
4041 }
4042
4043 if(success >= 2){
4044 saveInputVectors(p, pMan, networkValues1s);
4045 Cec4_ManSimulate( p, pMan );
4046 // saving the pi simulation values in a compacted format
4047 int jth_word = p->iData & 0xFFFF;
4048 int kth_bit = (p->iData & 0xFFFF0000) >> 16;
4049 if( kth_bit + outGold_bitwidth >= 64 ){
4050 kth_bit = 0;
4051 jth_word += 1;
4052 }
4053 saveSimVectors(p, vSimSave, outGold_bitwidth, jth_word, kth_bit);
4054 kth_bit += outGold_bitwidth;
4055 p->iData = (kth_bit << 16) | jth_word;
4056 if( pPars->fVerbose || pPars->fVeryVerbose){
4057 printf("**Exporting simulation values in file sim_values.txt\n");
4058 exportSimValues( p, "sim_values.txt" );
4059 }
4060 }
4061
4062
4063exit_cond:
4064 free(networkValues1s);
4065 free(networkValuesNotSet);
4066
4067 if(success < 2){
4068 return -1;
4069 } else {
4070 return 1;
4071 }
4072
4073}
4074
4075
4086
4087
4088void executeControlledSim(Gia_Man_t * p, Cec4_Man_t * pMan, Cec_ParSimGen_t * pPars , int levelOrder, Vec_Ptr_t * vSimSave, int experimentID){
4089
4090 char * outGold;
4091 //int outGold_bitwidth = pPars->bitwidthOutgold;
4092 int numClasses = totalNumClasses(p);
4093 int iTrials = 0, outer_loop_condition = iTrials < (numClasses * 1.5);
4094 int nthClass = 0, status, oldNumClasses = numClasses, iter;
4095 Vec_Int_t * luts_order, * vecTmp;
4096 Vec_Int_t * vLutsFaninCones;
4097 clock_t start_time = clock();
4098 outGold = generateOutGoldValues(p); // generate the first outgold values
4099 pPars->outGold = outGold;
4100 Vec_Ptr_t * vNodesWatchList = NULL;
4101 if(pPars->fUseWatchlist){
4102 printf("**Activating watchlist feauture\n");
4103 }
4104 while( existsOneClass(p) && outer_loop_condition ){
4105 luts_order = extractNthClass(p, nthClass);
4106 if( levelOrder != -1 ){
4107 // test different luts orders on which to apply simgen
4108 luts_order = computeLutsOrder(p, 1); // incresing level order // TODO: redo taking luts_order as input
4109 }
4110 // compute the fanin cones of the luts to apply implication only in the cone
4111 vLutsFaninCones = computeFaninCones( p, luts_order );
4112 if(pPars->fUseWatchlist){
4113 vNodesWatchList = generateWatchList(p);
4114 }
4115 status = computeInputVectors(p, pMan, pPars, luts_order, outGold, pPars->bitwidthOutgold, vLutsFaninCones, vNodesWatchList, vSimSave, experimentID);
4116 if( status == -1 ){
4117 if(pPars->fVerbose || pPars->fVeryVerbose)
4118 printf("FAILED - no valid input vectors found for class %d\n", nthClass);
4119 nthClass++;
4120 } else {
4121 numClasses = totalNumClasses(p);
4122 if (oldNumClasses == numClasses){
4123 nthClass++;
4124 }
4125 oldNumClasses = numClasses;
4126 free(outGold);
4127 outGold = generateOutGoldValues(p); // generate a new outgold since the classes are updated
4128 pPars->outGold = outGold;
4129 if(pPars->fVerbose || pPars->fVeryVerbose)
4130 printf("SUCCESSFUL - input vectors found for class %d\n", nthClass);
4131 //nthClass = 0;
4132 }
4133
4134 Vec_IntFree(vLutsFaninCones);
4135 Vec_IntFree(luts_order);
4136 if(pPars->fUseWatchlist){
4137 Vec_PtrForEachEntry( Vec_Int_t *, vNodesWatchList, vecTmp, iter ){
4138 if (vecTmp != NULL)
4139 Vec_IntFree(vecTmp);
4140 }
4141 Vec_PtrFree(vNodesWatchList);
4142 }
4143 if(nthClass >= numClasses){
4144 nthClass = 0;
4145 if (oldNumClasses == numClasses){
4146 iTrials++;
4147 }
4148 oldNumClasses = numClasses;
4149 iTrials++;
4150 }
4151 outer_loop_condition = iTrials < 3;
4152 clock_t end_time = clock();
4153 if ( (float)(end_time - start_time)/CLOCKS_PER_SEC > pPars->timeOutSim){ // hard limit of 1000 sec
4154 printf("Timeout of %f sec reached\n", pPars->timeOutSim);
4155 break;
4156 }
4157 if(pPars->fVerbose || pPars->fVeryVerbose){
4158 int quality = evaluate_equiv_classes(p, 0);
4159 printf("Time elapsed: %f (classes quality: %d)\n", (float)(clock() - start_time)/CLOCKS_PER_SEC, quality);
4160 }
4161 }
4162
4163 //drawNetworkGia( p, "network.dot");
4164 //drawConeNetworkGia( p, "cone_network.dot", 31);
4165
4166 free(outGold);
4167
4168}
4169
4181
4183
4184 extern Gia_Obj_t * Cec4_ManFindRepr( Gia_Man_t * p, Cec4_Man_t * pMan, int iObj );
4185 int i;
4186 Gia_Obj_t * pObj, * pRepr;
4187 p->iPatsPi = 0;
4188 Vec_WrdFill( p->vSimsPi, Vec_WrdSize(p->vSimsPi), 0 );
4189 pMan->nSatSat = 0;
4190 pMan->pNew = Cec4_ManStartNew( p );
4191 Gia_ManForEachAnd( p, pObj, i )
4192 {
4193 Gia_Obj_t * pObjNew;
4194 pMan->nAndNodes++;
4195 if ( Gia_ObjIsXor(pObj) )
4196 pObj->Value = Gia_ManHashXorReal( pMan->pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
4197 else
4198 pObj->Value = Gia_ManHashAnd( pMan->pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
4199 if ( pPars->nLevelMax && Gia_ObjLevel(p, pObj) > pPars->nLevelMax )
4200 continue;
4201 pObjNew = Gia_ManObj( pMan->pNew, Abc_Lit2Var(pObj->Value) );
4202 if ( Gia_ObjIsAnd(pObjNew) )
4203 if ( Vec_BitEntry(pMan->vFails, Gia_ObjFaninId0(pObjNew, Abc_Lit2Var(pObj->Value))) ||
4204 Vec_BitEntry(pMan->vFails, Gia_ObjFaninId1(pObjNew, Abc_Lit2Var(pObj->Value))) )
4205 Vec_BitWriteEntry( pMan->vFails, Abc_Lit2Var(pObjNew->Value), 1 );
4206 //if ( Gia_ObjIsAnd(pObjNew) )
4207 // Gia_ObjSetAndLevel( pMan->pNew, pObjNew );
4208 // select representative based on candidate equivalence classes
4209 pRepr= Gia_ObjReprObj( p, i );
4210 if ( pRepr == NULL )
4211 continue;
4212 if ( 1 ) // select representative based on recent counter-examples
4213 {
4214 pRepr = (Gia_Obj_t *) Cec4_ManFindRepr( p, pMan, i );
4215 if ( pRepr == NULL )
4216 continue;
4217 }
4218 int id_obj = Gia_ObjId( p, pObj );
4219 int id_repr = Gia_ObjId( p, pRepr );
4220
4221 if ( Abc_Lit2Var(pObj->Value) == Abc_Lit2Var(pRepr->Value))
4222 {
4223 if ( pPars->fBMiterInfo )
4224 {
4225 Bnd_ManMerge( id_repr, id_obj, pObj->fPhase ^ pRepr->fPhase );
4226 }
4227 if((pObj->Value ^ pRepr->Value) != (pObj->fPhase ^ pRepr->fPhase)){
4228 pObj->Value = Abc_LitNotCond( pRepr->Value, pObj->fPhase ^ pRepr->fPhase );
4229 }
4230 assert( (pObj->Value ^ pRepr->Value) == (pObj->fPhase ^ pRepr->fPhase) );
4231 Gia_ObjSetProved( p, i );
4232 if ( Gia_ObjId(p, pRepr) == 0 )
4233 pMan->iLastConst = i;
4234 continue;
4235 }
4236 if ( Cec4_ManSweepNode(pMan, i, Gia_ObjId(p, pRepr)) && Gia_ObjProved(p, i) )
4237 {
4238 if (pPars->fBMiterInfo){
4239
4240 Bnd_ManMerge( id_repr, id_obj, pObj->fPhase ^ pRepr->fPhase );
4241 // printf( "proven %d merged into %d (phase : %d)\n", Gia_ObjId(p, pObj), Gia_ObjId(p,pRepr), pObj->fPhase ^ pRepr -> fPhase );
4242
4243 }
4244 pObj->Value = Abc_LitNotCond( pRepr->Value, pObj->fPhase ^ pRepr->fPhase );
4245
4246
4247 }
4248 }
4249
4250 printf( "SAT calls = %d: P = %d (0=%d a=%.2f m=%d) D = %d (0=%d a=%.2f m=%d) F = %d Sim = %d Recyc = %d Xor = %.2f %%\n",
4251 pMan->nSatUnsat + pMan->nSatSat + pMan->nSatUndec,
4252 pMan->nSatUnsat, pMan->nConflicts[1][0], (float)pMan->nConflicts[1][1]/Abc_MaxInt(1, pMan->nSatUnsat-pMan->nConflicts[1][0]), pMan->nConflicts[1][2],
4253 pMan->nSatSat, pMan->nConflicts[0][0], (float)pMan->nConflicts[0][1]/Abc_MaxInt(1, pMan->nSatSat -pMan->nConflicts[0][0]), pMan->nConflicts[0][2],
4254 pMan->nSatUndec,
4255 pMan->nSimulates, pMan->nRecycles, 100.0*pMan->nGates[1]/Abc_MaxInt(1, pMan->nGates[0]+pMan->nGates[1]) );
4256
4257}
4258
4270
4271void printEncodedCube( char pCube, char pDCs, int nFanins ){
4272
4273 int i;
4274 for (i = 0; i < nFanins; i++){
4275 if ( pCube & (1 << i) )
4276 printf("1");
4277 else if ( pDCs & (1 << i) )
4278 printf("-");
4279 else
4280 printf("0");
4281 }
4282 printf("\n");
4283
4284}
4285
4297
4298void printISOP( char * pSop, int nCubes, int nFanins ){
4299
4300 int jth_cube = 0;
4301 while (jth_cube < nCubes){
4302 char pCube = *pSop; pSop++;
4303 char pDCs = *pSop; pSop++;
4304 printEncodedCube( pCube, pDCs, nFanins );
4305 jth_cube++;
4306 }
4307
4308}
4309
4321
4322void printISOPLUT(Gia_Man_t * pMan, int ObjId){
4323
4324 assert( Gia_ObjIsLut(pMan, ObjId));
4325 char * pSop[2]; int nCubes[2];
4326 getISOPObjId( pMan, ObjId, pSop, nCubes );
4327 printf("Negative Polarity\n");
4328 printISOP( pSop[0], nCubes[0], Gia_ObjLutSize(pMan, ObjId) );
4329 printf("Positive Polarity\n");
4330 printISOP( pSop[1], nCubes[1], Gia_ObjLutSize(pMan, ObjId) );
4331
4332}
4333
4344
4346
4347 extern void Gia_ManDupMapping( Gia_Man_t * pNew, Gia_Man_t * p );
4348 Cec4_Man_t * pManSim;
4349 int i, k, nWordsPerCi;
4350 Gia_Man_t * pMapped;
4351 Vec_Ptr_t * vSimPisSave;
4352 Cec_ParFra_t * pCECPars;
4353
4354 if (!Gia_ManHasMapping(p)){
4355 // apply technology mapping if not already done
4356 If_Par_t IfPars, * pIfPars = &IfPars;
4357 Gia_ManSetIfParsDefault( pIfPars );
4358 pIfPars->nLutSize = 6;
4359 pMapped = Gia_ManPerformMapping( p, pIfPars );
4360 if(pPars->fVerbose)
4361 printf("Performing LUT-mapping\n");
4362 } else {
4363 pMapped = Gia_ManDup( p );
4364 Gia_ManDupMapping( pMapped, p );
4365 if(pPars->fVerbose)
4366 printf("Using already mapped network\n");
4367 }
4368 pCECPars = (Cec_ParFra_t *) malloc(sizeof( Cec_ParFra_t )); // parameters of CEC
4369 pManSim = Cec4_ManCreate( pMapped, pCECPars );
4370 pManSim->pPars->fVerbose = 0; // disabling verbose sat solver
4371
4372 Cec_DeriveSOPs( pMapped );
4373
4374 /*
4375 if (pPars->fVeryVerbose)
4376 {
4377 printf("**Printing LUTs information**\n");
4378 Gia_ManForEachLut( pMapped, i ){
4379 printf("LUT %d\n", i);
4380 Gia_LutForEachFanin( pMapped, i, iFan, k ){
4381 printf("\tFANIN %d\n", iFan);
4382 }
4383 printISOPLUT( pMapped, i );
4384 }
4385 }
4386 */
4387
4388 // compute MFFCs
4389 Gia_ManLevelNum( pMapped); // compute levels
4390 computeMFFCs( pMapped );
4391 if (pPars->fUseWatchlist) {
4392 generateLutsRankings( pMapped );
4393 }
4394
4395
4396 // generate vectors of fanouts
4397 Gia_generateFanoutMapping( pMapped );
4398
4399 pMapped->nSimWords = (int) pPars->nSimWords ;
4400 vSimPisSave = Vec_PtrAlloc( Gia_ManCiNum(pMapped) );
4401 for ( i = 0; i < Gia_ManCiNum(pMapped); i++ ){
4402 Vec_Wrd_t * vSim = Vec_WrdAlloc( pMapped->nSimWords );
4403 Vec_PtrPush( vSimPisSave, vSim );
4404 }
4405 // simulate n rounds of random simulation and create classes
4406 Cec4_ManSimAlloc( pMapped, pMapped->nSimWords );
4407 if(pPars->nMaxIter >= 0){
4408 executeRandomSim( pMapped, pManSim, 0, pPars->nMaxIter, vSimPisSave, pPars->fVeryVerbose);
4409 } else if (pPars->nMaxIter == -1){
4410 executeRandomSim( pMapped, pManSim, 1, pPars->nMaxIter, vSimPisSave, pPars->fVeryVerbose);
4411 } else {
4412 printf("Invalid number of iterations %d\n", pPars->nMaxIter);
4413 return NULL;
4414 }
4415
4416 // extra data to compact multiple pi values in single words
4417 pMapped->iData = ((Vec_Wrd_t *)Vec_PtrEntry( vSimPisSave, 0 ))->nSize; // [0:15] number of words filled
4418 // [16:31] number of bits filled in the iData word
4419 assert(pMapped->iData > 0);
4420
4421 Cec_RemoveNonLutNodes( pMapped ); // remove all the non-LUT nodes from the equivalence classes
4422
4423 if(pPars->fVerbose || pPars->fVeryVerbose){
4424 // IMPORTANT: the number of classes changes due to the previous operation
4425 evaluate_equiv_classes(pMapped, 1);
4426 printf("**Printing Class information before running the Sim algos in file pre_classes.txt**\n");
4427 exportEquivClasses(pMapped, "pre_classes.txt");
4428 }
4429 //Cec4_ManPrintClasses2(pMapped);
4430 clock_t begin = clock();
4431 assert(pPars->expId > 0);
4432 executeControlledSim( pMapped, pManSim, pPars, -1 , vSimPisSave, pPars->expId );
4433
4434 float implicationSuccessRate = (float)pPars->nImplicationSuccess / (float)pPars->nImplicationExecution;
4435 float implicationSuccessCheckRate = (float)pPars->nImplicationSuccessChecks / (float)pPars->nImplicationTotalChecks;
4436 printf("Time elapsed: %f (implication time %f - %f successful recursions - %f successful checks)\n", (double)(clock() - begin) / CLOCKS_PER_SEC, pPars->fImplicationTime, implicationSuccessRate, implicationSuccessCheckRate);
4437
4438 //Cec4_ManPrintClasses2(pMapped);
4439 if(pPars->fVerbose || pPars->fVeryVerbose){
4440 printf("**Printing Class information before running the Sim algos in file post_classes.txt**\n");
4441 exportEquivClasses(pMapped, "post_classes.txt");
4442 evaluate_equiv_classes(pMapped, 1);
4443 }
4444
4445 // save random and controlled sim pis values
4446 if(p->vSimsPi != NULL){
4447 Vec_WrdFree( p->vSimsPi );
4448 }
4449 nWordsPerCi = ((Vec_Wrd_t *)Vec_PtrEntry( vSimPisSave, 0 ))->nSize;
4450 assert( nWordsPerCi > 0 );
4451 p->vSimsPi = Vec_WrdStart( Gia_ManCiNum(p) * nWordsPerCi );
4452
4453 // copy the sim pis
4454 assert( Gia_ManCiNum(p) == Vec_PtrSize(vSimPisSave) );
4455 for (i = 0; i < Gia_ManCiNum(p); i++){
4456 Vec_Wrd_t * vSim = (Vec_Wrd_t *)Vec_PtrEntry( vSimPisSave, i );
4457 assert( vSim->nSize == nWordsPerCi );
4458 word * pSim = Vec_WrdEntryP( p->vSimsPi, i * nWordsPerCi );
4459 for ( k = 0; k < nWordsPerCi; k++ )
4460 pSim[k] = Vec_WrdEntry( vSim, k );
4461 }
4462 p->nSimWords = nWordsPerCi;
4463
4464 if (pPars->pFileName != NULL){
4465 Vec_WrdDumpHex( pPars->pFileName, p->vSimsPi, nWordsPerCi , 1 );
4466 }
4467
4468 // free memory
4469 Vec_IntFree( pMapped->vTTLut );
4470 Vec_StrFree( pMapped->vTTISOPs );
4471 Cec4_ManDestroy( pManSim );
4472 Gia_ManStop( pMapped );
4473
4474 return p;
4475}
4476
4480
4481
4483
#define GLUCOSE_UNDEC
Definition AbcGlucose.h:36
#define GLUCOSE_UNSAT
INCLUDES ///.
Definition AbcGlucose.h:34
#define GLUCOSE_SAT
Definition AbcGlucose.h:35
Hop_Obj_t * Abc_ObjHopFromGia(Hop_Man_t *pHopMan, Gia_Man_t *p, int GiaId, Vec_Ptr_t *vCopies)
Definition abcDar.c:721
int nWords
Definition abcNpn.c:127
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL int Abc_NtkAigToBdd(Abc_Ntk_t *pNtk)
Definition abcFunc.c:869
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_AIG
Definition abc.h:67
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
word Abc_RandomW(int fReset)
Definition utilSort.c:1022
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_FALLOC(type, num)
Definition abc_global.h:266
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
unsigned Abc_Random(int fReset)
Definition utilSort.c:1004
#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
abctime timeSat
Definition abcDar.c:3942
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 Cec4_ObjGetCnfVar(Cec4_Man_t *p, int iObj)
Definition cecSatG2.c:574
int Cec4_ManCandIterNext(Cec4_Man_t *p)
Definition cecSatG2.c:1453
#define sat_solver_addclause
Definition cecSatG2.c:37
void Cec4_ManPrintStats(Gia_Man_t *p, Cec_ParFra_t *pPars, Cec4_Man_t *pMan, int fSim)
Definition cecSatG2.c:1054
void getISOPObjId(Gia_Man_t *pMan, int ObjId, char *pSop[2], int nCubes[2])
Definition cecSatG2.c:2251
int Cec4_ManSimulateCos(Gia_Man_t *p)
Definition cecSatG2.c:952
void Cec4_CallSATsolver(Gia_Man_t *p, Cec4_Man_t *pMan, Cec_ParFra_t *pPars)
Definition cecSatG2.c:4182
void Cec4_RefineInit(Gia_Man_t *p, Cec4_Man_t *pMan)
Definition cecSatG2.c:811
Vec_Int_t * Cec4_ManComputeMapping(Gia_Man_t *p, Gia_Man_t *pAig, int fVerbose)
Definition cecSatG2.c:2159
int selectSop(Vec_Int_t *vQualitySops, int ith_max_quality, int experimentID)
Definition cecSatG2.c:3357
void saveSimVectors(Gia_Man_t *p, Vec_Ptr_t *pValues, int bitLength, int jth_word, int kth_bit)
Definition cecSatG2.c:2943
#define sat_solver_start
Definition cecSatG2.c:35
void Cec4_RefineOneClassIter(Gia_Man_t *p, int iRepr)
Definition cecSatG2.c:719
void Cec4_ManSimulateTest2(Gia_Man_t *p, int nConfs, int fVerbose)
Definition cecSatG2.c:2066
int Cec4_ManSimulateOnlyTest(Gia_Man_t *p, int fVerbose)
Definition cecSatG2.c:2098
void Cec4_ManCexVerify(Gia_Man_t *p, int iObj0, int iObj1, int fPhase)
Definition cecSatG2.c:1176
void executeControlledSim(Gia_Man_t *p, Cec4_Man_t *pMan, Cec_ParSimGen_t *pPars, int levelOrder, Vec_Ptr_t *vSimSave, int experimentID)
Definition cecSatG2.c:4088
int Cec4_ManPackAddPattern(Gia_Man_t *p, Vec_Int_t *vLits, int fExtend)
Definition cecSatG2.c:1239
int compute_quality_sop(Gia_Man_t *p, char *pSop, int ObjId, int nFanins, int experimentID)
Definition cecSatG2.c:3276
#define sat_solver_read_cex
Definition cecSatG2.c:47
int * sortArray(int *array, int n)
Definition cecSatG2.c:2699
int Cec4_ManSweepNode(Cec4_Man_t *p, int iObj, int iRepr)
Definition cecSatG2.c:1645
#define sat_solver_addvar
Definition cecSatG2.c:40
int Cec4_ManGeneratePatterns(Cec4_Man_t *p)
Definition cecSatG2.c:1471
void Cec4_ManPrintClasses(Gia_Man_t *p)
Definition cecSatG2.c:1102
#define sat_solver_set_conflict_budget
Definition cecSatG2.c:43
Gia_Man_t * Cec4_ManSimulateTest(Gia_Man_t *p, Cec_ParFra_t *pPars)
Definition cecSatG2.c:2059
int computeNetworkValues(Gia_Man_t *p, Cec_ParSimGen_t *pPars, int ObjId, char *netValid, char lutValues1s, char *networkValues1s, char *networkValuesNotSet, Vec_Int_t *modifiedLuts, Vec_Int_t *vLutsFaninCones, Vec_Ptr_t *vNodesWatchlist, int experimentID)
Definition cecSatG2.c:3684
Gia_Man_t * Cec4_ManSimulateTest4(Gia_Man_t *p, int nBTLimit, int nBTLimitPo, int fVerbose)
Definition cecSatG2.c:2087
void Cec_DeriveSOPs(Gia_Man_t *p)
Definition cecSatG2.c:2480
void Cec4_ManSatSolverRecycle(Cec4_Man_t *p)
Definition cecSatG2.c:1532
typedefABC_NAMESPACE_IMPL_START struct Cec4_Man_t_ Cec4_Man_t
DECLARATIONS ///.
Definition cecSatG2.c:88
Vec_Str_t * encodeSOP(char *pSop, int nFanins, int nCubes)
Definition cecSatG2.c:2282
#define sat_solver_mark_cone
Definition cecSatG2.c:52
int totalNumClasses(Gia_Man_t *p)
Definition cecSatG2.c:2922
void Cec4_ManDestroy(Cec4_Man_t *p)
Definition cecSatG2.c:301
Vec_Ptr_t * generateWatchList(Gia_Man_t *p)
Definition cecSatG2.c:2775
Gia_Obj_t * Cec4_ManFindRepr(Gia_Man_t *p, Cec4_Man_t *pMan, int iObj)
Definition cecSatG2.c:1749
Vec_Int_t * extractNthClass(Gia_Man_t *p, int nth_class)
Definition cecSatG2.c:3118
void Cec4_ManSimulate_rec(Gia_Man_t *p, Cec4_Man_t *pMan, int iObj)
Definition cecSatG2.c:992
#define sat_solver_start_new_round
Definition cecSatG2.c:51
void Cec4_ManSimulateCis(Gia_Man_t *p)
Definition cecSatG2.c:925
int Cec4_ManVerify_rec(Gia_Man_t *p, int iObj, sat_solver *pSat)
Definition cecSatG2.c:1122
char * extractSOP(DdManager *dd, DdNode *bFunc, int nFanins, int polarity, int *_nCubes)
Definition cecSatG2.c:2325
#define sat_solver_reset
Definition cecSatG2.c:42
Vec_Wrd_t * Cec4_EvalCombine(Vec_Int_t *vPats, int nPats, int nInputs, int nWords)
FUNCTION DEFINITIONS ///.
Definition cecSatG2.c:164
void Cec4_CollectSuper(Gia_Obj_t *pObj, int fUseMuxes, Vec_Ptr_t *vSuper)
Definition cecSatG2.c:556
int checkCompatibilityImplication(Gia_Man_t *p, Cec_ParSimGen_t *pPars, char *netValid, int objId, char *networkValues1s, char *networkValuesNotSet, Vec_Int_t *vLuts2Imply, Vec_Int_t *vLutsValidity, int experimentID)
Definition cecSatG2.c:3489
void Cec4_ManPackAddPatterns(Gia_Man_t *p, int iBit, Vec_Int_t *vLits)
Definition cecSatG2.c:1199
void computeISOPs(Gia_Man_t *p, Abc_Ntk_t *pNtkNew)
Definition cecSatG2.c:2379
int Cec4_ManSolveTwo(Cec4_Man_t *p, int iObj0, int iObj1, int fPhase, int *pfEasy, int fVerbose, int fEffort)
Definition cecSatG2.c:1547
int computeInputVectors(Gia_Man_t *p, Cec4_Man_t *pMan, Cec_ParSimGen_t *pPars, Vec_Int_t *vLuts, char *outGold, int outGold_bitwidth, Vec_Int_t *vLutsFaninCones, Vec_Ptr_t *vNodesWatchlist, Vec_Ptr_t *vSimSave, int experimentID)
Definition cecSatG2.c:3929
void Cec4_ManVerifyEquivs(Gia_Man_t *p, Vec_Int_t *vRes, int fVerbose)
Definition cecSatG2.c:2191
void printISOPLUT(Gia_Man_t *pMan, int ObjId)
Definition cecSatG2.c:4322
void saveInputVectors(Gia_Man_t *p, Cec4_Man_t *pMan, char *pValues)
Definition cecSatG2.c:3877
Cec4_Man_t * Cec4_ManCreate(Gia_Man_t *pAig, Cec_ParFra_t *pPars)
Definition cecSatG2.c:269
void Cec4_AddClausesSuper(Gia_Man_t *p, Gia_Obj_t *pNode, Vec_Ptr_t *vSuper, sat_solver *pSat)
Definition cecSatG2.c:488
void Cec4_ManPrintClasses2(Gia_Man_t *p)
Definition cecSatG2.c:1091
void executeRandomSim(Gia_Man_t *p, Cec4_Man_t *pMan, int dynSim, int nMaxIter, Vec_Ptr_t *vSimSave, int verbose)
Definition cecSatG2.c:2974
void Cec4_ManPrintTfiConeStats(Gia_Man_t *p)
Definition cecSatG2.c:1030
int existsOneClass(Gia_Man_t *p)
Definition cecSatG2.c:3098
void Cec4_RefineOneClass(Gia_Man_t *p, Cec4_Man_t *pMan, Vec_Int_t *vNodes)
Definition cecSatG2.c:756
int Cec4_ManCexVerify_rec(Gia_Man_t *p, int iObj)
Definition cecSatG2.c:1161
void Cec4_ManSimAlloc(Gia_Man_t *p, int nWords)
Definition cecSatG2.c:1009
void Cec4_ManSimulateTest5(Gia_Man_t *p, int nConfs, int fVerbose)
Definition cecSatG2.c:2226
void Cec4_ManSimulateTest5Int(Gia_Man_t *p, int nConfs, int fVerbose)
Definition cecSatG2.c:2117
#define sat_solver_set_var_fanin_lit
Definition cecSatG2.c:50
#define sat_solver_read_cex_varvalue
Definition cecSatG2.c:41
int extract_quality_mffc(Gia_Man_t *p, int ObjId, char pDCs)
Definition cecSatG2.c:2666
void Cec4_EvalPatterns(Gia_Man_t *p, Vec_Int_t *vPats, int nPats)
Definition cecSatG2.c:181
void printISOP(char *pSop, int nCubes, int nFanins)
Definition cecSatG2.c:4298
int checkCompatibilityCube(Gia_Man_t *pMan, char *pCube, int nFanins, char *pCubeGold)
Definition cecSatG2.c:3248
#define sat_solver_add_and
Definition cecSatG2.c:38
#define sat_solver_conflictnum
Definition cecSatG2.c:44
Abc_Cex_t * Cec4_ManDeriveCex(Gia_Man_t *p, int iOut, int iPat)
Definition cecSatG2.c:939
int rouletteWheel(Vec_Int_t *vQualitySops, int numValid)
Definition cecSatG2.c:3322
void printEncodedCube(char pCube, char pDCs, int nFanins)
Definition cecSatG2.c:4271
void Gia_ManRemoveWrongChoices(Gia_Man_t *p)
Definition cecSatG2.c:1783
int evaluate_equiv_classes(Gia_Man_t *p, int verbose)
Definition cecSatG2.c:2892
void exportSimValues(Gia_Man_t *p, char *filename)
Definition cecSatG2.c:3900
int computeLutsToImply(Gia_Man_t *p, Cec_ParSimGen_t *pPars, char *netValid, int ObjId, char *networkValues1s, char *networkValuesNotSet, Vec_Int_t *vLutsFaninCones, Vec_Int_t *vLuts2Imply, Vec_Int_t *vLutsValidity, Vec_Ptr_t *vNodesWatchlist, int experimentID)
Definition cecSatG2.c:3562
void computeMFFCs(Gia_Man_t *p)
Definition cecSatG2.c:2593
void Cec_RemoveNonLutNodes(Gia_Man_t *p)
Definition cecSatG2.c:2834
int check_implication(Gia_Man_t *p, int ObjId, int validBit, int fanoutValue, int fanoutNotSet, char *inputsFaninsValues, char *networkValues1s, char *networkValuesNotSet, int experimentID)
Definition cecSatG2.c:3389
void Cec4_ManClearCis(Gia_Man_t *p)
Definition cecSatG2.c:932
Gia_Man_t * Cec_SimGenRun(Gia_Man_t *p, Cec_ParSimGen_t *pPars)
Definition cecSatG2.c:4345
int evaluate_mffc(Gia_Man_t *p, int rootId, int fanId, Vec_Int_t *vLeaves)
Definition cecSatG2.c:2565
Gia_Man_t * Cec4_ManSimulateTest3(Gia_Man_t *p, int nBTLimit, int fVerbose)
Definition cecSatG2.c:2077
void exportEquivClasses(Gia_Man_t *p, char *filename)
Definition cecSatG2.c:3033
Vec_Int_t * computeLutsOrder(Gia_Man_t *p, int reorder_type)
Definition cecSatG2.c:3148
int Cec4_ManPerformSweeping(Gia_Man_t *p, Cec_ParFra_t *pPars, Gia_Man_t **ppNew, int fSimOnly)
Definition cecSatG2.c:1861
void Cec4_ManSetParams(Cec_ParFra_t *pPars)
Definition cecSatG2.c:212
#define sat_solver_add_xor
Definition cecSatG2.c:39
int Cec4_ManSimHashKey(word *pSim, int nSims, int nTableSize)
Definition cecSatG2.c:703
void Cec4_AddClausesMux(Gia_Man_t *p, Gia_Obj_t *pNode, sat_solver *pSat)
Definition cecSatG2.c:380
void Gia_generateFanoutMapping(Gia_Man_t *p)
Definition cecSatG2.c:2807
void Cec4_ManConvertToLits(Gia_Man_t *p, Vec_Int_t *vRes)
Definition cecSatG2.c:2218
void Cec_SimGenSetParDefault(Cec_ParSimGen_t *pPars)
Definition cecSatG2.c:239
Gia_Man_t * Gia_ManLocalRehash(Gia_Man_t *p)
Definition cecSatG2.c:2128
void generateLutsRankings(Gia_Man_t *p)
Definition cecSatG2.c:2721
#define sat_solver_stop
Definition cecSatG2.c:36
void Cec4_ManSimulate(Gia_Man_t *p, Cec4_Man_t *pMan)
Definition cecSatG2.c:966
#define sat_solver
Definition cecSatG2.c:34
Gia_Man_t * Cec4_ManStartNew(Gia_Man_t *pAig)
Definition cecSatG2.c:351
void Cec4_ManVerify(Gia_Man_t *p, int iObj0, int iObj1, int fPhase, sat_solver *pSat)
Definition cecSatG2.c:1137
void Cec4_CollectSuper_rec(Gia_Obj_t *pObj, Vec_Ptr_t *vSuper, int fFirst, int fUseMuxes)
Definition cecSatG2.c:542
#define sat_solver_solve
Definition cecSatG2.c:45
char * generateOutGoldValues(Gia_Man_t *p)
Definition cecSatG2.c:3066
Vec_Int_t * computeFaninCones(Gia_Man_t *p, Vec_Int_t *vLuts)
Definition cecSatG2.c:3224
void computeFaninCones_rec(Gia_Man_t *p, int ObjId, Vec_Int_t *vLutsFaninCones)
Definition cecSatG2.c:3212
void Cec4_RefineClasses(Gia_Man_t *p, Cec4_Man_t *pMan, Vec_Int_t *vClasses)
Definition cecSatG2.c:783
int Cec4_ManGeneratePatterns_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int Value, Vec_Int_t *vPat, Vec_Int_t *vVisit)
Definition cecSatG2.c:1307
void Cec4_ManSimulateDumpInfo(Cec4_Man_t *pMan)
Definition cecSatG2.c:1819
int Cec4_ManPackAddPatternTry(Gia_Man_t *p, int iBit, Vec_Int_t *vLits)
Definition cecSatG2.c:1217
void Cec4_ManCandIterStart(Cec4_Man_t *p)
Definition cecSatG2.c:1437
void Cec4_ObjAddToFrontier(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Ptr_t *vFrontier, sat_solver *pSat)
Definition cecSatG2.c:563
#define sat_solver_set_jftr
Definition cecSatG2.c:49
int Cec4_ManGeneratePatternOne(Gia_Man_t *p, int iRepr, int iReprVal, int iCand, int iCandVal, Vec_Int_t *vPat, Vec_Int_t *vVisit)
Definition cecSatG2.c:1421
int executeImplications(Gia_Man_t *p, Cec_ParSimGen_t *pPars, char *netValid, int ObjId, char *networkValues1s, char *networkValuesNotSet, Vec_Int_t *vLutsFaninCones, Vec_Ptr_t *vNodesWatchlist, int experimentID)
Definition cecSatG2.c:3638
struct Cec_ParFra_t_ Cec_ParFra_t
Definition cec.h:96
struct Cec_ParSimGen_t_ Cec_ParSimGen_t
Definition cec.h:205
char * filename
Definition globals.c:40
Cube * p
Definition exorList.c:222
int Extra_bddCountCubes(DdManager *dd, DdNode **pFuncs, int nFuncs, int fMode, int nLimit, int *pGuide)
char * Extra_UtilStrsav(const char *s)
void Extra_PrintHex2(FILE *pFile, unsigned *pTruth, int nVars)
char * Extra_FileNameGeneric(char *FileName)
Gia_Man_t * Gia_ManDupMiterCones(Gia_Man_t *p, Vec_Int_t *vPairs)
Definition giaDup.c:1627
void Gia_ManDupMapping(Gia_Man_t *pNew, Gia_Man_t *p)
Definition giaStoch.c:216
struct Gia_Rpr_t_ Gia_Rpr_t
Definition gia.h:57
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
Vec_Wrd_t * Gia_ManSimPatSimOut(Gia_Man_t *pGia, Vec_Wrd_t *vSimsPi, int fOuts)
Definition giaSimBase.c:138
int Gia_ObjCheckMffc(Gia_Man_t *p, Gia_Obj_t *pRoot, int Limit, Vec_Int_t *vNodes, Vec_Int_t *vLeaves, Vec_Int_t *vInners)
Definition giaResub.c:71
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition giaUtil.c:1056
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachCoId(p, Id, i)
Definition gia.h:1240
Gia_Man_t * Gia_ManPerformMapping(Gia_Man_t *p, void *pIfPars)
Definition giaIf.c:2598
#define Gia_ManForEachCand(p, pObj, i)
Definition gia.h:1220
void Gia_ManStopP(Gia_Man_t **p)
Definition giaMan.c:224
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
#define Gia_ManForEachCoDriverId(p, DriverId, i)
Definition gia.h:1246
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
#define Gia_ClassForEachObj1(p, i, iObj)
Definition gia.h:1109
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
#define Gia_ManForEachLut(p, i)
Definition gia.h:1157
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition gia.h:1161
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
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
#define Gia_ManForEachClass(p, i)
Definition gia.h:1101
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManSetIfParsDefault(void *pIfPars)
FUNCTION DEFINITIONS ///.
Definition giaIf.c:59
int Gia_ManLutNum(Gia_Man_t *p)
Definition giaIf.c:146
#define Gia_LutForEachFanout2(p, i, iFan, k)
Definition gia.h:1178
void Gia_ManCollectTfi(Gia_Man_t *p, Vec_Int_t *vRoots, Vec_Int_t *vNodes)
Definition giaDfs.c:581
int Gia_ObjRecognizeExor(Gia_Obj_t *pObj, Gia_Obj_t **ppFan0, Gia_Obj_t **ppFan1)
Definition giaUtil.c:1018
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
void Bnd_ManFinalizeMappings()
Definition giaBound.c:232
int Gia_ManHashXorReal(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:469
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
void Bnd_ManMerge(int id1, int id2, int phaseDiff)
Definition giaBound.c:193
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
#define Gia_ManForEachRiRo(p, pObjRi, pObjRo, i)
Definition gia.h:1256
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
#define GIA_VOID
Definition gia.h:46
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
void Gia_ManCleanMark01(Gia_Man_t *p)
Definition giaUtil.c:218
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
#define Gia_ManForEachClass0(p, i)
Definition gia.h:1103
#define Gia_ManForEachCiId(p, Id, i)
Definition gia.h:1230
void Gia_AigerWrite(Gia_Man_t *p, char *pFileName, int fWriteSymbols, int fCompact, int fWriteNewLine)
Definition giaAiger.c:1595
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
struct If_Par_t_ If_Par_t
Definition if.h:78
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
abctime timeOther
Definition llb3Image.c:82
ABC_NAMESPACE_IMPL_START long start_time
Definition sharp.c:19
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
char * pSpec
Definition abc.h:159
void * pData
Definition abc.h:145
int iTemp
Definition abc.h:149
unsigned fPersist
Definition abc.h:139
abctime timeResimLoc
Definition cecSatG2.c:141
abctime timeSim
Definition cecSatG2.c:138
Gia_Man_t * pNew
Definition cecSatG2.c:93
abctime timeSatSat
Definition cecSatG2.c:135
abctime timeRefine
Definition cecSatG2.c:139
int iPosWrite
Definition cecSatG2.c:109
Vec_Int_t * vRefClasses
Definition cecSatG2.c:112
int nFaster[2]
Definition cecSatG2.c:130
abctime timeStart
Definition cecSatG2.c:142
int nSatUndec
Definition cecSatG2.c:124
int nGates[2]
Definition cecSatG2.c:129
Vec_Int_t * vClassUpdates
Definition cecSatG2.c:99
Cec_ParFra_t * pPars
Definition cecSatG2.c:91
abctime timeResimGlo
Definition cecSatG2.c:140
int nTableSize
Definition cecSatG2.c:116
Vec_Int_t * vCexStamps
Definition cecSatG2.c:100
int * pTable
Definition cecSatG2.c:115
int nPatterns
Definition cecSatG2.c:121
int nSimulates
Definition cecSatG2.c:126
Vec_Int_t * vCexMin
Definition cecSatG2.c:98
Vec_Ptr_t * vFrontier
Definition cecSatG2.c:96
int nConflicts[2][3]
Definition cecSatG2.c:128
Vec_Int_t * vRefBins
Definition cecSatG2.c:114
Vec_Int_t * vRefNodes
Definition cecSatG2.c:113
Vec_Bit_t * vFails
Definition cecSatG2.c:105
int nAndNodes
Definition cecSatG2.c:120
abctime timeSatUnsat
Definition cecSatG2.c:136
Vec_Int_t * vPat
Definition cecSatG2.c:103
abctime timeSatSat0
Definition cecSatG2.c:133
int iLastConst
Definition cecSatG2.c:110
Vec_Int_t * vDisprPairs
Definition cecSatG2.c:104
abctime timeCnf
Definition cecSatG2.c:131
sat_solver * pSat
Definition cecSatG2.c:95
abctime timeGenPats
Definition cecSatG2.c:132
Vec_Int_t * vCands
Definition cecSatG2.c:101
Vec_Ptr_t * vFanins
Definition cecSatG2.c:97
Vec_Int_t * vPairs
Definition cecSatG2.c:107
int nSatUnsat
Definition cecSatG2.c:123
abctime timeSatUndec
Definition cecSatG2.c:137
Vec_Int_t * vVisit
Definition cecSatG2.c:102
Gia_Man_t * pAig
Definition cecSatG2.c:92
abctime timeSatUnsat0
Definition cecSatG2.c:134
int nRecycles
Definition cecSatG2.c:127
Vec_Bit_t * vCoDrivers
Definition cecSatG2.c:106
int nItersSat
Definition cecSatG2.c:119
int nItersSim
Definition cecSatG2.c:118
int nCallsSince
Definition cecSatG2.c:125
int fCheckMiter
Definition cec.h:112
int fBMiterInfo
Definition cec.h:123
int nBTLimit
Definition cec.h:103
int nWords
Definition cec.h:100
int nBTLimitPo
Definition cec.h:104
int fUseCones
Definition cec.h:118
int nLevelMax
Definition cec.h:106
int nItersMax
Definition cec.h:102
int nRounds
Definition cec.h:101
int nSatVarMax
Definition cec.h:109
int nGenIters
Definition cec.h:110
int jType
Definition cec.h:99
int nCallsRecycle
Definition cec.h:108
int fVerbose
Definition cec.h:121
char * pDumpName
Definition cec.h:125
int fSatSweeping
Definition cec.h:116
int fVeryVerbose
Definition cec.h:209
char * pFileName
Definition cec.h:222
int nImplicationSuccess
Definition cec.h:219
float fImplicationTime
Definition cec.h:217
int nImplicationTotalChecks
Definition cec.h:220
int nImplicationSuccessChecks
Definition cec.h:221
int nImplicationExecution
Definition cec.h:218
float timeOutSim
Definition cec.h:215
int fUseWatchlist
Definition cec.h:216
int bitwidthOutgold
Definition cec.h:211
int nSimWords
Definition cec.h:212
char * outGold
Definition cec.h:214
int nSimWords
Definition gia.h:209
Vec_Int_t vCopies2
Definition gia.h:153
Vec_Int_t * vTTLut
Definition gia.h:253
unsigned * pMuxes
Definition gia.h:106
Vec_Str_t * vTTISOPs
Definition gia.h:252
char * pSpec
Definition gia.h:100
int nObjsAlloc
Definition gia.h:104
char * pName
Definition gia.h:99
int iData
Definition gia.h:200
unsigned fMark1
Definition gia.h:86
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
unsigned fMark0
Definition gia.h:81
int nLutSize
Definition if.h:104
char * pArray
Definition bblif.c:51
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition utilCex.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition utilCex.h:39
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * memset()
char * sprintf()
char * memmove()
VOID_HACK free()
char * malloc()
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.
Definition vecBit.h:42
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryReverse(vVec, pEntry, i)
Definition vecInt.h:62
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
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42