ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaSim2.c File Reference
#include "gia.h"
Include dependency graph for giaSim2.c:

Go to the source code of this file.

Classes

struct  Gia_Sim2_t_
 

Typedefs

typedef typedefABC_NAMESPACE_IMPL_START struct Gia_Sim2_t_ Gia_Sim2_t
 DECLARATIONS ///.
 

Functions

void Gia_ManResetRandom (Gia_ParSim_t *pPars)
 
void Gia_Sim2Delete (Gia_Sim2_t *p)
 FUNCTION DEFINITIONS ///.
 
Gia_Sim2_tGia_Sim2Create (Gia_Man_t *pAig, Gia_ParSim_t *pPars)
 
int Gia_Sim2CompareEqual (unsigned *p0, unsigned *p1, int nWords, int fCompl)
 
int Gia_Sim2CompareZero (unsigned *p0, int nWords, int fCompl)
 
void Gia_Sim2ClassCreate (Gia_Man_t *p, Vec_Int_t *vClass)
 
int Gia_Sim2ClassRefineOne (Gia_Sim2_t *p, int i)
 
int Gia_Sim2HashKey (unsigned *pSim, int nWords, int nTableSize)
 
void Gia_Sim2ProcessRefined (Gia_Sim2_t *p, Vec_Int_t *vRefined)
 
void Gia_Sim2InfoRefineEquivs (Gia_Sim2_t *p)
 
Abc_Cex_tGia_Sim2GenerateCounter (Gia_Man_t *pAig, int iFrame, int iOut, int nWords, int iPat)
 
int Gia_ManSimSimulateEquiv (Gia_Man_t *pAig, Gia_ParSim_t *pPars)
 

Typedef Documentation

◆ Gia_Sim2_t

typedef typedefABC_NAMESPACE_IMPL_START struct Gia_Sim2_t_ Gia_Sim2_t

DECLARATIONS ///.

CFile****************************************************************

FileName [giaSim.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Fast sequential simulator.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
giaSim.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 30 of file giaSim2.c.

Function Documentation

◆ Gia_ManResetRandom()

void Gia_ManResetRandom ( Gia_ParSim_t * pPars)
extern

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 580 of file giaSim.c.

581{
582 int i;
583 Gia_ManRandom( 1 );
584 for ( i = 0; i < pPars->RandSeed; i++ )
585 Gia_ManRandom( 0 );
586}
unsigned Gia_ManRandom(int fReset)
FUNCTION DEFINITIONS ///.
Definition giaUtil.c:49
int RandSeed
Definition gia.h:312
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_ManSimSimulateEquiv()

int Gia_ManSimSimulateEquiv ( Gia_Man_t * pAig,
Gia_ParSim_t * pPars )

Function*************************************************************

Synopsis [Performs simulation to refine equivalence classes.]

Description [Returns 1 if counter-example is detected.]

SideEffects []

SeeAlso []

Definition at line 638 of file giaSim2.c.

639{
640 Gia_Sim2_t * p;
641 Gia_Obj_t * pObj;
642 abctime clkTotal = Abc_Clock();
643 int i, RetValue = 0, iOut, iPat;
644 abctime nTimeToStop = pPars->TimeLimit ? pPars->TimeLimit * CLOCKS_PER_SEC + Abc_Clock(): 0;
645 assert( pAig->pReprs && pAig->pNexts );
646 ABC_FREE( pAig->pCexSeq );
647 p = Gia_Sim2Create( pAig, pPars );
648 Gia_ManResetRandom( pPars );
649 Gia_ManForEachRo( p->pAig, pObj, i )
650 Gia_Sim2InfoZero( p, Gia_Sim2Data(p, Gia_ObjValue(pObj)) );
651 for ( i = 0; i < pPars->nIters; i++ )
652 {
653 Gia_Sim2SimulateRound( p );
654 if ( pPars->fVerbose )
655 {
656 Abc_Print( 1, "Frame %4d out of %4d and timeout %3d sec. ", i+1, pPars->nIters, pPars->TimeLimit );
657 if ( pAig->pReprs && pAig->pNexts )
658 Abc_Print( 1, "Lits = %4d. ", Gia_ManEquivCountLitsAll(pAig) );
659 Abc_Print( 1, "Time = %7.2f sec\r", (1.0*Abc_Clock()-clkTotal)/CLOCKS_PER_SEC );
660 }
661 if ( pPars->fCheckMiter && Gia_Sim2CheckPos( p, &iOut, &iPat ) )
662 {
663 Gia_ManResetRandom( pPars );
664 pPars->iOutFail = iOut;
665 pAig->pCexSeq = Gia_Sim2GenerateCounter( pAig, i, iOut, p->nWords, iPat );
666 Abc_Print( 1, "Output %d of miter \"%s\" was asserted in frame %d. ", iOut, pAig->pName, i );
667 if ( !Gia_ManVerifyCex( pAig, pAig->pCexSeq, 0 ) )
668 {
669// Abc_Print( 1, "\n" );
670 Abc_Print( 1, "\nGenerated counter-example is INVALID. " );
671// Abc_Print( 1, "\n" );
672 }
673 else
674 {
675// Abc_Print( 1, "\n" );
676// if ( pPars->fVerbose )
677// Abc_Print( 1, "\nGenerated counter-example is verified correctly. " );
678// Abc_Print( 1, "\n" );
679 }
680 RetValue = 1;
681 break;
682 }
683 if ( pAig->pReprs && pAig->pNexts )
685 if ( Abc_Clock() > nTimeToStop )
686 {
687 i++;
688 break;
689 }
690 if ( i < pPars->nIters - 1 )
691 Gia_Sim2InfoTransfer( p );
692 }
693 Gia_Sim2Delete( p );
694 if ( pAig->pCexSeq == NULL )
695 Abc_Print( 1, "No bug detected after simulating %d frames with %d words. ", i, pPars->nWords );
696 Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
697 return RetValue;
698}
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_FREE(obj)
Definition abc_global.h:267
Cube * p
Definition exorList.c:222
void Gia_Sim2Delete(Gia_Sim2_t *p)
FUNCTION DEFINITIONS ///.
Definition giaSim2.c:60
void Gia_ManResetRandom(Gia_ParSim_t *pPars)
Definition giaSim.c:580
Gia_Sim2_t * Gia_Sim2Create(Gia_Man_t *pAig, Gia_ParSim_t *pPars)
Definition giaSim2.c:79
Abc_Cex_t * Gia_Sim2GenerateCounter(Gia_Man_t *pAig, int iFrame, int iOut, int nWords, int iPat)
Definition giaSim2.c:604
typedefABC_NAMESPACE_IMPL_START struct Gia_Sim2_t_ Gia_Sim2_t
DECLARATIONS ///.
Definition giaSim2.c:30
void Gia_Sim2InfoRefineEquivs(Gia_Sim2_t *p)
Definition giaSim2.c:516
#define Gia_ManForEachRo(p, pObj, i)
Definition gia.h:1252
int Gia_ManEquivCountLitsAll(Gia_Man_t *p)
Definition giaEquiv.c:357
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManVerifyCex(Gia_Man_t *pAig, Abc_Cex_t *p, int fDualOut)
DECLARATIONS ///.
Definition giaCex.c:48
Gia_Rpr_t * pReprs
Definition gia.h:126
int * pNexts
Definition gia.h:127
Abc_Cex_t * pCexSeq
Definition gia.h:150
char * pName
Definition gia.h:99
int nWords
Definition gia.h:310
int fCheckMiter
Definition gia.h:314
int TimeLimit
Definition gia.h:313
int iOutFail
Definition gia.h:316
int nIters
Definition gia.h:311
int fVerbose
Definition gia.h:315
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_Sim2ClassCreate()

void Gia_Sim2ClassCreate ( Gia_Man_t * p,
Vec_Int_t * vClass )

Function*************************************************************

Synopsis [Creates equivalence class.]

Description []

SideEffects []

SeeAlso []

Definition at line 367 of file giaSim2.c.

368{
369 int Repr = GIA_VOID, EntPrev = -1, Ent, i;
370 assert( Vec_IntSize(vClass) > 0 );
371 Vec_IntForEachEntry( vClass, Ent, i )
372 {
373 if ( i == 0 )
374 {
375 Repr = Ent;
376 Gia_ObjSetRepr( p, Ent, GIA_VOID );
377 EntPrev = Ent;
378 }
379 else
380 {
381 assert( Repr < Ent );
382 Gia_ObjSetRepr( p, Ent, Repr );
383 Gia_ObjSetNext( p, EntPrev, Ent );
384 EntPrev = Ent;
385 }
386 }
387 Gia_ObjSetNext( p, EntPrev, 0 );
388}
#define GIA_VOID
Definition gia.h:46
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the caller graph for this function:

◆ Gia_Sim2ClassRefineOne()

int Gia_Sim2ClassRefineOne ( Gia_Sim2_t * p,
int i )

Function*************************************************************

Synopsis [Refines one equivalence class.]

Description []

SideEffects []

SeeAlso []

Definition at line 401 of file giaSim2.c.

402{
403 Gia_Obj_t * pObj0, * pObj1;
404 unsigned * pSim0, * pSim1;
405 int Ent;
406 Vec_IntClear( p->vClassOld );
407 Vec_IntClear( p->vClassNew );
408 Vec_IntPush( p->vClassOld, i );
409 pObj0 = Gia_ManObj( p->pAig, i );
410 pSim0 = Gia_Sim2Data( p, i );
411 Gia_ClassForEachObj1( p->pAig, i, Ent )
412 {
413 pObj1 = Gia_ManObj( p->pAig, Ent );
414 pSim1 = Gia_Sim2Data( p, Ent );
415 if ( Gia_Sim2CompareEqual( pSim0, pSim1, p->nWords, Gia_ObjPhase(pObj0) ^ Gia_ObjPhase(pObj1) ) )
416 Vec_IntPush( p->vClassOld, Ent );
417 else
418 Vec_IntPush( p->vClassNew, Ent );
419 }
420 if ( Vec_IntSize( p->vClassNew ) == 0 )
421 return 0;
422 Gia_Sim2ClassCreate( p->pAig, p->vClassOld );
423 Gia_Sim2ClassCreate( p->pAig, p->vClassNew );
424 if ( Vec_IntSize(p->vClassNew) > 1 )
425 return 1 + Gia_Sim2ClassRefineOne( p, Vec_IntEntry(p->vClassNew,0) );
426 return 1;
427}
int Gia_Sim2CompareEqual(unsigned *p0, unsigned *p1, int nWords, int fCompl)
Definition giaSim2.c:307
void Gia_Sim2ClassCreate(Gia_Man_t *p, Vec_Int_t *vClass)
Definition giaSim2.c:367
int Gia_Sim2ClassRefineOne(Gia_Sim2_t *p, int i)
Definition giaSim2.c:401
#define Gia_ClassForEachObj1(p, i, iObj)
Definition gia.h:1109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_Sim2CompareEqual()

int Gia_Sim2CompareEqual ( unsigned * p0,
unsigned * p1,
int nWords,
int fCompl )

Function*************************************************************

Synopsis [Compares simulation info of two nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 307 of file giaSim2.c.

308{
309 int w;
310 if ( !fCompl )
311 {
312 for ( w = 0; w < nWords; w++ )
313 if ( p0[w] != p1[w] )
314 return 0;
315 return 1;
316 }
317 else
318 {
319 for ( w = 0; w < nWords; w++ )
320 if ( p0[w] != ~p1[w] )
321 return 0;
322 return 1;
323 }
324}
int nWords
Definition abcNpn.c:127
Here is the caller graph for this function:

◆ Gia_Sim2CompareZero()

int Gia_Sim2CompareZero ( unsigned * p0,
int nWords,
int fCompl )

Function*************************************************************

Synopsis [Compares simulation info of one node.]

Description []

SideEffects []

SeeAlso []

Definition at line 337 of file giaSim2.c.

338{
339 int w;
340 if ( !fCompl )
341 {
342 for ( w = 0; w < nWords; w++ )
343 if ( p0[w] != 0 )
344 return 0;
345 return 1;
346 }
347 else
348 {
349 for ( w = 0; w < nWords; w++ )
350 if ( p0[w] != ~0 )
351 return 0;
352 return 1;
353 }
354}
Here is the caller graph for this function:

◆ Gia_Sim2Create()

Gia_Sim2_t * Gia_Sim2Create ( Gia_Man_t * pAig,
Gia_ParSim_t * pPars )

Function*************************************************************

Synopsis [Creates fast simulation manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 79 of file giaSim2.c.

80{
81 Gia_Sim2_t * p;
82 Gia_Obj_t * pObj;
83 int i;
84 p = ABC_CALLOC( Gia_Sim2_t, 1 );
85 p->pAig = pAig;
86 p->pPars = pPars;
87 p->nWords = pPars->nWords;
88 p->pDataSim = ABC_ALLOC( unsigned, p->nWords * Gia_ManObjNum(p->pAig) );
89 if ( !p->pDataSim )
90 {
91 Abc_Print( 1, "Simulator could not allocate %.2f GB for simulation info.\n",
92 4.0 * p->nWords * Gia_ManObjNum(p->pAig) / (1<<30) );
94 return NULL;
95 }
96 p->vClassOld = Vec_IntAlloc( 100 );
97 p->vClassNew = Vec_IntAlloc( 100 );
98 if ( pPars->fVerbose )
99 Abc_Print( 1, "Memory: AIG = %7.2f MB. SimInfo = %7.2f MB.\n",
100 12.0*Gia_ManObjNum(p->pAig)/(1<<20), 4.0*p->nWords*Gia_ManObjNum(p->pAig)/(1<<20) );
101 // prepare AIG
102 Gia_ManSetPhase( pAig );
103 Gia_ManForEachObj( pAig, pObj, i )
104 pObj->Value = i;
105 return p;
106}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition gia.h:1190
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
unsigned Value
Definition gia.h:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_Sim2Delete()

void Gia_Sim2Delete ( Gia_Sim2_t * p)

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 60 of file giaSim2.c.

61{
62 Vec_IntFreeP( &p->vClassOld );
63 Vec_IntFreeP( &p->vClassNew );
64 ABC_FREE( p->pDataSim );
65 ABC_FREE( p );
66}
Here is the caller graph for this function:

◆ Gia_Sim2GenerateCounter()

Abc_Cex_t * Gia_Sim2GenerateCounter ( Gia_Man_t * pAig,
int iFrame,
int iOut,
int nWords,
int iPat )

Function*************************************************************

Synopsis [Returns the counter-example.]

Description []

SideEffects []

SeeAlso []

Definition at line 604 of file giaSim2.c.

605{
606 Abc_Cex_t * p;
607 unsigned * pData;
608 int f, i, w, Counter;
609 p = Abc_CexAlloc( Gia_ManRegNum(pAig), Gia_ManPiNum(pAig), iFrame+1 );
610 p->iFrame = iFrame;
611 p->iPo = iOut;
612 // fill in the binary data
613 Counter = p->nRegs;
614 pData = ABC_ALLOC( unsigned, nWords );
615 for ( f = 0; f <= iFrame; f++, Counter += p->nPis )
616 for ( i = 0; i < Gia_ManPiNum(pAig); i++ )
617 {
618 for ( w = nWords-1; w >= 0; w-- )
619 pData[w] = Gia_ManRandom( 0 );
620 if ( Abc_InfoHasBit( pData, iPat ) )
621 Abc_InfoSetBit( p->pData, Counter + i );
622 }
623 ABC_FREE( pData );
624 return p;
625}
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_Sim2HashKey()

int Gia_Sim2HashKey ( unsigned * pSim,
int nWords,
int nTableSize )

Function*************************************************************

Synopsis [Computes hash key of the simuation info.]

Description []

SideEffects []

SeeAlso []

Definition at line 440 of file giaSim2.c.

441{
442 static int s_Primes[16] = {
443 1291, 1699, 1999, 2357, 2953, 3313, 3907, 4177,
444 4831, 5147, 5647, 6343, 6899, 7103, 7873, 8147 };
445 unsigned uHash = 0;
446 int i;
447 if ( pSim[0] & 1 )
448 for ( i = 0; i < nWords; i++ )
449 uHash ^= ~pSim[i] * s_Primes[i & 0xf];
450 else
451 for ( i = 0; i < nWords; i++ )
452 uHash ^= pSim[i] * s_Primes[i & 0xf];
453 return (int)(uHash % nTableSize);
454
455}
Here is the caller graph for this function:

◆ Gia_Sim2InfoRefineEquivs()

void Gia_Sim2InfoRefineEquivs ( Gia_Sim2_t * p)

Function*************************************************************

Synopsis [Refines equivalences after one simulation round.]

Description []

SideEffects []

SeeAlso []

Definition at line 516 of file giaSim2.c.

517{
518 Vec_Int_t * vRefined;
519 Gia_Obj_t * pObj;
520 unsigned * pSim;
521 int i, Count = 0;
522 // process constant candidates
523 vRefined = Vec_IntAlloc( 100 );
524 Gia_ManForEachObj1( p->pAig, pObj, i )
525 {
526 if ( !Gia_ObjIsConst(p->pAig, i) )
527 continue;
528 pSim = Gia_Sim2Data( p, i );
529//Extra_PrintBinary( stdout, pSim, 32 * p->nWords ); printf( "\n" );
530 if ( !Gia_Sim2CompareZero( pSim, p->nWords, Gia_ObjPhase(pObj) ) )
531 {
532 Vec_IntPush( vRefined, i );
533 Count++;
534 }
535 }
536 Gia_Sim2ProcessRefined( p, vRefined );
537 Vec_IntFree( vRefined );
538 // process other classes
539 Gia_ManForEachClass( p->pAig, i )
540 Count += Gia_Sim2ClassRefineOne( p, i );
541// if ( Count )
542// printf( "Refined %d times.\n", Count );
543}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int Gia_Sim2CompareZero(unsigned *p0, int nWords, int fCompl)
Definition giaSim2.c:337
void Gia_Sim2ProcessRefined(Gia_Sim2_t *p, Vec_Int_t *vRefined)
Definition giaSim2.c:468
#define Gia_ManForEachObj1(p, pObj, i)
Definition gia.h:1192
#define Gia_ManForEachClass(p, i)
Definition gia.h:1101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Gia_Sim2ProcessRefined()

void Gia_Sim2ProcessRefined ( Gia_Sim2_t * p,
Vec_Int_t * vRefined )

Function*************************************************************

Synopsis [Refines nodes belonging to candidate constant class.]

Description []

SideEffects []

SeeAlso []

Definition at line 468 of file giaSim2.c.

469{
470 unsigned * pSim;
471 int * pTable, nTableSize, i, k, Key;
472 if ( Vec_IntSize(vRefined) == 0 )
473 return;
474 nTableSize = Abc_PrimeCudd( 1000 + Vec_IntSize(vRefined) / 3 );
475 pTable = ABC_CALLOC( int, nTableSize );
476 Vec_IntForEachEntry( vRefined, i, k )
477 {
478 pSim = Gia_Sim2Data( p, i );
479 Key = Gia_Sim2HashKey( pSim, p->nWords, nTableSize );
480 if ( pTable[Key] == 0 )
481 {
482 assert( Gia_ObjRepr(p->pAig, i) == 0 );
483 assert( Gia_ObjNext(p->pAig, i) == 0 );
484 Gia_ObjSetRepr( p->pAig, i, GIA_VOID );
485 }
486 else
487 {
488 Gia_ObjSetNext( p->pAig, pTable[Key], i );
489 Gia_ObjSetRepr( p->pAig, i, Gia_ObjRepr(p->pAig, pTable[Key]) );
490 if ( Gia_ObjRepr(p->pAig, i) == GIA_VOID )
491 Gia_ObjSetRepr( p->pAig, i, pTable[Key] );
492 assert( Gia_ObjRepr(p->pAig, i) > 0 );
493 }
494 pTable[Key] = i;
495 }
496/*
497 Vec_IntForEachEntry( vRefined, i, k )
498 {
499 if ( Gia_ObjIsHead( p->pAig, i ) )
500 Gia_Sim2ClassRefineOne( p, i );
501 }
502*/
503 ABC_FREE( pTable );
504}
int Gia_Sim2HashKey(unsigned *pSim, int nWords, int nTableSize)
Definition giaSim2.c:440
Here is the call graph for this function:
Here is the caller graph for this function: